Commit efa7f7b0 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Solution pour connaître la version déployée exacte.

parent 437d4a99
<?php
use Zend\Config\Writer\PhpArray;
require __DIR__ . '/../vendor/autoload.php';
$OUTPUT_CONFIG_FILE = __DIR__ . '/../config/autoload/deploy-info.local.php';
function versionFromGit()
{
$GIT_VERSION = 'git --no-pager describe --tags --always';
$GIT_COMMIT = 'git rev-parse --verify --short=8 HEAD';
$output = [];
exec($GIT_VERSION, $output, $return);
$tag = $return === 0 ? implode('', $output) : 'Version inconnue';
$output = [];
exec($GIT_COMMIT, $output, $return);
$commit = $return === 0 ? implode('', $output) : 'Commit inconnu';
$version = sprintf("%s (%s)", $tag, $commit);
return $version;
}
$version = versionFromGit();
$config = [
'deploy-info' => [
'about' => "Ce fichier de config est généré par " . __FILE__,
'version' => $version,
],
];
$configWriter = new PhpArray();
$configWriter->setUseBracketArraySyntax(true);
$configWriter->toFile($OUTPUT_CONFIG_FILE, $config);
......@@ -4,6 +4,8 @@
# This script runs required operations in order to set up the application.
#
php bin/generate-deploy-info-config.php
# Composer install
composer install --no-dev --no-suggest --optimize-autoloader
......
......@@ -7,7 +7,20 @@ use ZF\Rest\AbstractResourceListener;
class VersionResource extends AbstractResourceListener
{
const VERSION_NUMBER = '1.1.3';
/**
* @var VersionEntity
*/
private $versionEntity;
/**
* VersionResource constructor.
*
* @param VersionEntity $versionEntity
*/
public function __construct(VersionEntity $versionEntity)
{
$this->versionEntity = $versionEntity;
}
/**
* Fetch a resource
......@@ -17,6 +30,6 @@ class VersionResource extends AbstractResourceListener
*/
public function fetch($id)
{
return new VersionEntity(self::VERSION_NUMBER);
return $this->versionEntity;
}
}
<?php
namespace ImportData\V1\Rest\Version;
use Zend\ServiceManager\ServiceLocatorInterface as ContainerInterface;
class VersionResourceFactory
{
public function __invoke($services)
/**
* @param ContainerInterface $container
* @return VersionResource
*/
public function __invoke(ContainerInterface $container)
{
return new VersionResource();
$config = $container->get('config');
if (isset($config['version'])) {
$version = $config['version'];
} else {
$version = "Inconnue";
}
$entity = new VersionEntity($version);
return new VersionResource($entity);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment