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

Source for file Custom.php

Documentation is available at Custom.php

  1. <?
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3.  
  4. /**
  5.  * Custom predicate built by supplying a string expression
  6.  *
  7.  * PHP versions 4 and 5
  8.  *
  9.  * This library is free software; you can redistribute it and/or
  10.  * modify it under the terms of the GNU Lesser General Public
  11.  * License as published by the Free Software Foundation; either
  12.  * version 2.1 of the License, or (at your option) any later version.
  13.  *
  14.  * This library is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17.  * Lesser General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU Lesser General Public
  20.  * License along with this library; if not, write to the Free Software
  21.  * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA
  22.  *
  23.  * @category   File Formats
  24.  * @package    File_Archive
  25.  * @author     Vincent Lascaux <vincentlascaux@php.net>
  26.  * @copyright  1997-2005 The PHP Group
  27.  * @license    http://www.gnu.org/copyleft/lesser.html  LGPL
  28.  * @version    CVS: $Id: Custom.php,v 1.3 2005/02/18 21:00:49 vincentlascaux Exp $
  29.  * @link       http://pear.php.net/package/File_Archive
  30.  */
  31.  
  32. require_once "File/Archive/Predicate.php";
  33.  
  34. /**
  35.  * Custom predicate built by supplying a string expression
  36.  *
  37.  * Example:
  38.  *     new File_Archive_Predicate_Custom("return strlen($source->getFilename())<100;")
  39.  *     new File_Archive_Predicate_Custom("strlen($source->getFilename())<100;")
  40.  *     new File_Archive_Predicate_Custom("strlen($source->getFilename())<100")
  41.  *
  42.  * @see        File_Archive_Predicate File_Archive_Reader_Filter
  43.  */
  44. class File_Archive_Predicate_Custom extends File_Archive_Predicate
  45. {
  46.     var $expression;
  47.  
  48.     /**
  49.      * @param string $expression PHP code that evaluates too a boolean
  50.      *        It can use the $source variable
  51.      *        If return is ommited, it will be added to the begining of the expression
  52.      *        A ; will also be added at the end so that you don't need to write it
  53.      */
  54.     function File_Archive_Predicate_Custom($expression)
  55.     {
  56.         $this->expression = $expression.";";
  57.         if(strpos($this->expression, "return") === false) {
  58.             $this->expression = "return ".$this->expression;
  59.         }
  60.  
  61.     }
  62.     /**
  63.      * @see File_Archive_Predicate::isTrue
  64.      */
  65.     function isTrue(&$source)
  66.     {
  67.         return eval($this->expression);
  68.     }
  69. }
  70.  
  71. ?>

Documentation generated on Mon, 11 Mar 2019 14:24:01 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.