1 | <?php |
||
0 ignored issues
–
show
|
|||
2 | /** @var object $loader */ |
||
3 | // check if loader is initialized |
||
4 | if (!defined('root')) { |
||
5 | die('Hack attempt'); |
||
6 | } |
||
7 | |||
8 | // global environment |
||
9 | define('env_name', 'Cron'); |
||
10 | // this environment have no layouts |
||
11 | define('env_no_layout', true); |
||
12 | define('env_no_uri', true); |
||
13 | define('env_type', 'cli'); |
||
14 | /** set default locale */ |
||
15 | $_GET['lang'] = 'en'; |
||
16 | |||
17 | require_once(root . '/Loader/Autoload.php'); |
||
18 | |||
19 | // make fast-access alias \App::$Object |
||
20 | // class_alias('Ffcms\Core\App', 'App'); |
||
21 | class App extends Ffcms\Core\App {} |
||
22 | /** |
||
23 | * Alias for translate function for fast usage. Example: __('Welcome my friend') |
||
24 | * @param string $text |
||
25 | * @param array $params |
||
26 | * @return string |
||
27 | */ |
||
28 | function __($text, array $params = []) |
||
29 | { |
||
30 | return \App::$Translate->translate($text, $params); |
||
31 | } |
||
32 | |||
33 | try { |
||
34 | // prepare to run |
||
35 | $app = \App::factory([ |
||
36 | 'Database' => true, |
||
37 | 'User' => true, |
||
38 | 'Mailer' => true, |
||
39 | 'Cache' => true |
||
40 | ]); |
||
41 | |||
42 | $cronManager = new \Ffcms\Core\Managers\CronManager(); |
||
43 | $logs = $cronManager->run(); |
||
44 | if (PHP_SAPI === 'cli') { |
||
45 | if ($logs && \Ffcms\Core\Helper\Type\Any::isArray($logs) && count($logs) > 0) { |
||
46 | echo 'Run cron tasks: ' . PHP_EOL . implode(PHP_EOL, $logs); |
||
47 | } else { |
||
48 | echo 'No tasks runned'; |
||
49 | } |
||
50 | } |
||
51 | } catch (Exception $e) { |
||
52 | echo (new \Ffcms\Core\Exception\NativeException($e->getMessage()))->display(); |
||
53 | } |
||
54 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.