Layer: Controller · Source: lib/controller/api/PostsApiController.php:34 (lines 34–477)
final class PostsApiController extends ApiController
Posts API Controller
Handles API requests for blog posts
| Tag | Value |
|---|---|
@category | Controller Class |
@author | Blogware Team |
@license | MIT |
@version | 1.0 |
@since | Since Release 1.0 |
| Relation | Type | Meaning |
|---|---|---|
| extends | ''ApiController'' | parent class/interface |
None.
| Visibility | Type | Name | Default | Line |
|---|---|---|---|---|
private | (untyped) | $postDao | 39 | |
private | (untyped) | $postService | 44 | |
private | (untyped) | $topicDao | 49 | |
private | (untyped) | $commentDao | 54 | |
private | (untyped) | $mediaDao | 59 | |
private | (untyped) | $sanitizer | 64 | |
private | (untyped) | $hateoas | 69 |
| Visibility | Method | Summary | Line |
|---|---|---|---|
| public | __construct() | Constructor | 83 |
| private | resolve() | Resolve an optional constructor dependency. | 106 |
| public | index() | Get all published posts (public endpoint) | 123 |
| public | show() | Get a single post by ID (public endpoint) | 176 |
| public | comments() | Get comments for a post (public endpoint) | 237 |
| public | store() | Create a new post (requires authentication) | 289 |
| public | update() | Update an existing post (requires authentication) | 349 |
| public | destroy() | Delete a post (requires authentication) | 430 |
| private | generateSlug() | Generate URL-friendly slug | 472 |
public function __construct(?PostDao $postDao = null, ?TopicDao $topicDao = null, ?CommentDao $commentDao = null, ?MediaDao $mediaDao = null, ?Sanitize $sanitizer = null)
lines 83–97 (15)
Constructor
All dependencies are optional so ApiRouter can keep building this controller with no arguments; tests pass mocks instead.
| Parameter | Type | Default | Description |
|---|---|---|---|
$postDao | ''?PostDao'' | null | Data access for posts |
$topicDao | ''?TopicDao'' | null | Data access for topics |
$commentDao | ''?CommentDao'' | null | Data access for comments |
$mediaDao | ''?MediaDao'' | null | Data access for media |
$sanitizer | ''?Sanitize'' | null | Input sanitizer |
private function resolve($provided, $class)
lines 106–113 (8)
Resolve an optional constructor dependency.
| Parameter | Type | Default | Description |
|---|---|---|---|
$provided | (untyped) | required | Injected instance or null |
$class | (untyped) | required | Fallback class name |
Returns: (none declared) — object
public function index($params = [])
lines 123–166 (44)
Get all published posts (public endpoint)
GET /api/v1/posts
| Parameter | Type | Default | Description |
|---|---|---|---|
$params | (untyped) | [] | Query parameters (page, per_page, sort_by, sort_order) |
Returns: (none declared) — void
public function show($params = [])
lines 176–227 (52)
Get a single post by ID (public endpoint)
GET /api/v1/posts/{id}
| Parameter | Type | Default | Description |
|---|---|---|---|
$params | (untyped) | [] | Route parameters including 'id' |
Returns: (none declared) — void
public function comments($params = [])
lines 237–279 (43)
Get comments for a post (public endpoint)
GET /api/v1/posts/{id}/comments
| Parameter | Type | Default | Description |
|---|---|---|---|
$params | (untyped) | [] | Route parameters including 'id' |
Returns: (none declared) — void
public function store($_params = [])
lines 289–339 (51)
Create a new post (requires authentication)
POST /api/v1/posts
| Parameter | Type | Default | Description |
|---|---|---|---|
$_params | (untyped) | [] | none |
Returns: (none declared) — void
public function update($params = [])
lines 349–420 (72)
Update an existing post (requires authentication)
PUT /api/v1/posts/{id}
| Parameter | Type | Default | Description |
|---|---|---|---|
$params | (untyped) | [] | Route parameters including 'id' |
Returns: (none declared) — void
public function destroy($params = [])
lines 430–462 (33)
Delete a post (requires authentication)
DELETE /api/v1/posts/{id}
| Parameter | Type | Default | Description |
|---|---|---|---|
$params | (untyped) | [] | Route parameters including 'id' |
Returns: (none declared) — void
private function generateSlug($title)
lines 472–476 (5)
Generate URL-friendly slug
| Parameter | Type | Default | Description |
|---|---|---|---|
$title | (untyped) | required | none |
Returns: (none declared) — string
| Alias | Fully-qualified name |
|---|---|
ApiController | ''Scriptlog\Controller\ApiController'' |
ApiAuth | ''Scriptlog\Core\ApiAuth'' |
ApiHateoas | ''Scriptlog\Core\ApiHateoas'' |
ApiResponse | ''Scriptlog\Core\ApiResponse'' |
FormValidator | ''Scriptlog\Core\FormValidator'' |
Sanitize | ''Scriptlog\Core\Sanitize'' |
CommentDao | ''Scriptlog\Dao\CommentDao'' |
MediaDao | ''Scriptlog\Dao\MediaDao'' |
PostDao | ''Scriptlog\Dao\PostDao'' |
TopicDao | ''Scriptlog\Dao\TopicDao'' |
CommentApiDto | ''Scriptlog\Dto\Api\CommentApiDto'' |
PostApiDto | ''Scriptlog\Dto\Api\PostApiDto'' |
PostService | ''Scriptlog\Service\PostService'' |
This page is generated from source by 'tools/gendoc'. Edits will be overwritten.