PageRenderTime 39ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/src/core/Build/BuilderElement/Task/Filesystem/Mkdir.php

http://cintient.googlecode.com/
PHP | 119 lines | 73 code | 7 blank | 39 comment | 8 complexity | f461a578d65587c19a95b618a5d7a86b MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. /*
  3. *
  4. * Cintient, Continuous Integration made simple.
  5. * Copyright (c) 2010, 2011, Pedro Mata-Mouros Fonseca
  6. *
  7. * This file is part of Cintient.
  8. *
  9. * Cintient is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * Cintient is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with Cintient. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. /**
  24. * Mkdir task is responsible for creating and properly setting up new
  25. * directories.
  26. *
  27. * @package Build
  28. * @subpackage Task
  29. * @author Pedro Mata-Mouros Fonseca <pedro.matamouros@gmail.com>
  30. * @copyright 2010-2011, Pedro Mata-Mouros Fonseca.
  31. * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPLv3 or later.
  32. * @version $LastChangedRevision: 356 $
  33. * @link $HeadURL: http://cintient.googlecode.com/svn/trunk/src/core/Build/BuilderElement/Task/Filesystem/Mkdir.php $
  34. * Changed by $LastChangedBy: pedro.matamouros $
  35. * Changed on $LastChangedDate: 2011-09-13 17:31:05 +0200 (Tue, 13 Sep 2011) $
  36. */
  37. class Build_BuilderElement_Task_Filesystem_Mkdir extends Build_BuilderElement
  38. {
  39. protected $_dir;
  40. public function __construct()
  41. {
  42. parent::__construct();
  43. $this->_dir = null;
  44. }
  45. /**
  46. * Creates a new instance of this builder element, with default values.
  47. */
  48. static public function create()
  49. {
  50. return new self();
  51. }
  52. public function toAnt()
  53. {
  54. if (!$this->getDir()) {
  55. SystemEvent::raise(SystemEvent::ERROR, 'Dir not set for mkdir task.', __METHOD__);
  56. return false;
  57. }
  58. $xml = new XmlDoc();
  59. $xml->startElement('mkdir');
  60. $xml->writeAttribute('dir', $this->getDir());
  61. $xml->endElement();
  62. return $xml->flush();
  63. }
  64. public function toHtml()
  65. {
  66. parent::toHtml();
  67. if (!$this->isVisible()) {
  68. return true;
  69. }
  70. $o = $this;
  71. h::li(array('class' => 'builderElement', 'id' => $o->getInternalId()), function() use ($o) {
  72. $o->getHtmlTitle(array('title' => 'Mkdir'));
  73. h::div(array('class' => 'builderElementForm'), function() use ($o) {
  74. // Dir, textfield
  75. h::div(array('class' => 'label'), 'Dir');
  76. h::div(array('class' => 'textfieldContainer'), function() use ($o) {
  77. h::input(array('class' => 'textfield', 'type' => 'text', 'name' => 'dir', 'value' => $o->getDir()));
  78. });
  79. });
  80. });
  81. }
  82. public function toPhing()
  83. {
  84. return $this->toAnt();
  85. }
  86. public function toPhp(Array &$context = array())
  87. {
  88. $php = '';
  89. if (!$this->getDir()) {
  90. SystemEvent::raise(SystemEvent::ERROR, 'Dir not set for mkdir task.', __METHOD__);
  91. return false;
  92. }
  93. $php .= "
  94. \$GLOBALS['result']['task'] = 'mkdir';
  95. \$getDir = expandStr('{$this->getDir()}');
  96. if (!file_exists(\$getDir)) {
  97. if (mkdir(\$getDir, " . DEFAULT_DIR_MASK . ", true) === false && {$this->getFailOnError()}) {
  98. \$GLOBALS['result']['ok'] = false;
  99. output('Could not create ' . \$getDir . '.');
  100. return false;
  101. } else {
  102. \$GLOBALS['result']['ok'] = \$GLOBALS['result']['ok'] & true;
  103. output('Created ' . \$getDir . '.');
  104. }
  105. } else {
  106. \$GLOBALS['result']['ok'] = \$GLOBALS['result']['ok'] & true;
  107. output(\$getDir . ' already exists.');
  108. }
  109. ";
  110. return $php;
  111. }
  112. }