Skip to content
This repository has been archived by the owner on Apr 17, 2024. It is now read-only.

Commit

Permalink
add: translate-all composer command
Browse files Browse the repository at this point in the history
  • Loading branch information
darkalchemy committed Jun 29, 2020
1 parent 444724a commit 7924725
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 33 deletions.
43 changes: 31 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Slim-Auth
A Slim 4 Skeleton.

![GitHub commits since tagged version](https://img.shields.io/github/commits-since/darkalchemy/Slim-Auth/0.3.15)
![GitHub commits since tagged version](https://img.shields.io/github/commits-since/darkalchemy/Slim-Auth/0.3.16)
[![GitHub Issues](https://img.shields.io/github/issues/darkalchemy/Slim-Auth)](https://github.com/darkalchemy/Slim-Auth/issues)
[![GitHub license](https://img.shields.io/github/license/darkalchemy/Slim-Auth.svg)](https://github.com/darkalchemy/Slim-Auth/blob/master/LICENSE)
[![Total Downloads](https://img.shields.io/packagist/dt/darkalchemy/Slim-Auth.svg)](https://packagist.org/packages/darlachemy/slim-auth)
Expand Down Expand Up @@ -40,23 +40,28 @@ To install with composer:
```
composer create-project darkalchemy/slim-auth
```
edit config/settings.php as needed and create the database.

cd into project, edit config/settings.php as needed and create the database.
```
cd slim-auth
nano config/settings.php
```

For Development:
```
npm install
npm run build-dev
composer compile
composer migrate
npm install # install dependencies
npm run build-dev # create initial js/css resources
composer compile # compile twig templates
composer migrate # import database
```

For Production:
```
composer install --no-dev
npm install
npm run build
composer compile
composer migrate
composer install --no-dev # install non-dev dependencies
npm install # install dependencies
npm run build # create initial js/css resources
composer compile # compile twig templates
composer migrate # import database
```

Set up cron job, this is necessary to be able to run scripts as www-data when needed:
Expand Down Expand Up @@ -98,7 +103,7 @@ sudo update-locale
## restart webserver (apache2|nginx)
sudo service nginx restart
## edit bootstrap/container.php and add the correct local to the 'I18n::class' section
## edit bootstrap/container.php and add the correct locale to the 'I18n::class' section
nano bootstrap/container.php
```

Expand Down Expand Up @@ -126,6 +131,20 @@ If you want to use redis as your session handler, you should add this to php.ini
; session.save_path = "unix:///dev/shm/redis.sock?database=1"
```

### Available command line commands
```
composer cleanup # runs php_cs_fixer
composer clear_cache # clears all file based caches
composer compile # compile all twig templates
composer migrate # migrate the database
composer rollback # rollback all database changes
composer set-perms # set writable perms for cache/log folders for both webserver and cli
composer translate [lang] # translate all strings for listed language
composer translate-all # translate all strings for all currently available languages
npm build # create minified js/css resources
npm build-dev # create js/css resources
```

### TODO
phpunit for testing.

Expand Down
5 changes: 4 additions & 1 deletion app/Utilities/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,11 @@ function remove_cached_files(ContainerInterface $container)
removeDirectory(dirname($settings['router']['cache_file']), false);
}

function removeDirectory(string $path, bool $contentsOnly): bool
function removeDirectory(?string $path, bool $contentsOnly): bool
{
if (empty($path)) {
return true;
}
$iterator = new DirectoryIterator($path);
foreach ($iterator as $fileInfo) {
if ($fileInfo->isDot() || !$fileInfo->isDir()) {
Expand Down
20 changes: 16 additions & 4 deletions bin/utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
$processes = [
'compile',
'translate',
'translate-all',
'clear_cache',
];

Expand All @@ -30,11 +31,14 @@
}

switch ($process) {
case 'translate-all':
foreach ($languages as $locale) {
translate($locale, $root_path);
}

break;
case 'translate':
copy($root_path . '/bin/i18n.sh', $root_path . '/i18n.sh');
chmod($root_path . '/i18n.sh', 0775);
passthru(sprintf('./i18n.sh %s', $lang));
unlink($root_path . '/i18n.sh');
translate($lang, $root_path);

break;
case 'clear_cache':
Expand All @@ -46,3 +50,11 @@

break;
}

function translate(string $lang, string $path)
{
copy($path . '/bin/i18n.sh', $path . '/i18n.sh');
chmod($path . '/i18n.sh', 0775);
passthru(sprintf('./i18n.sh %s', $lang));
unlink($path . '/i18n.sh');
}
17 changes: 9 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,22 @@
"scripts": {
"cleanup": "vendor/friendsofphp/php-cs-fixer/php-cs-fixer fix --show-progress=dots -vvv",
"dump": "composer dump-autoload -a",
"post-install-cmd": [
"composer dump-autoload -o",
"Umpirsky\\PermissionsHandler\\ScriptHandler::setPermissions"
],
"post-update-cmd": "composer dump-autoload -o",
"post-create-project-cmd": "php -r \"copy('config/settings.example.php', 'config/settings.php');\"",
"migrate": "vendor/bin/phinx migrate -c config/phinx.php -e default --ansi",
"rollback": "vendor/bin/phinx rollback -c config/phinx.php -e default --ansi -t 0",
"translate": "php bin/utilities.php translate",
"translate-all": "php bin/utilities.php translate-all",
"clear_cache": "php bin/utilities.php clear_cache",
"set-perms": "Umpirsky\\PermissionsHandler\\ScriptHandler::setPermissions",
"post-install-cmd": [
"composer dump-autoload -o",
"Umpirsky\\PermissionsHandler\\ScriptHandler::setPermissions"
],
"compile": [
"php bin/utilities.php compile",
"Umpirsky\\PermissionsHandler\\ScriptHandler::setPermissions"
],
"translate": "php bin/utilities.php translate",
"clear_cache": "php bin/utilities.php clear_cache",
"set-perms": "Umpirsky\\PermissionsHandler\\ScriptHandler::setPermissions"
]
},
"extra": {
"writable-dirs": [
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "slim-auth",
"version": "0.3.15",
"version": "0.3.16",
"description": "",
"main": "index.js",
"directories": {
Expand Down

0 comments on commit 7924725

Please sign in to comment.