====== PostsApiController ======
**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
======= Docblock Metadata =======
^ Tag ^ Value ^
| ''@category'' | Controller Class |
| ''@author'' | Blogware Team |
| ''@license'' | MIT |
| ''@version'' | 1.0 |
| ''@since'' | Since Release 1.0 |
======= Inheritance =======
^ Relation ^ Type ^ Meaning ^
| extends | [[scriptlog:lib:controller:apicontroller|''ApiController'']] | parent class/interface |
======= Constants (0) =======
//None.//
======= Properties (7) =======
^ 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 |
======= Methods (9) =======
^ 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 |
======== __construct() ========
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'' | [[scriptlog:lib:dao:postdao|''?PostDao'']] | ''null'' | Data access for posts |
| ''$topicDao'' | [[scriptlog:lib:dao:topicdao|''?TopicDao'']] | ''null'' | Data access for topics |
| ''$commentDao'' | [[scriptlog:lib:dao:commentdao|''?CommentDao'']] | ''null'' | Data access for comments |
| ''$mediaDao'' | [[scriptlog:lib:dao:mediadao|''?MediaDao'']] | ''null'' | Data access for media |
| ''$sanitizer'' | [[scriptlog:lib:core:sanitize|''?Sanitize'']] | ''null'' | Input sanitizer |
======== resolve() ========
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
======== index() ========
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
======== show() ========
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
======== comments() ========
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
======== store() ========
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
======== update() ========
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
======== destroy() ========
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
======== generateSlug() ========
private function generateSlug($title)
//lines 472–476 (5)//
Generate URL-friendly slug
^ Parameter ^ Type ^ Default ^ Description ^
| ''$title'' | ''(untyped)'' | //required// | //none// |
**Returns:** ''(none declared)'' — string
======= Imports =======
^ Alias ^ Fully-qualified name ^
| ''ApiController'' | [[scriptlog:lib:controller:apicontroller|''Scriptlog\Controller\ApiController'']] |
| ''ApiAuth'' | [[scriptlog:lib:core:apiauth|''Scriptlog\Core\ApiAuth'']] |
| ''ApiHateoas'' | [[scriptlog:lib:core:apihateoas|''Scriptlog\Core\ApiHateoas'']] |
| ''ApiResponse'' | [[scriptlog:lib:core:apiresponse|''Scriptlog\Core\ApiResponse'']] |
| ''FormValidator'' | [[scriptlog:lib:core:formvalidator|''Scriptlog\Core\FormValidator'']] |
| ''Sanitize'' | [[scriptlog:lib:core:sanitize|''Scriptlog\Core\Sanitize'']] |
| ''CommentDao'' | [[scriptlog:lib:dao:commentdao|''Scriptlog\Dao\CommentDao'']] |
| ''MediaDao'' | [[scriptlog:lib:dao:mediadao|''Scriptlog\Dao\MediaDao'']] |
| ''PostDao'' | [[scriptlog:lib:dao:postdao|''Scriptlog\Dao\PostDao'']] |
| ''TopicDao'' | [[scriptlog:lib:dao:topicdao|''Scriptlog\Dao\TopicDao'']] |
| ''CommentApiDto'' | [[scriptlog:lib:dto:commentapidto|''Scriptlog\Dto\Api\CommentApiDto'']] |
| ''PostApiDto'' | [[scriptlog:lib:dto:postapidto|''Scriptlog\Dto\Api\PostApiDto'']] |
| ''PostService'' | [[scriptlog:lib:service:postservice|''Scriptlog\Service\PostService'']] |
----
//This page is generated from source by 'tools/gendoc'. Edits will be overwritten.//