3

I'm trying to install intervention. I run this command composer require intervention/image and composer.json is updated. I add 'Image' => 'Intervention\Image\Facades\Image::class'in $aliases array and it's ok. Then i addIntervention\Image\ImageServiceProvider::class` in the $providers array and it didn't work.

This is what i obtain when type composer update

PHP Fatal error:  Class 'Intervention\Image\ImageServiceProvider' not found in /home/vagrant/Code/laravel-basics/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php on line 146

[Symfony\Component\Debug\Exception\FatalErrorException]    
Class 'Intervention\Image\ImageServiceProvider' not found `

<?php

ProviderRepository.php

<?php

namespace Illuminate\Foundation;

use Illuminate\Filesystem\Filesystem; use Illuminate\Contracts\Foundation\Application as ApplicationContract;

class ProviderRepository { /** * The application implementation. * * @var \Illuminate\Contracts\Foundation\Application */ protected $app;

/**
 * The filesystem instance.
 *
 * @var \Illuminate\Filesystem\Filesystem
 */
protected $files;

/**
 * The path to the manifest file.
 *
 * @var string
 */
protected $manifestPath;

/**
 * Create a new service repository instance.
 *
 * @param  \Illuminate\Contracts\Foundation\Application  $app
 * @param  \Illuminate\Filesystem\Filesystem  $files
 * @param  string  $manifestPath
 * @return void
 */
public function __construct(ApplicationContract $app, Filesystem $files, $manifestPath)
{
    $this->app = $app;
    $this->files = $files;
    $this->manifestPath = $manifestPath;
}

/**
 * Register the application service providers.
 *
 * @param  array  $providers
 * @return void
 */
public function load(array $providers)
{
    $manifest = $this->loadManifest();

    // First we will load the service manifest, which contains information on all
    // service providers registered with the application and which services it
    // provides. This is used to know which services are "deferred" loaders.
    if ($this->shouldRecompile($manifest, $providers)) {
        $manifest = $this->compileManifest($providers);
    }

    // Next, we will register events to load the providers for each of the events
    // that it has requested. This allows the service provider to defer itself
    // while still getting automatically loaded when a certain event occurs.
    foreach ($manifest['when'] as $provider => $events) {
        $this->registerLoadEvents($provider, $events);
    }

    // We will go ahead and register all of the eagerly loaded providers with the
    // application so their services can be registered with the application as
    // a provided service. Then we will set the deferred service list on it.
    foreach ($manifest['eager'] as $provider) {
        $this->app->register($this->createProvider($provider));
    }

    $this->app->setDeferredServices($manifest['deferred']);
}

/**
 * Register the load events for the given provider.
 *
 * @param  string  $provider
 * @param  array  $events
 * @return void
 */
protected function registerLoadEvents($provider, array $events)
{
    if (count($events) < 1) {
        return;
    }

    $app = $this->app;

    $app->make('events')->listen($events, function () use ($app, $provider) {
        $app->register($provider);
    });
}

/**
 * Compile the application manifest file.
 *
 * @param  array  $providers
 * @return array
 */
protected function compileManifest($providers)
{
    // The service manifest should contain a list of all of the providers for
    // the application so we can compare it on each request to the service
    // and determine if the manifest should be recompiled or is current.
    $manifest = $this->freshManifest($providers);

    foreach ($providers as $provider) {
        $instance = $this->createProvider($provider);

        // When recompiling the service manifest, we will spin through each of the
        // providers and check if it's a deferred provider or not. If so we'll
        // add it's provided services to the manifest and note the provider.
        if ($instance->isDeferred()) {
            foreach ($instance->provides() as $service) {
                $manifest['deferred'][$service] = $provider;
            }

            $manifest['when'][$provider] = $instance->when();
        }

        // If the service providers are not deferred, we will simply add it to an
        // array of eagerly loaded providers that will get registered on every
        // request to this application instead of "lazy" loading every time.
        else {
            $manifest['eager'][] = $provider;
        }
    }

    return $this->writeManifest($manifest);
}

/**
 * Create a new provider instance.
 *
 * @param  string  $provider
 * @return \Illuminate\Support\ServiceProvider
 */
public function createProvider($provider)
{
    return new $provider($this->app);
}

/**
 * Determine if the manifest should be compiled.
 *
 * @param  array  $manifest
 * @param  array  $providers
 * @return bool
 */
public function shouldRecompile($manifest, $providers)
{
    return is_null($manifest) || $manifest['providers'] != $providers;
}

/**
 * Load the service provider manifest JSON file.
 *
 * @return array
 */
public function loadManifest()
{
    // The service manifest is a file containing a JSON representation of every
    // service provided by the application and whether its provider is using
    // deferred loading or should be eagerly loaded on each request to us.
    if ($this->files->exists($this->manifestPath)) {
        $manifest = json_decode($this->files->get($this->manifestPath), true);

        return array_merge(['when' => []], $manifest);
    }
}

/**
 * Write the service manifest file to disk.
 *
 * @param  array  $manifest
 * @return array
 */
public function writeManifest($manifest)
{
    $this->files->put(
        $this->manifestPath, json_encode($manifest,  JSON_PRETTY_PRINT)
    );

    return $manifest;
}

/**
 * Create a fresh service manifest data structure.
 *
 * @param  array  $providers
 * @return array
 */
protected function freshManifest(array $providers)
{
    return ['providers' => $providers, 'eager' => [], 'deferred' =>    []];
}

}

composer.json

{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
    "php": ">=5.5.9",
    "laravel/framework": "5.1.*",
    "intervention/image": "dev-master"
},
"require-dev": {
    "fzaninotto/faker": "~1.4",
    "mockery/mockery": "0.9.*",
    "phpunit/phpunit": "~4.0",
    "phpspec/phpspec": "~2.1"
},
"autoload": {
    "classmap": [
        "database",
        "app/Models"
    ],
    "psr-4": {
        "App\\": "app/"
    }
},
"autoload-dev": {
    "classmap": [
        "tests/TestCase.php"
    ]
},
"scripts": {
    "post-install-cmd": [
        "php artisan clear-compiled",
        "php artisan optimize"
    ],
    "post-update-cmd": [
        "php artisan clear-compiled",
        "php artisan optimize"
    ],
    "post-root-package-install": [
        "php -r \"copy('.env.example', '.env');\""
    ],
    "post-create-project-cmd": [
        "php artisan key:generate"
    ]
},
"config": {
    "preferred-install": "dist"
},

"require": {
"illuminate/html": "5.*"
},

"minimum-stability": "dev",
"prefer-stable": true

}

2 Answers2

4

I would try removing ::class.

This setup works for me:

'providers' => [
    'Intervention\Image\ImageServiceProvider',
],
'aliases' => [
    'Image' => 'Intervention\Image\Facades\Image',
]
whoacowboy
  • 6,982
  • 6
  • 44
  • 78
  • 1
    @DorinoCanciani the title of your post is __Intervention laravel 5__ ;P – whoacowboy Jun 17 '15 at 15:19
  • @DorinoCanciani can you verify that you have the Intervention package installed? `/vendor/intervention/image/src/Intervention/Image/ImageServiceProvider.php` – whoacowboy Jun 17 '15 at 20:45
0

If you're using the PHP 5.5 ::class reference, then you shouldn't put it in quotes. Putting it in quotes makes it a string, and that's not what it is. It's just a static reference to the fully qualified class name.

So you either want to use this

'providers' => [
    Intervention\Image\ImageServiceProvider::class,
],
'aliases' => [
    'Image' => Intervention\Image\Facades\Image::class,
]

or this

'providers' => [
    'Intervention\Image\ImageServiceProvider',
],
'aliases' => [
    'Image' => 'Intervention\Image\Facades\Image',
]
Ilyas Serter
  • 810
  • 1
  • 8
  • 12
  • i added Intervention\Image\ImageServiceProvider::class without quotes, to existing providers array with ::class reference and this is causing the problem – Dorino Canciani Jun 17 '15 at 14:28
  • Could you try running `composer dump-autoload` as well? Let me know if you're still getting an exception after that. – Ilyas Serter Jun 17 '15 at 15:50
  • When i run composer dump-autoload it's all ok but in the home page it returns me FatalErrorException in ProviderRepository.php line 146: Class 'Intervention\Image\ImageServiceProvider' not found. I added in the question the code from it. – Dorino Canciani Jun 17 '15 at 16:26
  • Now I'm really curious. Could you also paste the contents of your composer.json file and verify that `vendor/intervention/src` exists. Composer require command actually updates the dependencies, but it sounds like you may have added the service provider before updating the dependencies. So now it can't update at all due to a fatal error. A possible fix would be this: remove the service provider and aliases from the config, run composer update, and then add them back. I could help better if you share your composer.json file. – Ilyas Serter Jun 17 '15 at 17:02
  • I added the composer.json file – Dorino Canciani Jun 17 '15 at 21:18
  • Have you tried removing the service provider from app config, and running composer update? You can add it back once the update is done successfully. It seems like composer can't update dependencies because the app is exiting due to not found library. – Ilyas Serter Jun 18 '15 at 23:50