Drupal investigation

ApcCache.php 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Validator\Mapping\Cache;
  11. @trigger_error('The '.__NAMESPACE__.'\ApcCache class is deprecated since version 2.5 and will be removed in 3.0. Use DoctrineCache with the Doctrine\Common\Cache\ApcCache class instead.', E_USER_DEPRECATED);
  12. use Symfony\Component\Validator\Mapping\ClassMetadata;
  13. /**
  14. * @deprecated since version 2.5, to be removed in 3.0.
  15. * Use DoctrineCache with \Doctrine\Common\Cache\ApcCache instead.
  16. */
  17. class ApcCache implements CacheInterface
  18. {
  19. private $prefix;
  20. public function __construct($prefix)
  21. {
  22. if (!extension_loaded('apc')) {
  23. throw new \RuntimeException('Unable to use ApcCache to cache validator mappings as APC is not enabled.');
  24. }
  25. $this->prefix = $prefix;
  26. }
  27. public function has($class)
  28. {
  29. if (!function_exists('apc_exists')) {
  30. $exists = false;
  31. apc_fetch($this->prefix.$class, $exists);
  32. return $exists;
  33. }
  34. return apc_exists($this->prefix.$class);
  35. }
  36. public function read($class)
  37. {
  38. return apc_fetch($this->prefix.$class);
  39. }
  40. public function write(ClassMetadata $metadata)
  41. {
  42. apc_store($this->prefix.$metadata->getClassName(), $metadata);
  43. }
  44. }