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

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