Overview

Namespaces

  • Alpha
    • Controller
      • Front
    • Exception
    • Model
      • Type
    • Task
    • Util
      • Backup
      • Cache
      • Code
        • Highlight
        • Metric
      • Config
      • Convertor
      • Email
      • Extension
      • Feed
      • File
      • Graph
      • Helper
      • Http
        • Filter
        • Session
      • Image
      • Logging
      • Search
      • Security
    • View
      • Renderer
        • Html
        • Json
      • Widget

Classes

  • ActionLog
  • ActiveRecord
  • ActiveRecordProviderFactory
  • ActiveRecordProviderMySQL
  • ActiveRecordProviderSQLite
  • Article
  • ArticleComment
  • ArticleVote
  • BadRequest
  • BlacklistedClient
  • BlacklistedIP
  • Person
  • Rights
  • Tag

Interfaces

  • ActiveRecordProviderInterface
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: 
  3: namespace Alpha\Model;
  4: 
  5: use Alpha\Util\Logging\Logger;
  6: use Alpha\Util\Config\ConfigProvider;
  7: use Alpha\Exception\IllegalArguementException;
  8: 
  9: /**
 10:  * A factory for creating active record provider implementations that implement the
 11:  * ActiveRecordProviderInterface interface.
 12:  *
 13:  * @since 1.1
 14:  *
 15:  * @author John Collins <dev@alphaframework.org>
 16:  *
 17:  * @version $Id: ActiveRecordProviderFactory.php 1842 2014-11-12 22:27:01Z alphadevx $
 18:  *
 19:  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
 20:  * @copyright Copyright (c) 2015, John Collins (founder of Alpha Framework).
 21:  * All rights reserved.
 22:  *
 23:  * <pre>
 24:  * Redistribution and use in source and binary forms, with or
 25:  * without modification, are permitted provided that the
 26:  * following conditions are met:
 27:  *
 28:  * * Redistributions of source code must retain the above
 29:  *   copyright notice, this list of conditions and the
 30:  *   following disclaimer.
 31:  * * Redistributions in binary form must reproduce the above
 32:  *   copyright notice, this list of conditions and the
 33:  *   following disclaimer in the documentation and/or other
 34:  *   materials provided with the distribution.
 35:  * * Neither the name of the Alpha Framework nor the names
 36:  *   of its contributors may be used to endorse or promote
 37:  *   products derived from this software without specific
 38:  *   prior written permission.
 39:  *
 40:  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
 41:  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 42:  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 43:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 44:  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 45:  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 46:  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 47:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 48:  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 49:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 50:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 51:  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 52:  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 53:  * </pre>
 54:  */
 55: class ActiveRecordProviderFactory
 56: {
 57:     /**
 58:      * Trace logger.
 59:      *
 60:      * @var Alpha\Util\Logging\Logger
 61:      *
 62:      * @since 1.1
 63:      */
 64:     private static $logger = null;
 65: 
 66:     /**
 67:      * A static method that attempts to return a ActiveRecordProviderInterface instance
 68:      * based on the name of the provider class supplied.
 69:      *
 70:      * @param $providerName The fully-qualified class name of the provider class.
 71:      * @param $BO The (optional) active record instance to pass to the persistance provider for mapping.
 72:      *
 73:      * @throws Alpha\Exception\IllegalArguementException
 74:      *
 75:      * @return Alpha\Model\ActiveRecordProviderInterface
 76:      *
 77:      * @since 1.1
 78:      */
 79:     public static function getInstance($providerName, $BO = null)
 80:     {
 81:         if (self::$logger == null) {
 82:             self::$logger = new Logger('ActiveRecordProviderFactory');
 83:         }
 84: 
 85:         self::$logger->debug('>>getInstance(providerName=['.$providerName.'], BO=['.print_r($BO, true).'])');
 86: 
 87:         $config = ConfigProvider::getInstance();
 88: 
 89:         if (class_exists($providerName)) {
 90:             $instance = new $providerName();
 91: 
 92:             if (!$instance instanceof ActiveRecordProviderInterface) {
 93:                 throw new IllegalArguementException('The class ['.$providerName.'] does not implement the expected ActiveRecordProviderInterface interface!');
 94:             }
 95: 
 96:             if ($BO instanceof ActiveRecord) {
 97:                 $instance->setBO($BO);
 98:             }
 99: 
100:             self::$logger->debug('<<getInstance: [Object '.$providerName.']');
101: 
102:             return $instance;
103:         } else {
104:             throw new IllegalArguementException('The class ['.$providerName.'] is not defined anywhere!');
105:         }
106: 
107:         self::$logger->debug('<<getInstance');
108:     }
109: }
110: 
Alpha Framework 2.0.4 API Documentation API documentation generated by ApiGen 2.8.0