PHPLinq
[ class tree: PHPLinq ] [ index: PHPLinq ] [ all elements ]

Source for file Initiator.php

Documentation is available at Initiator.php

  1. <?php
  2. /**
  3.  * PHPLinq
  4.  *
  5.  * Copyright (c) 2008 - 2009 PHPLinq
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Lesser General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2.1 of the License, or (at your option) any later version.
  11.  * 
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * Lesser General Public License for more details.
  16.  * 
  17.  * You should have received a copy of the GNU Lesser General Public
  18.  * License along with this library; if not, write to the Free Software
  19.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  20.  *
  21.  * @category   PHPLinq
  22.  * @package    PHPLinq
  23.  * @copyright  Copyright (c) 2008 - 2009 PHPLinq (http://www.codeplex.com/PHPLinq)
  24.  * @license    http://www.gnu.org/licenses/lgpl.txt    LGPL
  25.  * @version    0.4.0, 2009-01-27
  26.  */
  27.  
  28.  
  29. /** PHPLinq */
  30. require_once('PHPLinq.php');
  31.  
  32. /** PHPLinq_ILinqProvider */
  33. require_once('PHPLinq/ILinqProvider.php');
  34.  
  35.  
  36. /**
  37.  * PHPLinq_Initiator
  38.  *
  39.  * @category   PHPLinq
  40.  * @package    PHPLinq
  41.  * @copyright  Copyright (c) 2008 - 2009 PHPLinq (http://www.codeplex.com/PHPLinq)
  42.  */
  43.     /**
  44.      * Registered PHPLinq_ILinqProvider classes
  45.      *
  46.      * @var string[] 
  47.      */
  48.     private static $_registeredProviders array();
  49.     
  50.     /**
  51.      * Register PHPLinq_ILinqProvider class
  52.      *
  53.      * @param string $class Class name implementing PHPLinq_ILinqProvider
  54.      * @param string $reference Path reference (for inclusion)
  55.      */
  56.     public static function registerProvider($class null$reference null{
  57.         if (!is_null($class&& $class != ''{
  58.             // Require code
  59.             if (is_null($reference|| $reference == ''{
  60.                 $reference str_replace('_''/'$class);
  61.                 $reference .= '.php';
  62.             }
  63.             require_once($reference);
  64.             
  65.             // Add registered PHPLinq_ILinqProvider
  66.             self::$_registeredProviders[$class;
  67.         }
  68.     }
  69.     
  70.     /**
  71.      * Default variable name
  72.      *
  73.      * @var string 
  74.      */
  75.     private $_from = '';
  76.     
  77.     /**
  78.      * Parent PHPLinq_ILinqProvider instance, used with join conditions
  79.      *
  80.      * @var PHPLinq_ILinqProvider 
  81.      */
  82.     private $_parentProvider = null;
  83.     
  84.     /**
  85.      * Create a new class instance
  86.      *
  87.      * @param string $name 
  88.      * @param PHPLinq_ILinqProvider $parentProvider Optional parent PHPLinq_ILinqProvider instance, used with join conditions
  89.      * @return PHPLinq_Initiator 
  90.      */
  91.     public function __construct($namePHPLinq_ILinqProvider $parentProvider null{
  92.         $this->_from = $name;
  93.         $this->_parentProvider = $parentProvider;
  94.         return $this;
  95.     }
  96.     
  97.     /**
  98.      * Set source of data
  99.      *
  100.      * @param mixed $source 
  101.      * @return PHPLinq_ILinqProvider 
  102.      */
  103.     public function in($source{
  104.         // Search correct provider
  105.         foreach (self::$_registeredProviders as $provider{
  106.             if (call_user_func(array($provider'handles')$source)) {
  107.                 $returnValue new $provider($this->_from$this->_parentProvider);
  108.                 return $returnValue->in($source);
  109.             }
  110.         }
  111.         
  112.         // No provider found...
  113.         throw new PHPLinq_Exception("No valid PHPLinq_ILinqProvider found for the specified data source.");
  114.     }
  115. }

Documentation generated on Tue, 27 Jan 2009 08:29:25 +0100 by phpDocumentor 1.4.1