From e74752cc3a3954a1802e17e3a411a6a5aaa86a9e Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Thu, 27 Dec 2012 14:10:43 +0100 Subject: [PATCH] put copyright in head files and create abstract log destination class --- .../TheliaApcUniversalClassLoader.php | 22 +++- .../Autoload/TheliaUniversalClassLoader.php | 22 +++- core/lib/Thelia/Core/Bundle/ModelBundle.php | 22 +++- core/lib/Thelia/Core/Bundle/NotORMBundle.php | 22 +++- core/lib/Thelia/Core/Bundle/TheliaBundle.php | 22 +++- .../Core/EventListener/RequestListener.php | 22 +++- .../Core/EventListener/ViewListener.php | 22 +++- core/lib/Thelia/Core/Template/Parser.php | 22 +++- .../Thelia/Core/Template/ParserInterface.php | 22 +++- core/lib/Thelia/Core/Thelia.php | 21 ++++ core/lib/Thelia/Core/TheliaHttpKernel.php | 27 ++++- core/lib/Thelia/Database/NotORM.php | 30 ++++- .../Thelia/Log/AbstractTlogDestination.php | 113 ++++++++++++++++++ core/lib/Thelia/Log/Tlog.php | 64 +++++++--- core/lib/Thelia/Model/Base/Base.php | 25 +++- 15 files changed, 448 insertions(+), 30 deletions(-) create mode 100644 core/lib/Thelia/Log/AbstractTlogDestination.php diff --git a/core/lib/Thelia/Autoload/TheliaApcUniversalClassLoader.php b/core/lib/Thelia/Autoload/TheliaApcUniversalClassLoader.php index 162109ee4..8ce43c9c1 100644 --- a/core/lib/Thelia/Autoload/TheliaApcUniversalClassLoader.php +++ b/core/lib/Thelia/Autoload/TheliaApcUniversalClassLoader.php @@ -1,5 +1,25 @@ . */ +/* */ +/*************************************************************************************/ namespace Thelia\Autoload; /** diff --git a/core/lib/Thelia/Autoload/TheliaUniversalClassLoader.php b/core/lib/Thelia/Autoload/TheliaUniversalClassLoader.php index a52a12b83..b8bade50c 100644 --- a/core/lib/Thelia/Autoload/TheliaUniversalClassLoader.php +++ b/core/lib/Thelia/Autoload/TheliaUniversalClassLoader.php @@ -1,5 +1,25 @@ . */ +/* */ +/*************************************************************************************/ namespace Thelia\Autoload; use Symfony\Component\ClassLoader\UniversalClassLoader; diff --git a/core/lib/Thelia/Core/Bundle/ModelBundle.php b/core/lib/Thelia/Core/Bundle/ModelBundle.php index a488a722c..dcda6fbac 100644 --- a/core/lib/Thelia/Core/Bundle/ModelBundle.php +++ b/core/lib/Thelia/Core/Bundle/ModelBundle.php @@ -1,5 +1,25 @@ . */ +/* */ +/*************************************************************************************/ namespace Thelia\Core\Bundle; use Symfony\Component\HttpKernel\Bundle\Bundle; diff --git a/core/lib/Thelia/Core/Bundle/NotORMBundle.php b/core/lib/Thelia/Core/Bundle/NotORMBundle.php index bf58c5351..7ab704607 100644 --- a/core/lib/Thelia/Core/Bundle/NotORMBundle.php +++ b/core/lib/Thelia/Core/Bundle/NotORMBundle.php @@ -1,5 +1,25 @@ . */ +/* */ +/*************************************************************************************/ namespace Thelia\Core\Bundle; use Symfony\Component\HttpKernel\Bundle\Bundle; diff --git a/core/lib/Thelia/Core/Bundle/TheliaBundle.php b/core/lib/Thelia/Core/Bundle/TheliaBundle.php index 2e2900fec..7104cff7d 100644 --- a/core/lib/Thelia/Core/Bundle/TheliaBundle.php +++ b/core/lib/Thelia/Core/Bundle/TheliaBundle.php @@ -1,5 +1,25 @@ . */ +/* */ +/*************************************************************************************/ namespace Thelia\Core\Bundle; use Symfony\Component\HttpKernel\Bundle\Bundle; diff --git a/core/lib/Thelia/Core/EventListener/RequestListener.php b/core/lib/Thelia/Core/EventListener/RequestListener.php index 1f0313196..989a99135 100644 --- a/core/lib/Thelia/Core/EventListener/RequestListener.php +++ b/core/lib/Thelia/Core/EventListener/RequestListener.php @@ -1,5 +1,25 @@ . */ +/* */ +/*************************************************************************************/ namespace Thelia\Core\EventListener; use Symfony\Component\EventDispatcher\EventSubscriberInterface; diff --git a/core/lib/Thelia/Core/EventListener/ViewListener.php b/core/lib/Thelia/Core/EventListener/ViewListener.php index 2ae401cc7..208050e64 100644 --- a/core/lib/Thelia/Core/EventListener/ViewListener.php +++ b/core/lib/Thelia/Core/EventListener/ViewListener.php @@ -1,5 +1,25 @@ . */ +/* */ +/*************************************************************************************/ namespace Thelia\Core\EventListener; use Symfony\Component\EventDispatcher\EventSubscriberInterface; diff --git a/core/lib/Thelia/Core/Template/Parser.php b/core/lib/Thelia/Core/Template/Parser.php index d6ef0f9fe..17070b012 100644 --- a/core/lib/Thelia/Core/Template/Parser.php +++ b/core/lib/Thelia/Core/Template/Parser.php @@ -1,5 +1,25 @@ . */ +/* */ +/*************************************************************************************/ namespace Thelia\Core\Template; use Symfony\Component\HttpFoundation\Response; diff --git a/core/lib/Thelia/Core/Template/ParserInterface.php b/core/lib/Thelia/Core/Template/ParserInterface.php index 18b923e9a..4b3102fbf 100644 --- a/core/lib/Thelia/Core/Template/ParserInterface.php +++ b/core/lib/Thelia/Core/Template/ParserInterface.php @@ -1,5 +1,25 @@ . */ +/* */ +/*************************************************************************************/ namespace Thelia\Core\Template; /** diff --git a/core/lib/Thelia/Core/Thelia.php b/core/lib/Thelia/Core/Thelia.php index cea9609bf..d08762ca4 100644 --- a/core/lib/Thelia/Core/Thelia.php +++ b/core/lib/Thelia/Core/Thelia.php @@ -1,4 +1,25 @@ . */ +/* */ +/*************************************************************************************/ namespace Thelia\Core; diff --git a/core/lib/Thelia/Core/TheliaHttpKernel.php b/core/lib/Thelia/Core/TheliaHttpKernel.php index 8f5b7d446..6d64350f7 100644 --- a/core/lib/Thelia/Core/TheliaHttpKernel.php +++ b/core/lib/Thelia/Core/TheliaHttpKernel.php @@ -1,5 +1,25 @@ . */ +/* */ +/*************************************************************************************/ namespace Thelia\Core; use Symfony\Component\HttpKernel\HttpKernel; @@ -9,6 +29,11 @@ use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; +/** + * + * @author Manuel Raynaud + */ + class TheliaHttpKernel extends HttpKernel { public function __construct(EventDispatcherInterface $dispatcher, ContainerInterface $container, ControllerResolverInterface $controllerResolver) diff --git a/core/lib/Thelia/Database/NotORM.php b/core/lib/Thelia/Database/NotORM.php index db87484c0..60ce55f8d 100644 --- a/core/lib/Thelia/Database/NotORM.php +++ b/core/lib/Thelia/Database/NotORM.php @@ -1,7 +1,35 @@ . */ +/* */ +/*************************************************************************************/ namespace Thelia\Database; +/** + * + * Class Thelia\Database\NotORM extending \NotORM library http://www.notorm.com/ + * + * This class create or redifine some setters + * + * @author Manuel Raynaud + */ class NotORM extends \NotORM { diff --git a/core/lib/Thelia/Log/AbstractTlogDestination.php b/core/lib/Thelia/Log/AbstractTlogDestination.php new file mode 100644 index 000000000..f363fd37d --- /dev/null +++ b/core/lib/Thelia/Log/AbstractTlogDestination.php @@ -0,0 +1,113 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Log; + +abstract class AbstractTlogDestination { + + //Tableau de TlogDestinationConfig paramétrant la destination + protected $_configs; + + //Tableau des lignes de logs stockés avant utilisation par ecrire() + protected $_logs; + + // Vaudra true si on est dans le back office. + protected $flag_back_office = false; + + public function __construct() { + $this->_configs = array(); + $this->_logs = array(); + + // Initialiser les variables de configuration + $this->_configs = $this->get_configs(); + + // Appliquer la configuration + $this->configurer(); + } + + //Affecte une valeur à une configuration de la destination + public function set_config($nom, $valeur) { + foreach($this->_configs as $config) { + if($config->nom == $nom) { + $config->valeur = $valeur; + // Appliquer les changements + $this->configurer($config); + + return true; + } + } + return false; + } + + //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) { + return $config->valeur; + } + } + return false; + } + + public function get_configs() { + return $this->_configs; + } + + public function mode_back_office($bool) { + $this->flag_back_office = $bool; + } + + //Ajoute une ligne de logs à la destination + public function ajouter($string) { + $this->_logs[] = $string; + } + + 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 { + $res = $logdata . $res; + } + } + + // 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) { + // Cette methode doit etre surchargée si nécessaire. + } + + //Lance l'écriture de tous les logs par la destination + //$res : contenu de la page html + abstract public function ecrire(&$res); + + // Retourne le titre de cette destination, tel qu'affiché dans le menu de selection + abstract public function get_titre(); + + // 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/Tlog.php b/core/lib/Thelia/Log/Tlog.php index 177f1484f..d9ce76182 100644 --- a/core/lib/Thelia/Log/Tlog.php +++ b/core/lib/Thelia/Log/Tlog.php @@ -1,20 +1,48 @@ . */ +/* */ +/*************************************************************************************/ namespace Thelia\Log; use Thelia\Model\Config; +/** + * + * Thelia Logger + * + * Allow to define different level and output. + * + * @author Franck Allimant + */ class Tlog { // Nom des variables de configuration - const VAR_NIVEAU = "tlog_niveau"; + const VAR_LEVEL = "tlog_level"; const VAR_DESTINATIONS = "tlog_destinations"; - const VAR_PREFIXE = "tlog_prefixe"; + const VAR_PREFIXE = "tlog_prefix"; const VAR_FILES = "tlog_files"; - const VAR_IP = "tlog_ip"; - const VAR_SHOW_REDIRECT = "tlog_show_redirect"; + const VAR_IP = "tlog_ip"; + const VAR_SHOW_REDIRECT = "tlog_show_redirect"; - // Les differents niveaux de trace + // all level of trace const TRACE = 1; const DEBUG = 2; const WARNING = 3; @@ -23,8 +51,8 @@ class Tlog const FATAL = 6; const MUET = PHP_INT_MAX; - // Valeurs par defaut - const DEFAUT_NIVEAU = self::MUET; + // default values + const DEFAULT_LEVEL = self::MUET; const DEFAUT_DESTINATIONS = "Thelia\Log\Destination\TlogDestinationHtml"; const DEFAUT_PREFIXE = "#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: "; const DEFAUT_FILES = "*"; @@ -36,7 +64,7 @@ class Tlog protected $destinations = array(); protected $mode_back_office = false; - protected $niveau = self::MUET; + protected $level = self::MUET; protected $prefixe = ""; protected $files = array(); protected $all_files = false; @@ -46,7 +74,7 @@ class Tlog protected static $ecrire_effectue = false; - // Les repertoires où rechercher les classes destination + // directories where are the Destinations Files public $dir_destinations = array(); public static function instance() { @@ -63,12 +91,12 @@ class Tlog } protected function init() { - $niveau = Config::read(self::VAR_NIVEAU, self::DEFAUT_NIVEAU); + $level = Config::read(self::VAR_LEVEL, self::DEFAULT_LEVEL); - $this->set_niveau($niveau); + $this->set_niveau($level); $this->dir_destinations = array( - __DIR__.'/tlog/destinations' + __DIR__.'/Destination' //, __DIR__.'/../client/tlog/destinations' ); @@ -85,7 +113,7 @@ class Tlog // Configuration // ------------- - public function set_destinations($destinations) { + public function set_destinations(AbstractTlogDestination $destinations) { if (! empty($destinations)) { $this->destinations = array(); @@ -95,8 +123,8 @@ class Tlog } } - public function set_niveau($niveau) { - $this->niveau = $niveau; + public function set_niveau($level) { + $this->niveau = $level; } public function set_prefixe($prefixe) { @@ -247,9 +275,9 @@ class Tlog // Permet de déterminer si la trace est active, en prenant en compte // le niveau et le filtrage par fichier - public function active($niveau) { + public function active($level) { - if ($this->niveau <= $niveau) { + if ($this->niveau <= $level) { $origine = $this->trouver_origine(); diff --git a/core/lib/Thelia/Model/Base/Base.php b/core/lib/Thelia/Model/Base/Base.php index c4ae7307d..ce88d7596 100644 --- a/core/lib/Thelia/Model/Base/Base.php +++ b/core/lib/Thelia/Model/Base/Base.php @@ -1,7 +1,30 @@ . */ +/* */ +/*************************************************************************************/ namespace Thelia\Model\Base; +/** + * @author Manuel Raynaud + */ abstract class Base { /**