PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

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

http://github.com/matamouros/cintient
PHP | 121 lines | 76 code | 7 blank | 38 comment | 10 complexity | 86d83b7780a8a70f6b6a1c297e572105 MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. /*
  3. *
  4. * Cintient, Continuous Integration made simple.
  5. * Copyright (c) 2010-2012, Pedro Mata-Mouros <pedro.matamouros@gmail.com>
  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$
  33. * @link $HeadURL$
  34. * Changed by $LastChangedBy$
  35. * Changed on $LastChangedDate$
  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->isActive()) {
  55. return true;
  56. }
  57. if (!$this->getDir()) {
  58. SystemEvent::raise(SystemEvent::ERROR, 'Dir not set for mkdir task.', __METHOD__);
  59. return false;
  60. }
  61. $xml = new XmlDoc();
  62. $xml->startElement('mkdir');
  63. $xml->writeAttribute('dir', $this->getDir());
  64. $xml->endElement();
  65. return $xml->flush();
  66. }
  67. public function toHtml(Array $_ = array(), Array $__ = array())
  68. {
  69. if (!$this->isVisible()) {
  70. return true;
  71. }
  72. $callbacks = array(
  73. array(
  74. 'cb' => 'getHtmlInputText',
  75. 'name' => 'dir',
  76. 'value' => $this->getDir()
  77. ),
  78. );
  79. parent::toHtml(array('title' => 'Mkdir'), $callbacks);
  80. }
  81. public function toPhing()
  82. {
  83. return $this->toAnt();
  84. }
  85. public function toPhp(Array &$context = array())
  86. {
  87. if (!$this->isActive()) {
  88. return '';
  89. }
  90. $php = '';
  91. if (!$this->getDir()) {
  92. SystemEvent::raise(SystemEvent::ERROR, 'Dir not set for mkdir task.', __METHOD__);
  93. return false;
  94. }
  95. $php .= "
  96. \$GLOBALS['result']['task'] = 'mkdir';
  97. \$getDir = expandStr('{$this->getDir()}');
  98. if (!file_exists(\$getDir)) {
  99. if (mkdir(\$getDir, " . DEFAULT_DIR_MASK . ", true) === false && {$this->getFailOnError()}) {
  100. \$GLOBALS['result']['ok'] = false;
  101. output('Could not create ' . \$getDir . '.');
  102. return false;
  103. } else {
  104. \$GLOBALS['result']['ok'] = \$GLOBALS['result']['ok'] & true;
  105. output('Created ' . \$getDir . '.');
  106. }
  107. } else {
  108. \$GLOBALS['result']['ok'] = \$GLOBALS['result']['ok'] & true;
  109. output(\$getDir . ' already exists.');
  110. }
  111. ";
  112. return $php;
  113. }
  114. }