diff --git a/core/autoload.php b/core/autoload.php index 91cdc216c..e82b17b04 100644 --- a/core/autoload.php +++ b/core/autoload.php @@ -1,31 +1,14 @@ add('Thelia', __DIR__ . '/lib/'); if (extension_loaded('apc') && $env == 'prod') { - $loader = new TheliaApcUniversalClassLoader('Thelia'); -} else { - $loader = new TheliaUniversalClassLoader(); + $loader->unregister(); + + require __DIR__ . '/vendor/symfony/class-loader/Symfony/Component/ClassLoader/ApcClassLoader.php'; + + $apcLoader = new Symfony\Component\ClassLoader\ApcClassLoader("thelia",$loader); + $apcLoader->register(); } - -$namespaces = require __DIR__ . '/vendor/composer/autoload_namespaces.php'; - -foreach ($namespaces as $namespace => $directory) { - $loader->registerNamespace($namespace, $directory); -} - -$loader->registerNamespace('Thelia', __DIR__ . '/lib/'); - -if(file_exists(__DIR__ . '/vendor/composer/autoload_classmap.php')) -{ - $classMap = require __DIR__ . '/vendor/composer/autoload_classmap.php'; - - $loader->addClassMap($classMap); -} - -$loader->register(); diff --git a/core/lib/Thelia/Core/Template/Parser.php b/core/lib/Thelia/Core/Template/Parser.php index 35f75b195..be278a75f 100644 --- a/core/lib/Thelia/Core/Template/Parser.php +++ b/core/lib/Thelia/Core/Template/Parser.php @@ -74,6 +74,9 @@ class Parser implements ParserInterface { $this->loadParser(); + + \Thelia\Log\Tlog::instance()->debug("tutu"); + return $this->content; } diff --git a/core/lib/Thelia/Log/AbstractTlogDestination.php b/core/lib/Thelia/Log/AbstractTlogDestination.php index 7124ecb8f..7aa197fcb 100644 --- a/core/lib/Thelia/Log/AbstractTlogDestination.php +++ b/core/lib/Thelia/Log/AbstractTlogDestination.php @@ -34,13 +34,11 @@ abstract class AbstractTlogDestination // Vaudra true si on est dans le back office. protected $flag_back_office = false; - protected $configModel; - public function __construct() { $this->_configs = array(); $this->_logs = array(); - + // Initialiser les variables de configuration $this->_configs = $this->get_configs(); @@ -49,13 +47,13 @@ abstract class AbstractTlogDestination } //Affecte une valeur à une configuration de la destination - public function set_config($nom, $valeur) + public function set_config($name, $value) { foreach ($this->_configs as $config) { - if ($config->nom == $nom) { - $config->valeur = $valeur; + if ($config->name == $name) { + $config->value = $value; // Appliquer les changements - $this->configurer($config); + $this->configurer(); return true; } @@ -64,22 +62,12 @@ abstract class AbstractTlogDestination 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) + public function get_config($name) { foreach ($this->_configs as $config) { - if ($config->nom == $nom) { - return $config->valeur; + if ($config->name == $name) { + return $config->value; } } @@ -116,7 +104,7 @@ 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() { // Cette methode doit etre surchargée si nécessaire. } diff --git a/core/lib/Thelia/Log/Destination/TlogDestinationFile.php b/core/lib/Thelia/Log/Destination/TlogDestinationFile.php index eaca21afa..196ffcaa1 100644 --- a/core/lib/Thelia/Log/Destination/TlogDestinationFile.php +++ b/core/lib/Thelia/Log/Destination/TlogDestinationFile.php @@ -34,19 +34,18 @@ class TlogDestinationFile extends AbstractTlogDestination const TLOG_DEFAULT_NAME = "log-thelia.txt"; const VAR_MODE = "tlog_destinationfile_mode"; - const VALEUR_MODE_DEFAUT = "A"; + const VALEUR_MODE_DEFAULT = "A"; protected $path_defaut = false; protected $fh = false; - public function __construct($configModel = null) + public function __construct() { $this->path_defaut = THELIA_ROOT . "log/" . self::TLOG_DEFAULT_NAME; - $this->setConfigModel($configModel); parent::__construct(); } - public function configurer($config = false) + public function configurer() { $file_path = $this->get_config(self::VAR_PATH_FILE); $mode = strtolower($this->get_config(self::VAR_MODE)) == 'a' ? 'a' : 'w'; @@ -83,16 +82,14 @@ class TlogDestinationFile extends AbstractTlogDestination "Chemin du fichier", "Attention, vous devez indiquer un chemin absolu.
Le répertoire de base de votre Thelia est ".dirname(getcwd()), $this->path_defaut, - TlogDestinationConfig::TYPE_TEXTFIELD, - $this->getConfigModel() + TlogDestinationConfig::TYPE_TEXTFIELD ), new TlogDestinationConfig( self::VAR_MODE, "Mode d'ouverture (A ou E)", "Indiquez E pour ré-initialiser le fichier à chaque requête, A pour ne jamais réinitialiser le fichier. Pensez à le vider de temps en temps !", - self::VALEUR_MODE_DEFAUT, - TlogDestinationConfig::TYPE_TEXTFIELD, - $this->getConfigModel() + self::VALEUR_MODE_DEFAULT, + TlogDestinationConfig::TYPE_TEXTFIELD ) ); } diff --git a/core/lib/Thelia/Log/Destination/TlogDestinationHtml.php b/core/lib/Thelia/Log/Destination/TlogDestinationHtml.php index a5af69554..a87ce561a 100644 --- a/core/lib/Thelia/Log/Destination/TlogDestinationHtml.php +++ b/core/lib/Thelia/Log/Destination/TlogDestinationHtml.php @@ -40,7 +40,7 @@ class TlogDestinationHtml extends AbstractTlogDestination } - public function configurer($config = false) + public function configurer() { $this->style = $this->get_config(self::VAR_STYLE); } @@ -57,15 +57,15 @@ class TlogDestinationHtml extends AbstractTlogDestination public function get_configs() { -// return array( -// new TlogDestinationConfig( -// self::VAR_STYLE, -// "Style d'affichage direct dans la page", -// "Vous pouvez aussi laisser ce champ vide, et créer un style \"tlog-trace\" dans votre feuille de style.", -// self::VALEUR_STYLE_DEFAUT, -// TlogDestinationConfig::TYPE_TEXTAREA -// ) -// ); + return array( + new TlogDestinationConfig( + self::VAR_STYLE, + "Style d'affichage direct dans la page", + "Vous pouvez aussi laisser ce champ vide, et créer un style \"tlog-trace\" dans votre feuille de style.", + self::VALEUR_STYLE_DEFAUT, + TlogDestinationConfig::TYPE_TEXTAREA + ) + ); } public function ecrire(&$res) diff --git a/core/lib/Thelia/Log/Tlog.php b/core/lib/Thelia/Log/Tlog.php index e85030496..633b4cb6f 100644 --- a/core/lib/Thelia/Log/Tlog.php +++ b/core/lib/Thelia/Log/Tlog.php @@ -22,8 +22,7 @@ /*************************************************************************************/ namespace Thelia\Log; -use Thelia\Model\Config; -use Symfony\Component\DependencyInjection\ContainerInterface; +use Thelia\Model\ConfigQuery; /** * @@ -53,7 +52,7 @@ class Tlog Implements TlogInterface const MUET = PHP_INT_MAX; // default values - const DEFAULT_LEVEL = self::DEBUG; + const DEFAULT_LEVEL = self::DEBUG; const DEFAUT_DESTINATIONS = "Thelia\Log\Destination\TlogDestinationFile"; const DEFAUT_PREFIXE = "#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: "; const DEFAUT_FILES = "*"; @@ -78,52 +77,45 @@ 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) + private function __construct() { - $this->container = $container; - - $this->init(); } -// public static function instance() { -// if (self::$instance == false) { -// self::$instance = new Tlog(); -// -// // On doit placer les initialisations à ce level pour pouvoir -// // utiliser la classe Tlog dans les classes de base (Cnx, BaseObj, etc.) -// // Les placer dans le constructeur provoquerait une boucle -// self::$instance->init(); -// } -// -// return self::$instance; -// } + /** + * + * @return \Thelia\Log\Tlog + */ + public static function instance() { + if (self::$instance == false) { + self::$instance = new Tlog(); + + // On doit placer les initialisations à ce level pour pouvoir + // utiliser la classe Tlog dans les classes de base (Cnx, BaseObj, etc.) + // Les placer dans le constructeur provoquerait une boucle + self::$instance->init(); + } + + return self::$instance; + } protected function init() { - $config = $this->container->get("model.config"); - $level = $config->read(self::VAR_LEVEL, self::DEFAULT_LEVEL); - - $this->set_level($level); + $this->set_level(ConfigQuery::read(self::VAR_LEVEL, self::DEFAULT_LEVEL)); $this->dir_destinations = array( __DIR__.'/Destination' //, __DIR__.'/../client/tlog/destinations' ); - $this->set_prefixe($config->read(self::VAR_PREFIXE, self::DEFAUT_PREFIXE)); - $this->set_files($config->read(self::VAR_FILES, self::DEFAUT_FILES)); - $this->set_ip($config->read(self::VAR_IP, self::DEFAUT_IP)); - $this->set_destinations($config->read(self::VAR_DESTINATIONS, self::DEFAUT_DESTINATIONS)); - $this->set_show_redirect($config->read(self::VAR_SHOW_REDIRECT, self::DEFAUT_SHOW_REDIRECT)); + $this->set_prefixe(ConfigQuery::read(self::VAR_PREFIXE, self::DEFAUT_PREFIXE)); + $this->set_files(ConfigQuery::read(self::VAR_FILES, self::DEFAUT_FILES)); + $this->set_ip(ConfigQuery::read(self::VAR_IP, self::DEFAUT_IP)); + $this->set_destinations(ConfigQuery::read(self::VAR_DESTINATIONS, self::DEFAUT_DESTINATIONS)); + $this->set_show_redirect(ConfigQuery::read(self::VAR_SHOW_REDIRECT, self::DEFAUT_SHOW_REDIRECT)); // Au cas ou il y aurait un exit() quelque part dans le code. register_shutdown_function(array($this, 'ecrire_si_exit')); @@ -345,7 +337,7 @@ class Tlog Implements TlogInterface // we are sometimes in functions = no class available: avoid php warning here $className = $hop['class']; - if (! empty($className) and ($className == ltrim($this->container->getParameter("logger.class"),'\\') or strtolower(get_parent_class($className)) == ltrim($this->container->getParameter("logger.class"),'\\'))) { + if (! empty($className) and ($className == ltrim(__CLASS__,'\\') or strtolower(get_parent_class($className)) == ltrim(__CLASS__,'\\'))) { $origine['line'] = $hop['line']; $origine['file'] = $hop['file']; break; @@ -414,7 +406,7 @@ class Tlog Implements TlogInterface { foreach ($actives as $active) { if (class_exists($active)) { - $class = new $active($this->container->get('model.config')); + $class = new $active(); if (!$class instanceof AbstractTlogDestination) { throw new \UnexpectedValueException($active." must extends Thelia\Tlog\AbstractTlogDestination"); diff --git a/core/lib/Thelia/Log/TlogDestinationConfig.php b/core/lib/Thelia/Log/TlogDestinationConfig.php index f68148430..4b1e6b74b 100644 --- a/core/lib/Thelia/Log/TlogDestinationConfig.php +++ b/core/lib/Thelia/Log/TlogDestinationConfig.php @@ -23,41 +23,46 @@ namespace Thelia\Log; +use Thelia\Model\Config; +use Thelia\Model\ConfigQuery; + class TlogDestinationConfig { const TYPE_TEXTAREA = 1; const TYPE_TEXTFIELD = 2; - public $titre; + public $name; + public $title; public $label; - public $defaut; + public $default; public $type; - public $valeur; + public $value; - public function __construct($nom, $titre, $label, $defaut, $type, $config = null) + public function __construct($name, $title, $label, $default, $type) { - $this->nom = $nom; - $this->titre = $titre; + $this->name = $name; + $this->title = $title; $this->label = $label; - $this->defaut = $defaut; + $this->default = $default; $this->type = $type; -// @$this->charger(); - - if ($config) { - $this->valeur = $config->read($this->nom, $this->defaut); - } + $this->load(); } -// public function charger() { -// // La variable n'existe pas ? La créer en y affectant la valeur par defaut -// if (! parent::charger($this->nom)) { -// $this->valeur = $this->defaut; -// $this->protege = 1; -// $this->cache = 1; -// -// $this->add(); -// } -// } + + public function load() + { + if (null === $config = ConfigQuery::create()->findOneByName($this->name)) + { + $config = new Config(); + $config->setName($this->name); + $config->setValue($this->default); + $config->setHidden(1); + $config->setSecure(1); + $config->save(); + } + + $this->value = $config->getValue(); + } }