-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from jaapio/feature/fileAdapter
extracted file interaction to adapter appraoch
- Loading branch information
Showing
3 changed files
with
133 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
/** | ||
* phpDocumentor | ||
* | ||
* PHP Version 5.5 | ||
* | ||
* @copyright 2010-2015 Mike van Riel / Naenius (http://www.naenius.com) | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT | ||
* @link http://phpdoc.org | ||
*/ | ||
|
||
namespace phpDocumentor\Reflection\Php\Factory\File; | ||
|
||
/** | ||
* Interface for Adapters uses by the File strategy class to interact with the file system. | ||
*/ | ||
interface Adapter | ||
{ | ||
|
||
/** | ||
* Returns true when the file exists. | ||
* | ||
* @param string $filePath | ||
* @return boolean | ||
*/ | ||
public function fileExists($filePath); | ||
|
||
/** | ||
* Returns the content of the file as a string. | ||
* | ||
* @param $filePath | ||
* @return string | ||
*/ | ||
public function getContents($filePath); | ||
|
||
/** | ||
* Returns md5 hash of the file. | ||
* | ||
* @param $filePath | ||
* @return string | ||
*/ | ||
public function md5($filePath); | ||
|
||
/** | ||
* Returns an relative path to the file. | ||
* | ||
* @param string $filePath | ||
* @return string | ||
*/ | ||
public function path($filePath); | ||
} |
63 changes: 63 additions & 0 deletions
63
src/phpDocumentor/Reflection/Php/Factory/File/LocalAdapter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
/** | ||
* phpDocumentor | ||
* | ||
* PHP Version 5.5 | ||
* | ||
* @copyright 2010-2015 Mike van Riel / Naenius (http://www.naenius.com) | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT | ||
* @link http://phpdoc.org | ||
*/ | ||
|
||
namespace phpDocumentor\Reflection\Php\Factory\File; | ||
|
||
/** | ||
* Adapter to interact with local readable files. | ||
*/ | ||
final class LocalAdapter implements Adapter | ||
{ | ||
|
||
/** | ||
* Returns true when the file exists. | ||
* | ||
* @param string $filePath | ||
* @return boolean | ||
*/ | ||
public function fileExists($filePath) | ||
{ | ||
return file_exists($filePath); | ||
} | ||
|
||
/** | ||
* Returns the content of the file as a string. | ||
* | ||
* @param $filePath | ||
* @return string | ||
*/ | ||
public function getContents($filePath) | ||
{ | ||
return file_get_contents($filePath); | ||
} | ||
|
||
/** | ||
* Returns md5 hash of the file. | ||
* | ||
* @param $filePath | ||
* @return string | ||
*/ | ||
public function md5($filePath) | ||
{ | ||
return md5_file($filePath); | ||
} | ||
|
||
/** | ||
* Returns an relative path to the file. | ||
* | ||
* @param string $filePath | ||
* @return string | ||
*/ | ||
public function path($filePath) | ||
{ | ||
return $filePath; | ||
} | ||
} |