From 4e21c258676c1d253d6dc7614a8a25721e3e4e13 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 9 Jan 2013 09:13:25 +0100 Subject: [PATCH] fix some CS --- .../Autoload/TheliaUniversalClassLoader.php | 6 +- core/lib/Thelia/Core/Bundle/LoggerBundle.php | 19 ++- core/lib/Thelia/Core/Bundle/ModelBundle.php | 7 +- core/lib/Thelia/Core/Bundle/NotORMBundle.php | 34 ++--- core/lib/Thelia/Core/Bundle/TheliaBundle.php | 6 +- core/lib/Thelia/Core/Template/Parser.php | 14 +- core/lib/Thelia/Core/Thelia.php | 12 +- core/lib/Thelia/Core/TheliaHttpKernel.php | 7 +- core/lib/Thelia/Database/NotORM.php | 28 ++-- core/lib/Thelia/Database/NotORM/Result.php | 12 +- .../Thelia/Log/AbstractTlogDestination.php | 52 ++++--- .../Log/Destination/TlogDestinationFile.php | 28 ++-- .../Log/Destination/TlogDestinationHtml.php | 25 ++-- .../Log/Destination/TlogDestinationNull.php | 16 +- .../Log/Destination/TlogDestinationText.php | 20 ++- core/lib/Thelia/Log/Tlog.php | 140 ++++++++++-------- core/lib/Thelia/Log/TlogDestinationConfig.php | 11 +- core/lib/Thelia/Log/TlogInterface.php | 7 +- core/lib/Thelia/Model/Accessory.php | 35 ++--- core/lib/Thelia/Model/Base/Base.php | 129 ++++++++++++---- core/lib/Thelia/Model/Config.php | 2 +- core/lib/Thelia/Tests/Log/TlogTest.php | 87 ++++++----- .../Thelia/Tests/Tools/DIGeneratorTest.php | 15 +- core/lib/Thelia/Tests/Tools/_files/A.php | 4 +- core/lib/Thelia/Tests/Tools/_files/B.php | 2 +- core/lib/Thelia/Tools/DIGenerator.php | 50 +++---- 26 files changed, 422 insertions(+), 346 deletions(-) diff --git a/core/lib/Thelia/Autoload/TheliaUniversalClassLoader.php b/core/lib/Thelia/Autoload/TheliaUniversalClassLoader.php index b8bade50c..19ffcadd4 100644 --- a/core/lib/Thelia/Autoload/TheliaUniversalClassLoader.php +++ b/core/lib/Thelia/Autoload/TheliaUniversalClassLoader.php @@ -30,7 +30,7 @@ use Symfony\Component\ClassLoader\UniversalClassLoader; * extends Symfony\Component\ClassLoader\UniversalClassLoader * * This class respect PSR-0 autoloading standard and allow to load traditionnal Thelia classes. - * + * * classMap can be used to. * * @author Manuel Raynaud @@ -76,7 +76,7 @@ class TheliaUniversalClassLoader extends UniversalClassLoader { return $this->directories; } - + /** * @param array $classMap Class to filename map */ @@ -101,7 +101,7 @@ class TheliaUniversalClassLoader extends UniversalClassLoader if (isset($this->classMap[$class])) { return $this->classMap[$class]; } - + foreach ($this->directories as $directory) { if (is_file($directory.DIRECTORY_SEPARATOR.$class.".class.php")) { diff --git a/core/lib/Thelia/Core/Bundle/LoggerBundle.php b/core/lib/Thelia/Core/Bundle/LoggerBundle.php index e295f34a4..9e9a0015b 100644 --- a/core/lib/Thelia/Core/Bundle/LoggerBundle.php +++ b/core/lib/Thelia/Core/Bundle/LoggerBundle.php @@ -42,25 +42,24 @@ class LoggerBundle extends Bundle /** * * Construct the depency injection builder - * + * * Reference all Model in the Container here * * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container */ public function build(ContainerBuilder $container) - { + { $container->setParameter("logger.class", "\Thelia\Log\Tlog"); $container->register("logger","%logger.class%") ->addArgument(new Reference('service_container')); - + $kernel = $container->get('kernel'); - - if($kernel->isDebug()) - { + + if ($kernel->isDebug()) { // $debug = function ($query, $parameters) // { -// +// // $pattern = '(^' . preg_quote(dirname(__FILE__)) . '(\\.php$|[/\\\\]))'; // can be static // foreach (debug_backtrace() as $backtrace) { // 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', is_scalar($parameters) ? $parameters : print_r($parameters, true), FILE_APPEND); -// +// // }; -// +// // $container->getDefinition('database') // ->addMethodCall('setDebug', array($debug)); - + $container->get('database') ->setLogger($container->get('logger')); } diff --git a/core/lib/Thelia/Core/Bundle/ModelBundle.php b/core/lib/Thelia/Core/Bundle/ModelBundle.php index dcda6fbac..dfc622f27 100644 --- a/core/lib/Thelia/Core/Bundle/ModelBundle.php +++ b/core/lib/Thelia/Core/Bundle/ModelBundle.php @@ -43,16 +43,15 @@ class ModelBundle extends Bundle /** * * Construct the depency injection builder - * + * * Reference all Model in the Container here * * @param \Symfony\Component\DependencyInjection\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) ->addArgument(new Reference("database")); } diff --git a/core/lib/Thelia/Core/Bundle/NotORMBundle.php b/core/lib/Thelia/Core/Bundle/NotORMBundle.php index 2f022c9a8..a138f8d74 100644 --- a/core/lib/Thelia/Core/Bundle/NotORMBundle.php +++ b/core/lib/Thelia/Core/Bundle/NotORMBundle.php @@ -26,8 +26,6 @@ use Symfony\Component\HttpKernel\Bundle\Bundle; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; -use Thelia\Log\Tlog; - /** * First Bundle use in Thelia * It initialize dependency injection container. @@ -53,20 +51,18 @@ class NotORMBundle extends Bundle $config = array( // \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION ); - + $kernel = $container->get('kernel'); $pdo = new \PDO(THELIA_DB_DSN,THELIA_DB_USER, THELIA_DB_PASSWORD, $config); - + $pdo->exec("SET NAMES UTF8"); - + $container->register('database','\Thelia\Database\NotORM') ->addArgument($pdo); - - if(defined('THELIA_DB_CACHE') && !$kernel->isDebug()) - { - switch(THELIA_DB_CACHE) - { + + if (defined('THELIA_DB_CACHE') && !$kernel->isDebug()) { + switch (THELIA_DB_CACHE) { case 'file': $container->register('database_cache','\NotORM_Cache_File') ->addArgument($kernel->getCacheDir().'/database.php'); @@ -76,8 +72,7 @@ class NotORMBundle extends Bundle ->addArgument($kernel->getCacheDir().'/database_include.php'); break; case 'apc': - if (extension_loaded('apc')) - { + if (extension_loaded('apc')) { $container->register('database_cache','\NotORM_Cache_APC'); } break; @@ -85,24 +80,19 @@ class NotORMBundle extends Bundle $container->register('database_cache','\NotORM_Cache_Session'); break; case 'memcache': - if(class_exists('Memcache')) - { + if (class_exists('Memcache')) { $container->register('database_cache','\NotORM_Cache_Memcache') ->addArgument(new \Memcache()); } break; - + } - - if($container->hasDefinition('database_cache')) - { + + if ($container->hasDefinition('database_cache')) { $container->getDefinition('database') ->addMethodCall('setCache', array(new Reference('database_cache'))); } } - - - - + } } diff --git a/core/lib/Thelia/Core/Bundle/TheliaBundle.php b/core/lib/Thelia/Core/Bundle/TheliaBundle.php index 4019b82fa..5a37150c3 100644 --- a/core/lib/Thelia/Core/Bundle/TheliaBundle.php +++ b/core/lib/Thelia/Core/Bundle/TheliaBundle.php @@ -75,7 +75,7 @@ class TheliaBundle extends Bundle $container->register('listener.router', 'Symfony\Component\HttpKernel\EventListener\RouterListener') ->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. * @@ -91,14 +91,14 @@ class TheliaBundle extends Bundle ->addArgument(new Reference('parser')) ; - + $container->register('dispatcher','Symfony\Component\EventDispatcher\EventDispatcher') ->addArgument(new Reference('service_container')) ->addMethodCall('addSubscriber', array(new Reference('listener.router'))) ->addMethodCall('addSubscriber', array(new Reference('thelia.listener.view'))) ; - + $container->register('http_kernel','Thelia\Core\TheliaHttpKernel') ->addArgument(new Reference('dispatcher')) ->addArgument(new Reference('service_container')) diff --git a/core/lib/Thelia/Core/Template/Parser.php b/core/lib/Thelia/Core/Template/Parser.php index 022274c62..75b36142a 100644 --- a/core/lib/Thelia/Core/Template/Parser.php +++ b/core/lib/Thelia/Core/Template/Parser.php @@ -55,9 +55,9 @@ class Parser implements ParserInterface protected $status = 200; /** - * + * * @param type $container - * + * * public function __construct(ContainerBuilder $container) */ public function __construct(ContainerInterface $container) @@ -73,15 +73,15 @@ class Parser implements ParserInterface public function getContent() { $this->loadParser(); - + $request = $this->container->get('request'); - + $this->content = $request->get("test"); - + $config = $this->container->get("model.config"); - + echo $config->read("toto","tutu"); - + return $this->content; } diff --git a/core/lib/Thelia/Core/Thelia.php b/core/lib/Thelia/Core/Thelia.php index a358f8312..e611ebafe 100644 --- a/core/lib/Thelia/Core/Thelia.php +++ b/core/lib/Thelia/Core/Thelia.php @@ -52,7 +52,7 @@ class Thelia extends Kernel //$this->container->set('kernel', $this); } - + /** * Gets the cache directory. * @@ -62,15 +62,14 @@ class Thelia extends Kernel */ public function getCacheDir() { - if(defined('THELIA_ROOT')) - { + if (defined('THELIA_ROOT')) { return THELIA_ROOT.'cache/'.$this->environment; } else { return parent::getCacheDir(); } - + } - + /** * Gets the log directory. * @@ -80,8 +79,7 @@ class Thelia extends Kernel */ public function getLogDir() { - if(defined('THELIA_ROOT')) - { + if (defined('THELIA_ROOT')) { return THELIA_ROOT.'log/'; } else { return parent::getLogDir(); diff --git a/core/lib/Thelia/Core/TheliaHttpKernel.php b/core/lib/Thelia/Core/TheliaHttpKernel.php index 6d64350f7..9d63f420e 100644 --- a/core/lib/Thelia/Core/TheliaHttpKernel.php +++ b/core/lib/Thelia/Core/TheliaHttpKernel.php @@ -30,7 +30,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** - * + * * @author Manuel Raynaud */ @@ -42,8 +42,7 @@ class TheliaHttpKernel extends HttpKernel $this->container = $container; } - - + /** * Handles a Request to convert it to a Response. * @@ -80,4 +79,4 @@ class TheliaHttpKernel extends HttpKernel return $response; } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Database/NotORM.php b/core/lib/Thelia/Database/NotORM.php index 270913d0e..cabc913f4 100644 --- a/core/lib/Thelia/Database/NotORM.php +++ b/core/lib/Thelia/Database/NotORM.php @@ -25,50 +25,50 @@ namespace Thelia\Database; use Thelia\Log\TlogInterface; use Thelia\Database\NotORM\Result; - /** - * + * * 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 */ class NotORM extends \NotORM { - + public $logger = false; - + public function setCache(\NotORM_Cache $cache) { $this->cache = $cache; } - + public function setLogger(TlogInterface $logger) { $this->logger = $logger; } - + public function setDebug($debug) { - if(is_callable($debug)) - { + if (is_callable($debug)) { $this->debug = $debug; } else { $this->debug = true; } } - + /** Get table data * @param string * @param array (["condition"[, array("value")]]) passed to NotORM_Result::where() * @return NotORM_Result */ - function __call($table, array $where) { + public function __call($table, array $where) + { $return = new Result($this->structure->getReferencingTable($table, ''), $this); if ($where) { call_user_func_array(array($return, 'where'), $where); } + return $return; } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Database/NotORM/Result.php b/core/lib/Thelia/Database/NotORM/Result.php index aa1cbb9d7..82f01cb5a 100644 --- a/core/lib/Thelia/Database/NotORM/Result.php +++ b/core/lib/Thelia/Database/NotORM/Result.php @@ -4,7 +4,8 @@ namespace Thelia\Database\NotORM; class Result extends \NotORM_Result { - protected function query($query, $parameters) { + protected function query($query, $parameters) + { if ($this->notORM->debug) { if (!is_callable($this->notORM->debug)) { $debug = "$query;"; @@ -22,9 +23,8 @@ class Result extends \NotORM_Result return false; } } - - if($this->notORM->logger !== false) - { + + if ($this->notORM->logger !== false) { $this->notORM->logger->debug($query); $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(print_r($this->notORM->errorInfo(), true)); $this->notORM->logger->fatal(print_r($return->errorInfo(), true)); + return false; } + return $return; } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Log/AbstractTlogDestination.php b/core/lib/Thelia/Log/AbstractTlogDestination.php index 8dc8eb3ef..7124ecb8f 100644 --- a/core/lib/Thelia/Log/AbstractTlogDestination.php +++ b/core/lib/Thelia/Log/AbstractTlogDestination.php @@ -23,8 +23,8 @@ namespace Thelia\Log; -abstract class AbstractTlogDestination { - +abstract class AbstractTlogDestination +{ //Tableau de TlogDestinationConfig paramétrant la destination protected $_configs; @@ -33,14 +33,15 @@ abstract class AbstractTlogDestination { // Vaudra true si on est dans le back office. protected $flag_back_office = false; - + protected $configModel; - public function __construct() { + public function __construct() + { $this->_configs = array(); $this->_logs = array(); - // Initialiser les variables de configuration + // Initialiser les variables de configuration $this->_configs = $this->get_configs(); // Appliquer la configuration @@ -48,9 +49,10 @@ abstract class AbstractTlogDestination { } //Affecte une valeur à une configuration de la destination - public function set_config($nom, $valeur) { - foreach($this->_configs as $config) { - if($config->nom == $nom) { + public function set_config($nom, $valeur) + { + foreach ($this->_configs as $config) { + if ($config->nom == $nom) { $config->valeur = $valeur; // Appliquer les changements $this->configurer($config); @@ -58,50 +60,55 @@ abstract class AbstractTlogDestination { return true; } } + return false; } - + public function setConfigModel($configModel) { $this->configModel = $configModel; } - + public function getConfigModel() { return $this->configModel; } //Récupère la valeur affectée à une configuration de la destination - public function get_config($nom) { - foreach($this->_configs as $config) { - if($config->nom == $nom) { + public function get_config($nom) + { + foreach ($this->_configs as $config) { + if ($config->nom == $nom) { return $config->valeur; } } + return false; } - public function get_configs() { + public function get_configs() + { return $this->_configs; } - public function mode_back_office($bool) { + public function mode_back_office($bool) + { $this->flag_back_office = $bool; } //Ajoute une ligne de logs à la destination - public function ajouter($string) { + public function ajouter($string) + { $this->_logs[] = $string; } - protected function inserer_apres_body(&$res, $logdata) { - + protected function inserer_apres_body(&$res, $logdata) + { $match = array(); if (preg_match("/(]*>)/i", $res, $match)) { $res = str_replace($match[0], $match[0] . "\n" . $logdata, $res); - } - else { + } else { $res = $logdata . $res; } } @@ -109,7 +116,8 @@ abstract class AbstractTlogDestination { // Demande à la destination de se configurer pour être prête // a fonctionner. Si $config est != false, celà indique // 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. } @@ -122,4 +130,4 @@ abstract class AbstractTlogDestination { // Retourne une brève description de la destination abstract public function get_description(); -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Log/Destination/TlogDestinationFile.php b/core/lib/Thelia/Log/Destination/TlogDestinationFile.php index a60740e1c..eaca21afa 100644 --- a/core/lib/Thelia/Log/Destination/TlogDestinationFile.php +++ b/core/lib/Thelia/Log/Destination/TlogDestinationFile.php @@ -25,9 +25,9 @@ namespace Thelia\Log\Destination; use Thelia\Log\AbstractTlogDestination; use Thelia\Log\TlogDestinationConfig; - -class TlogDestinationFile extends AbstractTlogDestination { +class TlogDestinationFile extends AbstractTlogDestination +{ // Nom des variables de configuration // ---------------------------------- const VAR_PATH_FILE = "tlog_destinationfile_path"; @@ -39,21 +39,22 @@ class TlogDestinationFile extends AbstractTlogDestination { protected $path_defaut = 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->setConfigModel($configModel); parent::__construct(); } - public function configurer($config = false) { + public function configurer($config = false) + { $file_path = $this->get_config(self::VAR_PATH_FILE); $mode = strtolower($this->get_config(self::VAR_MODE)) == 'a' ? 'a' : 'w'; if (! empty($file_path)) { if (! is_file($file_path)) { $dir = dirname($file_path); - if(! is_dir($dir)) { + if (! is_dir($dir)) { mkdir($dir, 0777, true); } } @@ -64,15 +65,18 @@ class TlogDestinationFile extends AbstractTlogDestination { } } - public function get_titre() { + public function get_titre() + { return "Text File"; } - public function get_description() { + public function get_description() + { return "Store logs into text file"; } - public function get_configs() { + public function get_configs() + { return array( new TlogDestinationConfig( self::VAR_PATH_FILE, @@ -93,13 +97,15 @@ class TlogDestinationFile extends AbstractTlogDestination { ); } - public function ajouter($texte) { + public function ajouter($texte) + { if ($this->fh) { fwrite($this->fh, $texte."\n"); } } - public function ecrire(&$res) { + public function ecrire(&$res) + { if ($this->fh) @fclose($this->fh); $this->fh = false; diff --git a/core/lib/Thelia/Log/Destination/TlogDestinationHtml.php b/core/lib/Thelia/Log/Destination/TlogDestinationHtml.php index 0abaf0c36..a5af69554 100644 --- a/core/lib/Thelia/Log/Destination/TlogDestinationHtml.php +++ b/core/lib/Thelia/Log/Destination/TlogDestinationHtml.php @@ -25,8 +25,8 @@ namespace Thelia\Log\Destination; use Thelia\Log\AbstractTlogDestination; -class TlogDestinationHtml extends AbstractTlogDestination { - +class TlogDestinationHtml extends AbstractTlogDestination +{ // Nom des variables de configuration // ---------------------------------- const VAR_STYLE = "tlog_destinationhtml_style"; @@ -34,24 +34,29 @@ class TlogDestinationHtml extends AbstractTlogDestination { private $style; - public function __construct() { + public function __construct() + { parent::__construct(); } - public function configurer($config = false) { + public function configurer($config = false) + { $this->style = $this->get_config(self::VAR_STYLE); } - public function get_titre() { + public function get_titre() + { 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."; } - public function get_configs() { + public function get_configs() + { // return array( // new TlogDestinationConfig( // self::VAR_STYLE, @@ -63,10 +68,10 @@ class TlogDestinationHtml extends AbstractTlogDestination { // ); } - public function ecrire(&$res) { - + public function ecrire(&$res) + { $block = sprintf('
%s
', $this->style, htmlspecialchars(implode("\n", $this->_logs))); $this->inserer_apres_body($res, $block); } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Log/Destination/TlogDestinationNull.php b/core/lib/Thelia/Log/Destination/TlogDestinationNull.php index caa6108d1..d3829c056 100644 --- a/core/lib/Thelia/Log/Destination/TlogDestinationNull.php +++ b/core/lib/Thelia/Log/Destination/TlogDestinationNull.php @@ -25,21 +25,25 @@ namespace Thelia\Log\Destination; use Thelia\Log\AbstractTlogDestination; -class TlogDestinationNull extends AbstractTlogDestination { - - public function get_titre() { +class TlogDestinationNull extends AbstractTlogDestination +{ + public function get_titre() + { return "Trou noir"; } - public function get_description() { + public function get_description() + { return "Cette destination ne provoque aucune sortie"; } - public function ajouter($string) { + public function ajouter($string) + { // Rien } - public function ecrire(&$res) { + public function ecrire(&$res) + { // Rien } } diff --git a/core/lib/Thelia/Log/Destination/TlogDestinationText.php b/core/lib/Thelia/Log/Destination/TlogDestinationText.php index b390b9b7b..052501566 100644 --- a/core/lib/Thelia/Log/Destination/TlogDestinationText.php +++ b/core/lib/Thelia/Log/Destination/TlogDestinationText.php @@ -25,26 +25,30 @@ namespace Thelia\Log\Destination; use Thelia\Log\AbstractTlogDestination; - -class TlogDestinationText extends AbstractTlogDestination { - - public function __construct() { +class TlogDestinationText extends AbstractTlogDestination +{ + public function __construct() + { parent::__construct(); } - public function get_titre() { + public function get_titre() + { 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."; } - public function ajouter($texte) { + public function ajouter($texte) + { echo $texte."\n"; } - public function ecrire(&$res) { + public function ecrire(&$res) + { // Rien } } diff --git a/core/lib/Thelia/Log/Tlog.php b/core/lib/Thelia/Log/Tlog.php index 87d9e6c2d..e85030496 100644 --- a/core/lib/Thelia/Log/Tlog.php +++ b/core/lib/Thelia/Log/Tlog.php @@ -26,11 +26,11 @@ use Thelia\Model\Config; use Symfony\Component\DependencyInjection\ContainerInterface; /** - * + * * Thelia Logger - * + * * Allow to define different level and output. - * + * * @author Franck Allimant */ class Tlog Implements TlogInterface @@ -77,19 +77,19 @@ class Tlog Implements TlogInterface // directories where are the Destinations Files public $dir_destinations = array(); - + protected $container; - + /** - * + * * @param type $container - * + * * public function __construct(ContainerBuilder $container) */ public function __construct(ContainerInterface $container) { $this->container = $container; - + $this->init(); } @@ -106,9 +106,10 @@ class Tlog Implements TlogInterface // return self::$instance; // } - protected function init() { + protected function init() + { $config = $this->container->get("model.config"); - + $level = $config->read(self::VAR_LEVEL, self::DEFAULT_LEVEL); $this->set_level($level); @@ -131,7 +132,8 @@ class Tlog Implements TlogInterface // Configuration // ------------- - public function set_destinations($destinations) { + public function set_destinations($destinations) + { if (! empty($destinations)) { $this->destinations = array(); @@ -141,40 +143,44 @@ class Tlog Implements TlogInterface } } - public function set_level($level) { + public function set_level($level) + { $this->level = $level; } - public function set_prefixe($prefixe) { - + public function set_prefixe($prefixe) + { $this->prefixe = $prefixe; } - public function set_files($files) { + public function set_files($files) + { $this->files = explode(";", $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; } - public function set_show_redirect($bool) { + public function set_show_redirect($bool) + { $this->show_redirect = $bool; } // Configuration d'une destination - public function set_config($destination, $param, $valeur) { - + public function set_config($destination, $param, $valeur) + { if (isset($this->destinations[$destination])) { $this->destinations[$destination]->set_config($param, $valeur); } } // Configuration d'une destination - public function get_config($destination, $param) { - + public function get_config($destination, $param) + { if (isset($this->destinations[$destination])) { return $this->destinations[$destination]->get_config($param); } @@ -185,7 +191,8 @@ class Tlog Implements TlogInterface // Methodes d'accès aux traces // --------------------------- - public function trace() { + public function trace() + { if ($this->level > self::TRACE) return; @@ -194,7 +201,8 @@ class Tlog Implements TlogInterface $this->out("TRACE", $args); } - public function debug() { + public function debug() + { if ($this->level > self::DEBUG) return; @@ -203,7 +211,8 @@ class Tlog Implements TlogInterface $this->out("DEBUG", $args); } - public function info() { + public function info() + { if ($this->level > self::INFO) return; @@ -212,7 +221,8 @@ class Tlog Implements TlogInterface $this->out("INFO", $args); } - public function warning() { + public function warning() + { if ($this->level > self::WARNING) return; @@ -221,7 +231,8 @@ class Tlog Implements TlogInterface $this->out("WARNING", $args); } - public function error() { + public function error() + { if ($this->level > self::ERROR) return; @@ -230,7 +241,8 @@ class Tlog Implements TlogInterface $this->out("ERREUR", $args); } - public function fatal() { + public function fatal() + { if ($this->level > self::FATAL) return; @@ -240,27 +252,28 @@ class Tlog Implements TlogInterface } // Mode back office - public static function mode_back_office($booleen) { - - foreach(Tlog::instance()->destinations as $dest) { + public static function mode_back_office($booleen) + { + foreach (Tlog::instance()->destinations as $dest) { $dest->mode_back_office($booleen); } } // Ecriture finale - public function ecrire(&$res) { - + public function ecrire(&$res) + { self::$ecrire_effectue = true; // Muet ? On ne fait rien if ($this->level == self::MUET) return; - foreach($this->destinations as $dest) { + foreach ($this->destinations as $dest) { $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 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) { echo " @@ -285,16 +298,15 @@ class Tlog Implements TlogInterface "; return true; - } - else { + } else { return false; } } // Permet de déterminer si la trace est active, en prenant en compte // le level et le filtrage par fichier - public function active($level) { - + public function active($level) + { if ($this->level <= $level) { $origine = $this->trouver_origine(); @@ -309,26 +321,27 @@ class Tlog Implements TlogInterface 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); } /* -- Methodes privees ---------------------------------------- */ // Adapté de LoggerLoginEvent dans log4php - private function trouver_origine() { - + private function trouver_origine() + { $origine = array(); - if(function_exists('debug_backtrace')) { + if (function_exists('debug_backtrace')) { $trace = debug_backtrace(); $prevHop = null; // make a downsearch to identify the caller $hop = array_pop($trace); - - while($hop !== null) { - if(isset($hop['class'])) { + + while ($hop !== null) { + if (isset($hop['class'])) { // we are sometimes in functions = no class available: avoid php warning here $className = $hop['class']; @@ -359,8 +372,8 @@ class Tlog Implements TlogInterface return $origine; } - private function out($level, $tabargs) { - + private function out($level, $tabargs) + { $text = ''; foreach ($tabargs as $arg) { @@ -384,34 +397,31 @@ class Tlog Implements TlogInterface $trace = $prefixe . $text; - foreach($this->destinations as $dest) { + foreach ($this->destinations as $dest) { $dest->ajouter($trace); } $this->linecount++; } } - + /** - * - * @param type $destinations - * @param array $actives array containing classes instanceof AbstractTlogDestination + * + * @param type $destinations + * @param array $actives array containing classes instanceof AbstractTlogDestination */ - protected function loadDestinations(&$destinations, array $actives = NULL) { - - foreach($actives as $active) - { - if(class_exists($active)) - { + protected function loadDestinations(&$destinations, array $actives = NULL) + { + foreach ($actives as $active) { + if (class_exists($active)) { $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"); } - + $destinations[$active] = $class; } } } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Log/TlogDestinationConfig.php b/core/lib/Thelia/Log/TlogDestinationConfig.php index b21ea91df..f68148430 100644 --- a/core/lib/Thelia/Log/TlogDestinationConfig.php +++ b/core/lib/Thelia/Log/TlogDestinationConfig.php @@ -35,8 +35,8 @@ class TlogDestinationConfig public $type; 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->titre = $titre; $this->label = $label; @@ -44,9 +44,8 @@ class TlogDestinationConfig $this->type = $type; // @$this->charger(); - - if($config) - { + + if ($config) { $this->valeur = $config->read($this->nom, $this->defaut); } } @@ -61,4 +60,4 @@ class TlogDestinationConfig // $this->add(); // } // } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Log/TlogInterface.php b/core/lib/Thelia/Log/TlogInterface.php index 39b8f47fa..8dfe9e7c1 100644 --- a/core/lib/Thelia/Log/TlogInterface.php +++ b/core/lib/Thelia/Log/TlogInterface.php @@ -2,15 +2,14 @@ namespace Thelia\Log; - Interface TlogInterface { - + public function trace(); public function debug(); public function info(); public function warning(); public function error(); public function fatal(); - -} \ No newline at end of file + +} diff --git a/core/lib/Thelia/Model/Accessory.php b/core/lib/Thelia/Model/Accessory.php index 35fc19a75..bf59b08a5 100644 --- a/core/lib/Thelia/Model/Accessory.php +++ b/core/lib/Thelia/Model/Accessory.php @@ -6,50 +6,45 @@ use Thelia\Model\Base\Base; class Accessory extends Base { - protected $id; + protected $product_id; protected $accessory; protected $position; - + protected $properties = array( - "id", "product_id", "accessory", "position" - ); - - public function getId() { - return $this->id; - } + ); - public function setId($id) { - $this->id = $id; - } - - public function getProductId() { + public function getProductId() + { return $this->product_id; } - public function setProductId($product_id) { + public function setProductId($product_id) + { $this->product_id = $product_id; } - public function getAccessory() { + public function getAccessory() + { return $this->accessory; } - public function setAccessory($accessory) { + public function setAccessory($accessory) + { $this->accessory = $accessory; } - public function getPosition() { + public function getPosition() + { return $this->position; } - public function setPosition($position) { + public function setPosition($position) + { $this->position = $position; } - - } diff --git a/core/lib/Thelia/Model/Base/Base.php b/core/lib/Thelia/Model/Base/Base.php index ce88d7596..ce64164c4 100644 --- a/core/lib/Thelia/Model/Base/Base.php +++ b/core/lib/Thelia/Model/Base/Base.php @@ -27,97 +27,161 @@ namespace Thelia\Model\Base; */ abstract class Base { + /** + * Primary key + * @var int + */ + protected $id; /** * * @var \NotORM */ protected $db; - + /** * * @var string */ protected $table; - + /** * * @var string date when the record had been updated */ protected $updated_at; - /** * * @var string date when the record had been saved */ protected $created_at; - - - + /** + * + * base properties for all models + * + * @var array + */ + private $baseProperties = array( + "created_at", + "update_at" + ); - /** - * - * - * + /** + * + * + * * @param \NotORM $NotORM */ - public function __construct(\NotORM $NotORM) { + public function __construct(\NotORM $NotORM) + { $this->db = $NotORM; $this->table = $this->getTableName(); } - - public function getUpdatedAt() { + + public function getUpdatedAt() + { return $this->updated_at; } - public function setUpdatedAt($updated_at) { + public function setUpdatedAt($updated_at) + { $this->updated_at = $updated_at; } - public function getCreatedAt() { + public function getCreatedAt() + { return $this->created_at; } - public function setCreatedAt($created_at) { + public function setCreatedAt($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 */ - public function getDb() { + public function getDb() + { return $this->db; } - public function getTable() { + public function getTable() + { return $this->table; } - public function save() { $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 */ protected function getTableName() - { + { return $this->underscore(__CLASS__); } - + /** - * + * * extract from symfony 1.4 - * - * change camelized wirnd into underscore word. - * + * + * change camelized wirnd into underscore word. + * * ex : AttributeCategory => attribute_category - * - * @param string $camel_cased_word + * + * @param string $camel_cased_word * @return string */ protected function underscore($camel_cased_word) @@ -126,9 +190,10 @@ abstract class Base $tmp = str_replace('::', '/', $tmp); $tmp = self::pregtr($tmp, array('/([A-Z]+)([A-Z][a-z])/' => '\\1_\\2', '/([a-z\d])([A-Z])/' => '\\1_\\2')); + return strtolower($tmp); } - + public static function pregtr($search, $replacePairs) { return preg_replace(array_keys($replacePairs), array_values($replacePairs), $search); diff --git a/core/lib/Thelia/Model/Config.php b/core/lib/Thelia/Model/Config.php index 56c064ce7..16ba351bf 100644 --- a/core/lib/Thelia/Model/Config.php +++ b/core/lib/Thelia/Model/Config.php @@ -6,7 +6,7 @@ use Thelia\Model\Base\Base; class Config extends Base { - + public function read($search, $default) { return $this->db->config()->where("name",$search)->fetch()?:$default; diff --git a/core/lib/Thelia/Tests/Log/TlogTest.php b/core/lib/Thelia/Tests/Log/TlogTest.php index 3a23c2eb8..7e0698584 100644 --- a/core/lib/Thelia/Tests/Log/TlogTest.php +++ b/core/lib/Thelia/Tests/Log/TlogTest.php @@ -21,7 +21,6 @@ /* */ /*************************************************************************************/ - namespace Thelia\Tests\Log; use Thelia\Log\Tlog; @@ -30,18 +29,19 @@ use Thelia\Core\Thelia; class TlogTest extends \PHPUnit_Framework_TestCase { 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"; - - public function setUp() { + + public function setUp() + { parent::setUp(); - + $_SERVER['REMOTE_ADDR'] = '::1'; - + $containerMock = $this->getMock("Symfony\Component\DependencyInjection\Container", array("get", "getParameter")); - + $configModel = new ConfigModel(); - + $containerMock->expects($this->any()) ->method("get") ->will($this->returnValue($configModel)); @@ -49,140 +49,139 @@ class TlogTest extends \PHPUnit_Framework_TestCase ->method("getParameter") ->with($this->stringContains("logger.class")) ->will($this->returnValue("Thelia\Log\Tlog")); - - + $this->logger = new Tlog($containerMock); - + $this->logger->set_destinations("Thelia\Log\Destination\TlogDestinationText"); $this->logger->set_level(Tlog::TRACE); $this->logger->set_files("*"); } - + public function testTraceWithTraceLevel() { - + $logger = $this->logger; $logger->set_level(Tlog::TRACE); - + //"#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: " $this->expectOutputRegex(sprintf($this->regex, "foo")); $logger->trace("foo"); } - + public function testTraceWitoutTraceLevel() { $logger = $this->logger; $logger->set_level(Tlog::MUET); - + $this->expectOutputRegex("/^$/"); $logger->trace("foo"); } - + public function testDebugWithDebugLevel() { - + $logger = $this->logger; $logger->set_level(Tlog::DEBUG); - + //"#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: " $this->expectOutputRegex(sprintf($this->regex, "foo")); $logger->debug("foo"); } - + public function testDebugWitoutDebugLevel() { $logger = $this->logger; $logger->set_level(Tlog::MUET); - + $this->expectOutputRegex("/^$/"); $logger->debug("foo"); } - + public function testInfoWithInfoLevel() { - + $logger = $this->logger; $logger->set_level(Tlog::INFO); - + //"#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: " $this->expectOutputRegex(sprintf($this->regex, "foo")); $logger->info("foo"); } - + public function testInfoWitoutInfoLevel() { $logger = $this->logger; $logger->set_level(Tlog::MUET); - + $this->expectOutputRegex("/^$/"); $logger->info("foo"); } - + public function testWarningWithWarningLevel() { - + $logger = $this->logger; $logger->set_level(Tlog::WARNING); - + //"#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: " $this->expectOutputRegex(sprintf($this->regex, "foo")); $logger->warning("foo"); } - + public function testWarningWitoutWarningLevel() { $logger = $this->logger; $logger->set_level(Tlog::MUET); - + $this->expectOutputRegex("/^$/"); $logger->warning("foo"); } - + public function testErrorWithErrorLevel() { - + $logger = $this->logger; $logger->set_level(Tlog::ERROR); - + //"#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: " $this->expectOutputRegex(sprintf($this->regex, "foo")); $logger->error("foo"); } - + public function testErrorWitoutErrorLevel() { $logger = $this->logger; $logger->set_level(Tlog::MUET); - + $this->expectOutputRegex("/^$/"); $logger->error("foo"); } - + public function testFatalWithFatalLevel() { - + $logger = $this->logger; $logger->set_level(Tlog::FATAL); - + //"#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: " $this->expectOutputRegex(sprintf($this->regex, "foo")); $logger->fatal("foo"); } - + public function testFatalWitoutFatalLevel() { $logger = $this->logger; $logger->set_level(Tlog::MUET); - + $this->expectOutputRegex("/^$/"); $logger->fatal("foo"); } } - class ConfigModel { - public function __call($name, $arguments) { + public function __call($name, $arguments) + { return $arguments[1]; } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Tests/Tools/DIGeneratorTest.php b/core/lib/Thelia/Tests/Tools/DIGeneratorTest.php index 9edbef9e6..0c0bb8250 100644 --- a/core/lib/Thelia/Tests/Tools/DIGeneratorTest.php +++ b/core/lib/Thelia/Tests/Tools/DIGeneratorTest.php @@ -32,34 +32,34 @@ class DIGeneratorTest extends \PHPUnit_Framework_TestCase public function testGenDiModelWithoutModels() { $models = DIGenerator::genDiModel(__DIR__ . '/_filesEmpty'); - + $this->assertEmpty($models); } - + /** * @covers DIGenerator::genDiModel */ public function testGenDiModelWithModels() { $models = DIGenerator::genDiModel(__DIR__ . '/_files'); - + $this->assertArrayHasKey("A", $models); $this->assertArrayHasKey("B", $models); $this->assertEquals("Thelia\Tests\Tools\_files\A", $models["A"]); $this->assertCount(2, $models, "There is more than 2 models in this directory"); } - + /** * @covers DIGenerator::genDiModel */ public function testGenDiModelWithModelsAndExclusion() { $models = DIGenerator::genDiModel(__DIR__ . '/_files',array('B')); - + $this->assertArrayHasKey("A", $models); $this->assertCount(1, $models, "There is more than 2 models in this directory"); } - + /** * @expectedException RuntimeException * @covers DIGenerator::genDiModel @@ -67,7 +67,6 @@ class DIGeneratorTest extends \PHPUnit_Framework_TestCase public function testGenDiModelWithWrongDirectory() { $models = DIGenerator::genDiModel(__DIR__ . '/wrongDirectory'); - - + } } diff --git a/core/lib/Thelia/Tests/Tools/_files/A.php b/core/lib/Thelia/Tests/Tools/_files/A.php index f116cbd52..6a4e77ce0 100644 --- a/core/lib/Thelia/Tests/Tools/_files/A.php +++ b/core/lib/Thelia/Tests/Tools/_files/A.php @@ -2,6 +2,6 @@ namespace Thelia\Tests\Tools\_files; -class A { - +class A +{ } diff --git a/core/lib/Thelia/Tests/Tools/_files/B.php b/core/lib/Thelia/Tests/Tools/_files/B.php index d9c5fd0c1..d88b51ed4 100644 --- a/core/lib/Thelia/Tests/Tools/_files/B.php +++ b/core/lib/Thelia/Tests/Tools/_files/B.php @@ -4,5 +4,5 @@ namespace Thelia\Tests\Tools\_files; class B { - + } diff --git a/core/lib/Thelia/Tools/DIGenerator.php b/core/lib/Thelia/Tools/DIGenerator.php index 22d1ec4bf..a17586a55 100644 --- a/core/lib/Thelia/Tools/DIGenerator.php +++ b/core/lib/Thelia/Tools/DIGenerator.php @@ -23,58 +23,54 @@ namespace Thelia\Tools; class DIGenerator -{ +{ /** * Find all models in a directory - * + * * @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) - * + * * @throws \RuntimeException id $directory is not a valid directory - * + * */ public static function genDiModel($directory, array $exclude = array()) { if(!is_string($directory)) return array(); - - if(!is_dir($directory)) - { + + if (!is_dir($directory)) { throw new \RuntimeException($directory." is not a valid directory"); } - + $results = array(); - + $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory)); - - foreach($files as $file) - { + + foreach ($files as $file) { //$file is instance of SplFileInfo if(!$file->isFile()) continue; - + $filePath = $file->getRealPath(); - + $classes = self::findClasses($filePath); - - foreach($classes as $class) - { + + foreach ($classes as $class) { $classInfo = new \ReflectionClass($class); $shortName = $classInfo->getShortName(); - if(!in_array($shortName, $exclude)) - { + if (!in_array($shortName, $exclude)) { $results[$shortName] = $class; } } } - + return $results; - + } - + /** * Extract the classes in the given file - * + * * copied from Composer\Autoload\GenerateClassMap::findClasses() * * @param string $path The file to check @@ -132,5 +128,5 @@ class DIGenerator return $classes; } - -} \ No newline at end of file + +}