fix some CS
This commit is contained in:
@@ -30,7 +30,7 @@ use Symfony\Component\ClassLoader\UniversalClassLoader;
|
|||||||
* extends Symfony\Component\ClassLoader\UniversalClassLoader
|
* extends Symfony\Component\ClassLoader\UniversalClassLoader
|
||||||
*
|
*
|
||||||
* This class respect PSR-0 autoloading standard and allow to load traditionnal Thelia classes.
|
* This class respect PSR-0 autoloading standard and allow to load traditionnal Thelia classes.
|
||||||
*
|
*
|
||||||
* classMap can be used to.
|
* classMap can be used to.
|
||||||
*
|
*
|
||||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||||
@@ -76,7 +76,7 @@ class TheliaUniversalClassLoader extends UniversalClassLoader
|
|||||||
{
|
{
|
||||||
return $this->directories;
|
return $this->directories;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $classMap Class to filename map
|
* @param array $classMap Class to filename map
|
||||||
*/
|
*/
|
||||||
@@ -101,7 +101,7 @@ class TheliaUniversalClassLoader extends UniversalClassLoader
|
|||||||
if (isset($this->classMap[$class])) {
|
if (isset($this->classMap[$class])) {
|
||||||
return $this->classMap[$class];
|
return $this->classMap[$class];
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->directories as $directory) {
|
foreach ($this->directories as $directory) {
|
||||||
|
|
||||||
if (is_file($directory.DIRECTORY_SEPARATOR.$class.".class.php")) {
|
if (is_file($directory.DIRECTORY_SEPARATOR.$class.".class.php")) {
|
||||||
|
|||||||
@@ -42,25 +42,24 @@ class LoggerBundle extends Bundle
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Construct the depency injection builder
|
* Construct the depency injection builder
|
||||||
*
|
*
|
||||||
* Reference all Model in the Container here
|
* Reference all Model in the Container here
|
||||||
*
|
*
|
||||||
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function build(ContainerBuilder $container)
|
public function build(ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
$container->setParameter("logger.class", "\Thelia\Log\Tlog");
|
$container->setParameter("logger.class", "\Thelia\Log\Tlog");
|
||||||
$container->register("logger","%logger.class%")
|
$container->register("logger","%logger.class%")
|
||||||
->addArgument(new Reference('service_container'));
|
->addArgument(new Reference('service_container'));
|
||||||
|
|
||||||
$kernel = $container->get('kernel');
|
$kernel = $container->get('kernel');
|
||||||
|
|
||||||
if($kernel->isDebug())
|
if ($kernel->isDebug()) {
|
||||||
{
|
|
||||||
// $debug = function ($query, $parameters)
|
// $debug = function ($query, $parameters)
|
||||||
// {
|
// {
|
||||||
//
|
//
|
||||||
// $pattern = '(^' . preg_quote(dirname(__FILE__)) . '(\\.php$|[/\\\\]))'; // can be static
|
// $pattern = '(^' . preg_quote(dirname(__FILE__)) . '(\\.php$|[/\\\\]))'; // can be static
|
||||||
// foreach (debug_backtrace() as $backtrace) {
|
// foreach (debug_backtrace() as $backtrace) {
|
||||||
// if (isset($backtrace["file"]) && !preg_match($pattern, $backtrace["file"])) { // stop on first file outside NotORM source codes
|
// if (isset($backtrace["file"]) && !preg_match($pattern, $backtrace["file"])) { // stop on first file outside NotORM source codes
|
||||||
@@ -69,12 +68,12 @@ class LoggerBundle extends Bundle
|
|||||||
// }
|
// }
|
||||||
// file_put_contents(THELIA_ROOT . 'log/request_debug.log', "$backtrace[file]:$backtrace[line]:$query", FILE_APPEND);
|
// file_put_contents(THELIA_ROOT . 'log/request_debug.log', "$backtrace[file]:$backtrace[line]:$query", FILE_APPEND);
|
||||||
// file_put_contents(THELIA_ROOT . 'log/request_debug.log', is_scalar($parameters) ? $parameters : print_r($parameters, true), FILE_APPEND);
|
// file_put_contents(THELIA_ROOT . 'log/request_debug.log', is_scalar($parameters) ? $parameters : print_r($parameters, true), FILE_APPEND);
|
||||||
//
|
//
|
||||||
// };
|
// };
|
||||||
//
|
//
|
||||||
// $container->getDefinition('database')
|
// $container->getDefinition('database')
|
||||||
// ->addMethodCall('setDebug', array($debug));
|
// ->addMethodCall('setDebug', array($debug));
|
||||||
|
|
||||||
$container->get('database')
|
$container->get('database')
|
||||||
->setLogger($container->get('logger'));
|
->setLogger($container->get('logger'));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,16 +43,15 @@ class ModelBundle extends Bundle
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Construct the depency injection builder
|
* Construct the depency injection builder
|
||||||
*
|
*
|
||||||
* Reference all Model in the Container here
|
* Reference all Model in the Container here
|
||||||
*
|
*
|
||||||
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function build(ContainerBuilder $container)
|
public function build(ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
foreach(DIGenerator::genDiModel(realpath(THELIA_ROOT . "core/lib/Thelia/Model"), array('Base')) as $name => $class)
|
foreach (DIGenerator::genDiModel(realpath(THELIA_ROOT . "core/lib/Thelia/Model"), array('Base')) as $name => $class) {
|
||||||
{
|
|
||||||
$container->register('model.'.$name, $class)
|
$container->register('model.'.$name, $class)
|
||||||
->addArgument(new Reference("database"));
|
->addArgument(new Reference("database"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,8 +26,6 @@ use Symfony\Component\HttpKernel\Bundle\Bundle;
|
|||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Component\DependencyInjection\Reference;
|
use Symfony\Component\DependencyInjection\Reference;
|
||||||
|
|
||||||
use Thelia\Log\Tlog;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* First Bundle use in Thelia
|
* First Bundle use in Thelia
|
||||||
* It initialize dependency injection container.
|
* It initialize dependency injection container.
|
||||||
@@ -53,20 +51,18 @@ class NotORMBundle extends Bundle
|
|||||||
$config = array(
|
$config = array(
|
||||||
// \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION
|
// \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION
|
||||||
);
|
);
|
||||||
|
|
||||||
$kernel = $container->get('kernel');
|
$kernel = $container->get('kernel');
|
||||||
|
|
||||||
$pdo = new \PDO(THELIA_DB_DSN,THELIA_DB_USER, THELIA_DB_PASSWORD, $config);
|
$pdo = new \PDO(THELIA_DB_DSN,THELIA_DB_USER, THELIA_DB_PASSWORD, $config);
|
||||||
|
|
||||||
$pdo->exec("SET NAMES UTF8");
|
$pdo->exec("SET NAMES UTF8");
|
||||||
|
|
||||||
$container->register('database','\Thelia\Database\NotORM')
|
$container->register('database','\Thelia\Database\NotORM')
|
||||||
->addArgument($pdo);
|
->addArgument($pdo);
|
||||||
|
|
||||||
if(defined('THELIA_DB_CACHE') && !$kernel->isDebug())
|
if (defined('THELIA_DB_CACHE') && !$kernel->isDebug()) {
|
||||||
{
|
switch (THELIA_DB_CACHE) {
|
||||||
switch(THELIA_DB_CACHE)
|
|
||||||
{
|
|
||||||
case 'file':
|
case 'file':
|
||||||
$container->register('database_cache','\NotORM_Cache_File')
|
$container->register('database_cache','\NotORM_Cache_File')
|
||||||
->addArgument($kernel->getCacheDir().'/database.php');
|
->addArgument($kernel->getCacheDir().'/database.php');
|
||||||
@@ -76,8 +72,7 @@ class NotORMBundle extends Bundle
|
|||||||
->addArgument($kernel->getCacheDir().'/database_include.php');
|
->addArgument($kernel->getCacheDir().'/database_include.php');
|
||||||
break;
|
break;
|
||||||
case 'apc':
|
case 'apc':
|
||||||
if (extension_loaded('apc'))
|
if (extension_loaded('apc')) {
|
||||||
{
|
|
||||||
$container->register('database_cache','\NotORM_Cache_APC');
|
$container->register('database_cache','\NotORM_Cache_APC');
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -85,24 +80,19 @@ class NotORMBundle extends Bundle
|
|||||||
$container->register('database_cache','\NotORM_Cache_Session');
|
$container->register('database_cache','\NotORM_Cache_Session');
|
||||||
break;
|
break;
|
||||||
case 'memcache':
|
case 'memcache':
|
||||||
if(class_exists('Memcache'))
|
if (class_exists('Memcache')) {
|
||||||
{
|
|
||||||
$container->register('database_cache','\NotORM_Cache_Memcache')
|
$container->register('database_cache','\NotORM_Cache_Memcache')
|
||||||
->addArgument(new \Memcache());
|
->addArgument(new \Memcache());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if($container->hasDefinition('database_cache'))
|
if ($container->hasDefinition('database_cache')) {
|
||||||
{
|
|
||||||
$container->getDefinition('database')
|
$container->getDefinition('database')
|
||||||
->addMethodCall('setCache', array(new Reference('database_cache')));
|
->addMethodCall('setCache', array(new Reference('database_cache')));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ class TheliaBundle extends Bundle
|
|||||||
$container->register('listener.router', 'Symfony\Component\HttpKernel\EventListener\RouterListener')
|
$container->register('listener.router', 'Symfony\Component\HttpKernel\EventListener\RouterListener')
|
||||||
->setArguments(array(new Reference('matcher')))
|
->setArguments(array(new Reference('matcher')))
|
||||||
;
|
;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @TODO add an other listener on kernel.request for checking some params Like check if User is log in, set the language and other.
|
* @TODO add an other listener on kernel.request for checking some params Like check if User is log in, set the language and other.
|
||||||
*
|
*
|
||||||
@@ -91,14 +91,14 @@ class TheliaBundle extends Bundle
|
|||||||
->addArgument(new Reference('parser'))
|
->addArgument(new Reference('parser'))
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$container->register('dispatcher','Symfony\Component\EventDispatcher\EventDispatcher')
|
$container->register('dispatcher','Symfony\Component\EventDispatcher\EventDispatcher')
|
||||||
->addArgument(new Reference('service_container'))
|
->addArgument(new Reference('service_container'))
|
||||||
->addMethodCall('addSubscriber', array(new Reference('listener.router')))
|
->addMethodCall('addSubscriber', array(new Reference('listener.router')))
|
||||||
->addMethodCall('addSubscriber', array(new Reference('thelia.listener.view')))
|
->addMethodCall('addSubscriber', array(new Reference('thelia.listener.view')))
|
||||||
;
|
;
|
||||||
|
|
||||||
$container->register('http_kernel','Thelia\Core\TheliaHttpKernel')
|
$container->register('http_kernel','Thelia\Core\TheliaHttpKernel')
|
||||||
->addArgument(new Reference('dispatcher'))
|
->addArgument(new Reference('dispatcher'))
|
||||||
->addArgument(new Reference('service_container'))
|
->addArgument(new Reference('service_container'))
|
||||||
|
|||||||
@@ -55,9 +55,9 @@ class Parser implements ParserInterface
|
|||||||
protected $status = 200;
|
protected $status = 200;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param type $container
|
* @param type $container
|
||||||
*
|
*
|
||||||
* public function __construct(ContainerBuilder $container)
|
* public function __construct(ContainerBuilder $container)
|
||||||
*/
|
*/
|
||||||
public function __construct(ContainerInterface $container)
|
public function __construct(ContainerInterface $container)
|
||||||
@@ -73,15 +73,15 @@ class Parser implements ParserInterface
|
|||||||
public function getContent()
|
public function getContent()
|
||||||
{
|
{
|
||||||
$this->loadParser();
|
$this->loadParser();
|
||||||
|
|
||||||
$request = $this->container->get('request');
|
$request = $this->container->get('request');
|
||||||
|
|
||||||
$this->content = $request->get("test");
|
$this->content = $request->get("test");
|
||||||
|
|
||||||
$config = $this->container->get("model.config");
|
$config = $this->container->get("model.config");
|
||||||
|
|
||||||
echo $config->read("toto","tutu");
|
echo $config->read("toto","tutu");
|
||||||
|
|
||||||
return $this->content;
|
return $this->content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ class Thelia extends Kernel
|
|||||||
//$this->container->set('kernel', $this);
|
//$this->container->set('kernel', $this);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the cache directory.
|
* Gets the cache directory.
|
||||||
*
|
*
|
||||||
@@ -62,15 +62,14 @@ class Thelia extends Kernel
|
|||||||
*/
|
*/
|
||||||
public function getCacheDir()
|
public function getCacheDir()
|
||||||
{
|
{
|
||||||
if(defined('THELIA_ROOT'))
|
if (defined('THELIA_ROOT')) {
|
||||||
{
|
|
||||||
return THELIA_ROOT.'cache/'.$this->environment;
|
return THELIA_ROOT.'cache/'.$this->environment;
|
||||||
} else {
|
} else {
|
||||||
return parent::getCacheDir();
|
return parent::getCacheDir();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the log directory.
|
* Gets the log directory.
|
||||||
*
|
*
|
||||||
@@ -80,8 +79,7 @@ class Thelia extends Kernel
|
|||||||
*/
|
*/
|
||||||
public function getLogDir()
|
public function getLogDir()
|
||||||
{
|
{
|
||||||
if(defined('THELIA_ROOT'))
|
if (defined('THELIA_ROOT')) {
|
||||||
{
|
|
||||||
return THELIA_ROOT.'log/';
|
return THELIA_ROOT.'log/';
|
||||||
} else {
|
} else {
|
||||||
return parent::getLogDir();
|
return parent::getLogDir();
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -42,8 +42,7 @@ class TheliaHttpKernel extends HttpKernel
|
|||||||
|
|
||||||
$this->container = $container;
|
$this->container = $container;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles a Request to convert it to a Response.
|
* Handles a Request to convert it to a Response.
|
||||||
*
|
*
|
||||||
@@ -80,4 +79,4 @@ class TheliaHttpKernel extends HttpKernel
|
|||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,50 +25,50 @@ namespace Thelia\Database;
|
|||||||
use Thelia\Log\TlogInterface;
|
use Thelia\Log\TlogInterface;
|
||||||
use Thelia\Database\NotORM\Result;
|
use Thelia\Database\NotORM\Result;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Class Thelia\Database\NotORM extending \NotORM library http://www.notorm.com/
|
* Class Thelia\Database\NotORM extending \NotORM library http://www.notorm.com/
|
||||||
*
|
*
|
||||||
* This class create or redifine some setters
|
* This class create or redifine some setters
|
||||||
*
|
*
|
||||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||||
*/
|
*/
|
||||||
class NotORM extends \NotORM
|
class NotORM extends \NotORM
|
||||||
{
|
{
|
||||||
|
|
||||||
public $logger = false;
|
public $logger = false;
|
||||||
|
|
||||||
public function setCache(\NotORM_Cache $cache)
|
public function setCache(\NotORM_Cache $cache)
|
||||||
{
|
{
|
||||||
$this->cache = $cache;
|
$this->cache = $cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setLogger(TlogInterface $logger)
|
public function setLogger(TlogInterface $logger)
|
||||||
{
|
{
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setDebug($debug)
|
public function setDebug($debug)
|
||||||
{
|
{
|
||||||
if(is_callable($debug))
|
if (is_callable($debug)) {
|
||||||
{
|
|
||||||
$this->debug = $debug;
|
$this->debug = $debug;
|
||||||
} else {
|
} else {
|
||||||
$this->debug = true;
|
$this->debug = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get table data
|
/** Get table data
|
||||||
* @param string
|
* @param string
|
||||||
* @param array (["condition"[, array("value")]]) passed to NotORM_Result::where()
|
* @param array (["condition"[, array("value")]]) passed to NotORM_Result::where()
|
||||||
* @return NotORM_Result
|
* @return NotORM_Result
|
||||||
*/
|
*/
|
||||||
function __call($table, array $where) {
|
public function __call($table, array $where)
|
||||||
|
{
|
||||||
$return = new Result($this->structure->getReferencingTable($table, ''), $this);
|
$return = new Result($this->structure->getReferencingTable($table, ''), $this);
|
||||||
if ($where) {
|
if ($where) {
|
||||||
call_user_func_array(array($return, 'where'), $where);
|
call_user_func_array(array($return, 'where'), $where);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ namespace Thelia\Database\NotORM;
|
|||||||
|
|
||||||
class Result extends \NotORM_Result
|
class Result extends \NotORM_Result
|
||||||
{
|
{
|
||||||
protected function query($query, $parameters) {
|
protected function query($query, $parameters)
|
||||||
|
{
|
||||||
if ($this->notORM->debug) {
|
if ($this->notORM->debug) {
|
||||||
if (!is_callable($this->notORM->debug)) {
|
if (!is_callable($this->notORM->debug)) {
|
||||||
$debug = "$query;";
|
$debug = "$query;";
|
||||||
@@ -22,9 +23,8 @@ class Result extends \NotORM_Result
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->notORM->logger !== false)
|
if ($this->notORM->logger !== false) {
|
||||||
{
|
|
||||||
$this->notORM->logger->debug($query);
|
$this->notORM->logger->debug($query);
|
||||||
$this->notORM->logger->debug($parameters);
|
$this->notORM->logger->debug($parameters);
|
||||||
}
|
}
|
||||||
@@ -34,8 +34,10 @@ class Result extends \NotORM_Result
|
|||||||
$this->notORM->logger->fatal($this->notORM->errorCode());
|
$this->notORM->logger->fatal($this->notORM->errorCode());
|
||||||
$this->notORM->logger->fatal(print_r($this->notORM->errorInfo(), true));
|
$this->notORM->logger->fatal(print_r($this->notORM->errorInfo(), true));
|
||||||
$this->notORM->logger->fatal(print_r($return->errorInfo(), true));
|
$this->notORM->logger->fatal(print_r($return->errorInfo(), true));
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,8 +23,8 @@
|
|||||||
|
|
||||||
namespace Thelia\Log;
|
namespace Thelia\Log;
|
||||||
|
|
||||||
abstract class AbstractTlogDestination {
|
abstract class AbstractTlogDestination
|
||||||
|
{
|
||||||
//Tableau de TlogDestinationConfig paramétrant la destination
|
//Tableau de TlogDestinationConfig paramétrant la destination
|
||||||
protected $_configs;
|
protected $_configs;
|
||||||
|
|
||||||
@@ -33,14 +33,15 @@ abstract class AbstractTlogDestination {
|
|||||||
|
|
||||||
// Vaudra true si on est dans le back office.
|
// Vaudra true si on est dans le back office.
|
||||||
protected $flag_back_office = false;
|
protected $flag_back_office = false;
|
||||||
|
|
||||||
protected $configModel;
|
protected $configModel;
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct()
|
||||||
|
{
|
||||||
$this->_configs = array();
|
$this->_configs = array();
|
||||||
$this->_logs = array();
|
$this->_logs = array();
|
||||||
|
|
||||||
// Initialiser les variables de configuration
|
// Initialiser les variables de configuration
|
||||||
$this->_configs = $this->get_configs();
|
$this->_configs = $this->get_configs();
|
||||||
|
|
||||||
// Appliquer la configuration
|
// Appliquer la configuration
|
||||||
@@ -48,9 +49,10 @@ abstract class AbstractTlogDestination {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Affecte une valeur à une configuration de la destination
|
//Affecte une valeur à une configuration de la destination
|
||||||
public function set_config($nom, $valeur) {
|
public function set_config($nom, $valeur)
|
||||||
foreach($this->_configs as $config) {
|
{
|
||||||
if($config->nom == $nom) {
|
foreach ($this->_configs as $config) {
|
||||||
|
if ($config->nom == $nom) {
|
||||||
$config->valeur = $valeur;
|
$config->valeur = $valeur;
|
||||||
// Appliquer les changements
|
// Appliquer les changements
|
||||||
$this->configurer($config);
|
$this->configurer($config);
|
||||||
@@ -58,50 +60,55 @@ abstract class AbstractTlogDestination {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setConfigModel($configModel)
|
public function setConfigModel($configModel)
|
||||||
{
|
{
|
||||||
$this->configModel = $configModel;
|
$this->configModel = $configModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getConfigModel()
|
public function getConfigModel()
|
||||||
{
|
{
|
||||||
return $this->configModel;
|
return $this->configModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Récupère la valeur affectée à une configuration de la destination
|
//Récupère la valeur affectée à une configuration de la destination
|
||||||
public function get_config($nom) {
|
public function get_config($nom)
|
||||||
foreach($this->_configs as $config) {
|
{
|
||||||
if($config->nom == $nom) {
|
foreach ($this->_configs as $config) {
|
||||||
|
if ($config->nom == $nom) {
|
||||||
return $config->valeur;
|
return $config->valeur;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_configs() {
|
public function get_configs()
|
||||||
|
{
|
||||||
return $this->_configs;
|
return $this->_configs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function mode_back_office($bool) {
|
public function mode_back_office($bool)
|
||||||
|
{
|
||||||
$this->flag_back_office = $bool;
|
$this->flag_back_office = $bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Ajoute une ligne de logs à la destination
|
//Ajoute une ligne de logs à la destination
|
||||||
public function ajouter($string) {
|
public function ajouter($string)
|
||||||
|
{
|
||||||
$this->_logs[] = $string;
|
$this->_logs[] = $string;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function inserer_apres_body(&$res, $logdata) {
|
protected function inserer_apres_body(&$res, $logdata)
|
||||||
|
{
|
||||||
$match = array();
|
$match = array();
|
||||||
|
|
||||||
if (preg_match("/(<body[^>]*>)/i", $res, $match)) {
|
if (preg_match("/(<body[^>]*>)/i", $res, $match)) {
|
||||||
$res = str_replace($match[0], $match[0] . "\n" . $logdata, $res);
|
$res = str_replace($match[0], $match[0] . "\n" . $logdata, $res);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$res = $logdata . $res;
|
$res = $logdata . $res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -109,7 +116,8 @@ abstract class AbstractTlogDestination {
|
|||||||
// Demande à la destination de se configurer pour être prête
|
// Demande à la destination de se configurer pour être prête
|
||||||
// a fonctionner. Si $config est != false, celà indique
|
// a fonctionner. Si $config est != false, celà indique
|
||||||
// que seul le paramètre de configuration indiqué a été modifié.
|
// que seul le paramètre de configuration indiqué a été modifié.
|
||||||
protected function configurer($config = false) {
|
protected function configurer($config = false)
|
||||||
|
{
|
||||||
// Cette methode doit etre surchargée si nécessaire.
|
// Cette methode doit etre surchargée si nécessaire.
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,4 +130,4 @@ abstract class AbstractTlogDestination {
|
|||||||
|
|
||||||
// Retourne une brève description de la destination
|
// Retourne une brève description de la destination
|
||||||
abstract public function get_description();
|
abstract public function get_description();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,9 +25,9 @@ namespace Thelia\Log\Destination;
|
|||||||
|
|
||||||
use Thelia\Log\AbstractTlogDestination;
|
use Thelia\Log\AbstractTlogDestination;
|
||||||
use Thelia\Log\TlogDestinationConfig;
|
use Thelia\Log\TlogDestinationConfig;
|
||||||
|
|
||||||
class TlogDestinationFile extends AbstractTlogDestination {
|
|
||||||
|
|
||||||
|
class TlogDestinationFile extends AbstractTlogDestination
|
||||||
|
{
|
||||||
// Nom des variables de configuration
|
// Nom des variables de configuration
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
const VAR_PATH_FILE = "tlog_destinationfile_path";
|
const VAR_PATH_FILE = "tlog_destinationfile_path";
|
||||||
@@ -39,21 +39,22 @@ class TlogDestinationFile extends AbstractTlogDestination {
|
|||||||
protected $path_defaut = false;
|
protected $path_defaut = false;
|
||||||
protected $fh = false;
|
protected $fh = false;
|
||||||
|
|
||||||
public function __construct($configModel = null) {
|
public function __construct($configModel = null)
|
||||||
|
{
|
||||||
$this->path_defaut = THELIA_ROOT . "log/" . self::TLOG_DEFAULT_NAME;
|
$this->path_defaut = THELIA_ROOT . "log/" . self::TLOG_DEFAULT_NAME;
|
||||||
$this->setConfigModel($configModel);
|
$this->setConfigModel($configModel);
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function configurer($config = false) {
|
public function configurer($config = false)
|
||||||
|
{
|
||||||
$file_path = $this->get_config(self::VAR_PATH_FILE);
|
$file_path = $this->get_config(self::VAR_PATH_FILE);
|
||||||
$mode = strtolower($this->get_config(self::VAR_MODE)) == 'a' ? 'a' : 'w';
|
$mode = strtolower($this->get_config(self::VAR_MODE)) == 'a' ? 'a' : 'w';
|
||||||
|
|
||||||
if (! empty($file_path)) {
|
if (! empty($file_path)) {
|
||||||
if (! is_file($file_path)) {
|
if (! is_file($file_path)) {
|
||||||
$dir = dirname($file_path);
|
$dir = dirname($file_path);
|
||||||
if(! is_dir($dir)) {
|
if (! is_dir($dir)) {
|
||||||
mkdir($dir, 0777, true);
|
mkdir($dir, 0777, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -64,15 +65,18 @@ class TlogDestinationFile extends AbstractTlogDestination {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_titre() {
|
public function get_titre()
|
||||||
|
{
|
||||||
return "Text File";
|
return "Text File";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_description() {
|
public function get_description()
|
||||||
|
{
|
||||||
return "Store logs into text file";
|
return "Store logs into text file";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_configs() {
|
public function get_configs()
|
||||||
|
{
|
||||||
return array(
|
return array(
|
||||||
new TlogDestinationConfig(
|
new TlogDestinationConfig(
|
||||||
self::VAR_PATH_FILE,
|
self::VAR_PATH_FILE,
|
||||||
@@ -93,13 +97,15 @@ class TlogDestinationFile extends AbstractTlogDestination {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ajouter($texte) {
|
public function ajouter($texte)
|
||||||
|
{
|
||||||
if ($this->fh) {
|
if ($this->fh) {
|
||||||
fwrite($this->fh, $texte."\n");
|
fwrite($this->fh, $texte."\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ecrire(&$res) {
|
public function ecrire(&$res)
|
||||||
|
{
|
||||||
if ($this->fh) @fclose($this->fh);
|
if ($this->fh) @fclose($this->fh);
|
||||||
|
|
||||||
$this->fh = false;
|
$this->fh = false;
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ namespace Thelia\Log\Destination;
|
|||||||
|
|
||||||
use Thelia\Log\AbstractTlogDestination;
|
use Thelia\Log\AbstractTlogDestination;
|
||||||
|
|
||||||
class TlogDestinationHtml extends AbstractTlogDestination {
|
class TlogDestinationHtml extends AbstractTlogDestination
|
||||||
|
{
|
||||||
// Nom des variables de configuration
|
// Nom des variables de configuration
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
const VAR_STYLE = "tlog_destinationhtml_style";
|
const VAR_STYLE = "tlog_destinationhtml_style";
|
||||||
@@ -34,24 +34,29 @@ class TlogDestinationHtml extends AbstractTlogDestination {
|
|||||||
|
|
||||||
private $style;
|
private $style;
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct()
|
||||||
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function configurer($config = false) {
|
public function configurer($config = false)
|
||||||
|
{
|
||||||
$this->style = $this->get_config(self::VAR_STYLE);
|
$this->style = $this->get_config(self::VAR_STYLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_titre() {
|
public function get_titre()
|
||||||
|
{
|
||||||
return "Affichage direct dans la page, en HTML";
|
return "Affichage direct dans la page, en HTML";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_description() {
|
public function get_description()
|
||||||
|
{
|
||||||
return "Permet d'afficher les logs directement dans la page resultat, avec une mise en forme HTML.";
|
return "Permet d'afficher les logs directement dans la page resultat, avec une mise en forme HTML.";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_configs() {
|
public function get_configs()
|
||||||
|
{
|
||||||
// return array(
|
// return array(
|
||||||
// new TlogDestinationConfig(
|
// new TlogDestinationConfig(
|
||||||
// self::VAR_STYLE,
|
// self::VAR_STYLE,
|
||||||
@@ -63,10 +68,10 @@ class TlogDestinationHtml extends AbstractTlogDestination {
|
|||||||
// );
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ecrire(&$res) {
|
public function ecrire(&$res)
|
||||||
|
{
|
||||||
$block = sprintf('<pre class="tlog-trace" style="%s">%s</pre>', $this->style, htmlspecialchars(implode("\n", $this->_logs)));
|
$block = sprintf('<pre class="tlog-trace" style="%s">%s</pre>', $this->style, htmlspecialchars(implode("\n", $this->_logs)));
|
||||||
|
|
||||||
$this->inserer_apres_body($res, $block);
|
$this->inserer_apres_body($res, $block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,21 +25,25 @@ namespace Thelia\Log\Destination;
|
|||||||
|
|
||||||
use Thelia\Log\AbstractTlogDestination;
|
use Thelia\Log\AbstractTlogDestination;
|
||||||
|
|
||||||
class TlogDestinationNull extends AbstractTlogDestination {
|
class TlogDestinationNull extends AbstractTlogDestination
|
||||||
|
{
|
||||||
public function get_titre() {
|
public function get_titre()
|
||||||
|
{
|
||||||
return "Trou noir";
|
return "Trou noir";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_description() {
|
public function get_description()
|
||||||
|
{
|
||||||
return "Cette destination ne provoque aucune sortie";
|
return "Cette destination ne provoque aucune sortie";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ajouter($string) {
|
public function ajouter($string)
|
||||||
|
{
|
||||||
// Rien
|
// Rien
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ecrire(&$res) {
|
public function ecrire(&$res)
|
||||||
|
{
|
||||||
// Rien
|
// Rien
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,26 +25,30 @@ namespace Thelia\Log\Destination;
|
|||||||
|
|
||||||
use Thelia\Log\AbstractTlogDestination;
|
use Thelia\Log\AbstractTlogDestination;
|
||||||
|
|
||||||
|
class TlogDestinationText extends AbstractTlogDestination
|
||||||
class TlogDestinationText extends AbstractTlogDestination {
|
{
|
||||||
|
public function __construct()
|
||||||
public function __construct() {
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_titre() {
|
public function get_titre()
|
||||||
|
{
|
||||||
return "Affichage direct dans la page, en texte brut";
|
return "Affichage direct dans la page, en texte brut";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_description() {
|
public function get_description()
|
||||||
|
{
|
||||||
return "Permet d'afficher les logs directement dans la page resultat, au format texte brut.";
|
return "Permet d'afficher les logs directement dans la page resultat, au format texte brut.";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ajouter($texte) {
|
public function ajouter($texte)
|
||||||
|
{
|
||||||
echo $texte."\n";
|
echo $texte."\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ecrire(&$res) {
|
public function ecrire(&$res)
|
||||||
|
{
|
||||||
// Rien
|
// Rien
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,11 +26,11 @@ use Thelia\Model\Config;
|
|||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Thelia Logger
|
* Thelia Logger
|
||||||
*
|
*
|
||||||
* Allow to define different level and output.
|
* Allow to define different level and output.
|
||||||
*
|
*
|
||||||
* @author Franck Allimant <franck@cqfdev.fr>
|
* @author Franck Allimant <franck@cqfdev.fr>
|
||||||
*/
|
*/
|
||||||
class Tlog Implements TlogInterface
|
class Tlog Implements TlogInterface
|
||||||
@@ -77,19 +77,19 @@ class Tlog Implements TlogInterface
|
|||||||
|
|
||||||
// directories where are the Destinations Files
|
// directories where are the Destinations Files
|
||||||
public $dir_destinations = array();
|
public $dir_destinations = array();
|
||||||
|
|
||||||
protected $container;
|
protected $container;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param type $container
|
* @param type $container
|
||||||
*
|
*
|
||||||
* public function __construct(ContainerBuilder $container)
|
* public function __construct(ContainerBuilder $container)
|
||||||
*/
|
*/
|
||||||
public function __construct(ContainerInterface $container)
|
public function __construct(ContainerInterface $container)
|
||||||
{
|
{
|
||||||
$this->container = $container;
|
$this->container = $container;
|
||||||
|
|
||||||
$this->init();
|
$this->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,9 +106,10 @@ class Tlog Implements TlogInterface
|
|||||||
// return self::$instance;
|
// return self::$instance;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
protected function init() {
|
protected function init()
|
||||||
|
{
|
||||||
$config = $this->container->get("model.config");
|
$config = $this->container->get("model.config");
|
||||||
|
|
||||||
$level = $config->read(self::VAR_LEVEL, self::DEFAULT_LEVEL);
|
$level = $config->read(self::VAR_LEVEL, self::DEFAULT_LEVEL);
|
||||||
|
|
||||||
$this->set_level($level);
|
$this->set_level($level);
|
||||||
@@ -131,7 +132,8 @@ class Tlog Implements TlogInterface
|
|||||||
// Configuration
|
// Configuration
|
||||||
// -------------
|
// -------------
|
||||||
|
|
||||||
public function set_destinations($destinations) {
|
public function set_destinations($destinations)
|
||||||
|
{
|
||||||
if (! empty($destinations)) {
|
if (! empty($destinations)) {
|
||||||
|
|
||||||
$this->destinations = array();
|
$this->destinations = array();
|
||||||
@@ -141,40 +143,44 @@ class Tlog Implements TlogInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function set_level($level) {
|
public function set_level($level)
|
||||||
|
{
|
||||||
$this->level = $level;
|
$this->level = $level;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function set_prefixe($prefixe) {
|
public function set_prefixe($prefixe)
|
||||||
|
{
|
||||||
$this->prefixe = $prefixe;
|
$this->prefixe = $prefixe;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function set_files($files) {
|
public function set_files($files)
|
||||||
|
{
|
||||||
$this->files = explode(";", $files);
|
$this->files = explode(";", $files);
|
||||||
|
|
||||||
$this->all_files = in_array('*', $this->files);
|
$this->all_files = in_array('*', $this->files);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function set_ip($ips) {
|
public function set_ip($ips)
|
||||||
|
{
|
||||||
if (! empty($ips) && ! in_array($_SERVER['REMOTE_ADDR'], explode(";", $ips))) $this->level = self::MUET;
|
if (! empty($ips) && ! in_array($_SERVER['REMOTE_ADDR'], explode(";", $ips))) $this->level = self::MUET;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function set_show_redirect($bool) {
|
public function set_show_redirect($bool)
|
||||||
|
{
|
||||||
$this->show_redirect = $bool;
|
$this->show_redirect = $bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configuration d'une destination
|
// Configuration d'une destination
|
||||||
public function set_config($destination, $param, $valeur) {
|
public function set_config($destination, $param, $valeur)
|
||||||
|
{
|
||||||
if (isset($this->destinations[$destination])) {
|
if (isset($this->destinations[$destination])) {
|
||||||
$this->destinations[$destination]->set_config($param, $valeur);
|
$this->destinations[$destination]->set_config($param, $valeur);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configuration d'une destination
|
// Configuration d'une destination
|
||||||
public function get_config($destination, $param) {
|
public function get_config($destination, $param)
|
||||||
|
{
|
||||||
if (isset($this->destinations[$destination])) {
|
if (isset($this->destinations[$destination])) {
|
||||||
return $this->destinations[$destination]->get_config($param);
|
return $this->destinations[$destination]->get_config($param);
|
||||||
}
|
}
|
||||||
@@ -185,7 +191,8 @@ class Tlog Implements TlogInterface
|
|||||||
// Methodes d'accès aux traces
|
// Methodes d'accès aux traces
|
||||||
// ---------------------------
|
// ---------------------------
|
||||||
|
|
||||||
public function trace() {
|
public function trace()
|
||||||
|
{
|
||||||
if ($this->level > self::TRACE)
|
if ($this->level > self::TRACE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -194,7 +201,8 @@ class Tlog Implements TlogInterface
|
|||||||
$this->out("TRACE", $args);
|
$this->out("TRACE", $args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function debug() {
|
public function debug()
|
||||||
|
{
|
||||||
if ($this->level > self::DEBUG)
|
if ($this->level > self::DEBUG)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -203,7 +211,8 @@ class Tlog Implements TlogInterface
|
|||||||
$this->out("DEBUG", $args);
|
$this->out("DEBUG", $args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function info() {
|
public function info()
|
||||||
|
{
|
||||||
if ($this->level > self::INFO)
|
if ($this->level > self::INFO)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -212,7 +221,8 @@ class Tlog Implements TlogInterface
|
|||||||
$this->out("INFO", $args);
|
$this->out("INFO", $args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function warning() {
|
public function warning()
|
||||||
|
{
|
||||||
if ($this->level > self::WARNING)
|
if ($this->level > self::WARNING)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -221,7 +231,8 @@ class Tlog Implements TlogInterface
|
|||||||
$this->out("WARNING", $args);
|
$this->out("WARNING", $args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function error() {
|
public function error()
|
||||||
|
{
|
||||||
if ($this->level > self::ERROR)
|
if ($this->level > self::ERROR)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -230,7 +241,8 @@ class Tlog Implements TlogInterface
|
|||||||
$this->out("ERREUR", $args);
|
$this->out("ERREUR", $args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fatal() {
|
public function fatal()
|
||||||
|
{
|
||||||
if ($this->level > self::FATAL)
|
if ($this->level > self::FATAL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -240,27 +252,28 @@ class Tlog Implements TlogInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Mode back office
|
// Mode back office
|
||||||
public static function mode_back_office($booleen) {
|
public static function mode_back_office($booleen)
|
||||||
|
{
|
||||||
foreach(Tlog::instance()->destinations as $dest) {
|
foreach (Tlog::instance()->destinations as $dest) {
|
||||||
$dest->mode_back_office($booleen);
|
$dest->mode_back_office($booleen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ecriture finale
|
// Ecriture finale
|
||||||
public function ecrire(&$res) {
|
public function ecrire(&$res)
|
||||||
|
{
|
||||||
self::$ecrire_effectue = true;
|
self::$ecrire_effectue = true;
|
||||||
|
|
||||||
// Muet ? On ne fait rien
|
// Muet ? On ne fait rien
|
||||||
if ($this->level == self::MUET) return;
|
if ($this->level == self::MUET) return;
|
||||||
|
|
||||||
foreach($this->destinations as $dest) {
|
foreach ($this->destinations as $dest) {
|
||||||
$dest->ecrire($res);
|
$dest->ecrire($res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ecrire_si_exit() {
|
public function ecrire_si_exit()
|
||||||
|
{
|
||||||
// Si les infos de debug n'ont pas été ecrites, le faire maintenant
|
// Si les infos de debug n'ont pas été ecrites, le faire maintenant
|
||||||
if (self::$ecrire_effectue === false) {
|
if (self::$ecrire_effectue === false) {
|
||||||
|
|
||||||
@@ -272,8 +285,8 @@ class Tlog Implements TlogInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function afficher_redirections($url) {
|
public function afficher_redirections($url)
|
||||||
|
{
|
||||||
if ($this->level != self::MUET && $this->show_redirect) {
|
if ($this->level != self::MUET && $this->show_redirect) {
|
||||||
echo "
|
echo "
|
||||||
<html>
|
<html>
|
||||||
@@ -285,16 +298,15 @@ class Tlog Implements TlogInterface
|
|||||||
";
|
";
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Permet de déterminer si la trace est active, en prenant en compte
|
// Permet de déterminer si la trace est active, en prenant en compte
|
||||||
// le level et le filtrage par fichier
|
// le level et le filtrage par fichier
|
||||||
public function active($level) {
|
public function active($level)
|
||||||
|
{
|
||||||
if ($this->level <= $level) {
|
if ($this->level <= $level) {
|
||||||
|
|
||||||
$origine = $this->trouver_origine();
|
$origine = $this->trouver_origine();
|
||||||
@@ -309,26 +321,27 @@ class Tlog Implements TlogInterface
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function is_file_active($file) {
|
public function is_file_active($file)
|
||||||
|
{
|
||||||
return ($this->all_files || in_array($file, $this->files)) && ! in_array("!$file", $this->files);
|
return ($this->all_files || in_array($file, $this->files)) && ! in_array("!$file", $this->files);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -- Methodes privees ---------------------------------------- */
|
/* -- Methodes privees ---------------------------------------- */
|
||||||
|
|
||||||
// Adapté de LoggerLoginEvent dans log4php
|
// Adapté de LoggerLoginEvent dans log4php
|
||||||
private function trouver_origine() {
|
private function trouver_origine()
|
||||||
|
{
|
||||||
$origine = array();
|
$origine = array();
|
||||||
|
|
||||||
if(function_exists('debug_backtrace')) {
|
if (function_exists('debug_backtrace')) {
|
||||||
|
|
||||||
$trace = debug_backtrace();
|
$trace = debug_backtrace();
|
||||||
$prevHop = null;
|
$prevHop = null;
|
||||||
// make a downsearch to identify the caller
|
// make a downsearch to identify the caller
|
||||||
$hop = array_pop($trace);
|
$hop = array_pop($trace);
|
||||||
|
|
||||||
while($hop !== null) {
|
while ($hop !== null) {
|
||||||
if(isset($hop['class'])) {
|
if (isset($hop['class'])) {
|
||||||
// we are sometimes in functions = no class available: avoid php warning here
|
// we are sometimes in functions = no class available: avoid php warning here
|
||||||
$className = $hop['class'];
|
$className = $hop['class'];
|
||||||
|
|
||||||
@@ -359,8 +372,8 @@ class Tlog Implements TlogInterface
|
|||||||
return $origine;
|
return $origine;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function out($level, $tabargs) {
|
private function out($level, $tabargs)
|
||||||
|
{
|
||||||
$text = '';
|
$text = '';
|
||||||
|
|
||||||
foreach ($tabargs as $arg) {
|
foreach ($tabargs as $arg) {
|
||||||
@@ -384,34 +397,31 @@ class Tlog Implements TlogInterface
|
|||||||
|
|
||||||
$trace = $prefixe . $text;
|
$trace = $prefixe . $text;
|
||||||
|
|
||||||
foreach($this->destinations as $dest) {
|
foreach ($this->destinations as $dest) {
|
||||||
$dest->ajouter($trace);
|
$dest->ajouter($trace);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->linecount++;
|
$this->linecount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param type $destinations
|
* @param type $destinations
|
||||||
* @param array $actives array containing classes instanceof AbstractTlogDestination
|
* @param array $actives array containing classes instanceof AbstractTlogDestination
|
||||||
*/
|
*/
|
||||||
protected function loadDestinations(&$destinations, array $actives = NULL) {
|
protected function loadDestinations(&$destinations, array $actives = NULL)
|
||||||
|
{
|
||||||
foreach($actives as $active)
|
foreach ($actives as $active) {
|
||||||
{
|
if (class_exists($active)) {
|
||||||
if(class_exists($active))
|
|
||||||
{
|
|
||||||
$class = new $active($this->container->get('model.config'));
|
$class = new $active($this->container->get('model.config'));
|
||||||
|
|
||||||
if(!$class instanceof AbstractTlogDestination)
|
if (!$class instanceof AbstractTlogDestination) {
|
||||||
{
|
|
||||||
throw new \UnexpectedValueException($active." must extends Thelia\Tlog\AbstractTlogDestination");
|
throw new \UnexpectedValueException($active." must extends Thelia\Tlog\AbstractTlogDestination");
|
||||||
}
|
}
|
||||||
|
|
||||||
$destinations[$active] = $class;
|
$destinations[$active] = $class;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,8 +35,8 @@ class TlogDestinationConfig
|
|||||||
public $type;
|
public $type;
|
||||||
public $valeur;
|
public $valeur;
|
||||||
|
|
||||||
public function __construct($nom, $titre, $label, $defaut, $type, $config = null) {
|
public function __construct($nom, $titre, $label, $defaut, $type, $config = null)
|
||||||
|
{
|
||||||
$this->nom = $nom;
|
$this->nom = $nom;
|
||||||
$this->titre = $titre;
|
$this->titre = $titre;
|
||||||
$this->label = $label;
|
$this->label = $label;
|
||||||
@@ -44,9 +44,8 @@ class TlogDestinationConfig
|
|||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
|
|
||||||
// @$this->charger();
|
// @$this->charger();
|
||||||
|
|
||||||
if($config)
|
if ($config) {
|
||||||
{
|
|
||||||
$this->valeur = $config->read($this->nom, $this->defaut);
|
$this->valeur = $config->read($this->nom, $this->defaut);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -61,4 +60,4 @@ class TlogDestinationConfig
|
|||||||
// $this->add();
|
// $this->add();
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,15 +2,14 @@
|
|||||||
|
|
||||||
namespace Thelia\Log;
|
namespace Thelia\Log;
|
||||||
|
|
||||||
|
|
||||||
Interface TlogInterface
|
Interface TlogInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
public function trace();
|
public function trace();
|
||||||
public function debug();
|
public function debug();
|
||||||
public function info();
|
public function info();
|
||||||
public function warning();
|
public function warning();
|
||||||
public function error();
|
public function error();
|
||||||
public function fatal();
|
public function fatal();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,50 +6,45 @@ use Thelia\Model\Base\Base;
|
|||||||
|
|
||||||
class Accessory extends Base
|
class Accessory extends Base
|
||||||
{
|
{
|
||||||
protected $id;
|
|
||||||
protected $product_id;
|
protected $product_id;
|
||||||
protected $accessory;
|
protected $accessory;
|
||||||
protected $position;
|
protected $position;
|
||||||
|
|
||||||
protected $properties = array(
|
protected $properties = array(
|
||||||
"id",
|
|
||||||
"product_id",
|
"product_id",
|
||||||
"accessory",
|
"accessory",
|
||||||
"position"
|
"position"
|
||||||
);
|
);
|
||||||
|
|
||||||
public function getId() {
|
|
||||||
return $this->id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setId($id) {
|
public function getProductId()
|
||||||
$this->id = $id;
|
{
|
||||||
}
|
|
||||||
|
|
||||||
public function getProductId() {
|
|
||||||
return $this->product_id;
|
return $this->product_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setProductId($product_id) {
|
public function setProductId($product_id)
|
||||||
|
{
|
||||||
$this->product_id = $product_id;
|
$this->product_id = $product_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAccessory() {
|
public function getAccessory()
|
||||||
|
{
|
||||||
return $this->accessory;
|
return $this->accessory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setAccessory($accessory) {
|
public function setAccessory($accessory)
|
||||||
|
{
|
||||||
$this->accessory = $accessory;
|
$this->accessory = $accessory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPosition() {
|
public function getPosition()
|
||||||
|
{
|
||||||
return $this->position;
|
return $this->position;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setPosition($position) {
|
public function setPosition($position)
|
||||||
|
{
|
||||||
$this->position = $position;
|
$this->position = $position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,97 +27,161 @@ namespace Thelia\Model\Base;
|
|||||||
*/
|
*/
|
||||||
abstract class Base
|
abstract class Base
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Primary key
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
protected $id;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var \NotORM
|
* @var \NotORM
|
||||||
*/
|
*/
|
||||||
protected $db;
|
protected $db;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $table;
|
protected $table;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var string date when the record had been updated
|
* @var string date when the record had been updated
|
||||||
*/
|
*/
|
||||||
protected $updated_at;
|
protected $updated_at;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var string date when the record had been saved
|
* @var string date when the record had been saved
|
||||||
*/
|
*/
|
||||||
protected $created_at;
|
protected $created_at;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* base properties for all models
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $baseProperties = array(
|
||||||
|
"created_at",
|
||||||
|
"update_at"
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param \NotORM $NotORM
|
* @param \NotORM $NotORM
|
||||||
*/
|
*/
|
||||||
public function __construct(\NotORM $NotORM) {
|
public function __construct(\NotORM $NotORM)
|
||||||
|
{
|
||||||
$this->db = $NotORM;
|
$this->db = $NotORM;
|
||||||
$this->table = $this->getTableName();
|
$this->table = $this->getTableName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUpdatedAt() {
|
public function getUpdatedAt()
|
||||||
|
{
|
||||||
return $this->updated_at;
|
return $this->updated_at;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setUpdatedAt($updated_at) {
|
public function setUpdatedAt($updated_at)
|
||||||
|
{
|
||||||
$this->updated_at = $updated_at;
|
$this->updated_at = $updated_at;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCreatedAt() {
|
public function getCreatedAt()
|
||||||
|
{
|
||||||
return $this->created_at;
|
return $this->created_at;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setCreatedAt($created_at) {
|
public function setCreatedAt($created_at)
|
||||||
|
{
|
||||||
$this->created_at = $created_at;
|
$this->created_at = $created_at;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getBaseProperties()
|
||||||
|
{
|
||||||
|
return $this->baseProperties;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getProperties()
|
||||||
|
{
|
||||||
|
return $this->properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getId()
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setId($id)
|
||||||
|
{
|
||||||
|
$this->id = $id;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return \NotORM
|
* @return \NotORM
|
||||||
*/
|
*/
|
||||||
public function getDb() {
|
public function getDb()
|
||||||
|
{
|
||||||
return $this->db;
|
return $this->db;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTable() {
|
public function getTable()
|
||||||
|
{
|
||||||
return $this->table;
|
return $this->table;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function save()
|
public function save()
|
||||||
{
|
{
|
||||||
$this->updated_at = $this->created_at = date('Y-m-d H:i:s');
|
$this->updated_at = $this->created_at = date('Y-m-d H:i:s');
|
||||||
|
|
||||||
|
$values = $this->prepare();
|
||||||
|
|
||||||
|
// $this->db->insert_update(
|
||||||
|
// array("id", $this->getId()),
|
||||||
|
// $values,
|
||||||
|
//
|
||||||
|
// );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function prepare()
|
||||||
|
{
|
||||||
|
$properties = array_merge($this->getBaseProperties(), $this->getProperties());
|
||||||
|
|
||||||
|
$values = array();
|
||||||
|
|
||||||
|
foreach ($properties as $property) {
|
||||||
|
$values[$property] = $this->$property;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $values;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isNew()
|
||||||
|
{
|
||||||
|
return $this->getId() ? false:true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return string name of the current table
|
* @return string name of the current table
|
||||||
*/
|
*/
|
||||||
protected function getTableName()
|
protected function getTableName()
|
||||||
{
|
{
|
||||||
return $this->underscore(__CLASS__);
|
return $this->underscore(__CLASS__);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* extract from symfony 1.4
|
* extract from symfony 1.4
|
||||||
*
|
*
|
||||||
* change camelized wirnd into underscore word.
|
* change camelized wirnd into underscore word.
|
||||||
*
|
*
|
||||||
* ex : AttributeCategory => attribute_category
|
* ex : AttributeCategory => attribute_category
|
||||||
*
|
*
|
||||||
* @param string $camel_cased_word
|
* @param string $camel_cased_word
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function underscore($camel_cased_word)
|
protected function underscore($camel_cased_word)
|
||||||
@@ -126,9 +190,10 @@ abstract class Base
|
|||||||
$tmp = str_replace('::', '/', $tmp);
|
$tmp = str_replace('::', '/', $tmp);
|
||||||
$tmp = self::pregtr($tmp, array('/([A-Z]+)([A-Z][a-z])/' => '\\1_\\2',
|
$tmp = self::pregtr($tmp, array('/([A-Z]+)([A-Z][a-z])/' => '\\1_\\2',
|
||||||
'/([a-z\d])([A-Z])/' => '\\1_\\2'));
|
'/([a-z\d])([A-Z])/' => '\\1_\\2'));
|
||||||
|
|
||||||
return strtolower($tmp);
|
return strtolower($tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function pregtr($search, $replacePairs)
|
public static function pregtr($search, $replacePairs)
|
||||||
{
|
{
|
||||||
return preg_replace(array_keys($replacePairs), array_values($replacePairs), $search);
|
return preg_replace(array_keys($replacePairs), array_values($replacePairs), $search);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use Thelia\Model\Base\Base;
|
|||||||
|
|
||||||
class Config extends Base
|
class Config extends Base
|
||||||
{
|
{
|
||||||
|
|
||||||
public function read($search, $default)
|
public function read($search, $default)
|
||||||
{
|
{
|
||||||
return $this->db->config()->where("name",$search)->fetch()?:$default;
|
return $this->db->config()->where("name",$search)->fetch()?:$default;
|
||||||
|
|||||||
@@ -21,7 +21,6 @@
|
|||||||
/* */
|
/* */
|
||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
namespace Thelia\Tests\Log;
|
namespace Thelia\Tests\Log;
|
||||||
|
|
||||||
use Thelia\Log\Tlog;
|
use Thelia\Log\Tlog;
|
||||||
@@ -30,18 +29,19 @@ use Thelia\Core\Thelia;
|
|||||||
class TlogTest extends \PHPUnit_Framework_TestCase
|
class TlogTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
protected $logger;
|
protected $logger;
|
||||||
|
|
||||||
protected $regex = "/(\\d)(.)(\\s+)((?:[a-z][a-z]+))(\\s+)(\\[.*?\\])(\\s+)(\\{.*?\\})(\\s+)((?:2|1)\\d{3}(?:-|\\/)(?:(?:0[1-9])|(?:1[0-2]))(?:-|\\/)(?:(?:0[1-9])|(?:[1-2][0-9])|(?:3[0-1]))(?:T|\\s)(?:(?:[0-1][0-9])|(?:2[0-3])):(?:[0-5][0-9]):(?:[0-5][0-9]))(.)(\\s+)(%s)/is";
|
protected $regex = "/(\\d)(.)(\\s+)((?:[a-z][a-z]+))(\\s+)(\\[.*?\\])(\\s+)(\\{.*?\\})(\\s+)((?:2|1)\\d{3}(?:-|\\/)(?:(?:0[1-9])|(?:1[0-2]))(?:-|\\/)(?:(?:0[1-9])|(?:[1-2][0-9])|(?:3[0-1]))(?:T|\\s)(?:(?:[0-1][0-9])|(?:2[0-3])):(?:[0-5][0-9]):(?:[0-5][0-9]))(.)(\\s+)(%s)/is";
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp()
|
||||||
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
$_SERVER['REMOTE_ADDR'] = '::1';
|
||||||
|
|
||||||
$containerMock = $this->getMock("Symfony\Component\DependencyInjection\Container", array("get", "getParameter"));
|
$containerMock = $this->getMock("Symfony\Component\DependencyInjection\Container", array("get", "getParameter"));
|
||||||
|
|
||||||
$configModel = new ConfigModel();
|
$configModel = new ConfigModel();
|
||||||
|
|
||||||
$containerMock->expects($this->any())
|
$containerMock->expects($this->any())
|
||||||
->method("get")
|
->method("get")
|
||||||
->will($this->returnValue($configModel));
|
->will($this->returnValue($configModel));
|
||||||
@@ -49,140 +49,139 @@ class TlogTest extends \PHPUnit_Framework_TestCase
|
|||||||
->method("getParameter")
|
->method("getParameter")
|
||||||
->with($this->stringContains("logger.class"))
|
->with($this->stringContains("logger.class"))
|
||||||
->will($this->returnValue("Thelia\Log\Tlog"));
|
->will($this->returnValue("Thelia\Log\Tlog"));
|
||||||
|
|
||||||
|
|
||||||
$this->logger = new Tlog($containerMock);
|
$this->logger = new Tlog($containerMock);
|
||||||
|
|
||||||
$this->logger->set_destinations("Thelia\Log\Destination\TlogDestinationText");
|
$this->logger->set_destinations("Thelia\Log\Destination\TlogDestinationText");
|
||||||
$this->logger->set_level(Tlog::TRACE);
|
$this->logger->set_level(Tlog::TRACE);
|
||||||
$this->logger->set_files("*");
|
$this->logger->set_files("*");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTraceWithTraceLevel()
|
public function testTraceWithTraceLevel()
|
||||||
{
|
{
|
||||||
|
|
||||||
$logger = $this->logger;
|
$logger = $this->logger;
|
||||||
$logger->set_level(Tlog::TRACE);
|
$logger->set_level(Tlog::TRACE);
|
||||||
|
|
||||||
//"#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: "
|
//"#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: "
|
||||||
$this->expectOutputRegex(sprintf($this->regex, "foo"));
|
$this->expectOutputRegex(sprintf($this->regex, "foo"));
|
||||||
$logger->trace("foo");
|
$logger->trace("foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTraceWitoutTraceLevel()
|
public function testTraceWitoutTraceLevel()
|
||||||
{
|
{
|
||||||
$logger = $this->logger;
|
$logger = $this->logger;
|
||||||
$logger->set_level(Tlog::MUET);
|
$logger->set_level(Tlog::MUET);
|
||||||
|
|
||||||
$this->expectOutputRegex("/^$/");
|
$this->expectOutputRegex("/^$/");
|
||||||
$logger->trace("foo");
|
$logger->trace("foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDebugWithDebugLevel()
|
public function testDebugWithDebugLevel()
|
||||||
{
|
{
|
||||||
|
|
||||||
$logger = $this->logger;
|
$logger = $this->logger;
|
||||||
$logger->set_level(Tlog::DEBUG);
|
$logger->set_level(Tlog::DEBUG);
|
||||||
|
|
||||||
//"#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: "
|
//"#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: "
|
||||||
$this->expectOutputRegex(sprintf($this->regex, "foo"));
|
$this->expectOutputRegex(sprintf($this->regex, "foo"));
|
||||||
$logger->debug("foo");
|
$logger->debug("foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDebugWitoutDebugLevel()
|
public function testDebugWitoutDebugLevel()
|
||||||
{
|
{
|
||||||
$logger = $this->logger;
|
$logger = $this->logger;
|
||||||
$logger->set_level(Tlog::MUET);
|
$logger->set_level(Tlog::MUET);
|
||||||
|
|
||||||
$this->expectOutputRegex("/^$/");
|
$this->expectOutputRegex("/^$/");
|
||||||
$logger->debug("foo");
|
$logger->debug("foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testInfoWithInfoLevel()
|
public function testInfoWithInfoLevel()
|
||||||
{
|
{
|
||||||
|
|
||||||
$logger = $this->logger;
|
$logger = $this->logger;
|
||||||
$logger->set_level(Tlog::INFO);
|
$logger->set_level(Tlog::INFO);
|
||||||
|
|
||||||
//"#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: "
|
//"#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: "
|
||||||
$this->expectOutputRegex(sprintf($this->regex, "foo"));
|
$this->expectOutputRegex(sprintf($this->regex, "foo"));
|
||||||
$logger->info("foo");
|
$logger->info("foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testInfoWitoutInfoLevel()
|
public function testInfoWitoutInfoLevel()
|
||||||
{
|
{
|
||||||
$logger = $this->logger;
|
$logger = $this->logger;
|
||||||
$logger->set_level(Tlog::MUET);
|
$logger->set_level(Tlog::MUET);
|
||||||
|
|
||||||
$this->expectOutputRegex("/^$/");
|
$this->expectOutputRegex("/^$/");
|
||||||
$logger->info("foo");
|
$logger->info("foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWarningWithWarningLevel()
|
public function testWarningWithWarningLevel()
|
||||||
{
|
{
|
||||||
|
|
||||||
$logger = $this->logger;
|
$logger = $this->logger;
|
||||||
$logger->set_level(Tlog::WARNING);
|
$logger->set_level(Tlog::WARNING);
|
||||||
|
|
||||||
//"#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: "
|
//"#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: "
|
||||||
$this->expectOutputRegex(sprintf($this->regex, "foo"));
|
$this->expectOutputRegex(sprintf($this->regex, "foo"));
|
||||||
$logger->warning("foo");
|
$logger->warning("foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWarningWitoutWarningLevel()
|
public function testWarningWitoutWarningLevel()
|
||||||
{
|
{
|
||||||
$logger = $this->logger;
|
$logger = $this->logger;
|
||||||
$logger->set_level(Tlog::MUET);
|
$logger->set_level(Tlog::MUET);
|
||||||
|
|
||||||
$this->expectOutputRegex("/^$/");
|
$this->expectOutputRegex("/^$/");
|
||||||
$logger->warning("foo");
|
$logger->warning("foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testErrorWithErrorLevel()
|
public function testErrorWithErrorLevel()
|
||||||
{
|
{
|
||||||
|
|
||||||
$logger = $this->logger;
|
$logger = $this->logger;
|
||||||
$logger->set_level(Tlog::ERROR);
|
$logger->set_level(Tlog::ERROR);
|
||||||
|
|
||||||
//"#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: "
|
//"#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: "
|
||||||
$this->expectOutputRegex(sprintf($this->regex, "foo"));
|
$this->expectOutputRegex(sprintf($this->regex, "foo"));
|
||||||
$logger->error("foo");
|
$logger->error("foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testErrorWitoutErrorLevel()
|
public function testErrorWitoutErrorLevel()
|
||||||
{
|
{
|
||||||
$logger = $this->logger;
|
$logger = $this->logger;
|
||||||
$logger->set_level(Tlog::MUET);
|
$logger->set_level(Tlog::MUET);
|
||||||
|
|
||||||
$this->expectOutputRegex("/^$/");
|
$this->expectOutputRegex("/^$/");
|
||||||
$logger->error("foo");
|
$logger->error("foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFatalWithFatalLevel()
|
public function testFatalWithFatalLevel()
|
||||||
{
|
{
|
||||||
|
|
||||||
$logger = $this->logger;
|
$logger = $this->logger;
|
||||||
$logger->set_level(Tlog::FATAL);
|
$logger->set_level(Tlog::FATAL);
|
||||||
|
|
||||||
//"#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: "
|
//"#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: "
|
||||||
$this->expectOutputRegex(sprintf($this->regex, "foo"));
|
$this->expectOutputRegex(sprintf($this->regex, "foo"));
|
||||||
$logger->fatal("foo");
|
$logger->fatal("foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFatalWitoutFatalLevel()
|
public function testFatalWitoutFatalLevel()
|
||||||
{
|
{
|
||||||
$logger = $this->logger;
|
$logger = $this->logger;
|
||||||
$logger->set_level(Tlog::MUET);
|
$logger->set_level(Tlog::MUET);
|
||||||
|
|
||||||
$this->expectOutputRegex("/^$/");
|
$this->expectOutputRegex("/^$/");
|
||||||
$logger->fatal("foo");
|
$logger->fatal("foo");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class ConfigModel
|
class ConfigModel
|
||||||
{
|
{
|
||||||
public function __call($name, $arguments) {
|
public function __call($name, $arguments)
|
||||||
|
{
|
||||||
return $arguments[1];
|
return $arguments[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,34 +32,34 @@ class DIGeneratorTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function testGenDiModelWithoutModels()
|
public function testGenDiModelWithoutModels()
|
||||||
{
|
{
|
||||||
$models = DIGenerator::genDiModel(__DIR__ . '/_filesEmpty');
|
$models = DIGenerator::genDiModel(__DIR__ . '/_filesEmpty');
|
||||||
|
|
||||||
$this->assertEmpty($models);
|
$this->assertEmpty($models);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers DIGenerator::genDiModel
|
* @covers DIGenerator::genDiModel
|
||||||
*/
|
*/
|
||||||
public function testGenDiModelWithModels()
|
public function testGenDiModelWithModels()
|
||||||
{
|
{
|
||||||
$models = DIGenerator::genDiModel(__DIR__ . '/_files');
|
$models = DIGenerator::genDiModel(__DIR__ . '/_files');
|
||||||
|
|
||||||
$this->assertArrayHasKey("A", $models);
|
$this->assertArrayHasKey("A", $models);
|
||||||
$this->assertArrayHasKey("B", $models);
|
$this->assertArrayHasKey("B", $models);
|
||||||
$this->assertEquals("Thelia\Tests\Tools\_files\A", $models["A"]);
|
$this->assertEquals("Thelia\Tests\Tools\_files\A", $models["A"]);
|
||||||
$this->assertCount(2, $models, "There is more than 2 models in this directory");
|
$this->assertCount(2, $models, "There is more than 2 models in this directory");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers DIGenerator::genDiModel
|
* @covers DIGenerator::genDiModel
|
||||||
*/
|
*/
|
||||||
public function testGenDiModelWithModelsAndExclusion()
|
public function testGenDiModelWithModelsAndExclusion()
|
||||||
{
|
{
|
||||||
$models = DIGenerator::genDiModel(__DIR__ . '/_files',array('B'));
|
$models = DIGenerator::genDiModel(__DIR__ . '/_files',array('B'));
|
||||||
|
|
||||||
$this->assertArrayHasKey("A", $models);
|
$this->assertArrayHasKey("A", $models);
|
||||||
$this->assertCount(1, $models, "There is more than 2 models in this directory");
|
$this->assertCount(1, $models, "There is more than 2 models in this directory");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException RuntimeException
|
* @expectedException RuntimeException
|
||||||
* @covers DIGenerator::genDiModel
|
* @covers DIGenerator::genDiModel
|
||||||
@@ -67,7 +67,6 @@ class DIGeneratorTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function testGenDiModelWithWrongDirectory()
|
public function testGenDiModelWithWrongDirectory()
|
||||||
{
|
{
|
||||||
$models = DIGenerator::genDiModel(__DIR__ . '/wrongDirectory');
|
$models = DIGenerator::genDiModel(__DIR__ . '/wrongDirectory');
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,6 @@
|
|||||||
|
|
||||||
namespace Thelia\Tests\Tools\_files;
|
namespace Thelia\Tests\Tools\_files;
|
||||||
|
|
||||||
class A {
|
class A
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,5 +4,5 @@ namespace Thelia\Tests\Tools\_files;
|
|||||||
|
|
||||||
class B
|
class B
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,58 +23,54 @@
|
|||||||
namespace Thelia\Tools;
|
namespace Thelia\Tools;
|
||||||
|
|
||||||
class DIGenerator
|
class DIGenerator
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Find all models in a directory
|
* Find all models in a directory
|
||||||
*
|
*
|
||||||
* @param string $directory Directory where models have to be find.
|
* @param string $directory Directory where models have to be find.
|
||||||
* @param array $exclude Model to be exclude in the return
|
* @param array $exclude Model to be exclude in the return
|
||||||
*
|
*
|
||||||
* @return array key is the service name and value the full Class name (including namespace if needed)
|
* @return array key is the service name and value the full Class name (including namespace if needed)
|
||||||
*
|
*
|
||||||
* @throws \RuntimeException id $directory is not a valid directory
|
* @throws \RuntimeException id $directory is not a valid directory
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static function genDiModel($directory, array $exclude = array())
|
public static function genDiModel($directory, array $exclude = array())
|
||||||
{
|
{
|
||||||
if(!is_string($directory)) return array();
|
if(!is_string($directory)) return array();
|
||||||
|
|
||||||
if(!is_dir($directory))
|
if (!is_dir($directory)) {
|
||||||
{
|
|
||||||
throw new \RuntimeException($directory." is not a valid directory");
|
throw new \RuntimeException($directory." is not a valid directory");
|
||||||
}
|
}
|
||||||
|
|
||||||
$results = array();
|
$results = array();
|
||||||
|
|
||||||
$files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory));
|
$files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory));
|
||||||
|
|
||||||
foreach($files as $file)
|
foreach ($files as $file) {
|
||||||
{
|
|
||||||
//$file is instance of SplFileInfo
|
//$file is instance of SplFileInfo
|
||||||
if(!$file->isFile()) continue;
|
if(!$file->isFile()) continue;
|
||||||
|
|
||||||
$filePath = $file->getRealPath();
|
$filePath = $file->getRealPath();
|
||||||
|
|
||||||
$classes = self::findClasses($filePath);
|
$classes = self::findClasses($filePath);
|
||||||
|
|
||||||
foreach($classes as $class)
|
foreach ($classes as $class) {
|
||||||
{
|
|
||||||
$classInfo = new \ReflectionClass($class);
|
$classInfo = new \ReflectionClass($class);
|
||||||
$shortName = $classInfo->getShortName();
|
$shortName = $classInfo->getShortName();
|
||||||
if(!in_array($shortName, $exclude))
|
if (!in_array($shortName, $exclude)) {
|
||||||
{
|
|
||||||
$results[$shortName] = $class;
|
$results[$shortName] = $class;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $results;
|
return $results;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract the classes in the given file
|
* Extract the classes in the given file
|
||||||
*
|
*
|
||||||
* copied from Composer\Autoload\GenerateClassMap::findClasses()
|
* copied from Composer\Autoload\GenerateClassMap::findClasses()
|
||||||
*
|
*
|
||||||
* @param string $path The file to check
|
* @param string $path The file to check
|
||||||
@@ -132,5 +128,5 @@ class DIGenerator
|
|||||||
|
|
||||||
return $classes;
|
return $classes;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user