Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

firatkaya's avatar

"Your configuration files are not serializable." error when use artisan config:cache command

My config working well but I can't cache my markdown.php

'commonmark_options' => [
  'embeds' => [
    new CustomYouTube(),
  ],
  ...
  ...
],

When I set markdown.php config like this I get this error:

$ php artisan config:cache
Configuration cache cleared!

   LogicException 

  Your configuration files are not serializable.

  at C:\Users\FIRAT\WebstormProjects\project\vendor\laravel\framework\src\Illuminate\Foundation\Console\ConfigCacheCommand.php:80
     76▕             require $configPath;
     77▕         } catch (Throwable $e) {
     78▕             $this->files->delete($configPath);
     79▕
  ➜  80▕             throw new LogicException('Your configuration files are not serializable.', 0, $e);
     81▕         }
     82▕
     83▕         $this->info('Configuration cached successfully!');
     84▕     }

  1   C:\Users\FIRAT\WebstormProjects\project\bootstrap\cache\config.php:616
      Error::("Call to undefined method Ueberdosis\CommonMark\Services\CustomYouTube::__set_state()")

  2   C:\Users\FIRAT\WebstormProjects\project\vendor\laravel\framework\src\Illuminate\Foundation\Console\ConfigCacheCommand.php:76
      require()

config/markdown.php

<?php
  
  use App\Libraries\CommonMark\Extension\Embeds\Services\CustomYouTube;
  use BenFiratKaya\CommonMarkExtension\LinkTextViewerExtension;
  use BenFiratKaya\CommonMarkExtension\UnderlineExtension;
  use League\CommonMark\Extension\Autolink\AutolinkExtension;
  use League\CommonMark\Extension\ExternalLink\ExternalLinkExtension;
  use League\CommonMark\Extension\Strikethrough\StrikethroughExtension;
  use SimonVomEyser\CommonMarkExtension\LazyImageExtension;
  use Ueberdosis\CommonMark\EmbedExtension;
  
  return [
    'code_highlighting'       => [
      /*
       * To highlight code, we'll use Shiki under the hood. Make sure it's installed.
       *
       * More info: https://spatie.be/docs/laravel-markdown/v1/installation-setup
       */
      'enabled' => true,
      
      /*
       * The name of or path to a Shiki theme
       *
       * More info: https://github.com/shikijs/shiki/blob/master/docs/themes.md
       */
      'theme'   => 'one-dark-pro',
    ],
    
    /*
     * When enabled, anchor links will be added to all titles
     */
    'add_anchors_to_headings' => true,
    
    /*
     * These options will be passed to the league/commonmark package which is
     * used under the hood to render markdown.
     *
     * More info: https://spatie.be/docs/laravel-markdown/v1/using-the-blade-component/passing-options-to-commonmark
     */
    'commonmark_options'      => [
      'renderer'           => [
        'block_separator' => "\n",
        'inner_separator' => "\n",
        'soft_break'      => "\n",
      ],
      'commonmark'         => [
        'enable_em'              => true,
        'enable_strong'          => true,
        'use_asterisk'           => true,
        'use_underscore'         => true,
        'unordered_list_markers' => ['-', '*', '+'],
      ],
      'external_link'      => [
        'internal_hosts'     => '/(^|\.)voxelon\.net$/',
        'open_in_new_window' => true,
        'html_class'         => 'external-link',
        'nofollow'           => 'external',
        'noopener'           => 'external',
        'noreferrer'         => 'external',
      ],
      'link_text_viewer'   => [
        'internal_hosts' => '/(^|\.)voxelon\.net$/',
        'link_type'      => 'all',
      ],
      'embeds'             => [
        new CustomYouTube('100%', '300', true),
      ],
      'html_input'         => 'escape',
      'allow_unsafe_links' => false,
      'max_nesting_level'  => 3,
    ],
    
    /*
     * Rendering markdown to HTML can be resource intensive. By default
     * we'll cache the results.
     *
     * You can specify the name of a cache store here. When set to `null`
     * the default cache store will be used. If you do not want to use
     * caching set this value to `false`.
     */
    'cache_store'             => null,
    
    /*
     * This class will convert markdown to HTML
     *
     * You can change this to a class of your own to greatly
     * customize the rendering process
     *
     * More info: https://spatie.be/docs/laravel-markdown/v1/advanced-usage/customizing-the-rendering-process
     */
    'renderer_class'          => Spatie\LaravelMarkdown\MarkdownRenderer::class,
    
    /*
     * These extensions should be added to the markdown environment. A valid
     * extension implements League\CommonMark\Extension\ExtensionInterface
     *
     * More info: https://commonmark.thephpleague.com/2.1/extensions/overview/
     */
    'extensions'              => [
      new ExternalLinkExtension,
      new AutolinkExtension,
      new LinkTextViewerExtension,
      new LazyImageExtension,
      new EmbedExtension,
      new StrikethroughExtension,
      new UnderlineExtension
    ],
    
    /*
     * These block renderers should be added to the markdown environment. A valid
     * renderer implements League\CommonMark\Renderer\NodeRendererInterface;
     *
     * More info: https://commonmark.thephpleague.com/2.1/customization/rendering/
     */
    'block_renderers'         => [
      // ['class' => FencedCode::class, 'renderer' => new MyCustomCodeRenderer(), 'priority' => 0]
    ],
    
    /*
     * These inline renderers should be added to the markdown environment. A valid
     * renderer implements League\CommonMark\Renderer\NodeRendererInterface;
     *
     * More info: https://commonmark.thephpleague.com/2.1/customization/rendering/
     */
    'inline_renderers'        => [
      // ['class' => FencedCode::class, 'renderer' => new MyCustomCodeRenderer(), 'priority' => 0]
    ],
  ];

How can I fix this?

0 likes
8 replies
Sinnbeck's avatar

This seems to be a file in your own app? App\Libraries\CommonMark\Extension\Embeds\Services\CustomYouTube

Can you show the code?

firatkaya's avatar

@Sinnbeck

<?php
  
  namespace App\Libraries\CommonMark\Extension\Embeds\Services;
  
  use League\CommonMark\Util\HtmlElement;
  use Ueberdosis\CommonMark\Embed;
  use Ueberdosis\CommonMark\ServiceInterface;
  
  class CustomYouTube implements ServiceInterface {
    public string $width = '560';
    public string $height = '315';
    public bool $lazyLoad = true;
    public const pattern = '(?:.+?)?(?:\/v\/|watch\/|\?v=|\&v=|youtu\.be\/|\/v=|^youtu\.be\/|watch\%3Fv\%3D)([a-zA-Z0-9_-]{11})+?';
    
    public function __construct(string $width, string $height, bool $lazyLoad) {
      $this->width = $width;
      $this->height = $height;
      $this->lazyLoad = $lazyLoad;
    }
    
    public function render(Embed $node): HtmlElement {
      $attributes = [
        'width'           => $this->width,
        'height'          => $this->height,
        'src'             => 'https://www.youtube-nocookie.com/embed/' . $this->getId($node->getUrl()),
        'title'           => 'YouTube video player',
        'frameborder'     => '0',
        'allow'           => 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture',
        'allowfullscreen' => '',
      ];
      
      if ($this->lazyLoad) {
        $attributes = array_merge($attributes, [
          'loading' => 'lazy',
        ]);
      }
      
      // Output: <iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/eX2qFMC8cFo" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe>
      return new HtmlElement(
        'iframe',
        $attributes
      );
    }
    
    protected function getId($url) {
      preg_match('/' . self::pattern . '/', $url, $matches);
      
      return $matches[1] ?? '';
    }
  }

firatkaya's avatar

ServiceInterface:

<?php

namespace Ueberdosis\CommonMark;

use League\CommonMark\Util\HtmlElement;

interface ServiceInterface
{
    public function render(Embed $node): HtmlElement;
}

Sinnbeck's avatar

@firatkaya I'm a bit confused by the reference to Ueberdosis\CommonMark\Services\CustomYouTube

Does that class exist at all?

Snapey's avatar

in order to be cached, the config has to be entirely static, therefore you cannot new up a class in a config file

Please or to participate in this conversation.