AutowireServiceResource.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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\DependencyInjection\Config;
  11. @trigger_error('The '.__NAMESPACE__.'\AutowireServiceResource class is deprecated since Symfony 3.3 and will be removed in 4.0. Use ContainerBuilder::getReflectionClass() instead.', E_USER_DEPRECATED);
  12. use Symfony\Component\Config\Resource\SelfCheckingResourceInterface;
  13. use Symfony\Component\DependencyInjection\Compiler\AutowirePass;
  14. /**
  15. * @deprecated since version 3.3, to be removed in 4.0. Use ContainerBuilder::getReflectionClass() instead.
  16. */
  17. class AutowireServiceResource implements SelfCheckingResourceInterface, \Serializable
  18. {
  19. private $class;
  20. private $filePath;
  21. private $autowiringMetadata = array();
  22. public function __construct($class, $path, array $autowiringMetadata)
  23. {
  24. $this->class = $class;
  25. $this->filePath = $path;
  26. $this->autowiringMetadata = $autowiringMetadata;
  27. }
  28. public function isFresh($timestamp)
  29. {
  30. if (!file_exists($this->filePath)) {
  31. return false;
  32. }
  33. // has the file *not* been modified? Definitely fresh
  34. if (@filemtime($this->filePath) <= $timestamp) {
  35. return true;
  36. }
  37. try {
  38. $reflectionClass = new \ReflectionClass($this->class);
  39. } catch (\ReflectionException $e) {
  40. // the class does not exist anymore!
  41. return false;
  42. }
  43. return (array) $this === (array) AutowirePass::createResourceForClass($reflectionClass);
  44. }
  45. public function __toString()
  46. {
  47. return 'service.autowire.'.$this->class;
  48. }
  49. public function serialize()
  50. {
  51. return serialize(array($this->class, $this->filePath, $this->autowiringMetadata));
  52. }
  53. public function unserialize($serialized)
  54. {
  55. if (\PHP_VERSION_ID >= 70000) {
  56. list($this->class, $this->filePath, $this->autowiringMetadata) = unserialize($serialized, array('allowed_classes' => false));
  57. } else {
  58. list($this->class, $this->filePath, $this->autowiringMetadata) = unserialize($serialized);
  59. }
  60. }
  61. /**
  62. * @deprecated Implemented for compatibility with Symfony 2.8
  63. */
  64. public function getResource()
  65. {
  66. return $this->filePath;
  67. }
  68. }