Repository navigation
replace adapters by File objects to be more flexible #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| <?php | ||
| /** | ||
| * This file is part of phpDocumentor. | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| * | ||
| * @copyright 2010-2015 Mike van Riel<mike@phpdoc.org> | ||
| * @license http://www.opensource.org/licenses/mit-license.php MIT | ||
| * @link http://phpdoc.org | ||
| */ | ||
|
|
||
| namespace phpDocumentor\Reflection\File; | ||
|
|
||
|
|
||
| use phpDocumentor\Reflection\File; | ||
|
|
||
| /** | ||
| * Represents a local file on the file system. | ||
| */ | ||
| final class LocalFile implements File | ||
| { | ||
| /** | ||
| * Path to the file. | ||
| * @var string | ||
| */ | ||
| private $path; | ||
|
|
||
| /** | ||
| * LocalFile constructor. | ||
| * @param string $path | ||
| */ | ||
| public function __construct($path) | ||
| { | ||
| $this->path = $path; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the content of the file as a string. | ||
| * | ||
| * @return string | ||
| */ | ||
| public function getContents() | ||
| { | ||
| return file_get_contents($this->path); | ||
| } | ||
|
|
||
| /** | ||
| * Returns md5 hash of the file. | ||
| * | ||
| * @return string | ||
| */ | ||
| public function md5() | ||
| { | ||
| return md5_file($this->path); | ||
| } | ||
|
|
||
| /** | ||
| * Returns an relative path to the file. | ||
| * | ||
| * @return string | ||
| */ | ||
| public function path() | ||
| { | ||
| return $this->path; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,12 +14,11 @@ | |
| namespace phpDocumentor\Reflection\Php\Factory; | ||
|
|
||
| use InvalidArgumentException; | ||
| use phpDocumentor\Reflection\File as FileSystemFile; | ||
| use phpDocumentor\Reflection\Fqsen; | ||
| use phpDocumentor\Reflection\Middleware\ChainFactory; | ||
| use phpDocumentor\Reflection\Middleware\Middleware; | ||
| use phpDocumentor\Reflection\Php\Factory\File\Adapter; | ||
| use phpDocumentor\Reflection\Php\Factory\File\CreateCommand; | ||
| use phpDocumentor\Reflection\Php\Factory\File\LocalAdapter; | ||
| use phpDocumentor\Reflection\Php\File as FileElement; | ||
| use phpDocumentor\Reflection\Php\NodesFactory; | ||
| use phpDocumentor\Reflection\Php\ProjectFactoryStrategy; | ||
|
|
@@ -56,17 +55,11 @@ final class File implements ProjectFactoryStrategy | |
| * Initializes the object. | ||
| * | ||
| * @param NodesFactory $nodesFactory | ||
| * @param Adapter $adapter | ||
| * @param Middleware[] $middleware | ||
| */ | ||
| public function __construct(NodesFactory $nodesFactory, Adapter $adapter = null, $middleware = array()) | ||
| public function __construct(NodesFactory $nodesFactory, $middleware = array()) | ||
| { | ||
| if ($adapter === null) { | ||
| $adapter = new LocalAdapter(); | ||
| } | ||
|
|
||
| $this->nodesFactory = $nodesFactory; | ||
| $this->adapter = $adapter; | ||
|
|
||
| $lastCallable = function ($command) { | ||
| return $this->createFile($command); | ||
|
|
@@ -78,20 +71,20 @@ public function __construct(NodesFactory $nodesFactory, Adapter $adapter = null, | |
| /** | ||
| * Returns true when the strategy is able to handle the object. | ||
| * | ||
| * @param string $filePath path to check. | ||
| * @param string $file path to check. | ||
| * @return boolean | ||
| */ | ||
| public function matches($filePath) | ||
| public function matches($file) | ||
| { | ||
| return is_string($filePath) && $this->adapter->fileExists($filePath); | ||
| return $file instanceof FileSystemFile; | ||
| } | ||
|
|
||
| /** | ||
| * Creates an File out of the given object. | ||
| * Since an object might contain other objects that need to be converted the $factory is passed so it can be | ||
| * used to create nested Elements. | ||
| * | ||
| * @param string $object path to the file to convert to an File object. | ||
| * @param FileSystemFile $object path to the file to convert to an File object. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be the interface and not the concrete instance?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Never mind :) |
||
| * @param StrategyContainer $strategies used to convert nested objects. | ||
| * @param Context $context | ||
| * @return File | ||
|
|
@@ -107,33 +100,33 @@ public function create($object, StrategyContainer $strategies, Context $context | |
| ); | ||
| } | ||
|
|
||
| $command = new CreateCommand($this->adapter, $object, $strategies); | ||
| $command = new CreateCommand($object, $strategies); | ||
| $middlewareChain = $this->middlewareChain; | ||
|
|
||
| return $middlewareChain($command); | ||
| } | ||
|
|
||
| /** | ||
| * @param $object | ||
| * @param StrategyContainer $strategies | ||
| * @param CreateCommand $command | ||
| * @return FileElement | ||
| */ | ||
| private function createFile(CreateCommand $command) | ||
| { | ||
| $code = $this->adapter->getContents($command->getFilePath()); | ||
| $file = $command->getFile(); | ||
| $code = $file->getContents(); | ||
| $nodes = $this->nodesFactory->create($code); | ||
| $docBlock = $this->createDocBlock($command->getStrategies(), $code, $nodes); | ||
|
|
||
| $file = new FileElement( | ||
| $this->adapter->md5($command->getFilePath()), | ||
| $this->adapter->path($command->getFilePath()), | ||
| $result = new FileElement( | ||
| $file->md5(), | ||
| $file->path(), | ||
| $code, | ||
| $docBlock | ||
| ); | ||
|
|
||
| $this->createElements(new Fqsen('\\'), $nodes, $file, $command->getStrategies()); | ||
| $this->createElements(new Fqsen('\\'), $nodes, $result, $command->getStrategies()); | ||
|
|
||
| return $file; | ||
| return $result; | ||
| } | ||
|
|
||
| /** | ||
|
|
||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this test the interface and not the concrete instance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is the interface,
use phpDocumentor\Reflection\File as FileSystemFile;There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, sorry :)