mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 15:33:15 +00:00
Upgrade Configuration
This commit is contained in:
@@ -74,11 +74,7 @@ return call_user_func(function()
|
|||||||
throw new \Exception(sprintf("Unable to copy %s", $connexionFile));
|
throw new \Exception(sprintf("Unable to copy %s", $connexionFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
//get configuration object
|
$configuration = \Alchemy\Phrasea\Core\Configuration::build();
|
||||||
$appConf = new \Alchemy\Phrasea\Core\Configuration\Application();
|
|
||||||
$parser = new \Alchemy\Phrasea\Core\Configuration\Parser\Yaml();
|
|
||||||
$handler = new \Alchemy\Phrasea\Core\Configuration\Handler($appConf, $parser);
|
|
||||||
$configuration = new \Alchemy\Phrasea\Core\Configuration($handler);
|
|
||||||
|
|
||||||
//refactor credentials
|
//refactor credentials
|
||||||
$connexionINI = array();
|
$connexionINI = array();
|
||||||
@@ -127,7 +123,7 @@ return call_user_func(function()
|
|||||||
}
|
}
|
||||||
|
|
||||||
//rewrite service file
|
//rewrite service file
|
||||||
$serviceFile = $appConf->getServiceFile();
|
$serviceFile = $appConf->getServicesFile();
|
||||||
$services = $configuration->getConfigurationHandler()->getParser()->parse($serviceFile);
|
$services = $configuration->getConfigurationHandler()->getParser()->parse($serviceFile);
|
||||||
|
|
||||||
foreach ($services as $serviceName => $service)
|
foreach ($services as $serviceName => $service)
|
||||||
@@ -164,10 +160,7 @@ return call_user_func(function()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$configuration->write($arrayConf);
|
|
||||||
|
|
||||||
$app['install'] = true;
|
$app['install'] = true;
|
||||||
// $app->redirect("/setup/installer/");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@@ -11,8 +11,7 @@
|
|||||||
|
|
||||||
namespace Alchemy\Phrasea\Cache;
|
namespace Alchemy\Phrasea\Cache;
|
||||||
|
|
||||||
use Alchemy\Phrasea\Core\Configuration\Parser as FileParser,
|
use \Alchemy\Phrasea\Core\Service\Builder,
|
||||||
\Alchemy\Phrasea\Core\Service\Builder,
|
|
||||||
\Alchemy\Phrasea\Core;
|
\Alchemy\Phrasea\Core;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -43,13 +42,13 @@ class Manager
|
|||||||
*/
|
*/
|
||||||
protected $registry = array();
|
protected $registry = array();
|
||||||
|
|
||||||
public function __construct(Core $core, \SplFileObject $file, FileParser $parser)
|
public function __construct(Core $core, \SplFileObject $file)
|
||||||
{
|
{
|
||||||
$this->cacheFile = $file;
|
$this->cacheFile = $file;
|
||||||
$this->parser = $parser;
|
$this->parser = new \Symfony\Component\Yaml\Yaml();
|
||||||
$this->core = $core;
|
$this->core = $core;
|
||||||
|
|
||||||
$this->registry = $parser->parse($file);
|
$this->registry = $this->parser->parse($file);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function exists($name)
|
protected function exists($name)
|
||||||
|
@@ -176,13 +176,9 @@ class Installer implements ControllerProviderInterface
|
|||||||
$setupRegistry = new \Setup_Registry();
|
$setupRegistry = new \Setup_Registry();
|
||||||
$setupRegistry->set('GV_ServerName', $servername, \registry::TYPE_STRING);
|
$setupRegistry->set('GV_ServerName', $servername, \registry::TYPE_STRING);
|
||||||
|
|
||||||
$appbox = \appbox::create($setupRegistry, $conn, $appbox_name, true);
|
$appbox = \appbox::create($app['Core'], $setupRegistry, $conn, $appbox_name, true);
|
||||||
|
|
||||||
$handler = new \Alchemy\Phrasea\Core\Configuration\Handler(
|
$configuration = \Alchemy\Phrasea\Core\Configuration::build();
|
||||||
new \Alchemy\Phrasea\Core\Configuration\Application(),
|
|
||||||
new \Alchemy\Phrasea\Core\Configuration\Parser\Yaml()
|
|
||||||
);
|
|
||||||
$configuration = new \Alchemy\Phrasea\Core\Configuration($handler);
|
|
||||||
|
|
||||||
if ($configuration->isInstalled())
|
if ($configuration->isInstalled())
|
||||||
{
|
{
|
||||||
|
@@ -26,10 +26,7 @@ require_once __DIR__ . '/../../vendor/symfony/src/Symfony/Component/DependencyIn
|
|||||||
|
|
||||||
require_once __DIR__ . '/Core/Configuration/Specification.php';
|
require_once __DIR__ . '/Core/Configuration/Specification.php';
|
||||||
require_once __DIR__ . '/Core/Configuration.php';
|
require_once __DIR__ . '/Core/Configuration.php';
|
||||||
require_once __DIR__ . '/Core/Configuration/Application.php';
|
require_once __DIR__ . '/Core/Configuration/ApplicationSpecification.php';
|
||||||
require_once __DIR__ . '/Core/Configuration/Handler.php';
|
|
||||||
require_once __DIR__ . '/Core/Configuration/Parser.php';
|
|
||||||
require_once __DIR__ . '/Core/Configuration/Parser/Yaml.php';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -57,12 +54,7 @@ class Core extends \Pimple
|
|||||||
|
|
||||||
public function __construct($environement = null)
|
public function __construct($environement = null)
|
||||||
{
|
{
|
||||||
$appConf = new Core\Configuration\Application();
|
$this->configuration = Core\Configuration::build(null, $environement);
|
||||||
$parser = new Core\Configuration\Parser\Yaml();
|
|
||||||
|
|
||||||
$handler = new Core\Configuration\Handler($appConf, $parser);
|
|
||||||
|
|
||||||
$this->configuration = new Core\Configuration($handler, $environement);
|
|
||||||
|
|
||||||
$core = $this;
|
$core = $this;
|
||||||
|
|
||||||
@@ -112,9 +104,7 @@ class Core extends \Pimple
|
|||||||
|
|
||||||
$file = new \SplFileObject(__DIR__ . '/../../../tmp/cache_registry.yml');
|
$file = new \SplFileObject(__DIR__ . '/../../../tmp/cache_registry.yml');
|
||||||
|
|
||||||
$parser = new Core\Configuration\Parser\Yaml();
|
return new \Alchemy\Phrasea\Cache\Manager($core, $file);
|
||||||
|
|
||||||
return new \Alchemy\Phrasea\Cache\Manager($core, $file, $parser);
|
|
||||||
});
|
});
|
||||||
/**
|
/**
|
||||||
* Set Entity Manager using configuration
|
* Set Entity Manager using configuration
|
||||||
|
@@ -12,8 +12,7 @@
|
|||||||
namespace Alchemy\Phrasea\Core;
|
namespace Alchemy\Phrasea\Core;
|
||||||
|
|
||||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
||||||
use Alchemy\Phrasea\Core\Configuration\Application;
|
use Alchemy\Phrasea\Core\Configuration\ApplicationSpecification;
|
||||||
use Alchemy\Phrasea\Core\Configuration\Parser as ConfigurationParser;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle configuration file mechanism of phraseanet
|
* Handle configuration file mechanism of phraseanet
|
||||||
@@ -30,12 +29,7 @@ class Configuration
|
|||||||
* @var ParameterBag\ParameterBag
|
* @var ParameterBag\ParameterBag
|
||||||
*/
|
*/
|
||||||
protected $configuration;
|
protected $configuration;
|
||||||
|
protected $specifications;
|
||||||
/**
|
|
||||||
* Class that take care of configuration process
|
|
||||||
* @var Configuration\Handler
|
|
||||||
*/
|
|
||||||
private $configurationHandler;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the current environnement
|
* Return the current environnement
|
||||||
@@ -43,48 +37,25 @@ class Configuration
|
|||||||
*/
|
*/
|
||||||
private $environment;
|
private $environment;
|
||||||
|
|
||||||
/**
|
public static function build($specifications = null, $environment = null)
|
||||||
*
|
|
||||||
* @param type $envName the name of the loaded environnement
|
|
||||||
*/
|
|
||||||
public function __construct(Configuration\Handler $handler, $environment = null)
|
|
||||||
{
|
{
|
||||||
$this->configurationHandler = $handler;
|
if (!$specifications)
|
||||||
$this->installed = false;
|
|
||||||
$this->environment = $environment;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
|
$specifications = new Configuration\ApplicationSpecification();
|
||||||
//if one of this files are missing consider phraseanet not installed
|
|
||||||
$handler->getSpecification()->getConfigurationFile();
|
|
||||||
$handler->getSpecification()->getServiceFile();
|
|
||||||
$handler->getSpecification()->getConnexionFile();
|
|
||||||
|
|
||||||
$this->installed = true;
|
|
||||||
}
|
|
||||||
catch (\Exception $e)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
return new self($specifications, $environment);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function __construct(Configuration\Specification $specifications, $environment = null)
|
||||||
* Getter
|
|
||||||
* @return Configuration\Handler
|
|
||||||
*/
|
|
||||||
public function getConfigurationHandler()
|
|
||||||
{
|
{
|
||||||
return $this->configurationHandler;
|
$this->specifications = $specifications;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
$configurations = $this->specifications->getConfigurations();
|
||||||
* Setter
|
$environment = $environment ? : $configurations[self::KEYWORD_ENV];
|
||||||
* @param Configuration\Handler $configurationHandler
|
|
||||||
*/
|
$this->setEnvironnement($environment);
|
||||||
public function setConfigurationHandler(Configuration\Handler $configurationHandler)
|
|
||||||
{
|
return $this;
|
||||||
$this->configurationHandler = $configurationHandler;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -94,10 +65,6 @@ class Configuration
|
|||||||
*/
|
*/
|
||||||
public function getEnvironnement()
|
public function getEnvironnement()
|
||||||
{
|
{
|
||||||
if (null === $this->environment && $this->isInstalled())
|
|
||||||
{
|
|
||||||
$this->refresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->environment;
|
return $this->environment;
|
||||||
}
|
}
|
||||||
@@ -107,10 +74,21 @@ class Configuration
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function setEnvironnement($environement = null)
|
public function setEnvironnement($environment)
|
||||||
{
|
{
|
||||||
$this->environment = $environement;
|
$this->environment = $environment;
|
||||||
$this->refresh();
|
|
||||||
|
if ($this->specifications->isSetup())
|
||||||
|
{
|
||||||
|
$configurations = $this->specifications->getConfigurations();
|
||||||
|
$this->configuration = new ParameterBag($configurations[$this->environment]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->configuration = new ParameterBag(array());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -183,7 +161,7 @@ class Configuration
|
|||||||
*/
|
*/
|
||||||
public function getPhraseanet()
|
public function getPhraseanet()
|
||||||
{
|
{
|
||||||
$phraseanetConf = $this->getConfiguration()->get('phraseanet');
|
$phraseanetConf = $this->configuration->get('phraseanet');
|
||||||
|
|
||||||
return new ParameterBag($phraseanetConf);
|
return new ParameterBag($phraseanetConf);
|
||||||
}
|
}
|
||||||
@@ -195,30 +173,49 @@ class Configuration
|
|||||||
*/
|
*/
|
||||||
public function isInstalled()
|
public function isInstalled()
|
||||||
{
|
{
|
||||||
return $this->installed;
|
return $this->specifications->isSetup();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function initialize()
|
||||||
* Return the configuration
|
|
||||||
*
|
|
||||||
* @return ParameterBag\ParameterBag
|
|
||||||
*/
|
|
||||||
public function getConfiguration()
|
|
||||||
{
|
{
|
||||||
|
return $this->specifications->initialize();
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->installed && null === $this->configuration)
|
public function setConfigurations($configurations)
|
||||||
{
|
{
|
||||||
$configuration = $this->configurationHandler->handle($this->environment);
|
return $this->specifications->setConfigurations($configurations);
|
||||||
$this->environment = $this->configurationHandler->getSelectedEnvironnment();
|
}
|
||||||
$this->configuration = new ParameterBag($configuration);
|
|
||||||
}
|
|
||||||
elseif (!$this->installed)
|
|
||||||
{
|
|
||||||
$configuration = array();
|
|
||||||
$this->configuration = new ParameterBag($configuration);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->configuration;
|
public function setServices($services)
|
||||||
|
{
|
||||||
|
return $this->specifications->setServices($services);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setConnexions($connexions)
|
||||||
|
{
|
||||||
|
return $this->specifications->setConnexions($connexions);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getConfigurations()
|
||||||
|
{
|
||||||
|
return $this->specifications->getConfigurations();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getServices()
|
||||||
|
{
|
||||||
|
return $this->specifications->getServices();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getConnexions()
|
||||||
|
{
|
||||||
|
return $this->specifications->getConnexions();
|
||||||
|
}
|
||||||
|
|
||||||
|
const KEYWORD_ENV = 'environment';
|
||||||
|
|
||||||
|
public function getSelectedEnvironnment()
|
||||||
|
{
|
||||||
|
return $this->selectedEnvironnment;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -230,130 +227,12 @@ class Configuration
|
|||||||
{
|
{
|
||||||
$connexions = $this->getConnexions();
|
$connexions = $this->getConnexions();
|
||||||
|
|
||||||
try
|
if (!isset($connexions[$name]))
|
||||||
{
|
{
|
||||||
$conn = $connexions->get($name);
|
throw new \Exception(sprintf('Unknown connexion name %s', $name));
|
||||||
}
|
|
||||||
catch (\Exception $e)
|
|
||||||
{
|
|
||||||
throw new \Exception(sprintf('Unknow connexion name %s declared in %s'
|
|
||||||
, $name
|
|
||||||
, $this->configurationHandler
|
|
||||||
->getSpecification()
|
|
||||||
->getConnexionFile()
|
|
||||||
->getFileName()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Parameterbag($conn);
|
return new Parameterbag($connexions[$name]);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return all connexions defined in connexions.yml
|
|
||||||
* @return ParameterBag
|
|
||||||
*/
|
|
||||||
public function getConnexions()
|
|
||||||
{
|
|
||||||
return new ParameterBag($this->configurationHandler->getParser()->parse(
|
|
||||||
$this->configurationHandler->getSpecification()->getConnexionFile()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a the configuration file as an SplFileObject
|
|
||||||
*
|
|
||||||
* @return \SplFileObject
|
|
||||||
*/
|
|
||||||
public function getFile()
|
|
||||||
{
|
|
||||||
return $this->configurationHandler->getSpecification()->getConfigurationFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the full configuration file as an Array
|
|
||||||
*
|
|
||||||
* @return Array
|
|
||||||
*/
|
|
||||||
public function all()
|
|
||||||
{
|
|
||||||
$allConf = $this->configurationHandler->getParser()->parse($this->getFile());
|
|
||||||
|
|
||||||
return $allConf;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return all services defined in services.yml
|
|
||||||
* @return ParameterBag
|
|
||||||
*/
|
|
||||||
public function getServices()
|
|
||||||
{
|
|
||||||
return new ParameterBag($this->configurationHandler->getParser()->parse(
|
|
||||||
$this->getServiceFile()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write datas in config file
|
|
||||||
*
|
|
||||||
* @param array $data
|
|
||||||
* @param type $flag
|
|
||||||
* @return Configuration
|
|
||||||
*/
|
|
||||||
public function write(Array $data, $flag = 0, $delete = false)
|
|
||||||
{
|
|
||||||
if ($delete)
|
|
||||||
{
|
|
||||||
$this->delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
$yaml = $this->configurationHandler->getParser()->dump($data, 5);
|
|
||||||
|
|
||||||
$filePathName = $this->configurationHandler
|
|
||||||
->getSpecification()
|
|
||||||
->getConfigurationPathName();
|
|
||||||
|
|
||||||
if (false === file_put_contents($filePathName, $yaml, $flag))
|
|
||||||
{
|
|
||||||
$filePath = $this->configurationHandler
|
|
||||||
->getSpecification()
|
|
||||||
->getConfigurationFilePath();
|
|
||||||
throw new \Exception(sprintf(_('Impossible d\'ecrire dans le dossier %s'), $filePath));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete configuration file
|
|
||||||
* @return Configuration
|
|
||||||
*/
|
|
||||||
public function delete()
|
|
||||||
{
|
|
||||||
$deleted = false;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
$filePathName = $this
|
|
||||||
->configurationHandler
|
|
||||||
->getSpecification()
|
|
||||||
->getConfigurationPathName();
|
|
||||||
|
|
||||||
$deleted = unlink($filePathName);
|
|
||||||
}
|
|
||||||
catch (\Exception $e)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$deleted)
|
|
||||||
{
|
|
||||||
throw new \Exception(sprintf(_('Impossible d\'effacer le fichier %s'), $filePathName));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -362,17 +241,17 @@ class Configuration
|
|||||||
*/
|
*/
|
||||||
public function getTemplating()
|
public function getTemplating()
|
||||||
{
|
{
|
||||||
return 'TemplateEngine\\' . $this->getConfiguration()->get('template_engine');
|
return 'TemplateEngine\\' . $this->configuration->get('template_engine');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCache()
|
public function getCache()
|
||||||
{
|
{
|
||||||
return 'Cache\\' . $this->getConfiguration()->get('cache');
|
return 'Cache\\' . $this->configuration->get('cache');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOpcodeCache()
|
public function getOpcodeCache()
|
||||||
{
|
{
|
||||||
return 'Cache\\' . $this->getConfiguration()->get('opcodecache');
|
return 'Cache\\' . $this->configuration->get('opcodecache');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -381,7 +260,7 @@ class Configuration
|
|||||||
*/
|
*/
|
||||||
public function getOrm()
|
public function getOrm()
|
||||||
{
|
{
|
||||||
return 'Orm\\' . $this->getConfiguration()->get('orm');
|
return 'Orm\\' . $this->configuration->get('orm');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -393,7 +272,7 @@ class Configuration
|
|||||||
public function getService($name)
|
public function getService($name)
|
||||||
{
|
{
|
||||||
$scopes = explode('\\', $name);
|
$scopes = explode('\\', $name);
|
||||||
$services = $this->getServices();
|
$services = new ParameterBag($this->getServices());
|
||||||
$service = null;
|
$service = null;
|
||||||
|
|
||||||
while ($scopes)
|
while ($scopes)
|
||||||
@@ -407,65 +286,11 @@ class Configuration
|
|||||||
}
|
}
|
||||||
catch (\Exception $e)
|
catch (\Exception $e)
|
||||||
{
|
{
|
||||||
throw new \Exception(sprintf('Unknow service name %s declared in %s'
|
throw new \Exception(sprintf('Unknow service name %s', $name));
|
||||||
, $scope
|
|
||||||
, $this->configurationHandler
|
|
||||||
->getSpecification()
|
|
||||||
->getServiceFile()
|
|
||||||
->getFileName()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $service;
|
return $service;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* return the service file
|
|
||||||
* @return \SplFileObject
|
|
||||||
*/
|
|
||||||
public function getServiceFile()
|
|
||||||
{
|
|
||||||
return $this->configurationHandler->getSpecification()->getServiceFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the connexion file
|
|
||||||
* @return \SplFileObject
|
|
||||||
*/
|
|
||||||
public function getConnexionFile()
|
|
||||||
{
|
|
||||||
return $this->configurationHandler->getSpecification()->getConnexionFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Refresh the configuration
|
|
||||||
* @return Configuration
|
|
||||||
*/
|
|
||||||
public function refresh()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
$this->configurationHandler->getSpecification()->getConfigurationFile();
|
|
||||||
$this->configurationHandler->getSpecification()->getServiceFile();
|
|
||||||
$this->configurationHandler->getSpecification()->getConnexionFile();
|
|
||||||
|
|
||||||
$this->installed = true;
|
|
||||||
}
|
|
||||||
catch (\Exception $e)
|
|
||||||
{
|
|
||||||
$this->installed = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->installed)
|
|
||||||
{
|
|
||||||
$configuration = $this->configurationHandler->handle($this->environment);
|
|
||||||
$this->environment = $this->configurationHandler->getSelectedEnvironnment();
|
|
||||||
$this->configuration = new ParameterBag($configuration);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,114 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Phraseanet
|
|
||||||
*
|
|
||||||
* (c) 2005-2010 Alchemy
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Alchemy\Phrasea\Core\Configuration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Precise some informations about phraseanet configuration mechanism
|
|
||||||
*
|
|
||||||
* @package
|
|
||||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
|
||||||
* @link www.phraseanet.com
|
|
||||||
*/
|
|
||||||
class Application implements Specification
|
|
||||||
{
|
|
||||||
const DEFAULT_ENV = 'prod';
|
|
||||||
const KEYWORD_ENV = 'environment';
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function getConfigurationFilePath()
|
|
||||||
{
|
|
||||||
return realpath(__DIR__ . '/../../../../../config');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function getConfigurationPathName()
|
|
||||||
{
|
|
||||||
$path = sprintf(
|
|
||||||
'%s/%s.%s'
|
|
||||||
, $this->getConfigurationFilePath()
|
|
||||||
, $this->getConfigurationFileName()
|
|
||||||
, $this->getConfigurationFileExtension()
|
|
||||||
);
|
|
||||||
|
|
||||||
return $path;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function getConfigurationFileName()
|
|
||||||
{
|
|
||||||
return 'config';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function getConfigurationFileExtension()
|
|
||||||
{
|
|
||||||
return 'yml';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the selected environnment from configuration file
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getSelectedEnv(Array $config)
|
|
||||||
{
|
|
||||||
if (!isset($config[self::KEYWORD_ENV]))
|
|
||||||
{
|
|
||||||
return self::DEFAULT_ENV;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $config[self::KEYWORD_ENV];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the main configuration file
|
|
||||||
*
|
|
||||||
* @return \SplFileObject
|
|
||||||
*/
|
|
||||||
public function getConfigurationFile()
|
|
||||||
{
|
|
||||||
return new \SplFileObject($this->getConfigurationPathName());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the main configuration file
|
|
||||||
*
|
|
||||||
* @return \SplFileObject
|
|
||||||
*/
|
|
||||||
public function getServiceFile()
|
|
||||||
{
|
|
||||||
return new \SplFileObject(realpath(__DIR__ . '/../../../../../config/services.yml'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the main configuration file
|
|
||||||
*
|
|
||||||
* @return \SplFileObject
|
|
||||||
*/
|
|
||||||
public function getConnexionFile()
|
|
||||||
{
|
|
||||||
return new \SplFileObject(realpath(__DIR__ . '/../../../../../config/connexions.yml'));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -0,0 +1,163 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Phraseanet
|
||||||
|
*
|
||||||
|
* (c) 2005-2010 Alchemy
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Alchemy\Phrasea\Core\Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Precise some informations about phraseanet configuration mechanism
|
||||||
|
*
|
||||||
|
* @package
|
||||||
|
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||||
|
* @link www.phraseanet.com
|
||||||
|
*/
|
||||||
|
class ApplicationSpecification implements Specification
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $parser;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->parser = new \Symfony\Component\Yaml\Yaml();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setConfigurations($configurations)
|
||||||
|
{
|
||||||
|
return file_put_contents(
|
||||||
|
$this->getConfigurationsPathFile(), $this->parser->dump($configurations, 5)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setConnexions($connexions)
|
||||||
|
{
|
||||||
|
return file_put_contents(
|
||||||
|
$this->getConnexionsPathFile(), $this->parser->dump($connexions, 5)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setServices($services)
|
||||||
|
{
|
||||||
|
return file_put_contents(
|
||||||
|
$this->getServicesPathFile(), $this->parser->dump($services, 5)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getConfigurations()
|
||||||
|
{
|
||||||
|
return $this->parser->parse(
|
||||||
|
file_get_contents($this->getConfigurationsPathFile())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getConnexions()
|
||||||
|
{
|
||||||
|
return $this->parser->parse(
|
||||||
|
file_get_contents($this->getConnexionsPathFile())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getServices()
|
||||||
|
{
|
||||||
|
return $this->parser->parse(
|
||||||
|
file_get_contents($this->getServicesPathFile())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getConfigurationsFile()
|
||||||
|
{
|
||||||
|
return new \SplFileObject($this->getConfigurationsPathFile());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getConnexionsFile()
|
||||||
|
{
|
||||||
|
return new \SplFileObject($this->getConnexionsPathFile());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getServicesFile()
|
||||||
|
{
|
||||||
|
return new \SplFileObject($this->getServicesPathFile());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete()
|
||||||
|
{
|
||||||
|
$files = array(
|
||||||
|
$this->getConnexionsPathFile(),
|
||||||
|
$this->getConfigurationsPathFile(),
|
||||||
|
$this->getServicesPathFile()
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($files as $file)
|
||||||
|
{
|
||||||
|
if (file_exists($file))
|
||||||
|
unlink($file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function initialize()
|
||||||
|
{
|
||||||
|
touch($this->getConnexionsPathFile());
|
||||||
|
touch($this->getConfigurationsPathFile());
|
||||||
|
touch($this->getServicesPathFile());
|
||||||
|
|
||||||
|
copy(
|
||||||
|
$this->getRealRootPath() . "/config/config.sample.yml"
|
||||||
|
, $this->getRealRootPath() . "/config/config.yml"
|
||||||
|
);
|
||||||
|
|
||||||
|
copy(
|
||||||
|
$this->getRealRootPath() . "/config/services.sample.yml"
|
||||||
|
, $this->getRealRootPath() . "/config/services.yml"
|
||||||
|
);
|
||||||
|
|
||||||
|
if (function_exists('chmod'))
|
||||||
|
{
|
||||||
|
chmod($this->getConnexionsPathFile(), 0700);
|
||||||
|
chmod($this->getConfigurationsPathFile(), 0700);
|
||||||
|
chmod($this->getServicesPathFile(), 0700);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isSetup()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$this->getConfigurationsFile();
|
||||||
|
$this->getConnexionsFile();
|
||||||
|
$this->getServicesFile();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (\Exception $e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getConfigurationsPathFile()
|
||||||
|
{
|
||||||
|
return $this->getRealRootPath() . '/config/config.yml';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getConnexionsPathFile()
|
||||||
|
{
|
||||||
|
return $this->getRealRootPath() . '/config/connexions.yml';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getServicesPathFile()
|
||||||
|
{
|
||||||
|
return $this->getRealRootPath() . '/config/services.yml';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getRealRootPath()
|
||||||
|
{
|
||||||
|
return realpath(__DIR__ . '/../../../../../');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -1,108 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Phraseanet
|
|
||||||
*
|
|
||||||
* (c) 2005-2010 Alchemy
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Alchemy\Phrasea\Core\Configuration;
|
|
||||||
|
|
||||||
use \Symfony\Component\Yaml\Yaml;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle configuration mechanism
|
|
||||||
*
|
|
||||||
* @package
|
|
||||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
|
||||||
* @link www.phraseanet.com
|
|
||||||
*/
|
|
||||||
class Handler
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Configuration file specification interface
|
|
||||||
* @var ConfigurationSpecification
|
|
||||||
*/
|
|
||||||
protected $confSpecification;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A file parser interface
|
|
||||||
* @var Parser\ParserInterface
|
|
||||||
*/
|
|
||||||
protected $parser;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The environnment selected
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $selectedEnvironnment;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tell handler the configuration specification ans which parser to use
|
|
||||||
*
|
|
||||||
* @param ConfigurationSpecification $configSpec
|
|
||||||
* @param Parser\ParserInterface $parser
|
|
||||||
*/
|
|
||||||
public function __construct(Specification $configSpec, Parser $parser)
|
|
||||||
{
|
|
||||||
$this->confSpecification = $configSpec;
|
|
||||||
$this->parser = $parser;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Getter
|
|
||||||
* @return Specification
|
|
||||||
*/
|
|
||||||
public function getSpecification()
|
|
||||||
{
|
|
||||||
return $this->confSpecification;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Getter
|
|
||||||
* @return Parser
|
|
||||||
*/
|
|
||||||
public function getParser()
|
|
||||||
{
|
|
||||||
return $this->parser;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle the configuration process and return the final configuration
|
|
||||||
*
|
|
||||||
* @param strinig $name the name of the loaded environnement
|
|
||||||
* @return Array
|
|
||||||
*/
|
|
||||||
public function handle($selectedEnv = null)
|
|
||||||
{
|
|
||||||
//get the correspondant file
|
|
||||||
$file = $this->confSpecification->getConfigurationFile();
|
|
||||||
//parse
|
|
||||||
$env = $this->parser->parse($file);
|
|
||||||
|
|
||||||
//get selected env
|
|
||||||
if (null === $selectedEnv)
|
|
||||||
{
|
|
||||||
$selectedEnv = $this->confSpecification->getSelectedEnv($env);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->selectedEnvironnment = $selectedEnv;
|
|
||||||
|
|
||||||
if (!isset($env[$selectedEnv]))
|
|
||||||
{
|
|
||||||
throw new \Exception(sprintf("The choosen development environment '%s' is not declared in %s", $selectedEnv, $file->getFileName()));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $env[$selectedEnv];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getSelectedEnvironnment()
|
|
||||||
{
|
|
||||||
return $this->selectedEnvironnment;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@@ -1,40 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Phraseanet
|
|
||||||
*
|
|
||||||
* (c) 2005-2010 Alchemy
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Alchemy\Phrasea\Core\Configuration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A interface to parse configuration file
|
|
||||||
*
|
|
||||||
* @package
|
|
||||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
|
||||||
* @link www.phraseanet.com
|
|
||||||
*/
|
|
||||||
interface Parser
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse the configuration file $file to an array
|
|
||||||
*
|
|
||||||
* @param \SplFileObject $file the file to parse
|
|
||||||
* @return Array
|
|
||||||
*/
|
|
||||||
public function parse(\SplFileObject $file);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Dump into string from array
|
|
||||||
*
|
|
||||||
* @param $conf
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function dump(Array $conf, $level);
|
|
||||||
|
|
||||||
}
|
|
@@ -1,49 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Phraseanet
|
|
||||||
*
|
|
||||||
* (c) 2005-2010 Alchemy
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
namespace Alchemy\Phrasea\Core\Configuration\Parser;
|
|
||||||
|
|
||||||
use Symfony\Component\Yaml\Yaml as SfYaml;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse a configuration file in yaml format and return an array of values
|
|
||||||
*
|
|
||||||
* @package
|
|
||||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
|
||||||
* @link www.phraseanet.com
|
|
||||||
*/
|
|
||||||
class Yaml implements \Alchemy\Phrasea\Core\Configuration\Parser
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @Override
|
|
||||||
*/
|
|
||||||
public function parse(\SplFileObject $file)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return SfYaml::parse($file->getPathname());
|
|
||||||
}
|
|
||||||
catch(\Exception $e)
|
|
||||||
{
|
|
||||||
throw new \Exception(sprintf('Failed to parse the configuration file %s', $e->getMessage()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @Override
|
|
||||||
*/
|
|
||||||
public function dump(Array $conf, $level = 1)
|
|
||||||
{
|
|
||||||
return SfYaml::dump($conf, $level);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -21,32 +21,22 @@ namespace Alchemy\Phrasea\Core\Configuration;
|
|||||||
interface Specification
|
interface Specification
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
public function setConfigurations($configurations);
|
||||||
* Return the pathname of the configuration file
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getConfigurationPathName();
|
|
||||||
|
|
||||||
/**
|
public function setConnexions($connexions);
|
||||||
* Return the path to the configuration file
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getConfigurationFilePath();
|
|
||||||
|
|
||||||
/**
|
public function setServices($services);
|
||||||
* Return the configurationFile extension
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getConfigurationFileExtension();
|
|
||||||
|
|
||||||
/**
|
public function getConfigurations();
|
||||||
* Return the name of the configuration file
|
|
||||||
*
|
public function getConnexions();
|
||||||
* @return string
|
|
||||||
*/
|
public function getServices();
|
||||||
public function getConfigurationFileName();
|
|
||||||
|
public function initialize();
|
||||||
|
|
||||||
|
public function delete();
|
||||||
|
|
||||||
|
public function isSetup();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -29,15 +29,6 @@ use Doctrine\ORM\Events as DoctrineEvents;
|
|||||||
class Doctrine extends ServiceAbstract implements ServiceInterface
|
class Doctrine extends ServiceAbstract implements ServiceInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
const ARRAYCACHE = 'array';
|
|
||||||
const MEMCACHE = 'memcache';
|
|
||||||
const XCACHE = 'xcache';
|
|
||||||
const REDIS = 'redis';
|
|
||||||
const APC = 'apc';
|
|
||||||
|
|
||||||
protected $caches = array(
|
|
||||||
self::MEMCACHE, self::APC, self::ARRAYCACHE, self::XCACHE, self::REDIS
|
|
||||||
);
|
|
||||||
protected $outputs = array(
|
protected $outputs = array(
|
||||||
'json', 'yaml', 'vdump'
|
'json', 'yaml', 'vdump'
|
||||||
);
|
);
|
||||||
@@ -50,7 +41,7 @@ class Doctrine extends ServiceAbstract implements ServiceInterface
|
|||||||
|
|
||||||
public function __construct(Core $core, $name, Array $options)
|
public function __construct(Core $core, $name, Array $options)
|
||||||
{
|
{
|
||||||
parent::__construct( $core, $name, $options);
|
parent::__construct($core, $name, $options);
|
||||||
|
|
||||||
$config = new \Doctrine\ORM\Configuration();
|
$config = new \Doctrine\ORM\Configuration();
|
||||||
|
|
||||||
@@ -126,27 +117,16 @@ class Doctrine extends ServiceAbstract implements ServiceInterface
|
|||||||
}
|
}
|
||||||
catch (\Exception $e)
|
catch (\Exception $e)
|
||||||
{
|
{
|
||||||
$connexionFile = $this
|
throw new \Exception("Connexion '%s' is not declared");
|
||||||
->core->getConfiguration()
|
|
||||||
->getConfigurationHandler()
|
|
||||||
->getSpecification()
|
|
||||||
->getConnexionFile();
|
|
||||||
|
|
||||||
throw new \Exception(sprintf(
|
|
||||||
"Connexion '%s' is not declared in %s"
|
|
||||||
, $connexion
|
|
||||||
, $connexionFile->getFileName()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$evm = new \Doctrine\Common\EventManager();
|
$evm = new \Doctrine\Common\EventManager();
|
||||||
|
|
||||||
$evm->addEventSubscriber(new \Gedmo\Timestampable\TimestampableListener());
|
$evm->addEventSubscriber(new \Gedmo\Timestampable\TimestampableListener());
|
||||||
|
|
||||||
// $evm->addEventListener(DoctrineEvents::postUpdate, new ClearCacheListener());
|
$evm->addEventListener(DoctrineEvents::postUpdate, new ClearCacheListener());
|
||||||
// $evm->addEventListener(DoctrineEvents::postRemove, new ClearCacheListener());
|
$evm->addEventListener(DoctrineEvents::postRemove, new ClearCacheListener());
|
||||||
// $evm->addEventListener(DoctrineEvents::postPersist, new ClearCacheListener());
|
$evm->addEventListener(DoctrineEvents::postPersist, new ClearCacheListener());
|
||||||
|
|
||||||
|
|
||||||
try
|
try
|
||||||
|
Reference in New Issue
Block a user