web/lib/Zend/Tool/Project/Context/Filesystem/Abstract.php
changeset 64 162c1de6545a
parent 19 1c2f13fd785c
child 68 ecaf28ffe26e
equal deleted inserted replaced
63:5b37998e522e 64:162c1de6545a
       
     1 <?php
       
     2 /**
       
     3  * Zend Framework
       
     4  *
       
     5  * LICENSE
       
     6  *
       
     7  * This source file is subject to the new BSD license that is bundled
       
     8  * with this package in the file LICENSE.txt.
       
     9  * It is also available through the world-wide-web at this URL:
       
    10  * http://framework.zend.com/license/new-bsd
       
    11  * If you did not receive a copy of the license and are unable to
       
    12  * obtain it through the world-wide-web, please send an email
       
    13  * to license@zend.com so we can send you a copy immediately.
       
    14  *
       
    15  * @category   Zend
       
    16  * @package    Zend_Tool
       
    17  * @subpackage Framework
       
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    20  * @version    $Id: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    21  */
       
    22 
       
    23 /**
       
    24  * @see Zend_Tool_Project_Context_Interface
       
    25  */
       
    26 require_once 'Zend/Tool/Project/Context/Interface.php';
       
    27 
       
    28 /**
       
    29  * This class is the front most class for utilizing Zend_Tool_Project
       
    30  *
       
    31  * A profile is a hierarchical set of resources that keep track of
       
    32  * items within a specific project.
       
    33  *
       
    34  * @category   Zend
       
    35  * @package    Zend_Tool
       
    36  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    37  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    38  */
       
    39 abstract class Zend_Tool_Project_Context_Filesystem_Abstract implements Zend_Tool_Project_Context_Interface
       
    40 {
       
    41 
       
    42     /**
       
    43      * @var Zend_Tool_Project_Profile_Resource
       
    44      */
       
    45     protected $_resource = null;
       
    46 
       
    47     /**
       
    48      * @var string
       
    49      */
       
    50     protected $_baseDirectory = null;
       
    51 
       
    52     /**
       
    53      * @var string
       
    54      */
       
    55     protected $_filesystemName = null;
       
    56 
       
    57     /**
       
    58      * init()
       
    59      *
       
    60      * @return Zend_Tool_Project_Context_Filesystem_Abstract
       
    61      */
       
    62     public function init()
       
    63     {
       
    64         $parentBaseDirectory = $this->_resource->getParentResource()->getContext()->getPath();
       
    65         $this->_baseDirectory = $parentBaseDirectory;
       
    66         return $this;
       
    67     }
       
    68 
       
    69     /**
       
    70      * setResource()
       
    71      *
       
    72      * @param Zend_Tool_Project_Profile_Resource $resource
       
    73      * @return Zend_Tool_Project_Context_Filesystem_Abstract
       
    74      */
       
    75     public function setResource(Zend_Tool_Project_Profile_Resource $resource)
       
    76     {
       
    77         $this->_resource = $resource;
       
    78         return $this;
       
    79     }
       
    80 
       
    81     /**
       
    82      * setBaseDirectory()
       
    83      *
       
    84      * @param string $baseDirectory
       
    85      * @return Zend_Tool_Project_Context_Filesystem_Abstract
       
    86      */
       
    87     public function setBaseDirectory($baseDirectory)
       
    88     {
       
    89         $this->_baseDirectory = rtrim(str_replace('\\', '/', $baseDirectory), '/');
       
    90         return $this;
       
    91     }
       
    92 
       
    93     /**
       
    94      * getBaseDirectory()
       
    95      *
       
    96      * @return string
       
    97      */
       
    98     public function getBaseDirectory()
       
    99     {
       
   100         return $this->_baseDirectory;
       
   101     }
       
   102 
       
   103     /**
       
   104      * setFilesystemName()
       
   105      *
       
   106      * @param string $filesystemName
       
   107      * @return Zend_Tool_Project_Context_Filesystem_Abstract
       
   108      */
       
   109     public function setFilesystemName($filesystemName)
       
   110     {
       
   111         $this->_filesystemName = $filesystemName;
       
   112         return $this;
       
   113     }
       
   114 
       
   115     /**
       
   116      * getFilesystemName()
       
   117      *
       
   118      * @return string
       
   119      */
       
   120     public function getFilesystemName()
       
   121     {
       
   122         return $this->_filesystemName;
       
   123     }
       
   124 
       
   125     /**
       
   126      * getPath()
       
   127      *
       
   128      * @return string
       
   129      */
       
   130     public function getPath()
       
   131     {
       
   132         $path = $this->_baseDirectory;
       
   133         if ($this->_filesystemName) {
       
   134             $path .= '/' . $this->_filesystemName;
       
   135         }
       
   136         return $path;
       
   137     }
       
   138 
       
   139     /**
       
   140      * exists()
       
   141      *
       
   142      * @return bool
       
   143      */
       
   144     public function exists()
       
   145     {
       
   146         return file_exists($this->getPath());
       
   147     }
       
   148 
       
   149     /**
       
   150      * create()
       
   151      *
       
   152      * Create this resource/context
       
   153      *
       
   154      */
       
   155     abstract public function create();
       
   156 
       
   157     /**
       
   158      * delete()
       
   159      *
       
   160      * Delete this resouce/context
       
   161      *
       
   162      */
       
   163     abstract public function delete();
       
   164 
       
   165 }