Orion PHP  0.11.12
The PHP5.3 framework
query.php
Go to the documentation of this file.
00001 <?php
00002 
00003 namespace Orion\Core;
00004 
00005 
00006 /**
00007  * \Orion\Core\Query
00008  * 
00009  * Orion Query factory.
00010  *
00011  * @author Thibaut Despoulain
00012  * @license BSD 4-clauses
00013  * @version 0.11.12
00014  */
00015 class Query
00016 {
00017     // The following constants are used as keys to translates comparators in DB-specific query classes.
00018     const ASCENDING = 'ASC';
00019     const DESCENDING = 'DESC';
00020     const EQUAL = '=';
00021     const NEQUAL = '!=';
00022     const LIKE = 'LIKE';
00023     const NOT = 'NOT';
00024     const REGEX = 'REGEX';
00025 
00026     /**
00027      * (Factory) Create and return a new Query instance based on Query\Base and specific to the DB type set in configuration.
00028      * @param String $class Name of the model class from whom the Factory call originates (Facultative).
00029      * @return \Orion\Core\Query\Base
00030      */
00031     public static final function Factory( $class=null )
00032     {
00033         if ( !\Orion::config()->get( 'DB_TYPE' ) )
00034             throw new Exception( 'No database type set in Orion configuration file.', E_ERROR, get_class() );
00035 
00036         try
00037         {
00038             $queryClass = '\\Orion\\Core\\Query\\' . ucfirst( strtolower( \Orion::config()->get( 'DB_TYPE' ) ) );
00039             return new $queryClass( $class );
00040         }
00041         catch ( Exception $e )
00042         {
00043             throw new Exception( 'Unable to load Query class for [' . \Orion::config()->get( 'DB_TYPE' ) . '] database type.', E_ERROR, get_class() );
00044         }
00045     }
00046 
00047 }
00048 
00049 ?>