Ejemplo n.º 1
0
 /**
  * Yaml parser
  *
  * __DIR__ support: (only available for Yaml files, of course!)
  * - '__DIR__' will behave as expected
  * - '___DIR___' (an extra underscore around) will be translated as a literal '__DIR__'
  *
  * @param  mixed $yaml
  * @return self
  */
 public static function parse($yaml)
 {
     ArgValidator::assert($yaml, 'string');
     if (is_file($yaml) && is_readable($yaml)) {
         $dir = realpath(dirname($yaml));
         $yaml = file_get_contents($yaml);
         $yaml = strtr($yaml, array('___DIR___' => '__DIR__', '__DIR__' => $dir));
     }
     return SymfonyYaml::parse($yaml);
 }
Ejemplo n.º 2
0
 /**
  * register a cron job
  *
  * @see Cron::trySchedule() for allowed cron expression syntax
  *
  * @param  string   $code      the cron job code / identifier
  * @param  string   $frequency cron expression
  * @param  callable $callback  the actual cron job
  * @param  array    $args      args to the cron job
  * @return self
  */
 public static function register($code, $frequency, $callback, array $args = array())
 {
     ArgValidator::assert($code, array('string', 'min' => 1));
     ArgValidator::assert($callback, 'callable');
     /*
      * validation of $frequency (cron expression):
      * will be done together when scheduling
      * (errors thrown if invalid cron expression)
      */
     $instance = self::getInstance();
     $cronRegistry = $instance->getCronRegistry();
     $cronRegistry[$code] = array('frequency' => $frequency, 'callback' => $callback, 'args' => $args);
     $instance->setCronRegistry($cronRegistry);
     return $instance;
 }
Ejemplo n.º 3
0
 public static function validateDateTime($year = null, $month = null, $day = null, $hour = null, $minute = null, $second = null)
 {
     foreach (array('year', 'month', 'day', 'hour', 'minute', 'second') as $var) {
         ArgValidator::assert(${$var}, array('string', 'int', 'null'));
     }
     $daysMap = array(1 => 31, 2 => 29, 3 => 31, 4 => 30, 5 => 31, 6 => 30, 7 => 31, 8 => 31, 9 => 30, 10 => 31, 11 => 30, 12 => 31);
     if (!is_null($year) && !is_null($month) && !is_null($day) && !checkdate($month, $day, $year) || !is_null($year) && !is_null($month) && ($month < 1 || $month > 12) || !is_null($month) && !is_null($day) && ($month < 1 || $month > 12 || $day > $daysMap[(int) $month]) || !is_null($day) && ($day < 1 || $day > 31)) {
         throw new Exception\InvalidArgumentException(sprintf('invalid date: %s-%s-%s given', $year, $month, $day));
     }
     if (!is_null($hour) && ($hour < 0 || $hour > 23) || !is_null($minute) && ($minute < 0 || $minute > 59) || !is_null($second) && ($second < 0 || $second > 59)) {
         throw new Exception\InvalidArgumentException(sprintf('invalid time: %s:%s:%s given', $hour, $minute, $second));
     }
     return true;
 }
Ejemplo n.º 4
0
 /**
  * normalize vcard source string after parsing
  *
  * @param  string $vcardStr vcard source string
  * @return string
  */
 public function normalizeSource($vcardStr)
 {
     ArgValidator::assert($vcardStr, 'string');
     /* convert chars outside ASCII range to <U+xxxx> expression */
     if (preg_match_all('/[^\\x{0000}-\\x{007F}]/u', $vcardStr, $matches)) {
         $conversion = array();
         foreach (array_unique($matches[0]) as $char) {
             $conversion[$char] = '<U+' . strtoupper(dechex(Utf8::uord($char))) . '>';
         }
         $vcardStr = strtr($vcardStr, $conversion);
     }
     /* workaround to enable comma-separated values */
     $vcardStr = strtr($vcardStr, array(self::JOINCHAR => ','));
     return $vcardStr;
 }
Ejemplo n.º 5
0
 /**
  * parse vcard source into intermediate object
  *
  * @param  string    $vcardStr vcard source string
  * @return Node|null
  */
 public function parseSource($vcardStr)
 {
     ArgValidator::assert($vcardStr, 'string');
     try {
         $card = $this->getReader()->read($vcardStr);
     } catch (ParseException $e) {
         return null;
     }
     return $card;
 }