File.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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-2009 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_Filesystem_Abstract
  24. */
  25. require_once 'Zend/Tool/Project/Context/Filesystem/Abstract.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-2009 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_File extends Zend_Tool_Project_Context_Filesystem_Abstract
  38. {
  39. /**
  40. * init()
  41. *
  42. * @return Zend_Tool_Project_Context_Filesystem_File
  43. */
  44. public function init()
  45. {
  46. // @todo check to ensure that this 'file' resource has no children
  47. parent::init();
  48. return $this;
  49. }
  50. /**
  51. * setResource()
  52. *
  53. * @param unknown_type $resource
  54. */
  55. public function setResource(Zend_Tool_Project_Profile_Resource $resource)
  56. {
  57. $this->_resource = $resource;
  58. $this->_resource->setAppendable(false);
  59. return $this;
  60. }
  61. /**
  62. * create()
  63. *
  64. * @return Zend_Tool_Project_Context_Filesystem_File
  65. */
  66. public function create()
  67. {
  68. // check to ensure the parent exists, if not, call it and create it
  69. if (($parentResource = $this->_resource->getParentResource()) instanceof Zend_Tool_Project_Profile_Resource) {
  70. if ((($parentContext = $parentResource->getContext()) instanceof Zend_Tool_Project_Context_Filesystem_Abstract)
  71. && (!$parentContext->exists())) {
  72. $parentResource->create();
  73. }
  74. }
  75. if (file_exists($this->getPath())) {
  76. // @todo propt user to determine if its ok to overwrite file
  77. }
  78. file_put_contents($this->getPath(), $this->getContents());
  79. return $this;
  80. }
  81. /**
  82. * delete()
  83. *
  84. * @return Zend_Tool_Project_Context_Filesystem_File
  85. */
  86. public function delete()
  87. {
  88. unlink($this->getPath());
  89. $this->_resource->setDeleted(true);
  90. return $this;
  91. }
  92. /**
  93. * getContents()
  94. *
  95. * @return null
  96. */
  97. public function getContents()
  98. {
  99. return null;
  100. }
  101. }