/** * TODO: Look at replacing the raw string functions with the Drupal equivalent * functions. Will need to test this carefully... * * Move this parser to a proper service. */ public static function parse($name_components, $format = '', $settings = array(), $tokens = NULL) { foreach (array('sep1', 'sep2', 'sep3') as $key) { if (!isset($settings[$key])) { $config = \Drupal::config('name.settings')->get(); $settings[$key] = $config[$key]; } } $parser = new self(); return $parser->format($name_components, $format, $settings, $tokens); }
public function format($source) { $this->tkns = token_get_all($source); $this->code = ''; // It skips parentheses and bracket blocks, and aligns '=' // everywhere else. $parenCount = 0; $bracketCount = 0; $contextCounter = 0; while (list($index, $token) = each($this->tkns)) { list($id, $text) = $this->getToken($token); $this->ptr = $index; switch ($id) { case T_FUNCTION: ++$contextCounter; $this->appendCode($text); break; case ST_CURLY_OPEN: $this->appendCode($text); $block = $this->walkAndAccumulateCurlyBlock($this->tkns); $aligner = new self(); $this->appendCode(str_replace(self::OPEN_TAG, '', $aligner->format(self::OPEN_TAG . $block))); break; case ST_PARENTHESES_OPEN: ++$parenCount; $this->appendCode($text); break; case ST_PARENTHESES_CLOSE: --$parenCount; $this->appendCode($text); break; case ST_BRACKET_OPEN: ++$bracketCount; $this->appendCode($text); break; case ST_BRACKET_CLOSE: --$bracketCount; $this->appendCode($text); break; case ST_EQUAL: if (!$parenCount && !$bracketCount) { $this->appendCode(sprintf(self::ALIGNABLE_EQUAL, $contextCounter) . $text); break; } default: $this->appendCode($text); break; } } $this->alignPlaceholders(self::ALIGNABLE_EQUAL, $contextCounter); return $this->code; }
public static function now($format = '') { $now = new self(); return $now->format(empty($format) ? 'Y-m-d H:i:s' : $format); }
public static function formatFromTimestamp($timestamp, $formatString = null) { $d = new self($timestamp); return $d->format($formatString); }
public static function encode(\stdClass $data) { $xmlObj = new self(); return $xmlObj->format($data); }
public static function formatPercise($timestamp) { $ts = new self(); $ts->setTimestamp($timestamp); return $ts->format("F j, Y, g:i a"); }