Skip to content

Commit

Permalink
Add symfony contollers
Browse files Browse the repository at this point in the history
public folder as folder for apache
twig usage begin
  • Loading branch information
sveneld committed Jul 10, 2024
1 parent 0ddf7f5 commit 261378a
Show file tree
Hide file tree
Showing 69 changed files with 680 additions and 60 deletions.
4 changes: 3 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
APP_ENV=dev
APP_DEBUG=1
APP_DEBUG=1
APP_SECRET=e77989ed21758e78331b20e477fc5582
APP_NAME=OpenSourceBikeShare
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
FROM php:7.4-apache

ENV APACHE_DOCUMENT_ROOT /var/www/html/public

RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf

RUN docker-php-ext-install mysqli pdo pdo_mysql
RUN a2enmod rewrite

Expand Down
1 change: 0 additions & 1 deletion actions-sms.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ function log_sms($sms_uuid, $sender, $receive_time, $sms_text, $ip)
$configuration->get('dbname'),
$logger
);
$localdb->connect();

#TODO does it needed???
$localdb->setAutocommit(true);
Expand Down
60 changes: 40 additions & 20 deletions common.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,51 @@
use BikeShare\User\User;
use Symfony\Component\Dotenv\Dotenv;

$dotenv = new Dotenv();
$dotenv->setProdEnvs(['prod']);
$dotenv->bootEnv(__DIR__.'/.env', 'dev', ['test'], true);

$kernel = new Kernel($_ENV['APP_ENV'], (bool) $_ENV['APP_DEBUG']);
$kernel->boot();
/**
* should be removed
*/
global $configuration,
$sms,
$db,
$db,
$mailer,
$smsSender,
$codeGenerator,
$phonePurifier,
$creditSystem,
$user,
$auth,
$rentSystemFactory,
$translator,
$logger;

if (empty($kernel)) {
$dotenv = new Dotenv();
$dotenv->setProdEnvs(['prod']);
$dotenv->bootEnv(__DIR__.'/.env', 'dev', ['test'], true);

$kernel = new Kernel($_ENV['APP_ENV'], (bool) $_ENV['APP_DEBUG']);
$kernel->boot();
$container = $kernel->getContainer();


$logger = $kernel->getContainer()->get('logger');
Monolog\ErrorHandler::register($logger);
#Should be removed in the future. Currently, we are using it to log errors in old code
set_error_handler(
function ($severity, $message, $file, $line) use ($logger) {
$logger->error($message, ['severity' => $severity, 'file' => $file, 'line' => $line]);

return true;
}
);
}

$logger = $kernel->getContainer()->get('logger');
Monolog\ErrorHandler::register($logger);
#Should be removed in the future. Currently, we are using it to log errors in old code
set_error_handler(
function ($severity, $message, $file, $line) use ($logger) {
$logger->error($message, ['severity' => $severity, 'file' => $file, 'line' => $line]);

return true;
}
);

$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);
Expand Down Expand Up @@ -83,7 +105,6 @@ function logrequest($userid)
$configuration->get('dbname'),
$logger
);
$localdb->connect();

#TODO does it needed???
$localdb->setAutocommit(true);
Expand All @@ -107,7 +128,6 @@ function logresult($userid, $text)
$configuration->get('dbname'),
$logger
);
$localdb->connect();

#TODO does it needed???
$localdb->setAutocommit(true);
Expand All @@ -125,7 +145,7 @@ function logresult($userid, $text)
$logtext=$text;
}

$logtext = strip_tags($localdb->escape($logtext));
$logtext = substr(strip_tags($localdb->escape($logtext)), 0, 200);

$result = $localdb->query("INSERT INTO sent SET number='$userid',text='$logtext'");
}
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"symfony/runtime": "^5.4",
"symfony/twig-bundle": "^5.4",
"symfony/dotenv": "^5.4",
"symfony/translation": "^5.4"
"symfony/translation": "^5.4",
"symfony/asset": "^5.4"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.10|^4.0",
Expand Down
8 changes: 4 additions & 4 deletions config/bundles.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\MonologBundle\MonologBundle;
declare(strict_types=1);

return [
FrameworkBundle::class => ['all' => true],
MonologBundle::class => ['all' => true],
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
\Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
];
2 changes: 2 additions & 0 deletions config/packages/framework.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
->storageFactoryId('session.storage.factory.php_bridge')
->handlerId(null);

$framework->secret('%env(APP_SECRET)%');

$cache = $framework->cache();

$cache->pool('cache.static')
Expand Down
1 change: 1 addition & 0 deletions config/packages/translation.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
return static function (FrameworkConfig $framework) {
$framework
->defaultLocale('en')
->enabledLocales(['en', 'sk', 'de', 'ua'])
->translator()
->defaultPath('%kernel.project_dir%/translations')
;
Expand Down
7 changes: 7 additions & 0 deletions config/packages/twig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

use Symfony\Config\TwigConfig;

return static function (TwigConfig $twig) {
$twig->global('siteName')->value('%env(APP_NAME)%');
};
20 changes: 20 additions & 0 deletions config/routes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;

return function (RoutingConfigurator $routes) {
$routes->add('home', '/')
->controller([\BikeShare\Controller\HomeController::class, 'index']);
$routes->add('command', '/command.php')
->controller([\BikeShare\Controller\CommandController::class, 'index']);
$routes->add('scan', '/scan.php/{action}/{id}')
->controller([\BikeShare\Controller\ScanController::class, 'index']);
$routes->add('admin', '/admin.php')
->controller([\BikeShare\Controller\AdminController::class, 'index']);
$routes->add('register', '/register.php')
->controller([\BikeShare\Controller\RegisterController::class, 'index']);
$routes->add('sms_request', '/receive.php')
->controller([\BikeShare\Controller\SmsRequestController::class, 'index']);
$routes->add('agree', '/agree.php')
->controller([\BikeShare\Controller\AgreeController::class, 'index']);
};
2 changes: 2 additions & 0 deletions cron.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

die('Deprectaed see LongRentalCheckCommand');

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

Expand Down
2 changes: 2 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

die('Deprectaed see HomeController');

require_once 'vendor/autoload.php';
require_once "actions-web.php";

Expand Down
1 change: 0 additions & 1 deletion install/generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
$logger->pushHandler(new RotatingFileHandler(__DIR__ . '/../var/log/log.log', 30, Logger::WARNING));
ErrorHandler::register($logger);
$db = new MysqliDb($dbserver, $dbuser, $dbpassword, $dbname, $logger);
$db->connect();

// create new PDF document
$pdf = new TCPDF('L', PDF_UNIT, 'A5', true, 'UTF-8', false);
Expand Down
5 changes: 0 additions & 5 deletions install/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ function return_bytes($val) {
* @var DbInterface $db
*/
$db = new MysqliDb($_POST["dbserver"], $_POST["dbuser"], $_POST["dbpassword"], $_POST["dbname"], $logger);
$db->connect();
$sql=file_get_contents("../docker-data/mysql/create-database.sql");
$sql=explode(";",$sql);
foreach ($sql as $value)
Expand Down Expand Up @@ -253,7 +252,6 @@ function return_bytes($val) {
* @var DbInterface $db
*/
$db = new MysqliDb($dbserver, $dbuser, $dbpassword, $dbname, $logger);
$db->connect();
$result=$db->query("REPLACE INTO users SET userName='".$_POST["username"]."',password=SHA2('".$_POST["password"]."',512),mail='".$_POST["email"]."',number='".$_POST["phone"]."',privileges=7");
$userid=$db->getLastInsertId();
if (!$connectors["sms"])
Expand All @@ -277,7 +275,6 @@ function return_bytes($val) {
* @var DbInterface $db
*/
$db = new MysqliDb($dbserver, $dbuser, $dbpassword, $dbname, $logger);
$db->connect();
$stands=explode(",",$_POST["stands"]);
foreach ($stands as $stand)
{
Expand Down Expand Up @@ -343,7 +340,6 @@ function return_bytes($val) {
* @var DbInterface $db
*/
$db = new MysqliDb($dbserver, $dbuser, $dbpassword, $dbname, $logger);
$db->connect();
?>
<h2>Set system options</h2>
<?php
Expand Down Expand Up @@ -415,7 +411,6 @@ function return_bytes($val) {
* @var DbInterface $db
*/
$db = new MysqliDb($dbserver, $dbuser, $dbpassword, $dbname, $logger);
$db->connect();
/**
* @var CreditSystemInterface $creditSystem
*/
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
Binary file added public/img/wbsLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
8 changes: 8 additions & 0 deletions src/App/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,12 @@ public function get($key)
{
return $this->params[$key] ?? null;
}

/**
* @deprecated Should migrate to env
*/
public function __call($name, $arguments)
{
return $this->params[$name] ?? null;
}
}
36 changes: 36 additions & 0 deletions src/Command/LongRentalCheckCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace BikeShare\Command;

use BikeShare\App\Kernel;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(name: 'app:long_rental_check', description: 'Check user which have long rental')]
class LongRentalCheckCommand extends Command
{
protected static $defaultName = 'app:long_rental_check';

private Kernel $kernel;

public function __construct(Kernel $kernel)
{
$this->kernel = $kernel;
parent::__construct();
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$kernel = $this->kernel;

require_once $this->kernel->getContainer()->getParameter('kernel.project_dir') . '/actions-web.php';

checklongrental();

return Command::SUCCESS;
}
}
33 changes: 33 additions & 0 deletions src/Controller/AdminController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace BikeShare\Controller;

use BikeShare\App\Kernel;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;

class AdminController extends AbstractController
{
private Kernel $kernel;

public function __construct(Kernel $kernel)
{
$this->kernel = $kernel;
}

/**
* @Route("/admin.php", name="admin")
*/
public function index(
Request $request
): Response {
$kernel = $this->kernel;

ob_start();
require_once $this->getParameter('kernel.project_dir') . '/admin.php';
$content = ob_get_clean();

return new Response($content);
}
}
36 changes: 36 additions & 0 deletions src/Controller/AgreeController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace BikeShare\Controller;

use BikeShare\App\Kernel;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class AgreeController extends AbstractController
{
private Kernel $kernel;

public function __construct(Kernel $kernel)
{
$this->kernel = $kernel;
}

/**
* @Route("/agree.php", name="agree")
*/
public function index(
Request $request
): Response {
$kernel = $this->kernel;

ob_start();
require_once $this->getParameter('kernel.project_dir') . '/agree.php';
$content = ob_get_clean();

return new Response($content);
}
}
Loading

0 comments on commit 261378a

Please sign in to comment.