Ubiquity  2.0.0
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  $this->urls[]=$url;
26  }
27  }
28  }
29 
30  public function parseArray($array,$existing=true){
31  foreach ($array as $url){
32  $this->urls[]=Url::fromArray($url,$existing);
33  }
34  }
35 
36  protected function parseUrl($path, $route) {
37  if (isset($route["controller"])) {
38  $controller=$route["controller"];
39  $action=$route["action"];
40  } elseif (isset($route["get"])) {
41  return $this->parseUrl($path,$route["get"]);
42  } else {
43  return;
44  }
45  $url=new Url($path, self::getLastModified($controller, $action));
46  return $url;
47  }
48 
49  public static function getLastModified($controller, $action) {
50  $classCode=UIntrospection::getClassCode($controller);
51  $lastModified=UFileSystem::lastModified(UIntrospection::getFileName($controller));
52  if(\is_array($classCode)){
53  $reflexAction=new \ReflectionMethod($controller.'::'.$action);
54  $views=UIntrospection::getLoadedViews($reflexAction, $classCode);
55  foreach ( $views as $view ) {
56  $file=ROOT . DS . "views" . DS . $view;
57  $viewDate=UFileSystem::lastModified($file);
58  if ($viewDate > $lastModified)
59  $lastModified=$viewDate;
60  }
61  }
62  return $lastModified;
63  }
67  public function getUrls() {
68  return $this->urls;
69  }
70 
71 }
72 
static fromArray($array, $existing=true)
Definition: Url.php:106
parseArray($array, $existing=true)
Definition: UrlParser.php:30
static lastModified($filename)
Definition: UFileSystem.php:84
Url for Seo module, use for sitemap generation.
Definition: Url.php:12
static getLastModified($controller, $action)
Definition: UrlParser.php:49
static getLoadedViews(\ReflectionMethod $r, $lines)
parseUrl($path, $route)
Definition: UrlParser.php:36