123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- <?php
-
- require_once 'phing/Task.php';
- class TstampTask extends Task
- {
- private $customFormats = array();
-
- private $prefix = "";
-
-
- public function setPrefix($prefix)
- {
- $this->prefix = $prefix;
-
- if (!empty($this->prefix))
- {
- $this->prefix.= ".";
- }
- }
-
-
- public function addFormat(TstampCustomFormat $cf)
- {
- $this->customFormats[] = $cf;
- }
-
- public function main()
- {
- foreach ($this->customFormats as $cf)
- {
- $cf->execute($this);
- }
-
- $dstamp = strftime('%Y%m%d');
- $this->prefixProperty('DSTAMP', $dstamp);
-
- $tstamp = strftime('%H%M');
- $this->prefixProperty('TSTAMP', $tstamp);
-
- $today = strftime('%B %d %Y');
- $this->prefixProperty('TODAY', $today);
- }
-
-
- public function prefixProperty($name, $value)
- {
- $this->getProject()->setNewProperty($this->prefix . $name, $value);
- }
- }
- class TstampCustomFormat
- {
- private $propertyName = "";
- private $pattern = "";
- private $locale = "";
-
-
- public function setProperty($propertyName)
- {
- $this->propertyName = $propertyName;
- }
-
- public function setPattern($pattern)
- {
- $this->pattern = $pattern;
- }
-
-
- public function setLocale($locale)
- {
- $this->locale = $locale;
- }
-
-
- public function execute(TstampTask $tstamp)
- {
- if (empty($this->propertyName))
- {
- throw new BuildException("property attribute must be provided");
- }
- if (empty($this->pattern))
- {
- throw new BuildException("pattern attribute must be provided");
- }
-
- if (!empty($this->locale))
- {
- setlocale(LC_ALL, $this->locale);
- }
-
- $value = strftime($this->pattern);
- $tstamp->prefixProperty($this->propertyName, $value);
-
- if (!empty($this->locale))
- {
-
- setlocale(LC_ALL, NULL);
- }
- }
- }
|