NOT a production-ready code!
Use at your own risk.
But I will be happy if you will get inspired by this 😉
I should be able to create a standalone, independent library to control directories by a JSON configuration and CLI. With use of object-oriented programming and PHP (in a version of my choice).
This library should be runnable just by a terminal emulator and a PHP executable.
for example:
php ./bin/dirsync --dry-run
No other libraries should be used (not even shinnies as the Symfony Console).
Create a JSON file with configuration directives:
- key starting with a hash sign
#
is processed as an Action, value (scalar, array, object...) is then used as a parameter toAction->runAction
itself- see
\JaroslavTyc\DirSync\Actions\ActionInterface
for details
- see
- key not starting by a hash sign
#
is considered as a dir name and is used for Create Dir Action directly as a value- any value pointed by that JSON key will be ignored (hint: use
null
there) - see
\JaroslavTyc\DirSync\Actions\CreateDirAction
for details
- any value pointed by that JSON key will be ignored (hint: use
for example:
{
"NewDirByDirSyncDirectName": null,
"#CreateDir": "NewDirByDirSyncCreateDirAction"
}
Process it:
php ./bin/dirsync --json-config=json_config_file_for_dir_sync.json
Should create two empty directories NewDirByDirSyncDirectName
and NewDirByDirSyncCreateDirAction
in a current working directory.
Create your own Action implementing \JaroslavTyc\DirSync\Actions\ActionInterface
and register them to \JaroslavTyc\DirSync\ActionsRunner
.
for example:
<?php
namespace JaroslavTyc\DirSync;
use JaroslavTyc\DirSync\Actions\ActionInterface;
class DeleteDirAction implements ActionInterface {
public function getName() : string {
return '#DeleteDir';
}
public function runAction($context,string $workingDir, bool $dryRun) {
// some nasty destroying code
}
}
$actionsRunner = new ActionsRunner();
$actionsRunner->registerAction(new DeleteDirAction());
All of this comes from the original Flowmedia task.
root dir
renamed toworking dir
, as root dir has specific meaning in Linuxworking dir
(formerlyroot dir
) has to be provided explicitly to the synchronization method itself to avoid accidents and confusion- all configuration options, except
working dir
, are wrapped by interfaceDirSyncOptionsInterface
, most of them originally enclosed by original taskDirSyncInterface
The easiest way is to get it via composer:
php composer.phar require jaroslavtyc/flowmedia-dir-sync