-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added
DbSchemaTrait
for migrations, added ArrayHelper::diff()
method
- Loading branch information
Showing
4 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace wdmg\helpers; | ||
|
||
trait DbSchemaTrait | ||
{ | ||
/** | ||
* @return \yii\db\Connection the database connection to be used for schema building. | ||
*/ | ||
protected abstract function getDb(); | ||
|
||
/** | ||
* Creates a medium text column. | ||
* @return ColumnSchemaBuilder the column instance which can be further customized. | ||
*/ | ||
public function mediumText() | ||
{ | ||
return $this->getDb()->getSchema()->createColumnSchemaBuilder('mediumtext'); | ||
} | ||
|
||
/** | ||
* Creates a long text column. | ||
* @return ColumnSchemaBuilder the column instance which can be further customized. | ||
*/ | ||
public function longText() | ||
{ | ||
return $this->getDb()->getSchema()->createColumnSchemaBuilder('longtext'); | ||
} | ||
|
||
/** | ||
* Creates a tiny text column. | ||
* @return ColumnSchemaBuilder the column instance which can be further customized. | ||
*/ | ||
public function tinyText() | ||
{ | ||
return $this->getDb()->getSchema()->createColumnSchemaBuilder('tinytext'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace wdmg\helpers; | ||
|
||
/** | ||
* Yii2 Custom file helper | ||
* | ||
* @category Helpers | ||
* @version 1.3.6 | ||
* @author Alexsander Vyshnyvetskyy <[email protected]> | ||
* @link https://github.com/wdmg/yii2-helpers | ||
* @copyright Copyright (c) 2019 - 2020 W.D.M.Group, Ukraine | ||
* @license https://opensource.org/licenses/MIT Massachusetts Institute of Technology (MIT) License | ||
* | ||
*/ | ||
|
||
use Yii; | ||
use yii\helpers\BaseFileHelper; | ||
use yii\base\InvalidArgumentException; | ||
|
||
class FileHelper extends BaseFileHelper | ||
{ | ||
|
||
/** | ||
* Safety a file/directory path. | ||
* | ||
* @param string $path the file/directory path to be normalized | ||
* @param null|string $root the base root path. If set as NULL use path of `@app` alias by default. | ||
* @param string $ds the directory separator to be used in the normalized result. Defaults to `DIRECTORY_SEPARATOR`. | ||
* @return string the safety file/directory path | ||
*/ | ||
public static function safetyPath($path, $root = null, $ds = DIRECTORY_SEPARATOR) { | ||
|
||
$path = parent::normalizePath($path, $ds); | ||
|
||
if (!$root) | ||
$root = Yii::getAlias('@app'); | ||
|
||
$pattern = str_replace('_SEPARATOR_', $ds, "/\_SEPARATOR_[A-Za-z0-9]{0,4}/is"); | ||
$safe = preg_replace($pattern, "$ds****", $root); | ||
return str_replace($root, $safe, $path); | ||
} | ||
} |