Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is the Herbert\Framework\Application::loadPluginX() function for? #1

Closed
unstoppablecarl opened this issue Feb 12, 2015 · 3 comments

Comments

@unstoppablecarl
Copy link

Could you explain what this function does, especially the variable variable $$x ?

https://github.com/getherbert/framework/blob/dev/Herbert/Framework/Application.php#L170

@jasonagnew
Copy link
Member

@unstoppablecarl hopefully this explains it a little.

$this->loadPluginX(
    'router',
    array_get($config, 'routes', [])
);

//Sets $x equals "router" there $$x creates a variable $router 

$this->loadPluginX(
     'enqueue',
     array_get($config, 'enqueue', [])
 );

//Sets $x equals "enqueue" there $$x creates a variable $enqueue 

The reason for this to allow files to be loaded like routes.php have access to $router:

// $router = Herbert\Framework\Router
$router->get();

@unstoppablecarl
Copy link
Author

I've never used variable variables. This is the first time I've seen a practical use. This is just for convenience, you could get the router by doing $container['router'] right?

@ConnorVG
Copy link
Contributor

Indeed, it is for convenience. Helps remove a lot of repeated code (by having a function for each one that calls loadPluginX) 😄

$container['router'] would return the router instance, yeah

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants