Skip to content

Commit

Permalink
symfony skeleton (#199)
Browse files Browse the repository at this point in the history
* symfony skeleton
  • Loading branch information
sveneld authored Jun 1, 2024
1 parent e304d37 commit a06f2e1
Show file tree
Hide file tree
Showing 35 changed files with 606 additions and 265 deletions.
3 changes: 2 additions & 1 deletion actions-qrcode.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
require("common.php");

require_once "common.php";

function response($message,$error=0,$log=1)
{
Expand Down
15 changes: 2 additions & 13 deletions admin.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
<?php

use BikeShare\Authentication\Auth;
use BikeShare\Db\DbInterface;
use BikeShare\User\User;
use Psr\Log\LoggerInterface;

require_once 'vendor/autoload.php';
require('actions-web.php');

/**
* @var DbInterface $db
* @var LoggerInterface $logger
*/
$user = new User($db);
$auth = new Auth($db);
require_once 'actions-web.php';

$auth->refreshSession();

Expand Down Expand Up @@ -54,6 +42,7 @@
echo 'var creditcurrency="' . $creditSystem->getCreditCurrency() . '"' . PHP_EOL;
$minRequiredCredit = $creditSystem->getMinRequiredCredit();
} else {
$minRequiredCredit = 0;
echo 'var creditenabled=0;', "\n";
}
?>
Expand Down
7 changes: 1 addition & 6 deletions agree.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
<?php

use BikeShare\Db\DbInterface;

require_once 'vendor/autoload.php';
require('actions-web.php');
require_once 'actions-web.php';

/**
* @var DbInterface $db
*/
?>
<!DOCTYPE html>
<html lang="en">
Expand Down
17 changes: 17 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env php
<?php

use BikeShare\App\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;

if (!is_file(dirname(__DIR__).'/vendor/autoload_runtime.php')) {
throw new LogicException('Symfony Runtime is missing. Try running "composer require symfony/runtime".');
}

require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

return function (array $context) {
$kernel = new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);

return new Application($kernel);
};
22 changes: 2 additions & 20 deletions command.php
Original file line number Diff line number Diff line change
@@ -1,35 +1,17 @@
<?php

use BikeShare\Authentication\Auth;
use BikeShare\Db\DbInterface;
use BikeShare\Purifier\PhonePurifier;
use BikeShare\Purifier\PhonePurifierInterface;
use BikeShare\Rent\RentSystemFactory;
use BikeShare\Rent\RentSystemInterface;
use BikeShare\User\User;
use Psr\Log\LoggerInterface;

require_once 'vendor/autoload.php';
require('actions-web.php');

/**
* @var DbInterface $db
* @var LoggerInterface $logger
*/
$auth = new Auth($db);
$user = new User($db);
/**
* @var PhonePurifierInterface $phonePurifier
*/
$phonePurifier = new PhonePurifier($configuration->get('countrycode'));
require_once 'actions-web.php';

$userid = $auth->getUserId();
$session = $auth->getSessionId();

/**
* @var RentSystemInterface $rentSystem
*/
$rentSystem = RentSystemFactory::create('web');
$rentSystem = $rentSystemFactory->getRentSystem('web');

$action="";
if (isset($_GET["action"])) $action=trim($_GET["action"]);
Expand Down
99 changes: 24 additions & 75 deletions common.php
Original file line number Diff line number Diff line change
@@ -1,98 +1,47 @@
<?php

require_once 'vendor/autoload.php';

use BikeShare\App\Configuration;
use BikeShare\Credit\CodeGenerator\CodeGenerator;
use BikeShare\App\Kernel;
use BikeShare\Authentication\Auth;
use BikeShare\Credit\CodeGenerator\CodeGeneratorInterface;
use BikeShare\Credit\CreditSystemFactory;
use BikeShare\Credit\CreditSystemInterface;
use BikeShare\Mail\DebugMailSender;
use BikeShare\Mail\MailSenderInterface;
use BikeShare\Mail\PHPMailerMailSender;
use BikeShare\Db\DbInterface;
use BikeShare\Db\MysqliDb;
use BikeShare\Purifier\PhonePurifier;
use BikeShare\Mail\MailSenderInterface;
use BikeShare\Purifier\PhonePurifierInterface;
use BikeShare\Sms\SmsSender;
use BikeShare\Rent\RentSystemFactory;
use BikeShare\Sms\SmsSenderInterface;
use BikeShare\SmsConnector\DebugConnector;
use BikeShare\SmsConnector\SmsConnectorFactory;
use BikeShare\SmsConnector\SmsConnectorInterface;
use BikeShare\User\User;
use Monolog\ErrorHandler;
use Monolog\Handler\RotatingFileHandler;
use Monolog\Logger;

require_once 'vendor/autoload.php';
\Symfony\Component\ErrorHandler\Debug::enable();

$configuration = new Configuration();
$kernel = new Kernel('dev', true);
$kernel->boot();

$logger = new Logger('BikeShare');
$logger->pushHandler(new RotatingFileHandler( __DIR__ . '/var/log/log.log', 30, Logger::WARNING));
ErrorHandler::register($logger);
$logger = $kernel->getContainer()->get('logger');
$configuration = $kernel->getContainer()->get(Configuration::class);
$sms = $kernel->getContainer()->get(SmsConnectorInterface::class);
$db = $kernel->getContainer()->get(DbInterface::class);
$db = $kernel->getContainer()->get(DbInterface::class);
$db->connect();
$mailer = $kernel->getContainer()->get(MailSenderInterface::class);
$smsSender = $kernel->getContainer()->get(SmsSenderInterface::class);
$codeGenerator = $kernel->getContainer()->get(CodeGeneratorInterface::class);
$phonePurifier = $kernel->getContainer()->get(PhonePurifierInterface::class);
$creditSystem = $kernel->getContainer()->get(CreditSystemInterface::class);
$user = $kernel->getContainer()->get(User::class);
$auth = $kernel->getContainer()->get(Auth::class);
$rentSystemFactory = $kernel->getContainer()->get(RentSystemFactory::class);

$locale = $configuration->get('systemlang') . ".utf8";
setlocale(LC_ALL, $locale);
putenv("LANG=" . $locale);
bindtextdomain("messages", dirname(__FILE__) . '/languages');
textdomain("messages");

$connectors = $configuration->get('connectors');
$sms = (new SmsConnectorFactory($logger))->getConnector(
!empty($connectors["sms"]) ? $connectors["sms"] : 'disabled',
!empty($connectors["config"][$connectors["sms"]]) ? json_decode($connectors["config"][$connectors["sms"]], true) : array(),
DEBUG
);

/**
* @var DbInterface $db
*/
$db = new MysqliDb(
$configuration->get('dbserver'),
$configuration->get('dbuser'),
$configuration->get('dbpassword'),
$configuration->get('dbname'),
$logger
);
$db->connect();

/**
* @var MailSenderInterface $mailer
*/
if (DEBUG === TRUE) {
$mailer = new DebugMailSender();
} else {
$mailer = new PHPMailerMailSender(
$configuration->get('systemname'),
$configuration->get('systememail'),
$configuration->get('email'),
new \PHPMailer\PHPMailer\PHPMailer(false)
);
}

/**
* @var SmsSenderInterface $smsSender
*/
$smsSender = new SmsSender(
DEBUG === TRUE ? new DebugConnector() : $sms,
$db
);

/**
* @var CodeGeneratorInterface $codeGenerator
*/
$codeGenerator = new CodeGenerator();

$user = new User($db);

/**
* @var PhonePurifierInterface $phonePurifier
*/
$phonePurifier = new PhonePurifier($configuration->get('countrycode'));

/**
* @var CreditSystemInterface $creditSystem
*/
$creditSystem = (new CreditSystemFactory())->getCreditSystem($configuration->get('credit'), $db);

function error($message)
{
global $db;
Expand Down
17 changes: 16 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,27 @@
"ext-mysqli": "*",
"ext-gettext": "*",
"ext-curl": "*",
"monolog/monolog": "^1.27"
"monolog/monolog": "^1.27",
"symfony/dependency-injection": "^5.4",
"symfony/http-kernel": "^5.4",
"symfony/framework-bundle": "^5.4",
"symfony/http-foundation": "^5.4",
"symfony/config": "^5.4",
"symfony/expression-language": "^5.4",
"symfony/monolog-bundle": "^3.10",
"symfony/console": "^5.4",
"symfony/runtime": "^5.4",
"symfony/twig-bundle": "^5.4"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.10|^4.0",
"phpunit/phpunit": "^9.5",
"php-mock/php-mock-phpunit": "^2.3",
"rector/rector": "^1.1"
},
"config": {
"allow-plugins": {
"symfony/runtime": true
}
}
}
9 changes: 9 additions & 0 deletions config/bundles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\MonologBundle\MonologBundle;

return [
FrameworkBundle::class => ['all' => true],
MonologBundle::class => ['all' => true],
];
18 changes: 18 additions & 0 deletions config/packages/framework.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

use Symfony\Config\FrameworkConfig;

return static function (FrameworkConfig $framework): void {
$framework->session()
->storageFactoryId('session.storage.factory.php_bridge')
->handlerId(null);

$cache = $framework->cache();

$cache->pool('cache.static')
->adapters(['cache.adapter.array'])
->defaultLifetime(180)
->public(true);
};
14 changes: 14 additions & 0 deletions config/packages/monolog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

use Symfony\Config\MonologConfig;

return static function (MonologConfig $monolog): void {
$monolog->handler('BikeShare')
->appName('BikeShare')
->type('rotating_file')
->path('%kernel.project_dir%/var/log/log.log')
->maxFiles(30)
->level('debug');
};
Loading

0 comments on commit a06f2e1

Please sign in to comment.