Пример #1
0
 /**
  * Class constructor
  * 
  * @return  void
  */
 private function __construct()
 {
     $this->_conf = Woops_Core_Config_Getter::getInstance();
     $this->_env = Woops_Core_Env_Getter::getInstance();
     $this->_request = Woops_Core_Request_Getter::getInstance();
     $this->_db = Woops_Database_Layer::getInstance()->getEngine();
     $this->_str = Woops_String_Utils::getInstance();
     $this->_pageId = $this->_getPageId();
     $this->_langName = $this->_getLanguage();
     $this->_page = $this->_getPage($this->_pageId, $this->_langName);
     $this->_template = $this->_getTemplate($this->_page->id_templates);
 }
Пример #2
0
 /**
  * Gets the unique class instance
  * 
  * This method is used to get the unique instance of the class
  * (singleton). If no instance is available, it will create it.
  * 
  * @return  Woops_Database_Layer    The unique instance of the class
  * @see     __construct
  */
 public static function getInstance()
 {
     // Checks if the unique instance already exists
     if (!is_object(self::$_instance)) {
         // Creates the unique instance
         self::$_instance = new self();
     }
     // Returns the unique instance
     return self::$_instance;
 }
Пример #3
0
<?php

################################################################################
#                                                                              #
#                WOOPS - Web Object Oriented Programming System                #
#                                                                              #
#                               COPYRIGHT NOTICE                               #
#                                                                              #
# Copyright (C) 2009 Jean-David Gadina - www.xs-labs.com                       #
# All rights reserved                                                          #
################################################################################
# $Id$
Woops_Database_Layer::getInstance()->registerDatabaseEngine('pdo', 'Woops_Mod_Pdo_Database_Engine');
Пример #4
0
<?php

################################################################################
#                                                                              #
#                WOOPS - Web Object Oriented Programming System                #
#                                                                              #
#                               COPYRIGHT NOTICE                               #
#                                                                              #
# Copyright (C) 2009 Jean-David Gadina - www.xs-labs.com                       #
# All rights reserved                                                          #
################################################################################
# $Id$
Woops_Database_Layer::getInstance()->registerDatabaseEngine('adodb', 'Woops_Mod_Adodb_Database_Engine');
Пример #5
0
 /**
  * Executes the needed database queries
  * 
  * @param   array           The selected tables
  * @param   string          The path to the SQL file
  * @param   string          The prefix to detect the table names
  * return   void
  */
 protected function _databaseQuery(array $tableNames, $filePath, $detectPrefix)
 {
     // Tags to replace
     $tags = array('/{\\$PREFIX}/', '/{\\$DEFAULT_LANGUAGE}/');
     // Replacement values
     $replace = array(self::$_conf->getVar('database', 'tablePrefix'), self::$_conf->getVar('lang', 'defaultLanguage'));
     // Gets the table names as keys
     $tableNames = array_flip($tableNames);
     // Gets the file lines
     $lines = file($filePath);
     // Replaces the tags
     $lines = preg_replace($tags, $replace, $lines);
     // Storage for the queries to perform
     $queries = array();
     // Flag to know if we are in a multiline SQL statement
     $inStatement = false;
     // Number of queries
     $queryCount = 0;
     // Process each line
     foreach ($lines as $line) {
         // Removes unneeded whitespace
         $line = trim($line);
         // Are we in a multiline SQL statement?
         if ($inStatement) {
             // Yes, adds the current line to the query
             $queries[$queryCount - 1] .= $line . self::$_str->NL;
             // Does the current line end the multiline SQL statement?
             if (substr($line, -1) === ';') {
                 // Yes, resets the flag
                 $inStatement = false;
             }
         } else {
             // Storage
             $matches = array();
             // Finds the table instructions
             preg_match('/^' . $detectPrefix . '`([^`]+)`/', $line, $matches);
             // Checks if we have an instruction
             if (isset($matches[1]) && !is_array($matches[1]) && isset($tableNames[$matches[1]])) {
                 // Yes, adds the current line to the query
                 $queries[] = $line . self::$_str->NL;
                 // Checks if the statement is ended
                 if (substr($line, -1) !== ';') {
                     // No, we are now in a multiline SQL statement
                     $inStatement = true;
                 }
                 // Increases the query counter
                 $queryCount++;
             }
         }
     }
     // We don't want any errors here
     try {
         // Database engine object
         static $engine;
         // Have we already the instance of the database engine
         if (!is_object($engine)) {
             // Gets the database engine
             $engine = Woops_Database_Layer::getInstance()->getEngine();
         }
         // Process each query
         foreach ($queries as $query) {
             // Executes the query
             $res = $engine->query($query);
             // Checks the query result
             if (!$res) {
                 // No result, returns the error message
                 return $engine->errorMessage();
             }
         }
     } catch (Exception $e) {
         // Returns the exception message
         return $e->getMessage();
     }
 }
Пример #6
0
 /**
  * Sets the needed static variables
  * 
  * @return  void
  */
 private static function _setStaticVars()
 {
     self::$_db = Woops_Database_Layer::getInstance()->getEngine();
     self::$_page = Woops_Page_Engine::getInstance()->getPageObject()->getXhtmlPage();
     // Static variables are set
     self::$_hasStatic = true;
 }