From 2ed783aead3dcb50818209314bb012de88c19456 Mon Sep 17 00:00:00 2001 From: Matthew Gamble Date: Tue, 9 Aug 2016 06:50:00 +1000 Subject: [PATCH] Resolve issues with Symfony dependencies This commit removes the dependency on the Symfony Config component. The only code other than getters that was actually being used was the constructors. In symfony 2, these were incredibly basic. In symfony 3, they perform some validation. This validation was causing a couple of "does not exist" tests to fail, as the Symfony Config module was performing these checks before the Lurker module, and throwing a different exception. Removing this dependency neatly solves this issue at the same time. --- composer.json | 1 - src/Lurker/Resource/DirectoryResource.php | 51 ++++++++++++++++++++++- src/Lurker/Resource/FileResource.php | 41 +++++++++++++++++- src/Lurker/Resource/ResourceInterface.php | 4 +- 4 files changed, 89 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index c62dbe7..fc67587 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,6 @@ "require" : { "php" : ">=5.3.3", - "symfony/config" : "^2.2|^3.0", "symfony/event-dispatcher" : "^2.2|^3.0" }, diff --git a/src/Lurker/Resource/DirectoryResource.php b/src/Lurker/Resource/DirectoryResource.php index 1444c94..3de001f 100644 --- a/src/Lurker/Resource/DirectoryResource.php +++ b/src/Lurker/Resource/DirectoryResource.php @@ -2,13 +2,60 @@ namespace Lurker\Resource; -use Symfony\Component\Config\Resource\DirectoryResource as BaseDirectoryResource; +use Lurker\Exception\InvalidArgumentException; /** * @package Lurker */ -class DirectoryResource extends BaseDirectoryResource implements ResourceInterface +class DirectoryResource implements ResourceInterface { + /** + * @var string + */ + private $resource; + + /** + * @var string|null + */ + private $pattern; + + /** + * @param string $resource + * @param string|null $pattern + */ + public function __construct($resource, $pattern = null) + { + $this->resource = realpath($resource); + $this->pattern = $pattern; + + if (false === $this->resource || !is_dir($this->resource)) { + throw new InvalidArgumentException(sprintf('The directory "%s" does not exist.', $resource)); + } + } + + /** + * @return string + */ + public function getResource() + { + return $this->resource; + } + + /** + * @return string + */ + public function getPattern() + { + return $this->pattern; + } + + /** + * @return string + */ + public function __toString() + { + return md5(serialize(array($this->resource, $this->pattern))); + } public function exists() { diff --git a/src/Lurker/Resource/FileResource.php b/src/Lurker/Resource/FileResource.php index 5e1798f..ac595e9 100644 --- a/src/Lurker/Resource/FileResource.php +++ b/src/Lurker/Resource/FileResource.php @@ -2,13 +2,50 @@ namespace Lurker\Resource; -use Symfony\Component\Config\Resource\FileResource as BaseFileResource; +use Lurker\Exception\InvalidArgumentException; /** * @package Lurker */ -class FileResource extends BaseFileResource implements ResourceInterface +class FileResource implements ResourceInterface { + /** + * @var string + */ + private $resource; + + /** + * @param string $resource + */ + public function __construct($resource) + { + $this->resource = realpath($resource); + + if (false === $this->resource && file_exists($resource)) { + $this->resource = $resource; + } + + if (false === $this->resource) { + throw new InvalidArgumentException(sprintf('The file "%s" does not exist.', $resource)); + } + } + + /** + * @return string + */ + public function getResource() + { + return $this->resource; + } + + /** + * @return string + */ + public function __toString() + { + return $this->resource; + } + public function getModificationTime() { if (!$this->exists()) { diff --git a/src/Lurker/Resource/ResourceInterface.php b/src/Lurker/Resource/ResourceInterface.php index fe0a888..776461e 100644 --- a/src/Lurker/Resource/ResourceInterface.php +++ b/src/Lurker/Resource/ResourceInterface.php @@ -2,12 +2,10 @@ namespace Lurker\Resource; -use Symfony\Component\Config\Resource\ResourceInterface as BaseResourceInterface; - /** * @package Lurker */ -interface ResourceInterface extends BaseResourceInterface +interface ResourceInterface { /** * @return boolean