public static function css($href, $media = "") { if (isset(Ant::getPlugin()->asset)) { $href = Ant::getPlugin()->asset($href); } return '<link type="text/css" rel="stylesheet" href="' . $href . '"' . ($media ? ' media="' . $media . '"' : '') . '/>'; }
public static function each($view, $collection, $item = 'item', array $scope = array()) { if (Fn::iterable($collection)) { $tmpl = $tmpl = Ant::init()->fromFile($view); foreach ($collection as $single) { $scope[$item] = $single; echo $tmpl->assign($scope)->draw(); } } }
/** * Get templates chain * * @param string $view * @param string $path * * @return array */ public function resolveChain($view, $path) { $view = preg_replace_callback('/@skip.+?@endskip/ms', '\\Ant\\Parser::skip', $view); $view = preg_replace_callback('/@php.+?@endphp/ms', '\\Ant\\Parser::skip', $view); $next = array('path' => $path, 'view' => $view); $chain = array($next['view']); $checks = array(); while (true) { $next = $this->checkNext($next['view']); if (false === $next) { break; } else { $next['view'] = preg_replace_callback('/@skip.+?@endskip/ms', '\\Ant\\Parser::skip', $next['view']); $next['view'] = preg_replace_callback('/@php.+?@endphp/ms', '\\Ant\\Parser::skip', $next['view']); $chain[] = $next['view']; } $checks[] = $next['path']; } if (null !== $path) { Ant::getCache()->chain($path, $checks); } return array_reverse($chain); }
/** * Check cache expired * * @param string $path template path * * @return bool */ public function check($path) { if (null === self::$map) { $this->getMap(); } $snapshot = Ant::snapshot(); $chainChanged = false; if (array_key_exists($path, self::$map['chain'])) { foreach (self::$map['chain'][$path] as $item) { $mtime = @filemtime($item); if (false === $mtime) { throw new Exception(sprintf('Cannot get file modification time %s', $path)); } $isDelete = false; if (false == array_key_exists($item, self::$map['view'])) { list($mt, $ss) = explode(':', self::$map['view'][$item]); if ($mt != $mtime or $snapshot != $ss) { $isDelete = true; } } else { $isDelete = true; } if ($isDelete) { self::$map['view'][$item] = $mtime . ':' . $snapshot; $chainPath = $this->cachePath . '/' . basename($item); if (file_exists($chainPath)) { if (false === @unlink($chainPath)) { throw new Exception(sprintf('Cannot delete file %s', $chainPath)); } } foreach (self::$map['chain'] as $k => $v) { $chainPath = $this->cachePath . '/' . basename($k); if (in_array($item, $v) and file_exists($chainPath)) { if (false === @unlink($chainPath)) { throw new Exception(sprintf('Cannot delete file %s', $chainPath)); } } } $this->isChanged = $chainChanged = true; break; } } } $viewChanged = true; $mtime = filemtime($path); if (array_key_exists($path, self::$map['view'])) { list($mt, $ss) = explode(':', self::$map['view'][$path]); $mt = (int) $mt; if (false !== $mtime and $mt == $mtime and $ss === $snapshot) { $viewChanged = false; } } if ($viewChanged == true) { self::$map['view'][$path] = $mtime . ':' . $snapshot; $this->isChanged = true; } if (false == file_exists($this->cachePath)) { return false; } return $viewChanged == false and $chainChanged == false; }
<?php require_once 'src/Ant.php'; $ant = new Ant(); $i = 1; while (!$ant->isOnHighway()) { echo $i++; echo ": "; echo $ant->run(); echo "\n"; }
public function abstract_classes_are_like_interfaces_with_some_builtin_behavior() { $ant = new Ant(); assert_that($ant->can_run())->is_identical_to(__); }