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

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