Ubiquity  2.0.3
php rapid development framework
UrlParser.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Ubiquity\seo;
4 
9 
10 class UrlParser {
11  public static $frequencies = [ 'always','hourly','daily','weekly','monthly','yearly','never' ];
12  private $urls;
13  private $config;
14 
19  public function getConfig() {
20  return $this->config;
21  }
22 
23  public function __construct() {
24  $this->urls = [ ];
25  $this->config = Startup::getConfig ();
26  }
27 
28  public function parse() {
29  $routes = CacheManager::getRoutes ();
30  foreach ( $routes as $path => $route ) {
31  $url = $this->parseUrl ( $path, $route );
32  if (isset ( $url )) {
33  if (! isset ( $this->urls [$path] ))
34  $this->urls [$path] = $url;
35  }
36  }
37  }
38 
39  public function parseArray($array, $existing = true) {
40  foreach ( $array as $url ) {
41  $this->urls [$url ['location']] = Url::fromArray ( $url, $existing );
42  }
43  }
44 
45  protected function parseUrl($path, $route) {
46  if (isset ( $route ["controller"] )) {
47  $controller = $route ["controller"];
48  $action = $route ["action"];
49  } elseif (isset ( $route ["get"] )) {
50  return $this->parseUrl ( $path, $route ["get"] );
51  } else {
52  return;
53  }
54  $lastModified = self::getLastModified ( $controller, $action );
55  if ($lastModified !== false) {
56  $url = new Url ( $path, $lastModified );
57  return $url;
58  }
59  return;
60  }
61 
62  public static function getLastModified($controller, $action) {
63  if (\class_exists ( $controller )) {
64  $classCode = UIntrospection::getClassCode ( $controller );
65  $lastModified = UFileSystem::lastModified ( UIntrospection::getFileName ( $controller ) );
66  if (\is_array ( $classCode )) {
67  $reflexAction = new \ReflectionMethod ( $controller . '::' . $action );
68  $views = UIntrospection::getLoadedViews ( $reflexAction, $classCode );
69  foreach ( $views as $view ) {
70  $file = ROOT . DS . "views" . DS . $view;
71  $viewDate = UFileSystem::lastModified ( $file );
72  if ($viewDate > $lastModified)
73  $lastModified = $viewDate;
74  }
75  }
76  return $lastModified;
77  }
78  return false;
79  }
80 
85  public function getUrls() {
86  return $this->urls;
87  }
88 }
89 
static fromArray($array, $existing=true)
Definition: Url.php:106
parseArray($array, $existing=true)
Definition: UrlParser.php:39
static lastModified($filename)
Url for Seo module, use for sitemap generation.
Definition: Url.php:12
static getLastModified($controller, $action)
Definition: UrlParser.php:62
static getLoadedViews(\ReflectionMethod $r, $lines)
parseUrl($path, $route)
Definition: UrlParser.php:45