jaroslavtyc / flowmedia-dir-sync
Just a proof of my skills to get a job
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Language:HTML
Requires
- php: >= 7.1
- ext-json: *
- ext-posix: *
Requires (Dev)
- phpunit/phpunit: ^9.3
- roave/security-advisories: dev-master
This package is auto-updated.
Last update: 2024-10-29 06:18:41 UTC
README
NOT a production-ready code!
Use at your own risk.
But I will be happy if you will get inspired by this 😉
Purpose
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).
Standalone
This library should be runnable just by a terminal emulator and a PHP executable.
for example:
php ./bin/dirsync --dry-run
Independent
No other libraries should be used (not even shinnies as the Symfony Console).
Usage
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.
More Actions
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());
Original task
All of this comes from the original Flowmedia task.
Differences against original 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
Installation
The easiest way is to get it via composer:
php composer.phar require jaroslavtyc/flowmedia-dir-sync