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

Source for file Object.php

Documentation is available at Object.php

  1. <?php
  2.  
  3. require_once dirname(__FILE__'/../VFS.php';
  4.  
  5. /**
  6.  * A wrapper for the VFS class to return objects, instead of arrays.
  7.  *
  8.  * $Horde: framework/VFS/lib/VFS/Object.php,v 1.1.2.1 2007/12/20 13:50:21 jan Exp $
  9.  *
  10.  * Copyright 2002-2007 Jon Wood <jon@jellybob.co.uk>
  11.  *
  12.  * See the enclosed file COPYING for license information (LGPL). If you
  13.  * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  14.  *
  15.  * @author  Jon Wood <jon@jellybob.co.uk>
  16.  * @package VFS
  17.  */
  18. class VFS_Object {
  19.  
  20.     /**
  21.      * The actual vfs that does the work
  22.      *
  23.      * @var VFS 
  24.      */
  25.     var $_vfs;
  26.  
  27.     /**
  28.      * The current path that has been passed to listFolder, if this
  29.      * changes, the list will be rebuilt.
  30.      *
  31.      * @var string 
  32.      */
  33.     var $_currentPath;
  34.  
  35.     /**
  36.      * The return value from a standard VFS listFolder call, to
  37.      * be read with the Object listFolder.
  38.      *
  39.      * @var array 
  40.      */
  41.     var $_folderList;
  42.  
  43.     /**
  44.      * Constructor.
  45.      *
  46.      * If you pass in an existing VFS object, it will be used as the VFS
  47.      * object for this object.
  48.      *
  49.      * @param VFS &$vfs  The VFS object to wrap.
  50.      */
  51.     function VFS_Object(&$vfs)
  52.     {
  53.         if (isset($vfs)) {
  54.             $this->_vfs $vfs;
  55.         }
  56.     }
  57.  
  58.     /**
  59.      * Attempts to return a concrete VFS_Object instance based on $driver.
  60.      *
  61.      * @param mixed $driver  The type of concrete VFS subclass to return. If
  62.      *                        $driver is an array then we will look in
  63.      *                        $driver[0]/lib/VFS/ for the subclass
  64.      *                        implementation named $driver[1].php.
  65.      * @param array $params  A hash containing any additional configuration or
  66.      *                        connection parameters a subclass might need.
  67.      *
  68.      * @return VFS_Object  The newly created concrete VFS_Object instance, or
  69.      *                      false on an error.
  70.      */
  71.     function &factory($driver$params = array())
  72.     {
  73.         $vfs &VFS::factory($driver$params = array());
  74.         $vfsobject &new VFS_Object($vfs);
  75.         return $vfsobject;
  76.     }
  77.  
  78.     /**
  79.      * Attempts to return a reference to a concrete VFS instance
  80.      * based on $driver. It will only create a new instance if no
  81.      * VFS instance with the same parameters currently exists.
  82.      *
  83.      * This should be used if multiple types of file backends (and,
  84.      * thus, multiple VFS instances) are required.
  85.      *
  86.      * This method must be invoked as: $var = &VFS::singleton()
  87.      *
  88.      * @param mixed $driver  The type of concrete VFS subclass to return. If
  89.      *                        $driver is an array then we will look in
  90.      *                        $driver[0]/lib/VFS/ for the subclass
  91.      *                        implementation named $driver[1].php.
  92.      * @param array $params  A hash containing any additional configuration or
  93.      *                        connection parameters a subclass might need.
  94.      *
  95.      * @return VFS_Object  The concrete VFS_Object reference, or false on
  96.      *                      error.
  97.      */
  98.     function &singleton($driver$params = array())
  99.     {
  100.         $vfs &VFS::singleton($driver$params = array());
  101.         $vfsobject &new VFS_Object($vfs);
  102.         return $vfsobject;
  103.     }
  104.  
  105.     /**
  106.      * Check the credentials that we have to see if there is a valid login.
  107.      *
  108.      * @return mixed  True on success, PEAR_Error describing the problem
  109.      *                 if the credentials are invalid.
  110.      */
  111.     function checkCredentials()
  112.     {
  113.         return $this->_vfs->checkCredentials();
  114.     }
  115.  
  116.     /**
  117.      * Set configuration parameters.
  118.      *
  119.      * @param array $params  An associative array of parameter name/value
  120.      *                        pairs.
  121.      */
  122.     function setParams($params = array())
  123.     {
  124.         $this->_vfs->setParams($params);
  125.     }
  126.  
  127.     /**
  128.      * Retrieve a file from the VFS.
  129.      *
  130.      * @param string $path  The pathname to the file.
  131.      *
  132.      * @return string  The file data.
  133.      */
  134.     function read($path)
  135.     {
  136.         return $this->_vfs->read(dirname($path)basename($path));
  137.     }
  138.  
  139.     /**
  140.      * Store a file in the VFS.
  141.      *
  142.      * @param string $path         The path to store the file in.
  143.      * @param string $tmpFile      The temporary file containing the data to be
  144.      *                              stored.
  145.      * @param boolean $autocreate  Automatically create directories?
  146.      *
  147.      * @return mixed  True on success or a PEAR_Error object on failure.
  148.      */
  149.     function write($path$tmpFile$autocreate = false)
  150.     {
  151.         return $this->_vfs->write(dirname($path)basename($path)$tmpFile$autocreate = false);
  152.     }
  153.  
  154.     /**
  155.      * Store a file in the VFS from raw data.
  156.      *
  157.      * @param string $path         The path to store the file in.
  158.      * @param string $data         The file data.
  159.      * @param boolean $autocreate  Automatically create directories?
  160.      *
  161.      * @return mixed  True on success or a PEAR_Error object on failure.
  162.      */
  163.     function writeData($path$data$autocreate = false)
  164.     {
  165.         return $this->_vfs->writeData(dirname($path)basename($path)$data$autocreate = false);
  166.     }
  167.  
  168.     /**
  169.      * Delete a file from the VFS.
  170.      *
  171.      * @param string $path  The path to store the file in.
  172.      * @param string $name  The filename to use.
  173.      *
  174.      * @return mixed  True on success or a PEAR_Error object on failure.
  175.      */
  176.     function deleteFile($path)
  177.     {
  178.         return $this->_vfs->deleteFile(dirname($path)basename($path));
  179.     }
  180.  
  181.     /**
  182.      * Rename a file in the VFS.
  183.      *
  184.      * @param string $oldpath  The old path to the file.
  185.      * @param string $oldname  The old filename.
  186.      * @param string $newpath  The new path of the file.
  187.      * @param string $newname  The new filename.
  188.      *
  189.      * @return mixed  True on success or a PEAR_Error object on failure.
  190.      */
  191.     function rename($oldpath$newpath)
  192.     {
  193.         return $this->_vfs->rename(dirname($oldpath)basename($oldpath)dirname($newpath)basename($newpath));
  194.     }
  195.  
  196.     /**
  197.      * Create a folder in the VFS.
  198.      *
  199.      * @param string $path  The path to the folder.
  200.      *
  201.      * @return mixed  True on success or a PEAR_Error object on failure.
  202.      */
  203.     function createFolder($path)
  204.     {
  205.         return $this->_vfs->createFolder(dirname($path));
  206.     }
  207.  
  208.     /**
  209.      * Deletes a folder from the VFS.
  210.      *
  211.      * @param string $path The path of the folder to delete.
  212.      *
  213.      * @return mixed  True on success or a PEAR_Error object on failure.
  214.      */
  215.     function deleteFolder($path)
  216.     {
  217.         return $this->_vfs->deleteFolder(dirname($path));
  218.     }
  219.  
  220.     /**
  221.      * Returns a VFS_ListItem object if the folder can
  222.      * be read, or a PEAR_Error if it can't be. Returns false once
  223.      * the folder has been completely read.
  224.      *
  225.      * @param string $path  The path of the diretory.
  226.      *
  227.      * @return mixed  File list (array) on success, a PEAR_Error
  228.      *                 object on failure, or false if the folder is
  229.      *                 completely read.
  230.      */
  231.     function listFolder($path)
  232.     {
  233.         if (!($path === $this->_currentPath)) {
  234.             $folderList $this->_vfs->listFolder($path);
  235.             if ($folderList{
  236.                 $this->_folderList $folderList;
  237.                 $this->_currentPath $path;
  238.             else {
  239.                 return PEAR::raiseError(sprintf(_("Could not read %s.")$path));
  240.             }
  241.         }
  242.  
  243.         require_once dirname(__FILE__'/ListItem.php';
  244.         if ($file array_shift($this->_folderList)) {
  245.             $file &new VFS_ListItem($path$file);
  246.             return $file;
  247.         else {
  248.             return false;
  249.         }
  250.     }
  251.  
  252.     /**
  253.      * Changes permissions for an Item on the VFS.
  254.      *
  255.      * @param string $path        Holds the path of directory of the Item.
  256.      * @param string $permission  TODO
  257.      *
  258.      * @return mixed  True on success or a PEAR_Error object on failure.
  259.      */
  260.     function changePermissions($path$permission)
  261.     {
  262.         return $this->_vfs->changePermissions(dirname($path)basename($path)$permission);
  263.     }
  264.  
  265.     /**
  266.      * Return the list of additional credentials required, if any.
  267.      *
  268.      * @return array  Credential list.
  269.      */
  270.     function getRequiredCredentials()
  271.     {
  272.         return $this->_vfs->getRequiredCredentials();
  273.     }
  274.  
  275.     /**
  276.      * Return the array specificying what permissions are changeable for this
  277.      * implementation.
  278.      *
  279.      * @return array  Changeable permisions.
  280.      */
  281.     function getModifiablePermissions()
  282.     {
  283.         return $this->_vfs->getModifiablePermissions();
  284.     }
  285.  
  286. }

Documentation generated on Mon, 11 Mar 2019 15:34:55 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.