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

  • RendererProviderFactory

Interfaces

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