Uncaught exception 'Exception' with message 'Serialization of 'Closure' is not allowed'

121 views
Skip to first unread message

kenjis

unread,
Aug 10, 2014, 5:51:55 PM8/10/14
to bear-p...@googlegroups.com
Kenji です。


Aura formでAura.Filterを使うようにProviderを作成してみたのですが、以下のエラーが出て
しまいました。

Fatal error: Uncaught exception 'Exception' with message 'Serialization of 'Closure' is not allowed' in /Users/kenji/tmp/bear/vendor/ray/di/src/Injector.php:311
Stack trace:
#0 [internal function]: ArrayObject->serialize()
#1 /Users/kenji/tmp/bear/vendor/ray/di/src/Injector.php(311): serialize(Array)
#2 [internal function]: Ray\Di\Injector->serialize()
#3 [internal function]: ArrayObject->serialize()
#4 /Users/kenji/tmp/bear/vendor/doctrine/cache/lib/Doctrine/Common/Cache/FilesystemCache.php(103): serialize(Object(Demo\Sandbox\Module\AppModule))
#5 /Users/kenji/tmp/bear/vendor/doctrine/cache/lib/Doctrine/Common/Cache/CacheProvider.php(94): Doctrine\Common\Cache\FilesystemCache->doSave('[][1]', Object(Demo\Sandbox\Module\AppModule), 0)
#6 /Users/kenji/tmp/bear/vendor/ray/di/src/CacheableModule.php(53): Doctrine\Common\Cache\CacheProvider->save(NULL, Object(Demo\Sandbox\Module\AppModule)) #7 /Users/kenji/tmp/bear/vendor/ray/di/src/InjectorFactory.php(83): Ray\Di\CacheableModule->get(Object(Doctrine\Common\Cache\FilesystemCa in /Users/kenji/tmp/bear/vendor/ray/di/src/Injector.php on line 311

オブジェクトにクロージャが含まれることが原因のようですが、このような場合は、どう
すればよいのでしょうか?


// Kenji

koriym

unread,
Aug 23, 2014, 10:45:16 PM8/23/14
to bear-p...@googlegroups.com
Kenjiさん

返事遅くてすいません!

オブジェクトにクロージャ等のシリアライズ不可のものが含まれているとシリアライズでエラーがでてしまいます。

Serializable インターフェイス などで「シリアライズ時に取り除く、アンシリアライズで装着する」というコードを含めてはどうでしょうか?


2014年8月11日月曜日 6時51分55秒 UTC+9 kenjis:

kenjis

unread,
Aug 24, 2014, 5:13:42 AM8/24/14
to bear-p...@googlegroups.com
Kenji です。


Aura.Filter のインスタンス化は以下のようにするようですが、

https://github.com/auraphp/Aura.Filter/blob/master/scripts/instance.php

return new RuleCollection(
    new RuleLocator(array_merge(
        require __DIR__ . '/registry.php',
        ['any' => function () {
            $rule = new \Aura\Filter\Rule\Any;
            $rule->setRuleLocator(new \Aura\Filter\RuleLocator(
                require __DIR__ . '/registry.php'
            ));
            return $rule;
        }]
    )),
    new Translator(require dirname(__DIR__) . '/intl/en_US.php')
);

これらのクラスでクロージャが含まれるものは、継承したクラスを作成し implements Serializable
し、それをProviderで使うようにするということでしょうか。

ちょっと面倒な気がしますが、どうにかシリアライズ可能にするしかないということですね。


// Kenji


2014年8月24日日曜日 11時45分16秒 UTC+9 koriym:

koriym

unread,
Aug 28, 2014, 3:01:49 AM8/28/14
to bear-p...@googlegroups.com
ファクトリーをインジェクトするという方法もあります。

2014年8月24日日曜日 18時13分42秒 UTC+9 kenjis:
Reply all
Reply to author
Forward
0 new messages