Skip to content

Commit

Permalink
feat: add scripts to run on leaf init
Browse files Browse the repository at this point in the history
  • Loading branch information
mychidarko committed May 17, 2023
1 parent fbfc5c9 commit aee2379
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
"autoload": {
"psr-4": {
"Leaf\\": "src"
}
},
"files": [
"src/scripts.php"
]
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down
20 changes: 20 additions & 0 deletions src/scripts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

if (class_exists('Leaf\Config')) {
\Leaf\Config::addScript(function ($app) {
$app->register('logWriter', function ($c) use ($app) {
$logWriter = $app->config('log.writer');
$file = $app->config('log.dir') . $app->config('log.file');

return is_object($logWriter) ? $logWriter : new \Leaf\LogWriter($file, $app->config('log.open') ?? true);
});

$app->register('log', function ($c) use ($app) {
$log = new \Leaf\Log($c->logWriter);
$log->enabled($app->config('log.enabled'));
$log->level($app->config('log.level'));

return $log;
});
});
}

0 comments on commit aee2379

Please sign in to comment.