commit 7631e4b912531d9300c67c90fe69b4a921d5c0bd Author: beejeebus Date: Mon Apr 7 04:39:05 2014 +1000 use serialize diff --git a/core/lib/Drupal/Core/Cache/PhpBackend.php b/core/lib/Drupal/Core/Cache/PhpBackend.php index f845ac0..0be649a 100644 --- a/core/lib/Drupal/Core/Cache/PhpBackend.php +++ b/core/lib/Drupal/Core/Cache/PhpBackend.php @@ -102,13 +102,6 @@ protected function prepareItem($cache, $allow_invalid) { * {@inheritdoc} */ public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = array()) { - if (is_object($data) && !method_exists($data, '__set_state')) { - throw new \InvalidArgumentException( - "Invalid argument given, PhpBackend only allows objects that implement __set_state() " . - "and fully support var_export(). You can use the PhpBackend to save arbitrary object " . - "graphs using serialize()/unserialize()." - ); - } $item = array( 'cid' => $cid, 'data' => $data, @@ -253,13 +246,12 @@ public function removeBin() { * The cache item to store. */ protected function writeItem($cid, array $item) { - $storage = $this->storage(); - $data = var_export($item, TRUE); - $content =<<save($cid, $content); + $data = str_replace('\\', '\\\\', serialize($item)); + $content = "storage()->save($cid, $content); } /** diff --git a/core/modules/system/lib/Drupal/system/Tests/Cache/GenericCacheBackendUnitTestBase.php b/core/modules/system/lib/Drupal/system/Tests/Cache/GenericCacheBackendUnitTestBase.php index e558816..4b20ea0 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Cache/GenericCacheBackendUnitTestBase.php +++ b/core/modules/system/lib/Drupal/system/Tests/Cache/GenericCacheBackendUnitTestBase.php @@ -135,10 +135,11 @@ public function testSetGet() { $backend = $this->getCacheBackend(); $this->assertIdentical(FALSE, $backend->get('test1'), "Backend does not contain data for cache id test1."); - $backend->set('test1', 7); + $with_backslash = array('foo' => '\Drupal\foo\Bar'); + $backend->set('test1', $with_backslash); $cached = $backend->get('test1'); $this->assert(is_object($cached), "Backend returned an object for cache id test1."); - $this->assertIdentical(7, $cached->data); + $this->assertIdentical($with_backslash, $cached->data); $this->assertTrue($cached->valid, 'Item is marked as valid.'); $this->assertEqual($cached->created, REQUEST_TIME, 'Created time is correct.'); $this->assertEqual($cached->expire, Cache::PERMANENT, 'Expire time is correct.');