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

Cannot Access some $App components inside ServiceProvider #25

Closed
raftalks opened this issue Jan 13, 2013 · 2 comments
Closed

Cannot Access some $App components inside ServiceProvider #25

raftalks opened this issue Jan 13, 2013 · 2 comments

Comments

@raftalks
Copy link
Contributor

I have created a basic workbench package and I am trying to inject Auth class instance to the main class of the package. It seems some of the components like Auth, Log, are not available inside the register method when using $this->app['auth'] or $this->app['log'].

It seems they are not loaded when the register method is called on service provider of workbench package.

I am getting the following errors
ReflectionException: Class auth does not exist
ReflectionException: Class log does not exist

This is the Service Provider Class I am using

<?php namespace Hbt\Acl;

use Illuminate\Support\ServiceProvider;

class AclServiceProvider extends ServiceProvider {

    /**
     * Indicates if loading of the provider is deferred.
     *
     * @var bool
     */
    protected $defer = false;

    /**
     * Bootstrap the application events.
     *
     * @return void
     */
    public function boot()
    {
        $this->package('hbt/acl');
    }

    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
                $log = $this->app['log'];
                $auth = $this->app['auth'];
        $this->app['acl'] = new Acl($auth , $log);
    }

....
@taylorotwell
Copy link
Member

Use the "boot" method instead of register.

On Jan 13, 2013, at 8:27 AM, Raf notifications@github.com wrote:

I have created a basic workbench package and I am trying to inject Auth class instance to the main class of the package. It seems some of the components like Auth, Log, are not available inside the register method when using $this->app['auth'] or $this->app['log'].

It seems they are not loaded when the register method is called on service provider of workbench package.

I am getting the following errors
ReflectionException: Class auth does not exist
ReflectionException: Class log does not exist

This is the Service Provider Class I am using

package('hbt/acl'); } /** * Register the service provider. * * @return void */ public function register() { $log = $this->app['log']; $auth = $this->app['auth']; $this->app['acl'] = new Acl($auth , $log); } ``` .... — Reply to this email directly or view it on GitHub.

@raftalks
Copy link
Contributor Author

Thanks, this works inside the boot method.

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

2 participants