Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
UrlParser.php
Go to the documentation of this file.
1<?php
2
3namespace Ubiquity\seo;
4
9
10class 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 $baseView=\ROOT.\DS."views".\DS;
70 foreach ( $views as $view ) {
71 $file = $baseView. $view;
72 if(\file_exists($file)){
73 $viewDate = UFileSystem::lastModified ( $file );
74 if ($viewDate > $lastModified){
75 $lastModified = $viewDate;
76 }
77 }
78 }
79 }
80 return $lastModified;
81 }
82 return false;
83 }
84
89 public function getUrls() {
90 return $this->urls;
91 }
92}
93
Manager for caches (Router, Rest, models).
Starts the framework.
Definition Startup.php:19
Url for Seo module, use for sitemap generation.
Definition Url.php:13
static fromArray($array, $existing=true)
Definition Url.php:108
parseArray($array, $existing=true)
Definition UrlParser.php:39
static getLastModified($controller, $action)
Definition UrlParser.php:62
parseUrl($path, $route)
Definition UrlParser.php:45
File system utilities Ubiquity\utils\base$UFileSystem This class is part of Ubiquity.
Ubiquity\utils\base$UIntrospection This class is part of Ubiquity.