Exemplo n.º 1
0
 /**
  * Database object constructor
  *
  * @param   array  $options  List of options used to configure the connection
  *
  */
 public function __construct($options)
 {
     $options['host'] = isset($options['host']) ? $options['host'] : 'localhost';
     $options['user'] = isset($options['user']) ? $options['user'] : '';
     $options['password'] = isset($options['password']) ? $options['password'] : '';
     $options['database'] = isset($options['database']) ? $options['database'] : '';
     // Finalize initialization
     parent::__construct($options);
 }
Exemplo n.º 2
0
 /**
  * Constructor.
  *
  * @param   array  $options  List of options used to configure the connection
  *
  */
 public function __construct($options)
 {
     // Get some basic values from the options.
     $options['host'] = isset($options['host']) ? $options['host'] : 'localhost';
     $options['user'] = isset($options['user']) ? $options['user'] : '';
     $options['password'] = isset($options['password']) ? $options['password'] : '';
     $options['database'] = isset($options['database']) ? $options['database'] : '';
     $options['select'] = isset($options['select']) ? (bool) $options['select'] : true;
     // Finalize initialisation
     parent::__construct($options);
 }
Exemplo n.º 3
0
 /**
  * Gets the date as an SQL datetime string.
  *
  * @param   boolean  $local  True to return the date string in the local time zone, false to return it in GMT.
  * @param   Driver   $db     The database driver or null to use JFactory::getDbo()
  *
  * @return  string  The date string in SQL datetime format.
  *
  * @link    http://dev.mysql.com/doc/refman/5.0/en/datetime.html
  */
 public function toSql($local = false, Driver $db = null)
 {
     if ($db === null) {
         $db = Driver::getInstance();
     }
     return $this->format($db->getDateFormat(), $local);
 }
Exemplo n.º 4
0
 public function __construct(array $values = array())
 {
     $this->application_name = '';
     $this->session_segment_name = null;
     $this->basePath = null;
     $this->templatePath = null;
     $this->languagePath = null;
     $this->temporaryPath = null;
     $this->filesystemBase = null;
     $this->sqlPath = null;
     parent::__construct($values);
     // Application service
     if (!isset($this['application'])) {
         $this['application'] = function (Container $c) {
             return Application::getInstance($c->application_name, $c);
         };
     }
     // Application Configuration service
     if (!isset($this['appConfig'])) {
         $this['appConfig'] = function (Container $c) {
             return new \Awf\Application\Configuration($c);
         };
     }
     // Database Driver service
     if (!isset($this['db'])) {
         $this['db'] = function (Container $c) {
             return Driver::getInstance($c);
         };
     }
     // Application Dispatcher service
     if (!isset($this['dispatcher'])) {
         $this['dispatcher'] = function (Container $c) {
             $className = '\\' . ucfirst($c->application_name) . '\\Dispatcher';
             if (!class_exists($className)) {
                 $className = '\\Awf\\Dispatcher\\Dispatcher';
             }
             return new $className($c);
         };
     }
     // Application Event Dispatcher service
     if (!isset($this['eventDispatcher'])) {
         $this['eventDispatcher'] = function (Container $c) {
             return new \Awf\Event\Dispatcher($c);
         };
     }
     // Filesystem Abstraction Layer service
     if (!isset($this['fileSystem'])) {
         $this['fileSystem'] = function (Container $c) {
             return \Awf\Filesystem\Factory::getAdapter($c, true);
         };
     }
     // Input Access service
     if (!isset($this['input'])) {
         $this['input'] = function (Container $c) {
             return new \Awf\Input\Input();
         };
     }
     // Mailer Object service
     if (!isset($this['mailer'])) {
         $this['mailer'] = $this->factory(function (Container $c) {
             return new \Awf\Mailer\Mailer($c);
         });
     }
     // Application Router service
     if (!isset($this['router'])) {
         $this['router'] = function (Container $c) {
             return new \Awf\Router\Router($c);
         };
     }
     // Session Manager service
     if (!isset($this['session'])) {
         $this['session'] = function () {
             return new Session\Manager(new Session\SegmentFactory(), new Session\CsrfTokenFactory(new Session\Randval(new Phpfunc())), $_COOKIE);
         };
     }
     // Application Session Segment service
     if (!isset($this['segment'])) {
         $this['segment'] = function (Container $c) {
             if (empty($c->session_segment_name)) {
                 $c->session_segment_name = 'Akeeba\\Awf\\' . $c->application_name;
             }
             return $c->session->newSegment($c->session_segment_name);
         };
     }
     // User Manager service
     if (!isset($this['userManager'])) {
         $this['userManager'] = function (Container $c) {
             return new \Awf\User\Manager($c);
         };
     }
 }
Exemplo n.º 5
0
 /**
  * Returns the instance of the database driver, creating it if it doesn't
  * exist.
  *
  * @return  Driver
  *
  * @throws \RuntimeException
  */
 protected function getDatabase()
 {
     if (!is_object($this->db)) {
         $options = array('driver' => $this->container['dbrestore']['dbtype'], 'database' => $this->container['dbrestore']['dbname'], 'select' => 0, 'host' => $this->container['dbrestore']['dbhost'], 'user' => $this->container['dbrestore']['dbuser'], 'password' => $this->container['dbrestore']['dbpass'], 'prefix' => $this->container['dbrestore']['prefix']);
         $class = '\\Awf\\Database\\Driver\\' . ucfirst(strtolower($options['driver']));
         $this->db = new $class($options);
         $this->db->setUTF();
     }
     return $this->db;
 }
Exemplo n.º 6
0
 /**
  * Sets the SQL statement string for later execution.
  *
  * @param   mixed    $query          The SQL statement to set either as a JDatabaseQuery object or a string.
  * @param   integer  $offset         The affected row offset to set.
  * @param   integer  $limit          The maximum affected rows to set.
  * @param   array    $driverOptions  The optional PDO driver options
  *
  * @return  Pdo  This object to support method chaining.
  *
  * @since   1.0
  */
 public function setQuery($query, $offset = null, $limit = null, $driverOptions = array())
 {
     $this->connect();
     $this->freeResult();
     if (is_string($query)) {
         // Allows taking advantage of bound variables in a direct query:
         $query = $this->getQuery(true)->setQuery($query);
     }
     if ($query instanceof QueryLimitable && !is_null($offset) && !is_null($limit)) {
         $query->setLimit($limit, $offset);
     }
     $sql = $this->replacePrefix((string) $query);
     $this->prepared = $this->connection->prepare($sql, $driverOptions);
     // Store reference to the DatabaseQuery instance:
     parent::setQuery($query, $offset, $limit);
     return $this;
 }
Exemplo n.º 7
0
 public function __construct(array $values = array())
 {
     $appNameForPaths = $values['application_name'];
     if (Helper::isBackend() && substr($appNameForPaths, -5) == 'Admin') {
         $appNameForPaths = substr($appNameForPaths, 0, -5);
     }
     // Set up the filesystem path
     if (empty($values['filesystemBase'])) {
         $values['filesystemBase'] = JPATH_ROOT;
     }
     // Set up the base path
     if (empty($values['basePath'])) {
         $basePath = '/components/com_' . $appNameForPaths . '/' . $values['application_name'];
         $values['basePath'] = (Helper::isBackend() ? JPATH_ADMINISTRATOR : JPATH_ROOT) . $basePath;
     }
     // Set up the template path
     if (empty($values['templatePath'])) {
         $values['templatePath'] = __DIR__ . '/../templates';
     }
     // Set up the temporary path
     if (empty($values['temporaryPath'])) {
         $values['temporaryPath'] = \JFactory::getConfig()->get('tmp_path', sys_get_temp_dir());
     }
     // Set up the language path
     if (empty($values['languagePath'])) {
         $values['languagePath'] = (Helper::isBackend() ? JPATH_ADMINISTRATOR : JPATH_ROOT) . '/language';
     }
     // Set up the SQL files path
     if (empty($values['sqlPath'])) {
         $values['sqlPath'] = JPATH_ADMINISTRATOR . '/components/com_' . $appNameForPaths . '/sql/xml';
     }
     // Application service
     if (!isset($this['application'])) {
         $this['application'] = function (Container $c) {
             return Application::getInstance($c->application_name, $c);
         };
     }
     // Session Manager service
     if (!isset($this['session'])) {
         $this['session'] = function () {
             return new \Awf\Platform\Joomla\Session\Manager(new \Awf\Platform\Joomla\Session\SegmentFactory(), new \Awf\Platform\Joomla\Session\CsrfTokenFactory());
         };
     }
     // Application Session Segment service
     if (!isset($this['segment'])) {
         $this['segment'] = function (Container $c) {
             if (empty($c->session_segment_name)) {
                 $c->session_segment_name = $c->application_name;
             }
             return $c->session->newSegment($c->session_segment_name);
         };
     }
     // Database Driver service
     if (!isset($this['db'])) {
         $this['db'] = function (Container $c) {
             $db = \JFactory::getDbo();
             $options = array('connection' => $db->getConnection(), 'prefix' => $db->getPrefix(), 'driver' => 'mysqli');
             switch ($db->name) {
                 case 'mysql':
                     $options['driver'] = 'Mysql';
                     break;
                 default:
                 case 'mysqli':
                     $options['driver'] = 'Mysqli';
                     break;
                 case 'sqlsrv':
                 case 'mssql':
                 case 'sqlazure':
                     $options['driver'] = 'Sqlsrv';
                     break;
                 case 'postgresql':
                     $options['driver'] = 'Postgresql';
                     break;
                 case 'pdo':
                     $options['driver'] = 'Pdo';
                     break;
                 case 'sqlite':
                     $options['driver'] = 'Sqlite';
                     break;
             }
             return Driver::getInstance($options);
         };
     }
     // Application Event Dispatcher service
     if (!isset($this['eventDispatcher'])) {
         $this['eventDispatcher'] = function (Container $c) {
             return new Dispatcher($c);
         };
     }
     // Application Configuration service
     if (!isset($values['appConfig'])) {
         $values['appConfig'] = function (Container $c) {
             return new Configuration($c);
         };
     }
     // Application Router service
     if (!isset($values['router'])) {
         $values['router'] = function (Container $c) {
             return new Router($c);
         };
     }
     // User Manager service
     if (!isset($values['userManager'])) {
         $values['userManager'] = function (Container $c) {
             return new Manager($c);
         };
     }
     parent::__construct($values);
     // Mailer Object service – returns a Joomla! JMail object
     // IMPORTANT! It has to appear AFTER the parent __construct method
     $this['mailer'] = $this->factory(function (Container $c) {
         return \JFactory::getMailer();
     });
 }