Skip to content

Commit

Permalink
Merge pull request #3 from angryTom/composer-json
Browse files Browse the repository at this point in the history
Added a composer json reader
  • Loading branch information
naneau committed Mar 31, 2015
2 parents c5d2a91 + 408eafc commit 6dfe030
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/Naneau/ProjectVersioner/Reader/ComposerJson.php
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);
}
}

0 comments on commit 6dfe030

Please sign in to comment.