This commit is contained in:
Romain Neutron
2012-01-11 21:06:33 +01:00
34 changed files with 1223 additions and 818 deletions

View File

@@ -35,12 +35,25 @@ try
); );
$configuration = new \Alchemy\Phrasea\Core\Configuration($handler); $configuration = new \Alchemy\Phrasea\Core\Configuration($handler);
$doctrine = new Phrasea\Core\Service\Doctrine($configuration->getDoctrine()->all()); $serviceName = $configuration->getOrm();
$confService = $configuration->getService($serviceName);
$app = new Application("Phraseanet Doctrine Console", $doctrine->getVersion()); if($confService->get("type") !== 'doctrine')
{
exit(sprintf("Doctrine is not declared as your ORM but %s is", $confService->get("type")));
}
$ormService = \Alchemy\Phrasea\Core\ServiceBuilder::build(
$serviceName
, \Alchemy\Phrasea\Core\ServiceBuilder::ORM
, $confService->get("type")
, $confService->get("options")
);
$em = $doctrine->getEntityManager(); $em = $ormService->getService();
/* @var $em \Doctrine\ORM\EntityManager */
$app = new Application("Phraseanet Doctrine Console", $ormService->getVersion());
$helpers = array( $helpers = array(
'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()), 'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),

View File

@@ -4,7 +4,7 @@
environment : dev environment : dev
#declare all your environment configuration #Declare all your environment configurations
################# #################
# DEVELOPPEMENT # # DEVELOPPEMENT #
@@ -16,80 +16,15 @@ dev:
maintenance: false maintenance: false
debug: true debug: true
display_errors: true display_errors: true
#Configure your phraseanet application connection
database:
host: <YOUR_HOST>
port: <YOUR_PORT>
dbname: <YOUR_DB_NAME>
user: <YOUR_USERNAME>
password: <YOUR_PASSWORD>
# Doctrine scope refers to Doctrine configuration #Assign your phraseanet application connection
# Pls refer to Doctrine documentation abstraction layer for database connection configuration #Connections are defined in connexions.yml configuration file
# DBAL connection : http://www.doctrine-project.org/docs/dbal/2.1/en/reference/configuration.html database: main_connexion
doctrine:
#configure the doctrine database connection
dbal:
driver: <YOUR_DRIVER>
host: <YOUR_HOST>
port: <YOUR_PORT>
dbname: <YOUR_DB_NAME>
user: <YOUR_USERNAME>
password: <YOUR_PASSWORD>
charset: UTF8
#configure orm
orm:
#Available cache driver [memcached, apc, array]
#Query cache : is used to cache the transformation of a DQL query to its SQL counterpart
#Result cache : is used to cache the results of your queries
#Metadata cache : is used to cache entity class metadatas
cache:
query: array
result: array
metadata: array
#Configure how to log SQL query #Assign your template engine service & ORM service
#Available type values [echo , monolog] #Services are defined in service.yml configuration file
# echo : logs to the standard output using echo/var_dump. template_engine: twig_debug
# monolog : logs with monolog service using different log handler orm: doctrine_dev
log:
#Active logs
enable: false
#Define how logs are handling
#Available type values [echo , monolog]
# echo : logs to the standard output using echo/var_dump.
# monolog : logs with monolog service using different log handler
type: monolog
#Define which handler to use see monolog configuration scope
handler: rotate
#Define output of logs
#Available output [normal, json, yaml]
# normal : output logs in a var_dump formatted style
# json : output logs in json
# yml : output logs yml
output: json
#Define the logs filename
filename: dev-doctrine-query.log
#Define how many day of logs is keeping. Override default value
max_day: 2
# Monolog Service Configuration
# Handlers type [stream, rotatingFile]
# stream : store logs to a single file
# rotatingFile: logs to files that are rotated every day and a limited number of files are kept
monolog:
#Define default ouput
output: yaml
#Define handlers
#Only stream & rotating file are currently available
handlers:
main:
type: stream
#Rotate handler is used to rotate logs every day in a new file
#max_day is used to keep the defined number of day logs
rotate:
type: rotatingFile
max_day: 10
############## ##############
# PRODUCTION # # PRODUCTION #
@@ -100,42 +35,10 @@ prod:
maintenance: false maintenance: false
debug: false debug: false
display_errors: false display_errors: false
database: database: main_connexion
host: <YOUR_HOST>
port: <YOUR_PORT>
dbname: <YOUR_DB_NAME>
user: <YOUR_USERNAME>
password: <YOUR_USERNAME>
doctrine: template_engine: twig
dbal: orm: doctrine_prod
driver: <YOUR_DRIVER>
host: <YOUR_HOST>
port: <YOUR_PORT>
dbname: <YOUR_DB_NAME>
user: <YOUR_USERNAME>
password: <YOUR_PASSWORD>
charset: UTF8
orm:
cache:
query: apc
result: apc
metadata: apc
log:
enable: true
type: monolog
handler: rotate
output: json
filename: prod-doctrine-query.log
monolog:
output: yaml
handlers:
main:
type: stream
rotate:
type: rotatingFile
max_day: 10
############## ##############
# TEST # # TEST #
@@ -146,37 +49,9 @@ test:
maintenance: false maintenance: false
debug: true debug: true
display_errors: true display_errors: true
database: database: main_connexion
host: <YOUR_HOST>
port: <YOUR_PORT> template_engine: twig_debug
dbname: <YOUR_DB_NAME> orm: doctrine_dev
user: <YOUR_USERNAME>
password: <YOUR_USERNAME>
#doctrine use a sqlite base to run tests
doctrine:
dbal:
driver: pdo_sqlite
path: <PATH_TO_A_SQLITE_DB>
charset: UTF8
orm:
cache:
query: array
result: array
metadata: array
log:
enable: true
type: monolog
handler: rotate
output: json
filename: test-doctrine-query.log
monolog:
output: yaml
handlers:
main:
type: stream
rotate:
type: rotatingFile
max_day: 10

View File

@@ -0,0 +1,19 @@
#Here you can define many connexions configurations
#Please refer to Doctrine documentation abstraction layer for database connection configuration
#DBAL connection : http://www.doctrine-project.org/docs/dbal/2.1/en/reference/configuration.html
#Define a connexion to MYSQL database named main_connexion
main_connexion:
host: <HOSTNAME>
port: <PORT>
user: <USERNAME>
password: <PASSWORD>
dbname: <DATABASE_NAME>
driver: pdo_mysql
charset: UTF8
#Define a connexion to a SQLite database named test_connexion
test_connexion:
driver: pdo_sqlite
path: /PATH/TO/SQLITE/DATABASE
charset: UTF8

View File

@@ -1,7 +0,0 @@
#Twig services options
twig:
options:
charset: utf-8
strict_variables: true
autoescape: true
optimizer: true

113
config/services.sample.yml Normal file
View File

@@ -0,0 +1,113 @@
#Define a template engine service
#Only Twig is avalaible as a template engine service
#see http://twig.sensiolabs.org/
#Define the service name first
twig:
#Template engine type
type: twig
options:
#When set to true, the generated templates have a __toString() method that you can use to display the generated nodes
debug: false
#The charset used by the templates
charset: utf-8
#Twig will silently ignore invalid variables (variables and or attributes/methods that do not exist)
#And replace them with a null value. When set to true, Twig throws an exception instead (default to false)
strict_variables: true
#Escaper adds automatic output escaping to Twig. It defines a new tag, autoescape, and a new filter, raw
autoescape: true
#Optimize the node tree before compilation
optimizer: true
twig_debug:
type: twig
options:
debug: true
charset: utf-8
strict_variables: true
autoescape: true
optimizer: true
#Doctrine developement service options
#Service name
doctrine_dev:
type: doctrine
options:
#Set automatically propers values for debug
#Query & result caches are setted to Array cache
#Auto-generating Proxy Classes is setted to false
debug: true
#Assign a connexion from connexions.yml to the DataBase Abstraction Layer
dbal: main_connexion
orm:
#Available cache driver [memcached, apc, array]
#Query cache : is used to cache the transformation of a DQL query to its SQL counterpart
#Result cache : is used to cache the results of your queries
#Metadata cache : is used to cache entity class metadatas
cache:
query: array
result: array
metadata: array
# Assign a service to log doctrine queries
log: query_logger
# Doctrine test service options
doctrine_test:
type: doctrine
options:
debug: true
#Doctrine use a different connection configuration base to run tests
dbal: test_connexion
orm:
cache:
query: array
result: array
metadata: array
log: query_logger
# Doctrine production service options
doctrine_prod:
type: doctrine
options:
debug: false
dbal: main_connexion
orm:
cache:
query: apc
result: apc
metadata: apc
log: query_logger
# Define a Log service
# This one is defined to handle the logs of doctrine queries
# Only Monolog is available as a logger service
# Please Notice that for doctrine ONLY a echo logger service is available, see below
# Monolog logger use the PHP Monolog library to handle logs using differents handlers
query_logger:
type: monolog
options:
#You can precise the output format
#This option is only available when log are used to log doctrine queries
#Available output [normal, json, yaml]
# normal : output logs in a var_dump formatted style
# json : output logs in json
# yml : output logs yml
output: json
#Name used for the Monolog channel
channel: query-logger
#Define how the logs will be handled
#Avalaibale Handler are [rotate, stream]
#Rotate handler is used to stores logs to files that are rotated every day
#And a limited number of files are kept by defining the max_day value
#Stream handler is used to stores logs in a single local file
handler: rotate
max_day: 2
#Name of the file where logs are written
filename: doctrine-query.log
# Define a echo log service for Doctrine
# echo logger logs doctrine queries to the standard output using echo/var_dump
# Notice that echo logger do not have options
sql_logger:
type: echo

View File

@@ -46,39 +46,99 @@ return call_user_func(function()
} }
elseif (\setup::needUpgradeConfigurationFile()) elseif (\setup::needUpgradeConfigurationFile())
{ {
//copy sample $registry = \registry::get_instance();
$file = __DIR__ . "/../../../../config/config.sample.yml";
$file1 = __DIR__ . "/../../../../config/config.yml"; //copy config sample
if (!copy($file, $file1)) $configSampleFile = __DIR__ . "/../../../../config/config.sample.yml";
$configFile = __DIR__ . "/../../../../config/config.yml";
if (!copy($configSampleFile, $configFile))
{ {
throw new \Exception(sprintf("Unable to copy %s", $file1)); throw new \Exception(sprintf("Unable to copy %s", $configSampleFile));
} }
//get connexion credentials //copy service sample
$conn = \connection::getPDOConnection(); $serviceSampleFile = __DIR__ . "/../../../../config/services.sample.yml";
$credentials = $conn->get_credentials(); $serviceFile = __DIR__ . "/../../../../config/services.yml";
if (!copy($serviceSampleFile, $serviceFile))
{
throw new \Exception(sprintf("Unable to copy %s", $serviceSampleFile));
}
//copy connexion sample
$connexionSampleFile = __DIR__ . "/../../../../config/connexions.sample.yml";
$connexionFile = __DIR__ . "/../../../../config/connexions.yml";
if (!copy($connexionSampleFile, $connexionFile))
{
throw new \Exception(sprintf("Unable to copy %s", $connexionFile));
}
//get configuration object //get configuration object
$app = new \Alchemy\Phrasea\Core\Configuration\Application(); $appConf = new \Alchemy\Phrasea\Core\Configuration\Application();
$parser = new \Alchemy\Phrasea\Core\Configuration\Parser\Yaml(); $parser = new \Alchemy\Phrasea\Core\Configuration\Parser\Yaml();
$handler = new \Alchemy\Phrasea\Core\Configuration\Handler($app, $parser); $handler = new \Alchemy\Phrasea\Core\Configuration\Handler($appConf, $parser);
$configuration = new \Alchemy\Phrasea\Core\Configuration($handler); $configuration = new \Alchemy\Phrasea\Core\Configuration($handler);
//refactor credentials //refactor credentials
$connexionINI = array(); $connexionINI = array();
foreach ($credentials as $key => $value)
{ require __DIR__ . "/../../../../config/connexion.inc";
$key = $key == 'hostname' ? 'host' : $key;
$connexionINI[$key] = (string) $value; $connexionINI['host'] = $hostname;
} $connexionINI['port'] = $port;
//write credentials to config file $connexionINI['user'] = $user;
$configuration->setAllDatabaseConnexion($connexionINI); $connexionINI['password'] = $password;
$connexionINI['dbname'] = $dbname;
$connexionINI['driver'] = 'pdo_mysql';
$connexionINI['charset'] = 'UTF8';
$request = $app["request"]; $request = $app["request"];
//write servername //write servername
$serverName = $request->getScheme() . '://' . $request->getHttpHost() . '/'; $serverName = $request->getScheme() . '://' . $request->getHttpHost() . '/';
$configuration->setServerName($serverName);
$app->redirect("/"); //write credentials to connexion file
$connexionFile = $appConf->getConnexionFile();
$connexion = array(
'main_connexion' => $connexionINI,
'test_connexion' => array(
'driver' => 'pdo_sqlite',
'path' => $registry->get("GV_RootPath") . 'lib/unitTest/tests.sqlite',
'charset' => 'UTF8'
));
$yaml = $configuration->getConfigurationHandler()->getParser()->dump($connexion, 2);
if (!file_put_contents($connexionFile->getPathname(), $yaml) !== false)
{
throw new \Exception(sprintf(_('Impossible d\'ecrire dans le fichier %s'), $connexionFile->getPathname()));
}
//rewrite service file
$serviceFile = $appConf->getServiceFile();
$service = $configuration->getConfigurationHandler()->getParser()->parse($serviceFile);
$yaml = $configuration->getConfigurationHandler()->getParser()->dump($service, 5);
if (!file_put_contents($serviceFile->getPathname(), $yaml) !== false)
{
throw new \Exception(sprintf(_('Impossible d\'ecrire dans le fichier %s'), $serviceFile->getPathname()));
}
$arrayConf = $configuration->all();
//rewrite main conf
foreach ($arrayConf as $key => $value)
{
if (is_array($value) && array_key_exists('phraseanet', $value))
{
$arrayConf[$key]["phraseanet"]["servername"] = $serverName;
}
}
$configuration->write($arrayConf);
$app->redirect("/setup/installer/");
} }
else else
{ {

View File

@@ -98,10 +98,9 @@ class Installer implements ControllerProviderInterface
\phrasea::use_i18n(\Session_Handler::get_locale()); \phrasea::use_i18n(\Session_Handler::get_locale());
$ld_path = array(__DIR__ . '/../../../../../templates/web'); $ld_path = array(__DIR__ . '/../../../../../templates/web');
$loader = new \Twig_Loader_Filesystem($ld_path); $loader = new \Twig_Loader_Filesystem($ld_path);
$twig = new \Twig_Environment($loader);
$twig = new \Twig_Environment($loader);
$twig->addExtension(new \Twig_Extensions_Extension_I18n()); $twig->addExtension(new \Twig_Extensions_Extension_I18n());
$request = $app['request']; $request = $app['request'];
@@ -180,15 +179,25 @@ class Installer implements ControllerProviderInterface
new \Alchemy\Phrasea\Core\Configuration\Parser\Yaml() new \Alchemy\Phrasea\Core\Configuration\Parser\Yaml()
); );
$configuration = new \Alchemy\Phrasea\Core\Configuration($handler); $configuration = new \Alchemy\Phrasea\Core\Configuration($handler);
if ($configuration->isInstalled()) if ($configuration->isInstalled())
{ {
// Get Entity Manager using the new configuration $serviceName = $configuration->getOrm();
$doctrineConf = $configuration->getDoctrine()->all(); $confService = $configuration->getService($serviceName);
$doctrine = new \Alchemy\Phrasea\Core\Service\Doctrine($doctrineConf);
$em = $doctrine->getEntityManager(); $ormService = \Alchemy\Phrasea\Core\ServiceBuilder::build(
$serviceName
, \Alchemy\Phrasea\Core\ServiceBuilder::ORM
, $confService->get("type")
, $confService->get("options")
);
if ($ormService->getType() === 'doctrine')
{
/* @var $em \Doctrine\ORM\EntityManager */ /* @var $em \Doctrine\ORM\EntityManager */
$em = $ormService->getService();
$metadatas = $em->getMetadataFactory()->getAllMetadata(); $metadatas = $em->getMetadataFactory()->getAllMetadata();
if (!empty($metadatas)) if (!empty($metadatas))
@@ -199,6 +208,7 @@ class Installer implements ControllerProviderInterface
$tool->createSchema($metadatas); $tool->createSchema($metadatas);
} }
} }
}
$registry = \registry::get_instance(); $registry = \registry::get_instance();
\setup::create_global_values($registry); \setup::create_global_values($registry);

View File

@@ -50,13 +50,11 @@ class Core extends \Pimple
static::initAutoloads(); static::initAutoloads();
$handler = new \Alchemy\Phrasea\Core\Configuration\Handler( $handler = new Core\Configuration\Handler(
new \Alchemy\Phrasea\Core\Configuration\Application(), new Core\Configuration\Application(),
new \Alchemy\Phrasea\Core\Configuration\Parser\Yaml() new Core\Configuration\Parser\Yaml()
); );
$this->configuration = new \Alchemy\Phrasea\Core\Configuration($handler); $this->configuration = new Core\Configuration($handler, $environement);
$this->configuration->setEnvironnement($environement);
/** /**
* Set version * Set version
@@ -66,21 +64,35 @@ class Core extends \Pimple
return new Core\Version(); return new Core\Version();
}); });
$core = $this;
/** /**
* Set Entity Manager using configuration * Set Entity Manager using configuration
*/ */
$doctrineConf = $this->configuration->getDoctrine()->all(); $this['EM'] = $this->share(function() use ($core)
$this['EM'] = $this->share(function() use ($doctrineConf)
{ {
$doctrine = new Core\Service\Doctrine($doctrineConf); $serviceName = $core->getConfiguration()->getOrm();
return $doctrine->getEntityManager();
$service = $core->getService(
$serviceName
, Core\ServiceBuilder::ORM
);
return $service->getService();
}); });
$twigConf = $this->configuration->getServices()->get('twig');
$this["Twig"] = $this->share(function() use ($twigConf)
$this["Twig"] = $this->share(function() use ($core)
{ {
$twig = new Core\Service\Twig($twigConf); $serviceName = $core->getConfiguration()->getTemplating();
return $twig->getTwig();
$service = $core->getService(
$serviceName
, Core\ServiceBuilder::TEMPLATE_ENGINE
);
return $service->getService();
}); });
if (\setup::is_installed()) if (\setup::is_installed())
@@ -149,11 +161,9 @@ class Core extends \Pimple
* *
* @param type $environnement * @param type $environnement
*/ */
private function init($environnement) private function init()
{ {
$this->loadConf($environnement); if ($this->getConfiguration()->isDisplayingErrors())
if ($this->getConfiguration()->displayErrors())
{ {
ini_set('display_errors', 1); ini_set('display_errors', 1);
error_reporting(E_ALL); error_reporting(E_ALL);
@@ -375,7 +385,6 @@ class Core extends \Pimple
public static function initAutoloads() public static function initAutoloads()
{ {
require_once __DIR__ . '/../../vendor/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php'; require_once __DIR__ . '/../../vendor/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
require_once __DIR__ . '/../../vendor/Twig/lib/Twig/Autoloader.php'; require_once __DIR__ . '/../../vendor/Twig/lib/Twig/Autoloader.php';
require_once __DIR__ . '/../../vendor/Twig-extensions/lib/Twig/Extensions/Autoloader.php'; require_once __DIR__ . '/../../vendor/Twig-extensions/lib/Twig/Extensions/Autoloader.php';
@@ -388,13 +397,11 @@ class Core extends \Pimple
$loader->registerNamespaces(array( $loader->registerNamespaces(array(
'Alchemy' => __DIR__ . '/../..', 'Alchemy' => __DIR__ . '/../..',
'Symfony\\Component\\Yaml' => realpath(__DIR__ . '/../../vendor/symfony/src'), 'Symfony' => realpath(__DIR__ . '/../../vendor/symfony/src'),
'Symfony\\Component\\Console' => realpath(__DIR__ . '/../../vendor/symfony/src'),
'Symfony\\Component\\Serializer' => realpath(__DIR__ . '/../../vendor/symfony/src'),
'Symfony\\Component\\DependencyInjection' => realpath(__DIR__ . '/../../vendor/symfony/src'),
'Doctrine\\ORM' => realpath(__DIR__ . '/../../vendor/doctrine2-orm/lib'), 'Doctrine\\ORM' => realpath(__DIR__ . '/../../vendor/doctrine2-orm/lib'),
'Doctrine\\DBAL' => realpath(__DIR__ . '/../../vendor/doctrine2-orm/lib/vendor/doctrine-dbal/lib'), 'Doctrine\\DBAL' => realpath(__DIR__ . '/../../vendor/doctrine2-orm/lib/vendor/doctrine-dbal/lib'),
'Doctrine\\Common' => realpath(__DIR__ . '/../../vendor/doctrine2-orm/lib/vendor/doctrine-common/lib'), 'Doctrine\\Common' => realpath(__DIR__ . '/../../vendor/doctrine2-orm/lib/vendor/doctrine-common/lib'),
'Doctrine\\Common\\DataFixtures' => realpath(__DIR__ . '/../../vendor/data-fixtures/lib'),
'Entities' => realpath(__DIR__ . '/../../Doctrine/'), 'Entities' => realpath(__DIR__ . '/../../Doctrine/'),
'Repositories' => realpath(__DIR__ . '/../../Doctrine/'), 'Repositories' => realpath(__DIR__ . '/../../Doctrine/'),
'Proxies' => realpath(__DIR__ . '/../../Doctrine/'), 'Proxies' => realpath(__DIR__ . '/../../Doctrine/'),
@@ -440,4 +447,16 @@ class Core extends \Pimple
return $this->conf->getEnvironnement(); return $this->conf->getEnvironnement();
} }
public function getService($serviceName, $serviceScope)
{
$configuration = $this->configuration->getService($serviceName);
return Core\ServiceBuilder::build(
$serviceName
, $serviceScope
, $configuration->get('type')
, $configuration->get('options')
);
}
} }

View File

@@ -47,10 +47,11 @@ class Configuration
* *
* @param type $envName the name of the loaded environnement * @param type $envName the name of the loaded environnement
*/ */
public function __construct(Configuration\Handler $handler) public function __construct(Configuration\Handler $handler, $environment = null)
{ {
$this->configurationHandler = $handler; $this->configurationHandler = $handler;
$this->installed = false; $this->installed = false;
$this->environment = $environment;
try try
{ {
@@ -89,7 +90,7 @@ class Configuration
*/ */
public function getEnvironnement() public function getEnvironnement()
{ {
if( null === $this->environment) if (null === $this->environment && $this->isInstalled())
{ {
$this->getConfiguration(); $this->getConfiguration();
} }
@@ -106,37 +107,6 @@ class Configuration
$this->environment = $environement; $this->environment = $environement;
} }
/**
* Return the DBAL Doctrine configuration
*
* @return ParameterBag
*/
public function getDoctrine()
{
$doctrine = $this->getConfiguration()->get('doctrine', array()); //get doctrine scope
if (count($doctrine) > 0)
{
$doctrine["debug"] = $this->isDebug(); //set debug
if (!!$doctrine["log"]['enable'])
{
$logger = isset($doctrine["log"]["type"]) ? $doctrine["log"]["type"] : 'monolog';
if (!in_array($doctrine["log"]["type"], $this->getAvailableDoctrineLogger()))
{
throw new \Exception(sprintf('Unknow logger %s', $logger));
}
$doctrineLogger = $this->getConfiguration()->get($logger); //set logger
$doctrine["logger"] = $doctrineLogger;
}
}
return new ParameterBag($doctrine);
}
/** /**
* Check if current environnement is on debug mode * Check if current environnement is on debug mode
* Default to false * Default to false
@@ -182,7 +152,7 @@ class Configuration
* Default to false * Default to false
* @return boolean * @return boolean
*/ */
public function displayErrors() public function isDisplayingErrors()
{ {
$phraseanet = $this->getPhraseanet(); $phraseanet = $this->getPhraseanet();
@@ -204,7 +174,7 @@ class Configuration
*/ */
public function getPhraseanet() public function getPhraseanet()
{ {
$phraseanetConf = $this->getConfiguration()->get('phraseanet', array()); $phraseanetConf = $this->getConfiguration()->get('phraseanet');
return new ParameterBag($phraseanetConf); return new ParameterBag($phraseanetConf);
} }
@@ -227,13 +197,13 @@ class Configuration
{ {
if (null === $this->configuration) if (null === $this->configuration)
{ {
$this->configuration = new Configuration\Parameter(); $this->configuration = new ParameterBag();
if ($this->installed) if ($this->installed)
{ {
$configuration = $this->configurationHandler->handle($this->environment); $configuration = $this->configurationHandler->handle($this->environment);
$this->environment = $this->configurationHandler->getSelectedEnvironnment(); $this->environment = $this->configurationHandler->getSelectedEnvironnment();
$this->configuration = new Configuration\Parameter($configuration); $this->configuration = new ParameterBag($configuration);
} }
} }
@@ -255,9 +225,39 @@ class Configuration
* *
* @return ParameterBag * @return ParameterBag
*/ */
public function getConnexion() public function getConnexion($name = 'main_connexion')
{ {
return new ParameterBag($this->getPhraseanet()->get('database')); $connexions = $this->getConnexions();
try
{
$conn = $connexions->get($name);
}
catch (\Exception $e)
{
throw new \Exception(sprintf('Unknow connexion name %s declared in %s'
, $name
, $this->configurationHandler
->getSpecification()
->getConnexionFile()
->getPathname()
)
);
}
return new Parameterbag($conn);
}
/**
* Return all connexions defined in connexions.yml
* @return ParameterBag
*/
public function getConnexions()
{
return new ParameterBag($this->configurationHandler->getParser()->parse(
$this->configurationHandler->getSpecification()->getConnexionFile()
)
);
} }
/** /**
@@ -282,96 +282,15 @@ class Configuration
} }
/** /**
* Write into the main file connexion credentials defined in $connexion * Return all services defined in services.yml
* @param array $connexion Array of connexion credentials
* @return Configuration
*/
public function setAllDatabaseConnexion(Array $connexion)
{
$arrayConf = $this->all();
foreach ($arrayConf as $key => $value)
{
if (is_array($value) && array_key_exists('phraseanet', $value))
{
foreach ($arrayConf[$key]['phraseanet'] as $kee => $value)
{
if ($kee === 'database')
{
$arrayConf[$key]['phraseanet']['database'] = $connexion;
}
}
}
}
$connexion["driver"] = 'pdo_mysql';
$connexion['charset'] = 'UTF8';
foreach ($arrayConf as $key => $value)
{
if (is_array($value) && array_key_exists('phraseanet', $value))
{
foreach ($arrayConf[$key]['doctrine'] as $kee => $value)
{
if ($kee === 'dbal')
{
if ($key == 'test')
{
$arrayConf[$key]['doctrine']['dbal'] = $this->getTestDBCredentials();
}
else
{
$arrayConf[$key]['doctrine']['dbal'] = $connexion;
}
break;
}
}
}
}
$this->write($arrayConf, FILE_APPEND, true);
return $this;
}
/**
* Return all services defined in service.yml
* @return ParameterBag * @return ParameterBag
*/ */
public function getServices() public function getServices()
{ {
$serviceFile = $this->configurationHandler->getSpecification()->getServiceFile(); return new ParameterBag($this->configurationHandler->getParser()->parse(
$services = $this->configurationHandler->getParser()->parse($serviceFile); $this->getServiceFile()
)
return new ParameterBag($services); );
}
/**
* Write into the main file the serverName
* @param type $serverName
* @return Configuration
*/
public function setServerName($serverName)
{
$arrayConf = $this->all();
foreach ($arrayConf as $key => $value)
{
if (is_array($value) && array_key_exists('phraseanet', $value))
{
foreach ($arrayConf[$key]['phraseanet'] as $kee => $value)
{
if ($kee === 'servername')
{
$arrayConf[$key]['phraseanet']['servername'] = $serverName;
}
}
}
}
$this->write($arrayConf, FILE_APPEND, true);
return $this;
} }
/** /**
@@ -427,16 +346,97 @@ class Configuration
} }
/** /**
* Return the test database credentials * Return configuration service for template_engine
* @return Array * @return string
*/ */
private function getTestDBCredentials() public function getTemplating()
{ {
return array( return $this->getConfiguration()->get('template_engine');
'driver' => 'pdo_sqlite', }
'path' => __DIR__ . '/../../../unitTest/tests.sqlite',
'charset' => 'UTF8' /**
* Return configuration service for orm
* @return string
*/
public function getOrm()
{
return $this->getConfiguration()->get('orm');
}
/**
* Return the selected service configuration
*
* @param type $name
* @return ParameterBag
*/
public function getService($name = 'twig')
{
$services = $this->getServices();
try
{
$template = $services->get($name);
}
catch (\Exception $e)
{
throw new \Exception(sprintf('Unknow service name %s declared in %s'
, $name
, $this->configurationHandler
->getSpecification()
->getServiceFile()
->getPathname()
)
); );
} }
return new ParameterBag($template);
}
/**
* 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->installed = true;
}
catch (\Exception $e)
{
$this->installed = false;
}
$this->configuration = new ParameterBag();
if ($this->installed)
{
$configuration = $this->configurationHandler->handle($this->environment);
$this->environment = $this->configurationHandler->getSelectedEnvironnment();
$this->configuration = new ParameterBag($configuration);
}
return $this;
}
} }

View File

@@ -97,7 +97,17 @@ class Application implements Specification
*/ */
public function getServiceFile() public function getServiceFile()
{ {
return new \SplFileObject(__DIR__ . '/../../../../../config/service.yml'); return new \SplFileObject(__DIR__ . '/../../../../../config/services.yml');
}
/**
* Return the main configuration file
*
* @return \SplFileObject
*/
public function getConnexionFile()
{
return new \SplFileObject(__DIR__ . '/../../../../../config/connexions.yml');
} }
} }

View File

@@ -0,0 +1,54 @@
<?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\Service\Log\Doctrine;
use Alchemy\Phrasea\Core,
Alchemy\Phrasea\Core\Service,
Alchemy\Phrasea\Core\Service\ServiceAbstract,
Alchemy\Phrasea\Core\Service\ServiceInterface;
use Alchemy\Phrasea\Core\Service\Log\Monolog as ParentLog;
use Doctrine\Logger\MonologSQLLogger;
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Monolog extends ParentLog implements ServiceInterface
{
const JSON_OUTPUT = 'json';
const YAML_OUTPUT = 'yaml';
const VAR_DUMP_OUTPUT = 'normal';
protected $outputs = array(
self::JSON_OUTPUT, self::YAML_OUTPUT, self::VAR_DUMP_OUTPUT
);
public function getService()
{
$output = isset($this->options["output"]) ? $this->options["output"] : self::JSON_OUTPUT;
if (!in_array($output, $this->outputs))
{
throw new \Exception(sprintf('Unknow log output class %s', $output));
}
return new MonologSQLLogger($this->monolog, $output);
}
public function getType()
{
return 'doctrine_monolog';
}
}

View File

@@ -0,0 +1,48 @@
<?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\Service\Log\Doctrine;
use Alchemy\Phrasea\Core,
Alchemy\Phrasea\Core\Service,
Alchemy\Phrasea\Core\Service\ServiceAbstract,
Alchemy\Phrasea\Core\Service\ServiceInterface;
use Doctrine\DBAL\Logging\EchoSQLLogger;
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Normal extends ServiceAbstract implements ServiceInterface
{
public function __construct($name, Array $options)
{
parent::__construct($name, $options);
}
public function getService()
{
return new EchoSQLLogger();
}
public function getType()
{
return 'echo';
}
public function getScope()
{
return 'log';
}
}

View File

@@ -0,0 +1,111 @@
<?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\Service\Log;
use Alchemy\Phrasea\Core,
Alchemy\Phrasea\Core\Service,
Alchemy\Phrasea\Core\Service\ServiceAbstract,
Alchemy\Phrasea\Core\Service\ServiceInterface;
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Monolog extends ServiceAbstract implements ServiceInterface
{
const DEFAULT_MAX_DAY = 10;
protected $handlers = array(
'rotate' => 'RotatingFile'
,'stream' => 'Stream'
);
/**
*
* @var \Monolog\Logger
*/
protected $monolog;
public function __construct($name, Array $options)
{
parent::__construct($name, $options);
//defaut to main handler
$handler = isset($options["handler"]) ? $options["handler"] : false;
if (!$handler)
{
throw new \Exception("You must specify at least one monolog handler");
}
if (!array_key_exists($handler, $this->handlers))
{
throw new \Exception(sprintf('Unknow monolog handler %s'), $handlerType);
}
$handlerName = $this->handlers[$handler];
$handlerClassName = sprintf('\Monolog\Handler\%sHandler', $handlerName);
if (!class_exists($handlerClassName))
{
throw new \Exception(sprintf('Unknow monolog handler class %s', $handlerClassName));
}
if (!isset($options["filename"]))
{
throw new \Exception('you must specify a file to write "filename: my_filename"');
}
$logPath = __DIR__ . '/../../../../logs';
$file = sprintf('%s/%s', $logPath, $options["filename"]);
if ($handler == 'rotate')
{
$maxDay = isset($options["max_day"]) ? (int) $options["max_day"] : self::DEFAULT_MAX_DAY;
$handlerInstance = new $handlerClassName($file, $maxDay);
}
else
{
$handlerInstance = new $handlerClassName($file);
}
$channel = isset($options["channel"]) ? $options["channel"] : false;
$monologLogger = new \Monolog\Logger($channel);
$monologLogger->pushHandler($handlerInstance);
$this->monolog = $monologLogger;
}
public function getService()
{
return $this->monolog;
}
public function getType()
{
return 'monolog';
}
public function getScope()
{
return 'log';
}
}

View File

@@ -9,10 +9,15 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Alchemy\Phrasea\Core\Service; namespace Alchemy\Phrasea\Core\Service\Orm;
use Doctrine\DBAL\Types\Type; use Alchemy\Phrasea\Core,
use Doctrine\Common\Cache\AbstractCache; Alchemy\Phrasea\Core\Service,
Alchemy\Phrasea\Core\Service\ServiceAbstract,
Alchemy\Phrasea\Core\Service\ServiceInterface;
use Doctrine\DBAL\Types\Type,
Doctrine\Common\Cache\AbstractCache;
/** /**
* *
@@ -20,38 +25,43 @@ use Doctrine\Common\Cache\AbstractCache;
* @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com * @link www.phraseanet.com
*/ */
class Doctrine class Doctrine extends ServiceAbstract implements ServiceInterface
{ {
const MEMCACHED = 'memcached'; const MEMCACHED = 'memcached';
const ARRAYCACHE = 'array'; const ARRAYCACHE = 'array';
const APC = 'apc'; const APC = 'apc';
protected $outputs = array(
'json', 'yaml', 'normal'
);
protected $loggers = array(
'monolog', 'echo'
);
protected $entityManager; protected $entityManager;
public function __construct(Array $doctrineConfiguration = array()) public function __construct($name, Array $options = array())
{ {
require_once __DIR__ . '/../../../../vendor/doctrine2-orm/lib/vendor/doctrine-common/lib/Doctrine/Common/ClassLoader.php'; parent::__construct($name, $options);
static::loadClasses(); static::loadClasses();
$config = new \Doctrine\ORM\Configuration(); $config = new \Doctrine\ORM\Configuration();
$handler = new Core\Configuration\Handler(
new Core\Configuration\Application(),
new Core\Configuration\Parser\Yaml()
);
$phraseaConfig = new Core\Configuration($handler);
/* /*
* debug mode * debug mode
*/ */
$debug = isset($doctrineConfiguration["debug"]) ? : false; $debug = isset($options["debug"]) ? : false;
/* /*
* doctrine cache * doctrine cache
*/ */
$cache = isset($doctrineConfiguration["orm"]["cache"]) ? $doctrineConfiguration["orm"]["cache"] : false; $cache = isset($options["orm"]["cache"]) ? $options["orm"]["cache"] : false;
/*
* doctrine log configuration
*/
$log = isset($doctrineConfiguration["log"]) ? $doctrineConfiguration["log"] : false;
/*
* service logger configuration
*/
$logger = !isset($doctrineConfiguration['logger']) ? : $doctrineConfiguration['logger'];
/* /*
* default query cache & meta chache * default query cache & meta chache
@@ -59,10 +69,17 @@ class Doctrine
$metaCache = $this->getCache(); $metaCache = $this->getCache();
$queryCache = $this->getCache(); $queryCache = $this->getCache();
//Handle logs
$logServiceName = isset($options["log"]) ? $options["log"] : false;
if ($logServiceName)
{
$serviceConf = $phraseaConfig->getService($logServiceName);
$this->handleLogs($config, $logServiceName, $serviceConf->all());
}
//handle cache //handle cache
$this->handleCache($metaCache, $queryCache, $cache, $debug); $this->handleCache($metaCache, $queryCache, $cache, $debug);
//Handle logs
$this->handleLogs($config, $log, $logger);
//set caches //set caches
$config->setMetadataCacheImpl($metaCache); $config->setMetadataCacheImpl($metaCache);
@@ -74,7 +91,7 @@ class Doctrine
$chainDriverImpl = new \Doctrine\ORM\Mapping\Driver\DriverChain(); $chainDriverImpl = new \Doctrine\ORM\Mapping\Driver\DriverChain();
$driverYaml = new \Doctrine\ORM\Mapping\Driver\YamlDriver( $driverYaml = new \Doctrine\ORM\Mapping\Driver\YamlDriver(
array(__DIR__ . '/../../../../conf.d/Doctrine') array(__DIR__ . '/../../../../../conf.d/Doctrine')
); );
$chainDriverImpl->addDriver($driverYaml, 'Entities'); $chainDriverImpl->addDriver($driverYaml, 'Entities');
@@ -83,15 +100,24 @@ class Doctrine
$config->setMetadataDriverImpl($chainDriverImpl); $config->setMetadataDriverImpl($chainDriverImpl);
$config->setProxyDir(realpath(__DIR__ . '/../../../../Doctrine/Proxies')); $config->setProxyDir(realpath(__DIR__ . '/../../../../../Doctrine/Proxies'));
$config->setProxyNamespace('Proxies'); $config->setProxyNamespace('Proxies');
$dbalConf = isset($doctrineConfiguration["dbal"]) ? $doctrineConfiguration["dbal"] : false; $connexion = isset($options["dbal"]) ? $options["dbal"] : false;
if (!$dbalConf) if(!$connexion)
{ {
throw new \Exception("Unable to read dbal configuration"); throw new \Exception("Missing dbal connexion for doctrine");
}
try
{
$dbalConf = $phraseaConfig->getConnexion($connexion)->all();
}
catch(\Exception $e)
{
throw new \Exception(sprintf("Unable to read %s configuration", $connexion));
} }
$evm = new \Doctrine\Common\EventManager(); $evm = new \Doctrine\Common\EventManager();
@@ -117,52 +143,54 @@ class Doctrine
protected static function loadClasses() protected static function loadClasses()
{ {
require_once __DIR__ . '/../../../../../vendor/doctrine2-orm/lib/vendor/doctrine-common/lib/Doctrine/Common/ClassLoader.php';
$classLoader = new \Doctrine\Common\ClassLoader( $classLoader = new \Doctrine\Common\ClassLoader(
'Doctrine\ORM' 'Doctrine\ORM'
, realpath(__DIR__ . '/../../../../vendor/doctrine2-orm/lib') , realpath(__DIR__ . '/../../../../../vendor/doctrine2-orm/lib')
); );
$classLoader->register(); $classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader( $classLoader = new \Doctrine\Common\ClassLoader(
'Doctrine\DBAL' 'Doctrine\DBAL'
, realpath(__DIR__ . '/../../../../vendor/doctrine2-orm/lib/vendor/doctrine-dbal/lib') , realpath(__DIR__ . '/../../../../../vendor/doctrine2-orm/lib/vendor/doctrine-dbal/lib')
);
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader(
'Doctrine\Common\DataFixtures'
, realpath(__DIR__ . '/../../../../vendor/data-fixtures/lib')
);
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader(
'PhraseaFixture'
, realpath(__DIR__ . '/../../../../conf.d/')
); );
$classLoader->register(); $classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader( $classLoader = new \Doctrine\Common\ClassLoader(
'Doctrine\Common' 'Doctrine\Common'
, realpath(__DIR__ . '/../../../../vendor/doctrine2-orm/lib/vendor/doctrine-common/lib') , realpath(__DIR__ . '/../../../../../vendor/doctrine2-orm/lib/vendor/doctrine-common/lib')
);
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader(
'Doctrine\Common\DataFixtures'
, realpath(__DIR__ . '/../../../../../vendor/data-fixtures/lib')
);
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader(
'PhraseaFixture'
, realpath(__DIR__ . '/../../../../../conf.d/')
); );
$classLoader->register(); $classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader( $classLoader = new \Doctrine\Common\ClassLoader(
'Entities' 'Entities'
, realpath(__DIR__ . '/../../../../Doctrine') , realpath(__DIR__ . '/../../../../../Doctrine')
); );
$classLoader->register(); $classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader( $classLoader = new \Doctrine\Common\ClassLoader(
'Repositories' 'Repositories'
, realpath(__DIR__ . '/../../../../Doctrine') , realpath(__DIR__ . '/../../../../../Doctrine')
); );
$classLoader->register(); $classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader( $classLoader = new \Doctrine\Common\ClassLoader(
'Proxies' 'Proxies'
, realpath(__DIR__ . '/../../../../Doctrine') , realpath(__DIR__ . '/../../../../../Doctrine')
); );
$classLoader->register(); $classLoader->register();
@@ -175,34 +203,34 @@ class Doctrine
$classLoader = new \Doctrine\Common\ClassLoader( $classLoader = new \Doctrine\Common\ClassLoader(
'Doctrine\Logger' 'Doctrine\Logger'
, realpath(__DIR__ . '/../../../../') , realpath(__DIR__ . '/../../../../../../../')
); );
$classLoader->register(); $classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader( $classLoader = new \Doctrine\Common\ClassLoader(
'Monolog' 'Monolog'
, realpath(__DIR__ . '/../../../../vendor/Silex/vendor/monolog/src') , realpath(__DIR__ . '/../../../../../vendor/Silex/vendor/monolog/src')
); );
$classLoader->register(); $classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader( $classLoader = new \Doctrine\Common\ClassLoader(
'Types' 'Types'
, realpath(__DIR__ . '/../../../../Doctrine') , realpath(__DIR__ . '/../../../../../Doctrine')
); );
$classLoader->register(); $classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader( $classLoader = new \Doctrine\Common\ClassLoader(
'Gedmo' 'Gedmo'
, __DIR__ . "/../../../../vendor/doctrine2-gedmo/lib" , __DIR__ . "/../../../../../vendor/doctrine2-gedmo/lib"
); );
$classLoader->register(); $classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader( $classLoader = new \Doctrine\Common\ClassLoader(
'DoctrineExtensions' 'DoctrineExtensions'
, __DIR__ . "/../../../../vendor/doctrine2-beberlei/lib" , __DIR__ . "/../../../../../vendor/doctrine2-beberlei/lib"
); );
$classLoader->register(); $classLoader->register();
@@ -215,14 +243,25 @@ class Doctrine
$platform = $this->entityManager->getConnection()->getDatabasePlatform(); $platform = $this->entityManager->getConnection()->getDatabasePlatform();
if(!Type::hasType('blob')) if (!Type::hasType('blob'))
{
Type::addType('blob', 'Types\Blob'); Type::addType('blob', 'Types\Blob');
if(!Type::hasType('enum')) }
if (!Type::hasType('enum'))
{
Type::addType('enum', 'Types\Enum'); Type::addType('enum', 'Types\Enum');
if(!Type::hasType('longblob')) }
if (!Type::hasType('longblob'))
{
Type::addType('longblob', 'Types\LongBlob'); Type::addType('longblob', 'Types\LongBlob');
if(!Type::hasType('varbinary')) }
if (!Type::hasType('varbinary'))
{
Type::addType('varbinary', 'Types\VarBinary'); Type::addType('varbinary', 'Types\VarBinary');
}
$platform->registerDoctrineTypeMapping('enum', 'enum'); $platform->registerDoctrineTypeMapping('enum', 'enum');
$platform->registerDoctrineTypeMapping('blob', 'blob'); $platform->registerDoctrineTypeMapping('blob', 'blob');
@@ -285,99 +324,53 @@ class Doctrine
* @param type $log * @param type $log
* @param type $logger * @param type $logger
*/ */
private function handleLogs(\Doctrine\ORM\Configuration &$config, $log, $logger) private function handleLogs(\Doctrine\ORM\Configuration &$config, $serviceName, Array $serviceConf)
{ {
$logEnable = isset($log["enable"]) ? !!$log["enable"] : false; $logType = $serviceConf['type'];
$logService = null;
if ($logEnable) switch ($logType)
{
$loggerService = isset($log["type"]) ? $log["type"] : '';
switch ($loggerService)
{ {
case 'monolog': case 'monolog':
//defaut to main handler $logService = Core\ServiceBuilder::build(
$doctrineHandler = isset($log["handler"]) ? $log["handler"] : 'main'; $serviceName
, Core\ServiceBuilder::LOG
if (!isset($logger["handlers"])) , $logType
{ , $serviceConf['options']
throw new \Exception("You must specify at least on monolog handler"); , 'doctrine'
} );
if (!array_key_exists($doctrineHandler, $logger["handlers"]))
{
throw new \Exception(sprintf('Unknow monolog handler %s'), $handlerType);
}
$handlerName = ucfirst($logger["handlers"][$doctrineHandler]["type"]);
$handlerClassName = sprintf('\Monolog\Handler\%sHandler', $handlerName);
if (!class_exists($handlerClassName))
{
throw new \Exception(sprintf('Unknow monolog handler class %s', $handlerClassName));
}
if (!isset($log["filename"]))
{
throw new \Exception('you must specify a file to write "filename: my_filename"');
}
$logPath = __DIR__ . '/../../../../../logs';
$file = sprintf('%s/%s', $logPath, $log["filename"]);
if ($doctrineHandler == 'rotate')
{
$maxDay = isset($log["max_day"]) ? (int) $log["max_day"] : false;
if(!$maxDay && isset($logger["handlers"]['rotate']["max_day"]))
{
$maxDay = (int) $logger["handlers"]['rotate']["max_day"];
}
else
{
$maxDay = 10;
}
$handlerInstance = new $handlerClassName($file, $maxDay);
}
else
{
$handlerInstance = new $handlerClassName($file);
}
$monologLogger = new \Monolog\Logger('query-logger');
$monologLogger->pushHandler($handlerInstance);
if (isset($log["output"]))
{
$output = $log["output"];
}
elseif (isset($logger["output"]))
{
$output = $logger["output"];
}
else
{
$output = null;
}
if (null === $output)
{
$sqlLogger = new \Doctrine\Logger\MonologSQLLogger($monologLogger);
}
else
{
$sqlLogger = new \Doctrine\Logger\MonologSQLLogger($monologLogger, $output);
}
$config->setSQLLogger($sqlLogger);
break; break;
case 'echo': case 'echo':
default: default:
$config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); $logService = Core\ServiceBuilder::build(
$serviceName
, Core\ServiceBuilder::LOG
, 'normal'
, array()
, 'doctrine'
);
break; break;
} }
if ($logService instanceof Alchemy\Phrasea\Core\Service\ServiceAbstract)
{
$config->setSQLLogger($logService->getService());
} }
} }
public function getService()
{
return $this->entityManager;
}
public function getType()
{
return 'doctrine';
}
public function getScope()
{
return 'orm';
}
} }

View File

@@ -0,0 +1,58 @@
<?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\Service;
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class ServiceAbstract
{
protected $name;
protected $options;
public function __construct($name, Array $options)
{
$this->name = $name;
$this->options = $options;
}
/**
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
*
* @return Array
*/
public function getOptions()
{
return $this->options;
}
/**
*
* @return string
*/
public function getVersion()
{
return 'Unknow';
}
}

View File

@@ -0,0 +1,32 @@
<?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\Service;
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
interface ServiceInterface
{
public function getName();
public function getType();
public function getService();
public function getOptions();
public function getScope();
}

View File

@@ -9,11 +9,14 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Alchemy\Phrasea\Core\Service; namespace Alchemy\Phrasea\Core\Service\TemplateEngine;
use Alchemy\Phrasea\Core; use Alchemy\Phrasea\Core,
Alchemy\Phrasea\Core\Service,
Alchemy\Phrasea\Core\Service\ServiceAbstract,
Alchemy\Phrasea\Core\Service\ServiceInterface;
class Twig class Twig extends ServiceAbstract implements ServiceInterface
{ {
/** /**
@@ -22,11 +25,11 @@ class Twig
*/ */
protected $twig; protected $twig;
protected $templatesPath = array(); protected $templatesPath = array();
protected $options;
public function __construct(Array $configuration) public function __construct($name, Array $options)
{ {
$this->options = $this->resolveOptions($configuration); parent::__construct($name, $options);
$this->options = $this->resolveOptions($options);
$this->templatesPath = $this->resolvePaths(); $this->templatesPath = $this->resolvePaths();
try try
@@ -194,41 +197,34 @@ class Twig
*/ */
private function resolveOptions(Array $configuration) private function resolveOptions(Array $configuration)
{ {
if (isset($configuration['options'])) $registry = \registry::get_instance();
{ $options = $configuration;
$options = $configuration['options'];
$options["optimizer"] = !!$options["optimizer"] ? -1 : 0; $options["optimizer"] = !!$options["optimizer"] ? -1 : 0;
} $options['cache'] = $registry->get('GV_RootPath') . 'tmp/cache_twig';
else $options['charset'] = 'utf-8';
{
$options = array(
'cache' => $registry->get('GV_RootPath') . 'tmp/cache_twig',
'debug' => false,
'strict_variables' => false,
'trim_blocks' => true,
'charset' => 'utf-8'
);
}
$confApp = new Core\Configuration\Application(); if (!!$options["debug"])
$confParser = new Core\Configuration\Parser\Yaml();
$handler = new Core\Configuration\Handler($confApp, $confParser);
$configuration = new Core\Configuration($handler);
if ($configuration->isDebug())
{ {
$options["debug"] = true;
unset($options["cache"]); unset($options["cache"]);
} }
else
{
$options["debug"] = false;
$options["cache"] = $registry->get('GV_RootPath') . 'tmp/cache_twig';
}
return $options; return $options;
} }
public function getService()
{
return $this->twig;
}
public function getType()
{
return 'twig';
}
public function getScope()
{
return 'template_engine';
}
} }

View File

@@ -0,0 +1,75 @@
<?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;
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class ServiceBuilder
{
const LOG = 'log';
const TEMPLATE_ENGINE = 'template_engine';
const ORM = 'orm';
protected static $scopes = array(
self::ORM, self::TEMPLATE_ENGINE, self::LOG
);
public static function build($serviceName, $serviceScope, $serviceType, Array $options, $namespace = null)
{
if (!in_array($serviceScope, self::$scopes))
{
throw new \Exception(sprintf("Unknow service scope of type %s", $serviceScope));
}
$composedScope = explode("_", $serviceScope);
if (count($composedScope) > 1)
{
$scope = "";
foreach ($composedScope as $word)
{
$scope .= ucfirst($word);
}
$serviceScope = $scope;
}
if (is_string($namespace))
{
$scope = sprintf("%s\%s", ucfirst($namespace), ucfirst($serviceScope));
}
$className = sprintf(
"\Alchemy\Phrasea\Core\Service\%s\%s"
, ucfirst($serviceScope)
, ucfirst($serviceType)
);
if (class_exists($className))
{
return new $className($serviceName, $options);
}
else
{
throw new \Exception(sprintf(
'Unknow service %s for %s scopes looked for classname %s'
, str_replace('/', '_', $serviceType)
, $serviceScope
, $className)
);
}
}
}

View File

@@ -81,7 +81,9 @@ class appbox extends base
); );
$configuration = new \Alchemy\Phrasea\Core\Configuration($handler); $configuration = new \Alchemy\Phrasea\Core\Configuration($handler);
$connexion = $configuration->getConnexion(); $choosenConnexion = $configuration->getPhraseanet()->get('database');
$connexion = $configuration->getConnexion($choosenConnexion);
$this->host = $connexion->get('host'); $this->host = $connexion->get('host');
$this->port = $connexion->get('port'); $this->port = $connexion->get('port');
@@ -415,34 +417,99 @@ class appbox extends base
$credentials['dbname'] = $dbname; $credentials['dbname'] = $dbname;
} }
$file = __DIR__ . "/../../config/config.sample.yml";
$file1 = __DIR__ . "/../../config/config.yml";
if (!copy($file, $file1))
{
throw new \Exception(sprintf("Unable to copy %s", $file1));
}
$handler = new \Alchemy\Phrasea\Core\Configuration\Handler(
new \Alchemy\Phrasea\Core\Configuration\Application(),
new \Alchemy\Phrasea\Core\Configuration\Parser\Yaml()
);
$configuration = new \Alchemy\Phrasea\Core\Configuration($handler);
$connexionINI = array();
foreach ($credentials as $key => $value) foreach ($credentials as $key => $value)
{ {
$key = $key == 'hostname' ? 'host' : $key; $key = $key == 'hostname' ? 'host' : $key;
$connexionINI[$key] = (string) $value; $connexionINI[$key] = (string) $value;
} }
$connexionINI['driver'] = 'pdo_mysql';
$connexionINI['charset'] = 'UTF8';
$serverName = $registry->get('GV_ServerName'); $serverName = $registry->get('GV_ServerName');
$configuration->setServerName($serverName);
$configuration->setAllDatabaseConnexion($connexionINI); $root = __DIR__ . '/../../';
//copy config sample
$configSampleFile = $root . "config/config.sample.yml";
$configFile = $root . "config/config.yml";
if (!copy($configSampleFile, $configFile))
{
throw new \Exception(sprintf("Unable to copy %s", $configSampleFile));
}
//copy service sample
$serviceSampleFile = $root . "config/services.sample.yml";
$serviceFile = $root . "config/services.yml";
if (!copy($serviceSampleFile, $serviceFile))
{
throw new \Exception(sprintf("Unable to copy %s", $serviceSampleFile));
}
//copy connexion sample
$connexionSampleFile = $root . "config/connexions.sample.yml";
$connexionFile = $root . "config/connexions.yml";
if (!copy($connexionSampleFile, $connexionFile))
{
throw new \Exception(sprintf("Unable to copy %s", $serviceSampleFile));
}
//get configuration object
$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);
//write credentials to config file
$connexionFile = $appConf->getConnexionFile();
$connexion = array(
'main_connexion' => $connexionINI,
'test_connexion' => array(
'driver' => 'pdo_sqlite',
'path' => $root . 'lib/unitTest/tests.sqlite',
'charset' => 'UTF8'
));
$yaml = $configuration->getConfigurationHandler()->getParser()->dump($connexion, 2);
if (!file_put_contents($connexionFile->getPathname(), $yaml) !== false)
{
throw new \Exception(sprintf(_('Impossible d\'ecrire dans le fichier %s'), $connexionFile->getPathname()));
}
//rewrite service file
$serviceFile = $appConf->getServiceFile();
$service = $configuration->getConfigurationHandler()->getParser()->parse($serviceFile);
$yaml = $configuration->getConfigurationHandler()->getParser()->dump($service, 5);
if (!file_put_contents($serviceFile->getPathname(), $yaml) !== false)
{
throw new \Exception(sprintf(_('Impossible d\'ecrire dans le fichier %s'), $serviceFile->getPathname()));
}
//rewrite servername in main config file
$arrayConf = $configuration->all();
foreach ($arrayConf as $key => $value)
{
if (is_array($value) && array_key_exists('phraseanet', $value))
{
$arrayConf[$key]["phraseanet"]["servername"] = $serverName;
}
}
$configuration->write($arrayConf);
if (function_exists('chmod')) if (function_exists('chmod'))
{ {
chmod($configuration->getFile()->getPathname(), 0700); chmod($configuration->getFile()->getPathname(), 0700);
chmod($serviceFile->getPathname(), 0700);
chmod($connexionFile->getPathname(), 0700);
} }
} }
try try

View File

@@ -93,13 +93,19 @@ class binaryAdapter_image_resize_gd extends binaryAdapter_processorAbstract
$size = $this->options['size']; $size = $this->options['size'];
if (!is_null($size) && !$origine->is_raw_image() if (
&& $tech_datas[system_file::TC_DATAS_WIDTH] < $size && $tech_datas[system_file::TC_DATAS_HEIGHT] < $size) !is_null($size)
&& isset($tech_datas[system_file::TC_DATAS_WIDTH])
&& isset($tech_datas[system_file::TC_DATAS_HEIGHT])
&& !$origine->is_raw_image()
&& $tech_datas[system_file::TC_DATAS_WIDTH] < $size
&& $tech_datas[system_file::TC_DATAS_HEIGHT] < $size
)
{ {
$size = max($tech_datas[system_file::TC_DATAS_WIDTH], $tech_datas[system_file::TC_DATAS_HEIGHT]); $size = max($tech_datas[system_file::TC_DATAS_WIDTH], $tech_datas[system_file::TC_DATAS_HEIGHT]);
} }
switch($origine->get_mime()) switch ($origine->get_mime())
{ {
case "image/jpeg" : case "image/jpeg" :
$imag_original = imagecreatefromjpeg($origine->getPathname()); $imag_original = imagecreatefromjpeg($origine->getPathname());
@@ -134,8 +140,7 @@ class binaryAdapter_image_resize_gd extends binaryAdapter_processorAbstract
$w_sub = (int) (($w_doc / $h_doc) * ($h_sub = $size)); $w_sub = (int) (($w_doc / $h_doc) * ($h_sub = $size));
$img_mini = imagecreatetruecolor($w_sub, $h_sub); $img_mini = imagecreatetruecolor($w_sub, $h_sub);
imagecopyresampled($img_mini, $imag_original, 0, 0, 0, 0, imagecopyresampled($img_mini, $imag_original, 0, 0, 0, 0, $w_sub, $h_sub, $w_doc, $h_doc);
$w_sub, $h_sub, $w_doc, $h_doc);
} }
if ($this->options['autorotate']) if ($this->options['autorotate'])

View File

@@ -142,7 +142,9 @@ class connection
); );
$configuration = new \Alchemy\Phrasea\Core\Configuration($handler); $configuration = new \Alchemy\Phrasea\Core\Configuration($handler);
$connexion = $configuration->getConnexion(); $choosenConnexion = $configuration->getPhraseanet()->get('database');
$connexion = $configuration->getConnexion($choosenConnexion);
$hostname = $connexion->get('host'); $hostname = $connexion->get('host');
$port = $connexion->get('port'); $port = $connexion->get('port');

View File

@@ -111,7 +111,9 @@ class phrasea
); );
$configuration = new \Alchemy\Phrasea\Core\Configuration($handler); $configuration = new \Alchemy\Phrasea\Core\Configuration($handler);
$connexion = $configuration->getConnexion(); $choosenConnexion = $configuration->getPhraseanet()->get('database');
$connexion = $configuration->getConnexion($choosenConnexion);
$hostname = $connexion->get('host'); $hostname = $connexion->get('host');
$port = $connexion->get('port'); $port = $connexion->get('port');

View File

@@ -63,12 +63,14 @@ class registry implements registryInterface
new \Alchemy\Phrasea\Core\Configuration\Parser\Yaml() new \Alchemy\Phrasea\Core\Configuration\Parser\Yaml()
); );
$configuration = new \Alchemy\Phrasea\Core\Configuration($handler); $configuration = new \Alchemy\Phrasea\Core\Configuration($handler);
$phraseanet = $configuration->getPhraseanet();
$this->cache->set('GV_RootPath', dirname(dirname(__DIR__)) . '/'); $this->cache->set('GV_RootPath', dirname(dirname(__DIR__)) . '/');
$this->cache->set('GV_ServerName', $phraseanet->get('servername')); if ($configuration->isInstalled())
{
$this->cache->set('GV_ServerName', $configuration->getPhraseanet()->get('servername'));
$this->cache->set('GV_debug', $configuration->isDebug()); $this->cache->set('GV_debug', $configuration->isDebug());
$this->cache->set('GV_maintenance', $configuration->isMaintained()); $this->cache->set('GV_maintenance', $configuration->isMaintained());
}
return $this; return $this;
} }

View File

@@ -69,14 +69,24 @@ class setup
public static function is_installed() public static function is_installed()
{ {
$appConf = new \Alchemy\Phrasea\Core\Configuration\Application(); $appConf = new \Alchemy\Phrasea\Core\Configuration\Application();
$installed = false;
return is_file($appConf->getConfigurationPathName()); try
{
$appConf->getConfigurationFile();
$appConf->getConnexionFile();
$appConf->getServiceFile();
$installed = true;
}
catch(\Exception $e)
{
}
return $installed;
} }
public static function needUpgradeConfigurationFile() public static function needUpgradeConfigurationFile()
{ {
return (is_file(__DIR__ . "/../../conf/connexion.inc") return (is_file(__DIR__ . "/../../config/connexion.inc")
&& is_file(__DIR__ . "/../../config.inc")); && is_file(__DIR__ . "/../../config/config.inc"));
} }
function create_global_values(registryInterface &$registry, $datas=array()) function create_global_values(registryInterface &$registry, $datas=array())

View File

@@ -51,7 +51,9 @@ class task_Scheduler
); );
$configuration = new \Alchemy\Phrasea\Core\Configuration($handler); $configuration = new \Alchemy\Phrasea\Core\Configuration($handler);
$connexion = $configuration->getConnexion(); $choosenConnexion = $configuration->getPhraseanet()->get('database');
$connexion = $configuration->getConnexion($choosenConnexion);
$hostname = $connexion->get('host'); $hostname = $connexion->get('host');
$port = $connexion->get('port'); $port = $connexion->get('port');

View File

@@ -58,14 +58,13 @@ class ConfigurationTest extends PhraseanetPHPUnitAuthenticatedAbstract
$this->assertEquals('prod', $configuration->getEnvironnement()); $this->assertEquals('prod', $configuration->getEnvironnement());
$this->assertTrue($configuration->isInstalled()); $this->assertTrue($configuration->isInstalled());
$this->assertInstanceOf( $this->assertInstanceOf(
'Alchemy\Phrasea\Core\Configuration\Parameter' '\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag'
, $configuration->getConfiguration() , $configuration->getConfiguration()
); );
$this->assertFalse($configuration->isDebug()); $this->assertFalse($configuration->isDebug());
$this->assertFalse($configuration->displayErrors()); $this->assertFalse($configuration->isDisplayingErrors());
$this->assertFalse($configuration->isMaintained()); $this->assertFalse($configuration->isMaintained());
$this->assertTrue(is_array($configuration->getPhraseanet()->all())); $this->assertTrue(is_array($configuration->getPhraseanet()->all()));
$this->assertTrue(is_array($configuration->getDoctrine()->all()));
} }
public function testInstalled() public function testInstalled()
@@ -85,8 +84,15 @@ class ConfigurationTest extends PhraseanetPHPUnitAuthenticatedAbstract
$configuration->setEnvironnement('prod'); $configuration->setEnvironnement('prod');
$this->assertFalse($configuration->isInstalled()); $this->assertFalse($configuration->isInstalled());
$this->assertTrue(is_array($configuration->getPhraseanet()->all())); try
$this->assertTrue(is_array($configuration->getDoctrine()->all())); {
$configuration->getPhraseanet();
$this->fail("should raise an exception because application is not yet installed");
}
catch (\Exception $e)
{
}
} }
public function testGetAvailableLogger() public function testGetAvailableLogger()
@@ -140,36 +146,36 @@ class ConfigurationTest extends PhraseanetPHPUnitAuthenticatedAbstract
$this->assertEquals('test', $configuration->getConfigurationHandler()->getSpecification()->getConfigurationFile()); $this->assertEquals('test', $configuration->getConfigurationHandler()->getSpecification()->getConfigurationFile());
} }
public function testBadDoctrineLogger() // public function testBadDoctrineLogger()
{ // {
$spec = $this->getMock( // $spec = $this->getMock(
'\Alchemy\Phrasea\Core\Configuration\Application' // '\Alchemy\Phrasea\Core\Configuration\Application'
, array('getConfigurationFile') // , array('getConfigurationFile')
); // );
//
$fileName = __DIR__ . '/confTestFiles/bad_doctrine_logger.yml'; // $fileName = __DIR__ . '/confTestFiles/bad_doctrine_logger.yml';
//
$spec->expects($this->any()) // $spec->expects($this->any())
->method('getConfigurationFile') // ->method('getConfigurationFile')
->will( // ->will(
$this->returnValue( // $this->returnValue(
new \SplFileObject($fileName) // new \SplFileObject($fileName)
) // )
); // );
//
$handler = new Configuration\Handler($spec, new Configuration\Parser\Yaml()); // $handler = new Configuration\Handler($spec, new Configuration\Parser\Yaml());
//
$configuration = new PhraseaCore\Configuration($handler); // $configuration = new PhraseaCore\Configuration($handler);
$configuration->setEnvironnement('prod'); // $configuration->setEnvironnement('prod');
//
try // try
{ // {
$configuration->getDoctrine(); // $configuration->getDoctrine();
$this->fail('An exception should be raised'); // $this->fail('An exception should be raised');
} // }
catch(Exception $e) // catch(Exception $e)
{ // {
//
} // }
} // }
} }

View File

@@ -1,139 +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.
*/
require_once __DIR__ . '/../../../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
use Alchemy\Phrasea\Core\Service\Doctrine;
use Symfony\Component\Yaml\Yaml;
use Alchemy\Phrasea\Core as PhraseaCore;
use Alchemy\Phrasea\Core\Configuration;
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class DoctrineTest extends PhraseanetPHPUnitAuthenticatedAbstract
{
/**
*
* @var \Alchemy\Phrasea\Core\Configuration\Application
*/
public function setUp()
{
parent::setUp();
}
public function tearDown()
{
parent::tearDown();
}
public function testInitialize()
{
try
{
$spec = $this->getMock(
'\Alchemy\Phrasea\Core\Configuration\Application'
, array('getConfigurationFile')
);
$fileName = __DIR__ . '/../Configuration/confTestFiles/good.yml';
$spec->expects($this->any())
->method('getConfigurationFile')
->will(
$this->returnValue(
new SplFileObject($fileName)
)
);
$handler = new Configuration\Handler($spec, new Configuration\Parser\Yaml());
$configuration = new PhraseaCore\Configuration($handler);
$configuration->setEnvironnement('prod');
$doctrineService = new Doctrine($configuration->getDoctrine()->all());
}
catch (Exception $e)
{
$this->fail($e->getMessage());
}
}
public function testNoDbalConf()
{
try
{
$doctrineService = new Doctrine();
$this->fail("should raised an exception");
}
catch (\Exception $e)
{
}
}
public function testGetVersion()
{
$spec = $this->getMock(
'\Alchemy\Phrasea\Core\Configuration\Application'
, array('getConfigurationFile')
);
$fileName = __DIR__ . '/../Configuration/confTestFiles/good.yml';
$spec->expects($this->any())
->method('getConfigurationFile')
->will(
$this->returnValue(
new SplFileObject($fileName)
)
);
$handler = new Configuration\Handler($spec, new Configuration\Parser\Yaml());
$configuration = new PhraseaCore\Configuration($handler);
$configuration->setEnvironnement('prod');
$doctrineService = new Doctrine($configuration->getDoctrine()->all());
$this->assertTrue(is_string($doctrineService->getVersion()));
}
public function testGetEntityManager()
{
$spec = $this->getMock(
'\Alchemy\Phrasea\Core\Configuration\Application'
, array('getConfigurationFile')
);
$fileName = __DIR__ . '/../Configuration/confTestFiles/good.yml';
$spec->expects($this->any())
->method('getConfigurationFile')
->will(
$this->returnValue(
new SplFileObject($fileName)
)
);
$handler = new Configuration\Handler($spec, new Configuration\Parser\Yaml());
$configuration = new PhraseaCore\Configuration($handler);
$configuration->setEnvironnement('prod');
$doctrineService = new Doctrine($configuration->getDoctrine()->all());
$this->assertInstanceOf('\Doctrine\ORM\EntityManager', $doctrineService->getEntityManager());
}
}

View File

@@ -2,6 +2,11 @@
require_once __DIR__ . '/../../bootstrap.php'; require_once __DIR__ . '/../../bootstrap.php';
$new_include_path = __DIR__ . "/../../vendor/" . PATH_SEPARATOR . get_include_path();
set_include_path($new_include_path);
require_once __DIR__ . "/../../vendor/Phlickr/Api.php";
/* /*
* This file is part of Phraseanet * This file is part of Phraseanet
* *

View File

@@ -11,19 +11,21 @@
require_once __DIR__ . "/../../lib/classes/bootstrap.class.php"; require_once __DIR__ . "/../../lib/classes/bootstrap.class.php";
use Silex\WebTestCase;
use Symfony\Component\HttpKernel\Client;
use Symfony\Component\HttpFoundation\Response;
use Doctrine\Common\DataFixtures\Loader;
use PhraseaFixture\Basket as MyFixture;
/** /**
* *
* @package * @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com * @link www.phraseanet.com
*/ */
bootstrap::execute('test'); bootstrap::execute('test');
use Silex\WebTestCase;
use Symfony\Component\HttpKernel\Client;
use Symfony\Component\HttpFoundation\Response;
use Doctrine\Common\DataFixtures\Loader;
use PhraseaFixture\Basket as MyFixture;
abstract class PhraseanetPHPUnitAbstract extends WebTestCase abstract class PhraseanetPHPUnitAbstract extends WebTestCase
{ {
@@ -730,8 +732,22 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
*/ */
protected function resetTwig() protected function resetTwig()
{ {
$serviceTwig = new \Alchemy\Phrasea\Core\Service\Twig(array()); $handler = new \Alchemy\Phrasea\Core\Configuration\Handler(
$this->app['Core']["Twig"] = $serviceTwig->getTwig(); new \Alchemy\Phrasea\Core\Configuration\Application(),
new \Alchemy\Phrasea\Core\Configuration\Parser\Yaml()
);
$configuration = new \Alchemy\Phrasea\Core\Configuration($handler);
$serviceName = $configuration->getTemplating();
$confService = $configuration->getService($serviceName);
$templateService = \Alchemy\Phrasea\Core\ServiceBuilder::build(
$serviceName
, \Alchemy\Phrasea\Core\ServiceBuilder::TEMPLATE_ENGINE
, $confService->get("type")
, $confService->get("options")
);
$this->app['Core']["Twig"] = $templateService->getService();
} }
/** /**

View File

@@ -1,54 +0,0 @@
<?php
require_once __DIR__ . '/PhraseanetPHPUnitAbstract.class.inc';
/**
* Test class for supertwig.
* Generated by PHPUnit on 2011-07-06 at 18:30:03.
*/
class supertwigTest extends PhraseanetPHPUnitAbstract
{
protected $object;
public function setUp()
{
parent::setUp();
$this->object = new supertwig();
}
public function testAddFilter()
{
$this->object->addFilter(array('nl2br'=>'nl2br'));
try
{
$this->object->addFilter(array('prout'=>'prout'));
$this->fail();
}
catch(Exception $e)
{
}
}
public function testRender()
{
$this->object->addFilter(array('nl2br'=>'nl2br'));
$this->assertEquals('mon beau camion', $this->object->render('test.html', array('test_string'=>'mon beau camion')));
$string = "mon\nBEAU CAMION\n";
$this->assertEquals("mon<br />\nBEAU CAMION<br />\n", $this->object->render('test.html', array('test_string'=>"mon\nBEAU CAMION\n")));
}
public function testDisplay()
{
ob_start();
$this->object->addFilter(array('nl2br'=>'nl2br'));
$this->object->display('test.html', array('test_string'=>'mon beau camion'));
$out = ob_get_clean();
$this->assertEquals('mon beau camion', $out);
}
}

View File

@@ -27,7 +27,7 @@
{% trans 'Vous etes maintenant deconnecte. A bientot.' %} {% trans 'Vous etes maintenant deconnecte. A bientot.' %}
</div> </div>
{% endif %} {% endif %}
{{errorWarning}}{{confirmWarning}} {{errorWarning|raw}}{{confirmWarning|raw}}
</div> </div>
<div style="margin-top:10px;"> <div style="margin-top:10px;">
<div style="margin-top:3px;">{% trans 'admin::compte-utilisateur identifiant' %}</div> <div style="margin-top:3px;">{% trans 'admin::compte-utilisateur identifiant' %}</div>

View File

@@ -25,7 +25,7 @@
{% trans 'Vous etes maintenant deconnecte. A bientot.' %} {% trans 'Vous etes maintenant deconnecte. A bientot.' %}
</div> </div>
{% endif %} {% endif %}
{{errorWarning}}{{confirmWarning}} {{errorWarning|raw}}{{confirmWarning|raw}}
</div> </div>
<div style="margin-top:10px;"> <div style="margin-top:10px;">
<div style="margin-top:3px;">{% trans 'admin::compte-utilisateur identifiant' %}</div> <div style="margin-top:3px;">{% trans 'admin::compte-utilisateur identifiant' %}</div>

View File

@@ -27,7 +27,7 @@
{% trans 'Vous etes maintenant deconnecte. A bientot.' %} {% trans 'Vous etes maintenant deconnecte. A bientot.' %}
</div> </div>
{% endif %} {% endif %}
{{errorWarning}}{{confirmWarning}} {{errorWarning|raw}}{{confirmWarning|raw}}
</div> </div>
<div style="margin-top:20px;"> <div style="margin-top:20px;">
<div style="margin-top:3px;">{% trans 'admin::compte-utilisateur identifiant' %}</div> <div style="margin-top:3px;">{% trans 'admin::compte-utilisateur identifiant' %}</div>

View File

@@ -105,7 +105,9 @@ phrasea::headers();
); );
$configuration = new \Alchemy\Phrasea\Core\Configuration($handler); $configuration = new \Alchemy\Phrasea\Core\Configuration($handler);
$connexion = $configuration->getConnexion(); $choosenConnexion = $configuration->getPhraseanet()->get('database');
$connexion = $configuration->getConnexion($choosenConnexion);
$hostname = $connexion->get('host'); $hostname = $connexion->get('host');
$port = $connexion->get('port'); $port = $connexion->get('port');