diff --git a/src/base/File.php b/src/base/File.php index 5216f62..472dfa0 100644 --- a/src/base/File.php +++ b/src/base/File.php @@ -99,6 +99,20 @@ public static function create($path) return Yii::createObject($config); } + /** + * Create plain file (with plain handler). + * @param string $path + * @return File + */ + public static function plain($path) + { + return Yii::createObject([ + 'class' => get_called_class(), + 'type' => 'plain', + 'path' => $path, + ]); + } + public function getMinimalPath() { return Yii::getAlias($this->minimal); @@ -136,6 +150,10 @@ public function getTypeByExtension($extension) public function findType() { + if ($this->type === 'plain') { + return $this->type; + } + return ($this->goal ? $this->goal->fileType : null) ?: static::getTypeByExtension($this->_extension) ?: 'template'; } @@ -360,4 +378,12 @@ public function chgrp($value) passthru("chgrp $value $path"); Yii::warning("chgrp $path '$value'", 'file'); } + public function symlink($dest) + { + if (file_exists($dest)) { + return true; + } + symlink($this->path, $dest); + Yii::warning("Symlinked $this->path $dest", 'file'); + } } diff --git a/src/handlers/BaseHandler.php b/src/handlers/BaseHandler.php index 506588c..df21c04 100644 --- a/src/handlers/BaseHandler.php +++ b/src/handlers/BaseHandler.php @@ -105,10 +105,10 @@ public function parsePath($path, $minimal = null) /** * Parses string input. To be redefined in real handlers. - * @param string $json + * @param string $input to parse * @return array */ - public function parse($json) + public function parse($input) { return []; } diff --git a/src/handlers/PlainHandler.php b/src/handlers/PlainHandler.php new file mode 100644 index 0000000..a865d32 --- /dev/null +++ b/src/handlers/PlainHandler.php @@ -0,0 +1,36 @@ +