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.
Merge pull request #1 from ivarb/master
Update AB remote with latest changes from master
- Loading branch information
Showing
5 changed files
with
61 additions
and
7 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,50 @@ | ||
<?php | ||
/** | ||
* ComposerJson.php | ||
* | ||
* @package ProjectVersioner | ||
* @subpackage Reader | ||
*/ | ||
|
||
namespace Naneau\ProjectVersioner\Reader; | ||
|
||
use Naneau\ProjectVersioner\ReaderInterface; | ||
|
||
use \RuntimeException; | ||
use \stdClass; | ||
|
||
/** | ||
* Finds the "version" from the composer.json file | ||
* | ||
* @category Naneau | ||
* @package ProjectVersioner | ||
* @subpackage Reader | ||
*/ | ||
class ComposerJson implements ReaderInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
**/ | ||
public function canRead($directory) | ||
{ | ||
return is_readable($directory . '/composer.json'); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
**/ | ||
public function read($directory) | ||
{ | ||
$json = @file_get_contents($directory . '/composer.json'); | ||
if ($json === false) { | ||
return false; | ||
} | ||
|
||
$json = json_decode($json); | ||
if (!($json instanceof stdClass) || empty($json->version)) { | ||
return false; | ||
} | ||
|
||
return trim($json->version); | ||
} | ||
} |
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
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