Skip to content

Commit

Permalink
+ plain file handler
Browse files Browse the repository at this point in the history
  • Loading branch information
hiqsol committed May 11, 2016
1 parent 2efa1a1 commit 7104741
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
26 changes: 26 additions & 0 deletions src/base/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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';
}

Expand Down Expand Up @@ -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');
}
}
4 changes: 2 additions & 2 deletions src/handlers/BaseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
}
Expand Down
36 changes: 36 additions & 0 deletions src/handlers/PlainHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/*
* Task runner, code generator and build tool for easier continuos integration
*
* @link https://github.com/hiqdev/hidev
* @package hidev
* @license BSD-3-Clause
* @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/)
*/

namespace hidev\handlers;

use Yii;

/**
* Handler for plain file operations.
*/
class PlainHandler extends BaseHandler
{
/**
* {@inheritdoc}
*/
public function render($data)
{
return $data;
}

/**
* {@inheritdoc}
*/
public function parse($input)
{
return $input;
}
}

0 comments on commit 7104741

Please sign in to comment.