Ubiquity  2.0.2
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 
15  public function __construct() {
16  $this->urls=[];
17  $this->config=Startup::getConfig();
18  }
19 
20  public function parse() {
21  $routes=CacheManager::getRoutes();
22  foreach ( $routes as $path => $route ) {
23  $url=$this->parseUrl($path, $route);
24  if (isset($url)) {
25  if(!isset($this->urls[$path]))
26  $this->urls[$path]=$url;
27  }
28  }
29  }
30 
31  public function parseArray($array,$existing=true){
32  foreach ($array as $url){
33  $this->urls[$url['location']]=Url::fromArray($url,$existing);
34  }
35  }
36 
37  protected function parseUrl($path, $route) {
38  if (isset($route["controller"])) {
39  $controller=$route["controller"];
40  $action=$route["action"];
41  } elseif (isset($route["get"])) {
42  return $this->parseUrl($path,$route["get"]);
43  } else {
44  return;
45  }
46  $lastModified=self::getLastModified($controller, $action);
47  if($lastModified!==false){
48  $url=new Url($path, $lastModified);
49  return $url;
50  }
51  return;
52  }
53 
54  public static function getLastModified($controller, $action) {
55  if(\class_exists($controller)){
56  $classCode=UIntrospection::getClassCode($controller);
57  $lastModified=UFileSystem::lastModified(UIntrospection::getFileName($controller));
58  if(\is_array($classCode)){
59  $reflexAction=new \ReflectionMethod($controller.'::'.$action);
60  $views=UIntrospection::getLoadedViews($reflexAction, $classCode);
61  foreach ( $views as $view ) {
62  $file=ROOT . DS . "views" . DS . $view;
63  $viewDate=UFileSystem::lastModified($file);
64  if ($viewDate > $lastModified)
65  $lastModified=$viewDate;
66  }
67  }
68  return $lastModified;
69  }
70  return false;
71  }
75  public function getUrls() {
76  return $this->urls;
77  }
78 
79 }
80 
static fromArray($array, $existing=true)
Definition: Url.php:106
parseArray($array, $existing=true)
Definition: UrlParser.php:31
static lastModified($filename)
Definition: UFileSystem.php:90
Url for Seo module, use for sitemap generation.
Definition: Url.php:12
static getLastModified($controller, $action)
Definition: UrlParser.php:54
static getLoadedViews(\ReflectionMethod $r, $lines)
parseUrl($path, $route)
Definition: UrlParser.php:37