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

config:cache command crashes on closures #9625

Closed
Anahkiasen opened this issue Jul 14, 2015 · 5 comments
Closed

config:cache command crashes on closures #9625

Anahkiasen opened this issue Jul 14, 2015 · 5 comments

Comments

@Anahkiasen
Copy link
Contributor

I have a third party package that uses a closure in its configuration (dingo/api), unfortunately that prevents me from using the config:cache command as this crashes the whole application with no friendly error message nor way to recover from it besides manually deleting the config cache:

PHP Fatal error:  Call to undefined method Closure::__set_state() in /Users/anahkiasen/config-closures/bootstrap/cache/config.php on line 22
PHP Stack trace:
PHP   1. {main}() /Users/anahkiasen/config-closures/artisan:0
PHP   2. Illuminate\Foundation\Console\Kernel->handle() /Users/anahkiasen/config-closures/artisan:36
PHP   3. Illuminate\Foundation\Console\Kernel->bootstrap() /Users/anahkiasen/config-closures/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:96
PHP   4. Illuminate\Foundation\Application->bootstrapWith() /Users/anahkiasen/config-closures/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:196
PHP   5. Illuminate\Foundation\Bootstrap\LoadConfiguration->bootstrap() /Users/anahkiasen/config-closures/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:203
PHP   6. require() /Users/anahkiasen/config-closures/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/LoadConfiguration.php:27

Fatal error: Call to undefined method Closure::__set_state() in /Users/anahkiasen/config-closures/bootstrap/cache/config.php on line 22

And the faulty part in the cached configuration file:

    array (
      'oauth' => 
      Closure::__set_state(array(
      )),
    ),

Shouldn't Laravel leverage serializable closures here?

@GrahamCampbell
Copy link
Member

This has come up before. We don't support closures on purpose because the overhead of unserializing is greater than anything gained otherwise.

@GrahamCampbell
Copy link
Member

Any config system that contain closures is badly designed.

@astroanu
Copy link

Any solution to this ? config:cache is unusable right now

@pratikshap31
Copy link

is it solved??

@KilianB
Copy link

KilianB commented Aug 4, 2023

Any config system that contain closures is badly designed.

@GrahamCampbell I have to confess that my laravel and php skills are very rudimentary, so could you please advise me how I could solve the following task without closures?

I want to dynamically declare CRUD routes

if (!function_exists('registerResourceRoute')) {
  function registerResourceRoute($endpoint, $tablename, $claim)
  {
    // Route::get($endpoint . '/{id}', $controller . '@getOne')->prefix('adminpanel')->middleware('jwtclaim:VIEW_' . strtoupper($endpoint));

    //Get a list of records
    //getList	GET http://my.api.url/posts?sort=["title","ASC"]&range=[0, 24]&filter={"title":"bar"}
    Route::get($endpoint, [
      function (Request $request) use ($tablename, $endpoint) {
        return App::make('App\Http\Controllers\CRUDController', ['tablename' => $tablename])->getList($request, $endpoint);
      }
    ])->prefix('adminpanel')->middleware('jwtclaim:VIEW_' . $claim);

    //Get a single record

    // adminpanel/bookings/1
    Route::get($endpoint . '/{id}', [
      function (Request $request, string $id) use ($tablename) {
        return App::make('App\Http\Controllers\CRUDController', ['tablename' => $tablename])->getOne($request, $id);
      }
    ])->prefix('adminpanel')->middleware('jwtclaim:VIEW_' . $claim);

    Route::post()
    Route::delete() 
   ....
registerResourceRoute('locations', 'public.location', 'DB');
registerResourceRoute('locationTranslations', 'public.locationTranslation', 'DB');
registerResourceRoute('locationMappings', 'public.location_mapping', 'DB');
registerResourceRoute('locationRegions', 'public.location_region', 'DB');
.... and 40 more

The controller code is 100% identical between all controllers, how would the syntax look like to solve this task without the need to write 40 - 50 controllers and without closures?

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

5 participants