forked from naneau/php-project-versioner
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
217 additions
and
1 deletion.
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,84 @@ | ||
<?php | ||
/** | ||
* FileSet.php | ||
* | ||
* @package ProjectVersioner | ||
* @subpackage Reader | ||
*/ | ||
|
||
namespace Naneau\ProjectVersioner\Reader; | ||
|
||
use Naneau\ProjectVersioner\ReaderInterface; | ||
|
||
use Symfony\Component\Finder\Finder; | ||
|
||
/** | ||
* File | ||
* | ||
* Creates a version based on the highest mtime of a set of files | ||
* | ||
* @category Naneau | ||
* @package ProjectVersioner | ||
* @subpackage Reader | ||
*/ | ||
class FileSet implements ReaderInterface | ||
{ | ||
/** | ||
* The finder | ||
* | ||
* @var Finder | ||
**/ | ||
private $finder; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param string $files | ||
* @return void | ||
**/ | ||
public function __construct($in = '**/*') | ||
{ | ||
$this | ||
->setFinder(new Finder); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
**/ | ||
public function canRead($directory) | ||
{ | ||
$this | ||
->getFinder()->in($directory) | ||
->name($this->getName()); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
**/ | ||
public function read($directory) | ||
{ | ||
} | ||
|
||
/** | ||
* Get the sf finder | ||
* | ||
* @return Finder | ||
*/ | ||
public function getFinder() | ||
{ | ||
return $this->finder; | ||
} | ||
|
||
/** | ||
* Set the sf finder | ||
* | ||
* @param Finder $finder | ||
* @return FileSet | ||
*/ | ||
public function setFinder(Finder $finder) | ||
{ | ||
$this->finder = $finder; | ||
|
||
return $this; | ||
} | ||
} |
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,104 @@ | ||
<?php | ||
/** | ||
* Finder.php | ||
* | ||
* @package ProjectVersioner | ||
* @subpackage Reader | ||
*/ | ||
|
||
namespace Naneau\ProjectVersioner\Reader; | ||
|
||
use Naneau\ProjectVersioner\ReaderInterface; | ||
|
||
use Symfony\Component\Finder\Finder as SfFinder; | ||
|
||
/** | ||
* Finder | ||
* | ||
* Uses the highest mtime from a finder as a version | ||
* | ||
* @category Naneau | ||
* @package ProjectVersioner | ||
* @subpackage Reader | ||
*/ | ||
class Finder implements ReaderInterface | ||
{ | ||
/** | ||
* the finder | ||
* | ||
* @var SfFinder | ||
*/ | ||
private $finder; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param SfFinder $finder | ||
* @return void | ||
**/ | ||
public function __construct(SfFinder $finder = null) | ||
{ | ||
if ($finder === null) { | ||
$finder = new SfFinder; | ||
} | ||
|
||
$this->setFinder($finder); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
**/ | ||
public function canRead($directory) | ||
{ | ||
$this->getFinder()->in($directory); | ||
|
||
// If at least one file/dir can be found, assume we can read | ||
foreach($this->getFinder() as $file) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
**/ | ||
public function read($directory) | ||
{ | ||
$highest = 0; | ||
foreach($this->getFinder() as $file) { | ||
|
||
$mtime = filemtime( | ||
$file->getPath() | ||
. DIRECTORY_SEPARATOR . $file->getFilename() | ||
); | ||
if ($mtime > $highest) { | ||
$highest = $mtime; | ||
} | ||
} | ||
|
||
return $highest; | ||
} | ||
|
||
/** | ||
* Get the finder | ||
* | ||
* @return SfFinder | ||
*/ | ||
public function getFinder() | ||
{ | ||
return $this->finder; | ||
} | ||
|
||
/** | ||
* Set the finder | ||
* | ||
* @param SfFinder $finder | ||
* @return Finder | ||
*/ | ||
public function setFinder(SfFinder $finder) | ||
{ | ||
$this->finder = $finder; | ||
|
||
return $this; | ||
} | ||
} |
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,26 @@ | ||
<?php | ||
|
||
use Naneau\ProjectVersioner\Versioner; | ||
use Naneau\ProjectVersioner\Reader\Finder as FinderReader; | ||
|
||
use Symfony\Component\Finder\Finder; | ||
|
||
class FinderTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testRead() | ||
{ | ||
$directory = __DIR__ . '/../projects/finder'; | ||
|
||
$time = time(); | ||
touch($directory . '/DirectoryOne/FileFour.txt', $time); | ||
|
||
$finder = new Finder; | ||
$finder->name('*.txt'); | ||
|
||
$readers = array(new FinderReader($finder)); | ||
|
||
$versioner = new Versioner($directory, $readers); | ||
|
||
$this->assertEquals($time, $versioner->get()); | ||
} | ||
} |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.