olive-cms/tools is available on Packagist (olive-cms/tools) and as such installable via Composer.
composer require olive-cms/tools
If you do not use Composer, you can grab the code from GitHub, and use any PSR-0 compatible autoloader (e.g. the Symfony2 ClassLoader component) to load Monolog classes.
// load autoload
require_once 'vendor/autoload.php';
use Olive\Tools;
/**
* file tools
* last argument type stream file -> default: 'w'
* @return bool
*/
Tools::file('/path/to/file', 'content');
Tools::file('/path/to/file', 'content', 'a');
Get Directorys of path
// @return array
$list = Tools::getDirList('/path/to/directory/');
Get all Directorys of path (Recursive)
// @return array
$list = Tools::getDirsList('/path/to/directory/');
Get Files Directorys of path
// @return array
$list = Tools::getDirFiles('/path/to/directory/');
Remove not empty Directory
// @return void
Tools::rmDir('/path/to/directory/');
Json encode with pretty
// @return string
$json = Tools::jsonEncode(['ali', 'mehdi']);
Json encode with pretty
// @return array | object
$array = Tools::getJsonFile('/path/to/file.json');
$object = Tools::getJsonFile('/path/to/file.json', false);
Merge arrays with compare
// @return array | object
$a=[
'arr1'=>[
'arr11'=>[1,2,3,4,5,6],
'arr12'=>[7,8,9,10,11]
],
'str1'=>'tools'
];
$b=[
'arr1'=>[
'arr11'=>[11,22,33],
'arr12'=>[
'op' => [111,222,333],
'op2' => 'lurem'
]
],
'str2'=>'merge'
];
$merged=Tools::arrayMerge($a, $b));
output:
Array
(
[arr1] => Array
(
[arr11] => Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 6
[6] => 11
[7] => 22
[8] => 33
)
[arr12] => Array
(
[op] => Array
(
[0] => 111
[1] => 222
[2] => 333
)
[op2] => lurem
[0] => 7
[1] => 8
[2] => 9
[3] => 10
[4] => 11
)
)
[str2] => merge
[str1] => tools
)
Run Callable Methods (functions, oops, string)
// return mixed
class Hello
{
public function say($name)
{
return 'hello ' . $name;
}
}
$testob = new Hello;
echo Tools::runCaller([$testob, 'say'], ['world']); // Hello world