Abstract.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Tool_Project_Context_Interface
  24. */
  25. require_once 'Zend/Tool/Project/Context/Interface.php';
  26. /**
  27. * This class is the front most class for utilizing Zend_Tool_Project
  28. *
  29. * A profile is a hierarchical set of resources that keep track of
  30. * items within a specific project.
  31. *
  32. * @category Zend
  33. * @package Zend_Tool
  34. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. */
  37. abstract class Zend_Tool_Project_Context_Filesystem_Abstract implements Zend_Tool_Project_Context_Interface
  38. {
  39. /**
  40. * @var Zend_Tool_Project_Profile_Resource
  41. */
  42. protected $_resource = null;
  43. /**
  44. * @var string
  45. */
  46. protected $_baseDirectory = null;
  47. /**
  48. * @var string
  49. */
  50. protected $_filesystemName = null;
  51. /**
  52. * init()
  53. *
  54. * @return Zend_Tool_Project_Context_Filesystem_Abstract
  55. */
  56. public function init()
  57. {
  58. $parentBaseDirectory = $this->_resource->getParentResource()->getContext()->getPath();
  59. $this->_baseDirectory = $parentBaseDirectory;
  60. return $this;
  61. }
  62. /**
  63. * setResource()
  64. *
  65. * @param Zend_Tool_Project_Profile_Resource $resource
  66. * @return Zend_Tool_Project_Context_Filesystem_Abstract
  67. */
  68. public function setResource(Zend_Tool_Project_Profile_Resource $resource)
  69. {
  70. $this->_resource = $resource;
  71. return $this;
  72. }
  73. /**
  74. * setBaseDirectory()
  75. *
  76. * @param string $baseDirectory
  77. * @return Zend_Tool_Project_Context_Filesystem_Abstract
  78. */
  79. public function setBaseDirectory($baseDirectory)
  80. {
  81. $this->_baseDirectory = rtrim(str_replace('\\', '/', $baseDirectory), '/');
  82. return $this;
  83. }
  84. /**
  85. * getBaseDirectory()
  86. *
  87. * @return string
  88. */
  89. public function getBaseDirectory()
  90. {
  91. return $this->_baseDirectory;
  92. }
  93. /**
  94. * setFilesystemName()
  95. *
  96. * @param string $filesystemName
  97. * @return Zend_Tool_Project_Context_Filesystem_Abstract
  98. */
  99. public function setFilesystemName($filesystemName)
  100. {
  101. $this->_filesystemName = $filesystemName;
  102. return $this;
  103. }
  104. /**
  105. * getFilesystemName()
  106. *
  107. * @return string
  108. */
  109. public function getFilesystemName()
  110. {
  111. return $this->_filesystemName;
  112. }
  113. /**
  114. * getPath()
  115. *
  116. * @return string
  117. */
  118. public function getPath()
  119. {
  120. $path = $this->_baseDirectory;
  121. if ($this->_filesystemName) {
  122. $path .= '/' . $this->_filesystemName;
  123. }
  124. return $path;
  125. }
  126. /**
  127. * exists()
  128. *
  129. * @return bool
  130. */
  131. public function exists()
  132. {
  133. return file_exists($this->getPath());
  134. }
  135. /**
  136. * create()
  137. *
  138. * Create this resource/context
  139. *
  140. */
  141. abstract public function create();
  142. /**
  143. * delete()
  144. *
  145. * Delete this resouce/context
  146. *
  147. */
  148. abstract public function delete();
  149. }