Skip to content

Modifying routing / exposing Permastruct class #37

@markeasting

Description

@markeasting

Hi again,

Backstory: I was trying to modify my BlogController, spliting up our post type actions into multiple controllers (otherwise, the controllers tend to become quite large, having many different post types). Naturally, I tried adding new routes to my routing config, but these weren't properly integrated with the Wordpress rewrite system.

I saw that the Permastruct class in config/routing.php parses the Wordpress rewrites into Symfony routes (nice!). However, since the class is not located in the /src directory, I cannot autoload this in my own routing.php file... Maybe move it to src/Routing and import it into the config file?

Also, it would be great if we could configure which controllers handle certain (custom) content types. Here's a proposal:

new Permastruct($collection, '', [
    'custom-post_type' => CustomController,
    'post' => PostController,
    'page' => PageController,
    'default' => BlogController,
]);

Besides this, it would help to type-hint controller methods using some kind of bundle-exposed interface:

namespace Metabolism\WordpressBundle\Interface;

interface ControllerInterface {
    function postAction(Post $post);
    function archiveAction(array $posts, PaginationService $paginationService);
}

// Alternative: 
interface ControllerInterface {
    function show(Post $post);
    function index(array $posts, PaginationService $paginationService); // or achive() / list()
}

Maybe it would be even better if these method names could be specified by the user (like [CustomController::class, 'myOwnMethod'], giving a bit more more flexibility.

Would love to hear your thoughts!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions