diff --git a/cli/bin/emails b/cli/bin/emails new file mode 100644 index 0000000..b7e44fd --- /dev/null +++ b/cli/bin/emails @@ -0,0 +1,3 @@ +#!/bin/bash + +php /app/public/index.php "$@" diff --git a/cli/public/index.php b/cli/public/index.php new file mode 100644 index 0000000..9f9ee18 --- /dev/null +++ b/cli/public/index.php @@ -0,0 +1,7 @@ +run(); \ No newline at end of file diff --git a/cli/setup/app.php b/cli/setup/app.php new file mode 100644 index 0000000..16c1e0f --- /dev/null +++ b/cli/setup/app.php @@ -0,0 +1,43 @@ +isDir()) { + continue; + } + $builder->addDefinitions($file->getRealPath()); + } +} + +$app = new \ProVM\Common\Wrapper\Application($builder->build()); + +$folder = implode(DIRECTORY_SEPARATOR, [ + __DIR__, + 'middleware' +]); +if (file_exists($folder)) { + $files = new FilesystemIterator($folder); + foreach ($files as $file) { + if ($file->isDir()) { + continue; + } + include_once $file->getRealPath(); + } +} + +return $app; diff --git a/cli/setup/composer.php b/cli/setup/composer.php new file mode 100644 index 0000000..f735a96 --- /dev/null +++ b/cli/setup/composer.php @@ -0,0 +1,6 @@ +getContainer()->get('commands_folder'); +$files = new FilesystemIterator($folder); +foreach ($files as $file) { + if ($file->isDir()) { + continue; + } + include_once $file->getRealPath(); +} diff --git a/cli/setup/settings/01_env.php b/cli/setup/settings/01_env.php new file mode 100644 index 0000000..09b3241 --- /dev/null +++ b/cli/setup/settings/01_env.php @@ -0,0 +1,16 @@ + function() { + $data = [ + 'host' => $_ENV['EMAIL_HOST'], + 'username' => $_ENV['EMAIL_USERNAME'], + 'password' => $_ENV['EMAIL_PASSWORD'], + 'folder' => $_ENV['EMAIL_FOLDER'], + 'attachments' => $_ENV['ATTACHMENTS_FOLDER'], + ]; + if (isset($_ENV['EMAIL_PORT'])) { + $data['port'] = $_ENV['EMAIL_PORT']; + } + return json_decode(json_encode($data)); + } +]; diff --git a/cli/setup/settings/02_folders.php b/cli/setup/settings/02_folders.php new file mode 100644 index 0000000..0dd206a --- /dev/null +++ b/cli/setup/settings/02_folders.php @@ -0,0 +1,18 @@ + dirname(__FILE__, 3), + 'resources_folder' => function(ContainerInterface $container) { + return implode(DIRECTORY_SEPARATOR, [ + $container->get('base_folder'), + 'resources' + ]); + }, + 'commands_folder' => function(ContainerInterface $container) { + return implode(DIRECTORY_SEPARATOR, [ + $container->get('resources_folder'), + 'commands' + ]); + } +]; diff --git a/cli/setup/settings/98_log.php b/cli/setup/settings/98_log.php new file mode 100644 index 0000000..55328ea --- /dev/null +++ b/cli/setup/settings/98_log.php @@ -0,0 +1,4 @@ + '/logs/php.log' +]; \ No newline at end of file diff --git a/cli/setup/setups/03_imap.php b/cli/setup/setups/03_imap.php new file mode 100644 index 0000000..dc555ca --- /dev/null +++ b/cli/setup/setups/03_imap.php @@ -0,0 +1,25 @@ + function(ContainerInterface $container) { + $emails = $container->get('email'); + if (isset($emails->port)) { + return new \Ddeboer\Imap\Server($emails->host, $emails->port); + } + return new \Ddeboer\Imap\Server($emails->host); + }, + \Ddeboer\Imap\ConnectionInterface::class => function(ContainerInterface $container) { + $emails = $container->get('email'); + $server = $container->get(\Ddeboer\Imap\ServerInterface::class); + return $server->authenticate($emails->username, $emails->password); + }, + \ProVM\Common\Service\Emails::class => function(ContainerInterface $container) { + return new \ProVM\Common\Service\Emails( + $container->get(\Ddeboer\Imap\ConnectionInterface::class), + $container->get(\Psr\Log\LoggerInterface::class), + $container->get('email')->folder, + $container->get('email')->attachments + ); + } +]; diff --git a/cli/setup/setups/98_log.php b/cli/setup/setups/98_log.php new file mode 100644 index 0000000..eaef107 --- /dev/null +++ b/cli/setup/setups/98_log.php @@ -0,0 +1,15 @@ + function(ContainerInterface $container) { + $handler = new \Monolog\Handler\RotatingFileHandler($container->get('log_file')); + $handler->setFormatter($container->get(\Monolog\Formatter\LineFormatter::class)); + return $handler; + }, + \Psr\Log\LoggerInterface::class => function(ContainerInterface $container) { + $logger = new \Monolog\Logger('file_logger'); + $logger->pushHandler($container->get(\Monolog\Handler\RotatingFileHandler::class)); + return $logger; + } +]; \ No newline at end of file