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

/lib/vendor/symfony/lib/plugins/sfPropelPlugin/lib/vendor/phing/tasks/system/TstampTask.php

https://github.com/IDCI-Consulting/WebsiteEval
PHP | 168 lines | 75 code | 21 blank | 72 comment | 5 complexity | e4965396282a7e75fd36b9c24d32d06e MD5 | raw file
  1. <?php
  2. /*
  3. * $Id: TstampTask.php 325 2007-12-20 15:44:58Z hans $
  4. *
  5. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16. *
  17. * This software consists of voluntary contributions made by many individuals
  18. * and is licensed under the LGPL. For more information please see
  19. * <http://phing.info>.
  20. */
  21. require_once 'phing/Task.php';
  22. /**
  23. * Sets properties to the current time, or offsets from the current time.
  24. * The default properties are TSTAMP, DSTAMP and TODAY;
  25. *
  26. * Based on Ant's Tstamp task.
  27. *
  28. * @author Michiel Rook <michiel.rook@gmail.com>
  29. * @version $Revision: 1.6 $
  30. * @package phing.tasks.system
  31. * @since 2.2.0
  32. */
  33. class TstampTask extends Task
  34. {
  35. private $customFormats = array();
  36. private $prefix = "";
  37. /**
  38. * Set a prefix for the properties. If the prefix does not end with a "."
  39. * one is automatically added.
  40. * @param prefix the prefix to use.
  41. */
  42. public function setPrefix($prefix)
  43. {
  44. $this->prefix = $prefix;
  45. if (!empty($this->prefix))
  46. {
  47. $this->prefix.= ".";
  48. }
  49. }
  50. /**
  51. * Adds a custom format
  52. *
  53. * @param TstampCustomFormat custom format
  54. */
  55. public function addFormat(TstampCustomFormat $cf)
  56. {
  57. $this->customFormats[] = $cf;
  58. }
  59. /**
  60. * Create the timestamps. Custom ones are done before
  61. * the standard ones.
  62. *
  63. * @throws BuildException
  64. */
  65. public function main()
  66. {
  67. foreach ($this->customFormats as $cf)
  68. {
  69. $cf->execute($this);
  70. }
  71. $dstamp = strftime('%Y%m%d');
  72. $this->prefixProperty('DSTAMP', $dstamp);
  73. $tstamp = strftime('%H%M');
  74. $this->prefixProperty('TSTAMP', $tstamp);
  75. $today = strftime('%B %d %Y');
  76. $this->prefixProperty('TODAY', $today);
  77. }
  78. /**
  79. * helper that encapsulates prefix logic and property setting
  80. * policy (i.e. we use setNewProperty instead of setProperty).
  81. */
  82. public function prefixProperty($name, $value)
  83. {
  84. $this->getProject()->setNewProperty($this->prefix . $name, $value);
  85. }
  86. }
  87. class TstampCustomFormat
  88. {
  89. private $propertyName = "";
  90. private $pattern = "";
  91. private $locale = "";
  92. /**
  93. * The property to receive the date/time string in the given pattern
  94. *
  95. * @param propertyName the name of the property.
  96. */
  97. public function setProperty($propertyName)
  98. {
  99. $this->propertyName = $propertyName;
  100. }
  101. /**
  102. * The date/time pattern to be used. The values are as
  103. * defined by the PHP strftime() function.
  104. *
  105. * @param pattern
  106. */
  107. public function setPattern($pattern)
  108. {
  109. $this->pattern = $pattern;
  110. }
  111. /**
  112. * The locale used to create date/time string.
  113. *
  114. * @param locale
  115. */
  116. public function setLocale($locale)
  117. {
  118. $this->locale = $locale;
  119. }
  120. /**
  121. * validate parameter and execute the format.
  122. *
  123. * @param TstampTask reference to task
  124. */
  125. public function execute(TstampTask $tstamp)
  126. {
  127. if (empty($this->propertyName))
  128. {
  129. throw new BuildException("property attribute must be provided");
  130. }
  131. if (empty($this->pattern))
  132. {
  133. throw new BuildException("pattern attribute must be provided");
  134. }
  135. if (!empty($this->locale))
  136. {
  137. setlocale(LC_ALL, $this->locale);
  138. }
  139. $value = strftime($this->pattern);
  140. $tstamp->prefixProperty($this->propertyName, $value);
  141. if (!empty($this->locale))
  142. {
  143. // reset locale
  144. setlocale(LC_ALL, NULL);
  145. }
  146. }
  147. }