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

Source for file Function.php

Documentation is available at Function.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. /**
  30.  * PHPLinq_Function
  31.  *
  32.  * @category   PHPLinq
  33.  * @package    PHPLinq
  34.  * @copyright  Copyright (c) 2008 - 2009 PHPLinq (http://www.codeplex.com/PHPLinq)
  35.  */
  36.     /**
  37.      * Parameter names
  38.      *
  39.      * @var string 
  40.      */
  41.     private $_parameterNames;
  42.     
  43.     /**
  44.      * Function code
  45.      *
  46.      * @var string 
  47.      */
  48.     private $_functionCode;
  49.     
  50.     /**
  51.      * Function reference
  52.      *
  53.      * @var mixed 
  54.      */
  55.     private $_functionReference = null;
  56.     
  57.     /**
  58.      * Construct function
  59.      *
  60.      * @param string $parameterNames Parameter names
  61.      * @param string $functionCode Function code
  62.      * @throws Exception
  63.      */
  64.     public function __construct($parameterNames ''$functionCode ''{
  65.         // Check parameters
  66.         if (strpos($parameterNames'$'=== false{
  67.             throw new PHPLinq_Exception('Missing arguments in parameter $parameterNames.');
  68.         }
  69.         if (strpos($functionCode'return'=== false{
  70.             throw new PHPLinq_Exception('Missing return statement in parameter $functionCode.');
  71.         }
  72.         
  73.         // Store parameters
  74.         $this->_parameterNames         = $parameterNames;
  75.         $this->_functionCode         = $functionCode;
  76.         $this->_functionReference     = null;
  77.     }
  78.     
  79.     /**
  80.      * Get function reference
  81.      *
  82.      * @return mixed 
  83.      */
  84.     public function getFunctionReference({
  85.         if (is_null($this->_functionReference)) {
  86.             // Compile anonymous function
  87.             $this->_functionReference = create_function($this->_parameterNames$this->_functionCode);
  88.         }
  89.         
  90.         return $this->_functionReference;
  91.     }
  92.     
  93.     /**
  94.      * Get parameters
  95.      *
  96.      * @return string 
  97.      */
  98.     public function getParameterNames({
  99.         return $this->_parameterNames;
  100.     }
  101.     
  102.     /**
  103.      * Get source code
  104.      *
  105.      * @return string 
  106.      */
  107.     public function getFunctionCode({
  108.         return $this->_functionCode;
  109.     }
  110. }

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