Ubiquity  2.0.2
php rapid development framework
ControllerSeo.php
Go to the documentation of this file.
1 <?php
10 
12  private $name;
13  private $urlsFile;
15  private $route;
16  private $inRobots;
17 
18  public function __construct($className=null){
19  if(isset($className) && \class_exists($className)){
21  if($route){
22  $this->route=$route["path"];
23  }
24  $ctrl=new $className();
25  $this->name=$className;
26  $this->urlsFile=$ctrl->_getUrlsFilename();
27  $this->siteMapTemplate=$ctrl->_getSeoTemplateFilename();
28  }
29  }
33  public function getName() {
34  return $this->name;
35  }
36 
40  public function getUrlsFile() {
41  return $this->urlsFile;
42  }
43 
47  public function getSiteMapTemplate() {
49  }
50 
54  public function getRoute() {
55  return $this->route;
56  }
57 
61  public function setName($name) {
62  $this->name = $name;
63  }
64 
68  public function setUrlsFile($urlsFile) {
69  $this->urlsFile = $urlsFile;
70  }
71 
76  $this->siteMapTemplate = $siteMapTemplate;
77  }
78 
82  public function setRoute($route) {
83  $this->route = $route;
84  }
85 
86  public function getPath(){
87  if(UString::isNotNull($this->route))
88  return $this->route;
89  $parts=\explode("\\", $this->name);
90  return end($parts);
91  }
92 
93  public function urlExists(){
94  return CacheManager::$cache->exists($this->urlsFile);
95  }
96 
97  public static function init(){
98  $result=[ ];
99  $config=Startup::getConfig();
100 
101  $robotsContent="";
102  $robotsFile=Startup::getApplicationDir() . DS . 'robots.txt';
103  if(\file_exists($robotsFile)){
104  $robotsContent=UFileSystem::load($robotsFile);
105  }
106  $files=CacheManager::getControllersFiles($config, true);
107  try {
108  $restCtrls=CacheManager::getRestCache();
109  } catch ( \Exception $e ) {
110  $restCtrls=[ ];
111  }
112 
113  foreach ( $files as $file ) {
114  if (is_file($file)) {
115  $controllerClass=ClassUtils::getClassFullNameFromFile($file);
116  if (isset($restCtrls[$controllerClass]) === false) {
117  if(\class_exists($controllerClass)){
118  $reflect=new \ReflectionClass($controllerClass);
119  if (!$reflect->isAbstract() && $reflect->isSubclassOf('Ubiquity\controllers\seo\SeoController')) {
120  $ctrlSeo=new ControllerSeo($controllerClass);
121  $path=$ctrlSeo->getPath();
122  $ctrlSeo->setInRobots(\strpos($robotsContent, $path)!==false);
123  $result[]=$ctrlSeo;
124  }
125  }
126  }
127  }
128  }
129  return $result;
130  }
134  public function getInRobots() {
135  return $this->inRobots;
136  }
137 
141  public function setInRobots($inRobots) {
142  $this->inRobots = $inRobots;
143  }
144 
145 
146 }
static getClassFullNameFromFile($filePathName)
get the full name (name \ namespace) of a class from its file path result example: (string) "I\Am\The...
Definition: ClassUtils.php:15
static getRouteInfoByControllerAction($controller, $action)
Definition: Router.php:49
static getControllersFiles(&$config, $silent=false)