Source for file system.inc.php

Documentation is available at system.inc.php

  1. <?php
  2. /**
  3. *  This file is part of the VCL for PHP project
  4. *
  5. *  Copyright (c) 2004-2008 qadram software S.L. <support@qadram.com>
  6. *
  7. *  Checkout AUTHORS file for more information on the developers
  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
  22. *  USA
  23. *
  24. */
  25.  
  26. /**
  27.  * Exception thrown when trying to access a property not defined
  28.  *
  29.  * This property is raised when trying to access a property which is not defined
  30.  * in the object you are using.
  31.  */
  32. class EPropertyNotFound extends Exception
  33. {
  34.        /**
  35.         * Constructor
  36.         *
  37.         * @param string $message Message to show on the exception
  38.         * @param integer $code Code to use as exception code
  39.         */
  40.         function __construct($message = null$code = 0)
  41.         {
  42.                 $backtrace debug_backtrace();
  43.                 $call $backtrace];
  44.                 $file basename$call'file' );
  45.                 $line $call'line' ];
  46.  
  47.                 $message=sprintf'Trying to access non-existant property %s in %s, line %d.'$message$file$line );
  48.                 // make sure everything is assigned properly
  49.                 parent::__construct($message$code);
  50.         }
  51. }
  52.  
  53. /**
  54.  * Object is the ultimate ancestor of all objects and components.
  55.  *
  56.  * Object encapsulates fundamental behavior common to objects by introducing methods that
  57.  *
  58.  * create, maintain and destroy instances of the object by allocating, initializing, and freeing required memory.
  59.  *
  60.  * respond when object instances are created or destroyed.
  61.  *
  62.  * return class-type and instance information on an object and runtime type information (RTTI) about its published properties.
  63.  *
  64.  * Use Object as an immediate base class when declaring simple objects that do not need to persist
  65.  * (are not saved and reloaded in the session) and that do not need to be assigned to other objects.
  66.  *
  67.  * Much of the capability of objects is established by methods that Object introduces.
  68.  * Many of these methods are used internally by IDEs and are not intended for users to
  69.  * call directly. Others are overridden in descendant objects that have more complex behavior.
  70.  *
  71.  * Although Object is the based object of a component framework, not all objects are components.
  72.  * All component classes are descended from Component.
  73.  *
  74.  * To create a class that belongs to the class library, you must, at least, inherit
  75.  * from Object, which provides the basic methods to work.
  76.  */
  77. class Object
  78. {
  79.         /**
  80.         * Global input object, easily accessible without declaring global
  81.         */
  82.         public $input=null;
  83.  
  84.         /**
  85.         * Constructs an object and initializes its data before the object is first used.
  86.         *
  87.         * Create constructs an object. The purpose, size, and behavior of objects differ
  88.         * greatly. The Create constructor defined by Object allocates memory but does not initialize data.
  89.         *
  90.         * Descendant objects usually define a constructor that creates the particular kind of
  91.         * object and initializes its data.
  92.         *
  93.         * In Object, this constructor basically assigns the globa Input object to be
  94.         * available as a field for all objects.
  95.         *
  96.         * @return Object 
  97.         */
  98.         function __construct()
  99.         {
  100.                 global $input;
  101.  
  102.                 //Assign the global input object so it can be used from inside
  103.                 $this->input=$input;
  104.         }
  105.  
  106.         /**
  107.          * Returns a string indicating the type of the object instance (as opposed to the type of the variable passed as an argument).
  108.          *
  109.          * Use ClassName to obtain the class name from an object instance.
  110.          * This is useful for differentiating object instances that are assigned to a
  111.          * variable that has the type of an ancestor class.
  112.          *
  113.          * <code>
  114.          * <?php
  115.          *         //Class definition
  116.          *         class Unit467 extends Page
  117.          *         {
  118.          *                function Unit467BeforeShow($sender, $params)
  119.          *                {
  120.          *                 echo $this->className();
  121.          *                 //This will echo Unit467 on the browser
  122.          *                }
  123.          *
  124.          *         }
  125.          * ?>
  126.          * </code>
  127.          *
  128.          * @return string Name of this object class
  129.          */
  130.         function className()
  131.         {
  132.                 return(get_class($this));
  133.         }
  134.  
  135.  
  136.         /**
  137.          * Determines whether an object is of a specific type.
  138.          *
  139.          * ClassNameIs determines whether an object instance has a class name that matches a specified string.
  140.          *
  141.          * <code>
  142.          * <?php
  143.          *         //Class definition
  144.          *         class Unit467 extends Page
  145.          *         {
  146.          *                function Unit467BeforeShow($sender, $params)
  147.          *                {
  148.          *                  if ($this->classNameIs("Unit467")) echo "This is the right form!";
  149.          *                }
  150.          *
  151.          *         }
  152.          * ?>
  153.          * </code>
  154.          *
  155.          * @param string $name Name to compare
  156.          * @return boolean True if classname of this object is $name
  157.          */
  158.         function classNameIs($name)
  159.         {
  160.                 return(strtolower($this->ClassName())==strtolower($name));
  161.         }
  162.  
  163.  
  164.         /**
  165.          * Check if a method exists declared on this object instance.
  166.          *
  167.          * <code>
  168.          * <?php
  169.          *         //Class definition
  170.          *         class Unit467 extends Page
  171.          *         {
  172.          *                function Unit467BeforeShow($sender, $params)
  173.          *                {
  174.          *                  if ($this->methodExists("Unit467BeforeShow")) echo "It exists!";
  175.          *                }
  176.          *
  177.          *         }
  178.          * ?>
  179.          * </code>
  180.          *
  181.          * @param string $method Method name to check
  182.          * @return boolean True if $method exists
  183.          */
  184.         function methodExists($method)
  185.         {
  186.                 return(method_exists($this,$method));
  187.         }
  188.  
  189.         /**
  190.          * Returns the type of the immediate ancestor of a class.
  191.          *
  192.          * ClassParent returns the name of the parent class for an object instance.
  193.          * For Object, ClassParent returns false.
  194.          * Avoid using ClassParent in application code.
  195.          *
  196.          * <code>
  197.          * <?php
  198.          *         //Class definition
  199.          *         class Unit467 extends Page
  200.          *         {
  201.          *                function Unit467BeforeShow($sender, $params)
  202.          *                {
  203.          *                   echo $this->classParent();
  204.          *                   //This will echo Page
  205.          *                }
  206.          *
  207.          *         }
  208.          * ?>
  209.          * </code>
  210.          *
  211.          * @return class Class from which this object inherits
  212.          */
  213.         function classParent()
  214.         {
  215.                 return(get_parent_class($this));
  216.         }
  217.  
  218.         /**
  219.          * Determines the relationship of two object types.
  220.          *
  221.          * Use InheritsFrom to determine if a particular class type or object is an
  222.          * instance of a class or one of its descendants. InheritsFrom returns true
  223.          * if the object type specified in the class parameter is an ancestor of the
  224.          * object type or the type of the object itself. Otherwise, it returns false.
  225.          *
  226.          * <code>
  227.          * <?php
  228.          *         //Class definition
  229.          *         class Unit467 extends Page
  230.          *         {
  231.          *                function Unit467BeforeShow($sender, $params)
  232.          *                {
  233.          *                   if ($this->inheritsFrom("Page")) echo "This is a page!";
  234.          *                }
  235.          *
  236.          *         }
  237.          * ?>
  238.          * </code>
  239.          *
  240.          * @param string $class Class name to check
  241.          * @return boolean True if this object inherits from $class
  242.          */
  243.         function inheritsFrom($class)
  244.         {
  245.                 return(is_subclass_of($this,$class)  || $this->classNameIs($class));
  246.         }
  247.  
  248.         /**
  249.          * Reads a property from the streams
  250.          * @param string $propertyname Name of the property to read
  251.          * @param string $valuename Value name to read
  252.          * @param string $stream Stream to read from
  253.          */
  254.         function readProperty($propertyname,$valuename,$stream='post')
  255.         {
  256.                 //TODO: Use also get array
  257.                 //TODO: Use the input object
  258.                 if (isset($_POST[$valuename]))
  259.                 {
  260.                         $value=$_POST[$valuename];
  261.                         $this->$propertyname=$value;
  262.                 }
  263.         }
  264.  
  265.  
  266.          /**
  267.          * To virtualize properties
  268.          *
  269.          * This PHP magic method is used on the class library to allow you
  270.          * create property (public and published) so you can write setters and
  271.          * getters and use property names in your code.
  272.          *
  273.          * @param string $nm Property name
  274.          * @return mixed 
  275.          */
  276.         function __get($nm)
  277.         {
  278.                 $method='get'.$nm;
  279.  
  280.                 //Search first for get$nm
  281.                 if (method_exists($this,$method))
  282.                 {
  283.                         return ($this->$method());
  284.                 }
  285.                 else
  286.                 {
  287.                         $method='read'.$nm;
  288.  
  289.                         //Search for read$nm
  290.                         if (method_exists($this,$method))
  291.                         {
  292.                                 return ($this->$method());
  293.                         }
  294.                         else
  295.                         {
  296.                                 //If not, search a component owned by it, with that name
  297.                                 if ($this->inheritsFrom('Component'))
  298.                                 {
  299.                                         /*
  300.                                         reset($this->components->items);
  301.                                         while (list($k,$v)=each($this->components->items))
  302.                                         {
  303.                                                 if (strtolower($v->Name)==strtolower($nm)) return($v);
  304.                                         }
  305.                                         */
  306.                                         ifisset$this->_childnames$nm ) )
  307.                                             return $this->_childnames$nm ];
  308.                                 }
  309.                                 throw new EPropertyNotFound($this->ClassName().'->'.$nm);
  310.                         }
  311.                 }
  312.         }
  313.  
  314.   /**
  315.   * To virtualize properties
  316.   *
  317.   * This PHP magic method is used on the class library to allow you
  318.   * create property (public and published) so you can write setters and
  319.   * getters and use property names in your code.
  320.   *
  321.   * @param string $nm Property name
  322.   * @param mixed $val Property value
  323.   */
  324.   function __set($nm$val)
  325.   {
  326.         $method='set'.$nm;
  327.  
  328.         if (method_exists($this,$method))
  329.         {
  330.                 $this->$method($val);
  331.         }
  332.         else
  333.         {
  334.                 $method='write'.$nm;
  335.  
  336.                 if (method_exists($this,$method))
  337.                 {
  338.                         $this->$method($val);
  339.                 }
  340.                 else
  341.                 {
  342.                         throw new EPropertyNotFound($this->ClassName().'->'.$nm);
  343.                 }
  344.         }
  345.   }
  346.  
  347.  
  348. }
  349.  
  350.  
  351. define('sGET',0);
  352. define('sPOST',1);
  353. define('sREQUEST',2);
  354. define('sCOOKIES',3);
  355. define('sSERVER',4);
  356.  
  357. global $filter_func;
  358.  
  359. /**
  360. * Native Input Filter, not working yet
  361. */
  362. {
  363.         /**
  364.         * Process user input to be clean
  365.         * @param string $input Input to be cleaned
  366.         * @return string 
  367.         */
  368.         function process($input)
  369.         {
  370.                 //TODO: Our own input filtering class in native PHP code
  371.                 //NOTE: Comment this line to don't raise the exception an get the unfiltered input
  372.                 throw new Exception("The Input Filter PHP extension is not setup on this PHP installation, so the contents returned by Input is *not* filtered");
  373.                 return($input);
  374.         }
  375. }
  376.  
  377. /**
  378. * Represents an input parameter from the user, it doesn't inherit from Object to
  379. * be faster and smaller.
  380. *
  381. * Objects of this type are returned from the Input object and you must use any of the
  382. * available methods like asString() to get the value filtered properly.
  383. */
  384. class InputParam
  385. {
  386.         public $name='';
  387.         public $stream;
  388.         public $filter_extension=false;
  389.         public $filter=null;
  390.  
  391.         /**
  392.         * Create the object
  393.         * @param $name   Key of the stream to look form
  394.         * @param $stream Stream to look for
  395.         */
  396.         function __construct($name$stream=SGET)
  397.         {
  398.                 global $filter_func;
  399.  
  400.                 $this->filter_extension=($filter_func!='');
  401.  
  402.                 //If not, creates the native filter
  403.                 if (!$this->filter_extension)
  404.                 {
  405.                         //TODO: Use a global native filter to reduce overhead
  406.                         $this->createNativeFilter();
  407.                 }
  408.  
  409.                 $this->name=$name;
  410.  
  411.                 //Set the stream to look for
  412.                 switch($stream)
  413.                 {
  414.                         case sGET$this->stream=&$_GETbreak;
  415.                         case sPOST$this->stream=&$_POSTbreak;
  416.                         case sREQUEST$this->stream=&$_REQUESTbreak;
  417.                         case sCOOKIES$this->stream=&$_COOKIESbreak;
  418.                         case sSERVER$this->stream=&$_SERVERbreak;
  419.                 }
  420.  
  421.         }
  422.  
  423.         /**
  424.         * Creates the native Input Filter to be used when there is no available extension
  425.         */
  426.         function createNativeFilter()
  427.         {
  428.                 $this->filter = new InputFilter();
  429.         }
  430.  
  431.         //TODO: Add filtering without the filtering extension installed
  432.  
  433.         /**
  434.         * Returns the input filtered as a string
  435.         *
  436.         * Use this property to get the value from the input as a string value.
  437.         * The input is sanitized to strip out dangerous content.
  438.         *
  439.         * @return string 
  440.         */
  441.         function asString()
  442.         {
  443.                 global $filter_func;
  444.  
  445.                 //Filter this out
  446.                 if ($this->filter_extension)
  447.                 {
  448.                         return $filter_func($this->stream[$this->name],FILTER_SANITIZE_STRING);
  449.                 }
  450.                 else
  451.                 {
  452.                         return $this->filter->process($this->stream[$this->name]);
  453.                 }
  454.         }
  455.  
  456.         /**
  457.         * Returns the input filtered as a string array
  458.         *
  459.         * Use this property to get the value from the input as a string array.
  460.         * The input is sanitized to strip out dangerous content.
  461.         *
  462.         * @return array 
  463.         */
  464.         function asStringArray()
  465.         {
  466.                 global $filter_func;
  467.                 //Filter this out
  468.                 if ($this->filter_extension)
  469.                 {
  470.                         $data=$this->stream[$this->name];
  471.                         reset($data);
  472.                         $result=array();
  473.                         while (list($k,$v)=each($data))
  474.                         {
  475.                                 $result[$filter_func($k,FILTER_SANITIZE_STRING)]=$filter_func($v,FILTER_SANITIZE_STRING);
  476.                         }
  477.                         return($result);
  478.                 }
  479.                 else
  480.                 {
  481.                         //TODO: Filter using a native library
  482.                         return $this->filter->process($this->stream[$this->name]);
  483.                 }
  484.         }
  485.  
  486.         /**
  487.         * Returns the input filtered as a integer
  488.         * @return integer 
  489.         */
  490.         function asInteger()
  491.         {
  492.                 global $filter_func;
  493.  
  494.                 if ($this->filter_extension)
  495.                 {
  496.                         return($filter_func($this->stream[$this->name],FILTER_SANITIZE_NUMBER_INT));
  497.                 }
  498.                 else
  499.                 {
  500.                         return $this->filter->process($this->stream[$this->name]);
  501.                 }
  502.         }
  503.  
  504.         /**
  505.         * Returns the input filtered as a boolean
  506.         *
  507.         * Use this property to get the value from the input as a boolean value.
  508.         * The input is validated and if it's not a boolean, an empty string is
  509.         * returned.
  510.         *
  511.         * @return boolean 
  512.         */
  513.         function asBoolean()
  514.         {
  515.                 global $filter_func;
  516.  
  517.                 if ($this->filter_extension)
  518.                 {
  519.                         if ($filter_func($this->stream[$this->name],FILTER_VALIDATE_BOOLEAN)) return($this->stream[$this->name]);
  520.                         else return('');
  521.                 }
  522.                 else
  523.                 {
  524.                         return $this->filter->process($this->stream[$this->name]);
  525.                 }
  526.         }
  527.  
  528.         /**
  529.         * Returns the input filtered as a float
  530.         *
  531.         * Use this property to get the value from the input as a float value.
  532.         * The input is sanitized to remove anything that might not be part of
  533.         * a float number.
  534.         *
  535.         * @param integer $flags Flags to be sent when getting the value asfloat
  536.         * @return float 
  537.         */
  538.         function asFloat($flags=0)
  539.         {
  540.                 global $filter_func;
  541.  
  542.                 if ($this->filter_extension)
  543.                 {
  544.                         return($filter_func($this->stream[$this->name],FILTER_SANITIZE_NUMBER_FLOAT$flags));
  545.                 }
  546.                 else
  547.                 {
  548.                         return $this->filter->process($this->stream[$this->name]);
  549.                 }
  550.         }
  551.  
  552.         /**
  553.         * Returns the input filtered as a regular expression
  554.         *
  555.         * Use this property to get the value from the input as a float value.
  556.         * The input is validated and if it's not a regular expression, an empty
  557.         * string is returned.
  558.         *
  559.         * @return string 
  560.         */
  561.         function asRegExp()
  562.         {
  563.                 global $filter_func;
  564.                 //Filter this out
  565.                 if ($this->filter_extension)
  566.                 {
  567.                         if ($filter_func($this->stream[$this->name],FILTER_VALIDATE_REGEXP)) return($this->stream[$this->name]);
  568.                         else return('');
  569.                 }
  570.                 else
  571.                 {
  572.                         return $this->filter->process($this->stream[$this->name]);
  573.                 }
  574.         }
  575.  
  576.         /**
  577.         * Returns the input filtered as an URL
  578.         *
  579.         * Use this property to get the value from the input as an URL.
  580.         * The input is sanitized to remove anything that might not be part of
  581.         * a URL.
  582.         *
  583.         * @return string 
  584.         */
  585.         function asURL()
  586.         {
  587.                 global $filter_func;
  588.                 //Filter this out
  589.                 if ($this->filter_extension)
  590.                 {
  591.                         return($filter_func($this->stream[$this->name],FILTER_SANITIZE_URL));
  592.                 }
  593.                 else
  594.                 {
  595.                         return $this->filter->process($this->stream[$this->name]);
  596.                 }
  597.         }
  598.  
  599.         /**
  600.         * Returns the input filtered as an email address
  601.         *
  602.         * Use this property to get the value from the input as an email.
  603.         * The input is sanitized to remove anything that might not be part of
  604.         * an email.
  605.         *
  606.         * @return string 
  607.         */
  608.         function asEmail()
  609.         {
  610.                 global $filter_func;
  611.                 //Filter this out
  612.                 if ($this->filter_extension)
  613.                 {
  614.                         return($filter_func($this->stream[$this->name],FILTER_SANITIZE_EMAIL));
  615.                 }
  616.                 else
  617.                 {
  618.                         return $this->filter->process($this->stream[$this->name]);
  619.                 }
  620.         }
  621.  
  622.         /**
  623.         * Returns the input filtered as an IP address
  624.         *
  625.         * Use this property to get the value from the input as an IP number.
  626.         * The input is validated to see if it's a valid IP and if not, an empty
  627.         * string is returned.
  628.         *
  629.         * @return string 
  630.         */
  631.         function asIP()
  632.         {
  633.                 global $filter_func;
  634.                 //Filter this out
  635.                 if ($this->filter_extension)
  636.                 {
  637.                         if ($filter_func($this->stream[$this->name],FILTER_VALIDATE_IP)) return($this->stream[$this->name]);
  638.                         else return('');
  639.                 }
  640.                 else
  641.                 {
  642.                         return $this->filter->process($this->stream[$this->name]);
  643.                 }
  644.         }
  645.  
  646.         /**
  647.         * Returns the input filtered as an string
  648.         *
  649.         * Use this property to get the value from the input as string.
  650.         * The input is sanitized to remove anything that may cause a security
  651.         * issue.
  652.         *
  653.         * @return string 
  654.         */
  655.         function asStripped()
  656.         {
  657.                 global $filter_func;
  658.                 //Filter this out
  659.                 if ($this->filter_extension)
  660.                 {
  661.                         return($filter_func($this->stream[$this->name],FILTER_SANITIZE_STRIPPED));
  662.                 }
  663.                 else
  664.                 {
  665.                         return $this->filter->process($this->stream[$this->name]);
  666.                 }
  667.         }
  668.  
  669.         /**
  670.         * URL-encode string, optionally strip or encode special characters.
  671.         *
  672.         * Use this property to get the value from the input as an encoded URL.
  673.         * The input is sanitized to remove anything that might not be part of
  674.         * an encoded url.
  675.         *
  676.         * @return string 
  677.         */
  678.         function asEncoded()
  679.         {
  680.                 global $filter_func;
  681.                 //Filter this out
  682.                 if ($this->filter_extension)
  683.                 {
  684.                         return($filter_func($this->stream[$this->name],FILTER_SANITIZE_ENCODED));
  685.                 }
  686.                 else
  687.                 {
  688.                         return $this->filter->process($this->stream[$this->name]);
  689.                 }
  690.         }
  691.  
  692.         /**
  693.         * HTML-escape '"<>& and characters with ASCII value less than 32, optionally
  694.         * strip or encode other special characters.
  695.         *
  696.         * @return string 
  697.         */
  698.         function asSpecialChars()
  699.         {
  700.                 global $filter_func;
  701.                 //Filter this out
  702.                 if ($this->filter_extension)
  703.                 {
  704.                         return($filter_func($this->stream[$this->name],FILTER_SANITIZE_SPECIAL_CHARS));
  705.                 }
  706.                 else
  707.                 {
  708.                         return $this->filter->process($this->stream[$this->name]);
  709.                 }
  710.         }
  711.  
  712.         /**
  713.         * Do nothing with the input
  714.         *
  715.         * Use it to get the input as-is, use it when you know, for sure, the
  716.         * input is safe.
  717.         *
  718.         * @return string 
  719.         */
  720.         function asUnsafeRaw()
  721.         {
  722.                 global $filter_func;
  723.                 //Filter this out
  724.                 if ($this->filter_extension)
  725.                 {
  726.                         return($filter_func($this->stream[$this->name],FILTER_UNSAFE_RAW));
  727.                 }
  728.                 else
  729.                 {
  730.                         return $this->filter->process($this->stream[$this->name]);
  731.                 }
  732.         }
  733. }
  734.  
  735. /**
  736. * This class represents an input param with no filtering at all.
  737. *
  738. * This kind of params are created when input filtering is disabled.
  739. *
  740. */
  741. class RawInputParam extends InputParam
  742. {
  743.         function asString()
  744.         {
  745.                 return $this->stream[$this->name];
  746.         }
  747.  
  748.         function asStringArray()
  749.         {
  750.                 return $this->stream[$this->name];
  751.         }
  752.  
  753.         function asInteger()
  754.         {
  755.                 return $this->stream[$this->name];
  756.         }
  757.  
  758.         function asBoolean()
  759.         {
  760.                 return $this->stream[$this->name];
  761.         }
  762.  
  763.         function asFloat($flags=0)
  764.         {
  765.                 return $this->stream[$this->name];
  766.         }
  767.  
  768.         function asRegExp()
  769.         {
  770.                 return $this->stream[$this->name];
  771.         }
  772.  
  773.         function asURL()
  774.         {
  775.                 return $this->stream[$this->name];
  776.         }
  777.  
  778.         function asEmail()
  779.         {
  780.                 return $this->stream[$this->name];
  781.         }
  782.  
  783.         function asIP()
  784.         {
  785.                 return $this->stream[$this->name];
  786.         }
  787.  
  788.         function asStripped()
  789.         {
  790.                 return $this->stream[$this->name];
  791.         }
  792.  
  793.         function asEncoded()
  794.         {
  795.                 return $this->stream[$this->name];
  796.         }
  797.  
  798.         function asSpecialChars()
  799.         {
  800.                 return $this->stream[$this->name];
  801.         }
  802.         function asUnsafeRaw()
  803.         {
  804.                 return $this->stream[$this->name];
  805.         }
  806. }
  807.  
  808. /**
  809.  * Input class, offers an easy way to get filtered input from the user.
  810.  *
  811.  * This is a sample on how to use it
  812.  * <code>
  813.  * <?php
  814.  * global $input;
  815.  * $action=$input->action;
  816.  * if (is_object($action))
  817.  * {
  818.  *     $toperform=$action->asString();
  819.  * }
  820.  * ?>
  821.  * </code>
  822.  */
  823. class Input
  824. {
  825.         public $disable=false;
  826.  
  827.         /**
  828.          * Magic method to search for the input from the user,
  829.          * checkout the order in which the variable is searched for:
  830.          * $_GET, $_POST, $_REQUEST, $_COOKIES, $_SERVER
  831.          *
  832.          * @return InputParam object or null if it's not found
  833.          *
  834.          */
  835.         function __get($nm)
  836.         {
  837.                 if (!$this->disable)
  838.                 {
  839.                         if (isset($_GET[$nm]))
  840.                         {
  841.                                 return(new InputParam($nmsGET));
  842.                         }
  843.                         else
  844.                         if (isset($_POST[$nm]))
  845.                         {
  846.                                 return(new InputParam($nmsPOST));
  847.                         }
  848.                         else
  849.                         if (isset($_REQUEST[$nm]))
  850.                         {
  851.                                 return(new InputParam($nmsREQUEST));
  852.                         }
  853.                         else
  854.                         if (isset($_COOKIES[$nm]))
  855.                         {
  856.                                 return(new InputParam($nmsCOOKIES));
  857.                         }
  858.                         else
  859.                         if (isset($_SERVER[$nm]))
  860.                         {
  861.                                 return(new InputParam($nmsSERVER));
  862.                         }
  863.                         else
  864.                         {
  865.                                 return(null);
  866.                         }
  867.                 }
  868.                 else
  869.                 {
  870.                         if (isset($_GET[$nm]))
  871.                         {
  872.                                 return(new RawInputParam($nmsGET));
  873.                         }
  874.                         else
  875.                         if (isset($_POST[$nm]))
  876.                         {
  877.                                 return(new RawInputParam($nmsPOST));
  878.                         }
  879.                         else
  880.                         if (isset($_REQUEST[$nm]))
  881.                         {
  882.                                 return(new RawInputParam($nmsREQUEST));
  883.                         }
  884.                         else
  885.                         if (isset($_COOKIES[$nm]))
  886.                         {
  887.                                 return(new RawInputParam($nmsCOOKIES));
  888.                         }
  889.                         else
  890.                         if (isset($_SERVER[$nm]))
  891.                         {
  892.                                 return(new RawInputParam($nmsSERVER));
  893.                         }
  894.                         else
  895.                         {
  896.                                 return(null);
  897.                         }
  898.                 }
  899.           }
  900.  
  901.           function __construct()
  902.           {
  903.                 global $filter_func;
  904.  
  905.                 //Checkout if filter extension has been installer or not
  906.                 //Starting with PHP 5.2.1, filter_data is filter_var
  907.                 if (function_exists('filter_var')) $filter_func='filter_var';
  908.                 else if (function_exists('filter_data')) $filter_func='filter_data';
  909.           }
  910. }
  911.  
  912. /**
  913.  * Global $input variable, use it to get filtered/sanitized input from the user
  914.  */
  915. global $input;
  916.  
  917. $input=new Input();
  918.  
  919. ?>

Documentation generated on Fri, 26 Dec 2008 11:46:47 +0100 by phpDocumentor 1.4.0a2