3

I am new to Laravel, I use almost all L5 packages outside Laravel. But I have some problems to make these work.

This is my composer.json file:

{
      "require": {
         "slim/slim": "2.*",
         "zeuxisoo/slim-whoops": "0.2.0",
         "filp/whoops": "1.1.2",

         "illuminate/database": "5.1.*",
         "illuminate/support": "5.1.*",
         "illuminate/session": "5.1.*",
         "illuminate/filesystem": "5.1.*",
         "illuminate/config": "5.1.*",
         "illuminate/session": "5.1.*",
         "illuminate/routing": "^5.1",
         "illuminate/events": "5.1.*",
         "illuminate/translation": "5.1.*",
         "illuminate/encryption": "5.1.*",
         "illuminate/queue": "5.1.*",
         "illuminate/mail": "5.1.*",
         "illuminate/view": "5.1.*",

         "laravelcollective/html": "5.1.*",

         "iron-io/iron_mq": "~2.0",
         "Mockery/Mockery": "~0.9.1",
         "pimple/pimple": "3.0",

         "philo/laravel-blade": "3.*",
         "jenssegers/mongodb": "^2.1",

         "illuminate/auth": "5.1.*",
         "illuminate/bus": "5.1.*",
         "illuminate/broadcasting": "5.1.*",
         "illuminate/cache": "5.1.*",
         "illuminate/console": "5.1.*", 
         "illuminate/container": "5.1.*",
         "illuminate/contracts": "5.1.*",
         "illuminate/cookie": "5.1.*",
         "illuminate/hashing": "5.1.*",
         "illuminate/http": "5.1.*",
         "illuminate/log": "5.1.*",
         "illuminate/pagination": "5.1.*",
         "illuminate/pipeline": "5.1.*",
         "illuminate/redis": "5.1.*",
         "illuminate/validation": "5.1.*"

},
    "autoload": {
        "psr-4": {
            "App\\": "app/"
        }
    }
}

And that is index.php:

    // Import Illuminate packages
    require_once '../../../vendor/autoload.php';

    // set database connection and setup
    require_once '../../../config/bootstrap.php';

    use Illuminate\Support\Facades\Response as Response;

    // Instantiate the container
    $app = new Illuminate\Container\Container();

    // Tell facade about the application instance
    Illuminate\Support\Facades\Facade::setFacadeApplication($app);

    // register application instance with container
    $app['app'] = $app;

    // set environment 
    $app['env'] = 'production';

    $app->instance('request', \Illuminate\Http\Request::capture());

    // Register service providers

    with(new Illuminate\Events\EventServiceProvider($app))->register();
    with(new Illuminate\Routing\RoutingServiceProvider($app))->register();

    with(new Illuminate\Auth\AuthServiceProvider($app))->register();
    with(new Illuminate\Broadcasting\BroadcastServiceProvider($app))->register();
    with(new Illuminate\Bus\BusServiceProvider($app))->register();
    with(new Illuminate\Cache\CacheServiceProvider($app))->register();

    with(new Illuminate\Routing\ControllerServiceProvider($app))->register();
    with(new Illuminate\Cookie\CookieServiceProvider($app))->register();
    with(new Illuminate\Database\DatabaseServiceProvider($app))->register();
    with(new Illuminate\Encryption\EncryptionServiceProvider($app))->register();
    with(new Illuminate\Filesystem\FilesystemServiceProvider($app))->register();

    with(new Illuminate\Hashing\HashServiceProvider($app))->register();
    with(new Illuminate\Mail\MailServiceProvider($app))->register();
    with(new Illuminate\Pagination\PaginationServiceProvider($app))->register();
    with(new Illuminate\Pipeline\PipelineServiceProvider($app))->register();
    with(new Illuminate\Queue\QueueServiceProvider($app))->register();
    with(new Illuminate\Redis\RedisServiceProvider($app))->register();
    with(new Illuminate\Auth\Passwords\PasswordResetServiceProvider($app))->register();
    with(new Illuminate\Session\SessionServiceProvider($app))->register();
    with(new Illuminate\Translation\TranslationServiceProvider($app))->register();
    with(new Illuminate\Validation\ValidationServiceProvider($app))->register();
    with(new Illuminate\View\ViewServiceProvider($app))->register();

    with(new Collective\Html\HtmlServiceProvider($app))->register();

    // Class aliases
    class_alias('Collective\Html\FormFacade', 'Form');
    class_alias('Collective\Html\HtmlFacade', 'Html');

    // Include all the routes
    $app['router']->get('/', 'TestController@index');

    $app['router']->get('/view', 'TestController@show');

    $app['router']->get('/{id}', 'TestController@create');

    // Instantiate the request
    $request = Illuminate\Http\Request::createFromGlobals();

    // Dispatch the router
    $response = $app['router']->dispatch($request);

    // Send the response
    $response->send();

And TestController class:

<?php

use Illuminate\Routing\Controller as Controller;
use Illuminate\Support\Facades\DB as DB;
use Illuminate\Support\Facades\View as View;


class TestController extends Controller {

   public function show() {
        return View::make('hello2');
   }
}

When I call TestController's show method I get this error:

[Fatal error] Uncaught exception 'ReflectionException' with message 'Class config does not exist' in /var/www/html/vendor/illuminate/container/Container.php:736

I do not know how to use config package and I think this is the reason why I get this error. The config package has no service provider so I can not initiate this.

I try to use illuminate packages outside laravel cause i am on a third party custom php framework and the job is to migrate gradually in L5 for several reasons. I want your experience if this is the best practise.

giorgos
  • 1,771
  • 4
  • 15
  • 14
  • So you included laravel/framework via composer? The config class is bound into the IoC container from within the laravel application, you would need to instantiate at least the application itself. Perhaps running `create-project laravel/laravel` will give you more insight how laravel bootstraps. Next time please add more information, for instance how you are using laravel, how you integrate, how you use those package outside of laravel and how you are trying to integrate with the third party php framework. – Luceos Jul 09 '15 at 10:52
  • @Luceos I updated my question with more information and code. – giorgos Jul 09 '15 at 14:35
  • 2
    why not only include laravel/framework.. It would load all dependancies automatically. – Luceos Jul 10 '15 at 08:04

0 Answers0