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