コード例 #1
0
ファイル: StorageImporter.php プロジェクト: rocksolid-tn/luya
 public static function getFindFilesDirectory()
 {
     $path = Yii::$app->storage->serverPath;
     if (is_dir($path) && file_exists($path)) {
         return FileHelper::findFiles($path, ['except' => ['.*']]);
     }
     return false;
 }
コード例 #2
0
 public function run()
 {
     $cmslayouts = Yii::getAlias('@app/views/cmslayouts');
     $layoutFiles = [];
     if (file_exists($cmslayouts)) {
         $files = FileHelper::findFiles($cmslayouts, ['recursive' => false, 'filter' => function ($path) {
             return !in_array(substr(basename($path), 0, 1), $this->ignorePrefix);
         }]);
         foreach ($files as $file) {
             $fileinfo = FileHelper::getFileInfo($file);
             $fileBaseName = $fileinfo->name . '.' . $fileinfo->extension;
             $readableFileName = $this->generateReadableName($fileinfo->name);
             $oldTwigName = $fileinfo->name . '.twig';
             if ($fileinfo->extension !== 'php') {
                 throw new Exception("layout file '{$file}': Since 1.0.0-beta6, cms layouts must be a php file with '<?= \$placeholders['content']; ?>' instead of a twig '{{placeholders.content}}'");
             }
             $layoutFiles[] = $fileBaseName;
             $layoutFiles[] = $oldTwigName;
             $content = file_get_contents($file);
             preg_match_all("/placeholders\\[[\\'\"](.*?)[\\'\"]\\]/", $content, $results);
             $_placeholders = [];
             foreach (array_unique($results[1]) as $holderName) {
                 if (!$this->verifyVariable($holderName)) {
                     throw new Exception("Wrong variable name detected '" . $holderName . "'. Special chars are not allowed in placeholder variables, allowed chars are a-zA-Z0-9");
                 }
                 $_placeholders[] = ['label' => $this->generateReadableName($holderName), 'var' => $holderName];
             }
             $_placeholders = ['placeholders' => $_placeholders];
             $layoutItem = Layout::find()->where(['or', ['view_file' => $fileBaseName], ['view_file' => $oldTwigName]])->one();
             if ($layoutItem) {
                 $match = $this->comparePlaceholders($_placeholders, json_decode($layoutItem->json_config, true));
                 if ($match) {
                     $layoutItem->updateAttributes(['name' => $readableFileName, 'view_file' => $fileBaseName]);
                 } else {
                     $layoutItem->updateAttributes(['name' => $readableFileName, 'view_file' => $fileBaseName, 'json_config' => json_encode($_placeholders)]);
                     $this->addLog('existing cmslayout ' . $readableFileName . ' updated');
                 }
             } else {
                 // add item into the database table
                 $data = new Layout();
                 $data->scenario = 'restcreate';
                 $data->setAttributes(['name' => $readableFileName, 'view_file' => $fileBaseName, 'json_config' => json_encode($_placeholders)]);
                 $data->save(false);
                 $this->addLog('new cmslayout ' . $readableFileName . ' found and added to database.');
             }
         }
         foreach (Layout::find()->where(['not in', 'view_file', $layoutFiles])->all() as $layoutItem) {
             $layoutItem->delete();
         }
     }
 }
コード例 #3
0
ファイル: Module.php プロジェクト: GAMITG/luya
 /**
  * Returns all controller files of this module from the `getControllerPath()` folder, where the key is the reusable 
  * id of this controller and value the file on the server.
  * 
  * @return array Returns an array where the key is the controller id and value the original file.
  * @since 1.0.0-beta5
  */
 public function getControllerFiles()
 {
     $files = [];
     foreach (FileHelper::findFiles($this->controllerPath) as $file) {
         $value = ltrim(str_replace([$this->controllerPath, 'Controller.php'], '', $file), '/');
         $files[Inflector::camel2id($value)] = $file;
     }
     return $files;
 }
コード例 #4
0
ファイル: Module.php プロジェクト: luyadev/luya-core
 /**
  * Returns all controller files of this module from the `getControllerPath()` folder, where the key is the reusable
  * id of this controller and value the file on the server.
  *
  * @return array Returns an array where the key is the controller id and value the original file.
  * @since 1.0.0-beta5
  */
 public function getControllerFiles()
 {
     try {
         // https://github.com/yiisoft/yii2/blob/master/framework/base/Module.php#L233
         $files = [];
         foreach (FileHelper::findFiles($this->controllerPath) as $file) {
             $value = ltrim(str_replace([$this->controllerPath, 'Controller.php'], '', $file), DIRECTORY_SEPARATOR);
             $files[Inflector::camel2id($value)] = $file;
         }
         return $files;
     } catch (InvalidParamException $e) {
         return [];
     }
 }