Skip to content
Snippets Groups Projects
Commit 0675db6d authored by Szász Márton's avatar Szász Márton
Browse files

initial backend structure

parent 5dedd303
Branches
No related tags found
No related merge requests found
Showing
with 447 additions and 342 deletions
...@@ -16,3 +16,5 @@ ...@@ -16,3 +16,5 @@
/vendor/ /vendor/
/web/bundles/ /web/bundles/
/.idea /.idea
/var/data/*
!var/data/.gitkeep
...@@ -12,10 +12,10 @@ class AppKernel extends Kernel ...@@ -12,10 +12,10 @@ class AppKernel extends Kernel
new Symfony\Bundle\SecurityBundle\SecurityBundle(), new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(), new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(), new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new AppBundle\AppBundle(), new AppBundle\AppBundle(),
new AKK\ModelBundle\AKKModelBundle(),
]; ];
if (in_array($this->getEnvironment(), ['dev', 'test'], true)) { if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
......
...@@ -14,6 +14,9 @@ ...@@ -14,6 +14,9 @@
Your application is now ready. You can start working on it at: Your application is now ready. You can start working on it at:
<code>{{ base_dir }}</code> <code>{{ base_dir }}</code>
</p> </p>
<p>
thing: {{ dump(thing) }}
</p>
</div> </div>
<div id="next"> <div id="next">
......
...@@ -41,7 +41,7 @@ twig: ...@@ -41,7 +41,7 @@ twig:
# Doctrine Configuration # Doctrine Configuration
doctrine: doctrine:
dbal: dbal:
driver: pdo_mysql driver: pdo_sqlite
host: '%database_host%' host: '%database_host%'
port: '%database_port%' port: '%database_port%'
dbname: '%database_name%' dbname: '%database_name%'
...@@ -53,17 +53,4 @@ doctrine: ...@@ -53,17 +53,4 @@ doctrine:
# e.g. database_path: '%kernel.project_dir%/var/data/data.sqlite' # e.g. database_path: '%kernel.project_dir%/var/data/data.sqlite'
# 2. Uncomment database_path in parameters.yml.dist # 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line: # 3. Uncomment next line:
#path: '%database_path%' path: '%database_path%'
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: '%mailer_transport%'
host: '%mailer_host%'
username: '%mailer_user%'
password: '%mailer_password%'
spool: { type: memory }
...@@ -8,12 +8,7 @@ parameters: ...@@ -8,12 +8,7 @@ parameters:
database_user: root database_user: root
database_password: ~ database_password: ~
# You should uncomment this if you want to use pdo_sqlite # You should uncomment this if you want to use pdo_sqlite
#database_path: '%kernel.project_dir%/var/data/data.sqlite' database_path: '%kernel.project_dir%/var/data/db.sqlite'
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: ~
mailer_password: ~
# A secret key that's used to generate certain security-related tokens # A secret key that's used to generate certain security-related tokens
secret: ThisTokenIsNotSoSecretChangeIt secret: ThisTokenIsNotSoSecretChangeIt
#!/usr/bin/env php #!/usr/bin/env php
<?php <?php
require_once dirname(__FILE__).'/../var/SymfonyRequirements.php'; require_once dirname(__FILE__).'/./SymfonyRequirements.php';
$lineSize = 70; $lineSize = 70;
$symfonyRequirements = new SymfonyRequirements(); $symfonyRequirements = new SymfonyRequirements();
......
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
"type": "project", "type": "project",
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"AppBundle\\": "src/AppBundle" "AppBundle\\": "src/AppBundle",
"AKK\\ModelBundle\\": "src/AKK/ModelBundle"
}, },
"classmap": [ "classmap": [
"app/AppKernel.php", "app/AppKernel.php",
...@@ -22,13 +23,11 @@ ...@@ -22,13 +23,11 @@
"require": { "require": {
"php": ">=5.5.9", "php": ">=5.5.9",
"doctrine/doctrine-bundle": "^1.6", "doctrine/doctrine-bundle": "^1.6",
"doctrine/orm": "^2.5",
"incenteev/composer-parameter-handler": "^2.0", "incenteev/composer-parameter-handler": "^2.0",
"sensio/distribution-bundle": "^5.0.19", "sensio/distribution-bundle": "^5.0.19",
"sensio/framework-extra-bundle": "^3.0.2", "sensio/framework-extra-bundle": "^3.0.2",
"symfony/monolog-bundle": "^3.1.0", "symfony/monolog-bundle": "^3.1.0",
"symfony/polyfill-apcu": "^1.0", "symfony/polyfill-apcu": "^1.0",
"symfony/swiftmailer-bundle": "^2.3.10",
"symfony/symfony": "3.3.*", "symfony/symfony": "3.3.*",
"twig/twig": "^1.0||^2.0" "twig/twig": "^1.0||^2.0"
}, },
......
This diff is collapsed.
<?php
namespace AKK\ModelBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class AKKModelBundle extends Bundle
{
}
<?php
/**
* Created by PhpStorm.
* User: marci
* Date: 8/11/17
* Time: 7:06 PM
*/
namespace AKK\ModelBundle\Data;
class Pass
{
/** @var int */
public $id;
/** @var PassType|null */
public $type;
/** @var User|null */
public $user;
/** @var \DateTime|null */
public $obtainDate;
/** @var \DateTime|null */
public $validityStartDate;
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: marci
* Date: 8/11/17
* Time: 7:04 PM
*/
namespace AKK\ModelBundle\Data;
class PassType
{
/** @var int */
public $id;
/** @var string|null */
public $name;
/** @var string|null */
public $displayName;
/** @var int|null */
public $priceHuf;
/** @var \DateInterval|null */
public $validity;
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: marci
* Date: 8/8/17
* Time: 11:38 PM
*/
namespace AKK\ModelBundle\Data;
class User
{
/** @var int */
public $id;
/** @var string|null */
public $username;
/** @var string|null */
public $password;
/** @var string|null */
public $email;
/** @var string|null */
public $firstName;
/** @var string|null */
public $lastName;
}
\ No newline at end of file
<?php
namespace AKK\ModelBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;
/**
* This is the class that loads and manages your bundle configuration.
*
* @link http://symfony.com/doc/current/cookbook/bundles/extension.html
*/
class AKKModelExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.php');
}
}
<?php
namespace AKK\ModelBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
/**
* This is the class that validates and merges configuration from your app/config files.
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/configuration.html}
*/
class Configuration implements ConfigurationInterface
{
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('akk_model');
// Here you should define the parameters that are allowed to
// configure your bundle. See the documentation linked above for
// more information on that topic.
return $treeBuilder;
}
}
<?php
/**
* Created by PhpStorm.
* User: marci
* Date: 8/11/17
* Time: 7:16 PM
*/
namespace AKK\ModelBundle\Repository\Detail;
use Doctrine\DBAL\Connection;
class RepositoryImpl
{
private $conn;
public function __construct(Connection $connection)
{
$this->conn = $connection;
}
/**
* @param string $fromArg
* @param array $constraints
* @return array
*/
public function select(string $fromArg, array $constraints = []): array
{
$sql = 'SELECT * FROM '.$fromArg;
$whereargs = [];
foreach ($constraints as $key => $value) {
if(is_numeric($key)) {
$whereargs[] = $value;
} else {
$whereargs[] = "`$key` = '$value'";
}
}
if(count($constraints)) {
$sql .= ' WHERE ' . implode(' AND ', $whereargs);
}
$queryResult = $this->conn->query($sql);
$all = $queryResult->fetchAll();
return $all;
}
/**
* @param string $from
* @param int $id
* @return array
*/
public function findById(string $from, int $id): array
{
return $this->select($from, ['id' => $id]);
}
/**
* @param string $target
* @param array $row
*/
public function insert(string $target, array $row): void
{
$sql = 'INSERT INTO '.$target
.' ('.implode(',', array_keys($row)).') VALUES ('
.implode(',', array_values($row)).')';
$this->conn->exec($sql);
}
public function updateById(string $target, array $row): void
{
$sql = 'UPDATE '.$target.' SET ';
$updateargs = [];
foreach ($row as $key => $item) {
$updateargs[] = "`$key`='$item'";
}
$sql .= implode(',', $updateargs);
$this->conn->exec($sql);
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: marci
* Date: 8/11/17
* Time: 7:15 PM
*/
namespace AKK\ModelBundle\Repository;
use AKK\ModelBundle\Data\Pass;
use AKK\ModelBundle\Data\PassType;
use AKK\ModelBundle\Repository\Detail\RepositoryImpl;
class PassRepository
{
/** @var RepositoryImpl */
private $repoImpl;
public function __construct(RepositoryImpl $repositoryImpl)
{
$this->repoImpl = $repositoryImpl;
}
public function objectToArray(Pass $pass)
{
$result = [
'id' => $pass->id
];
if($pass->type !== null) $result['pass_type_id'] = $pass->type->id;
if($pass->user !== null) $result['user_id'] = $pass->user->id;
if($pass->obtainDate !== null) $result['obtain_date'] = date('Y-m-d H:i:s', $pass->obtainDate);
if($pass->validityStartDate !== null) $result['validity_start_date'] = date('Y-m-d H:i:s', $pass->validityStartDate);
return $result;
}
public function arrayToObject(array $row): Pass
{
$result = new Pass();
$result->id = $row['id'];
if(array_key_exists('pass_type_id', $row)) {
$result->type = new PassType();
$result->type->id = $row['pass_type_id'];
}
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: marci
* Date: 8/11/17
* Time: 7:15 PM
*/
namespace AKK\ModelBundle\Repository;
use AKK\ModelBundle\Repository\Detail\RepositoryImpl;
class PassTypeRepository
{
/** @var RepositoryImpl */
private $repoImpl;
public function __construct(RepositoryImpl $repositoryImpl)
{
$this->repoImpl = $repositoryImpl;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: marci
* Date: 8/11/17
* Time: 7:15 PM
*/
namespace AKK\ModelBundle\Repository;
use AKK\ModelBundle\Repository\Detail\RepositoryImpl;
class UserRepository
{
/** @var RepositoryImpl */
private $repoImpl;
public function __construct(RepositoryImpl $repositoryImpl)
{
$this->repoImpl = $repositoryImpl;
}
}
\ No newline at end of file
<?php
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Parameter;
/*
$container->setDefinition(
'akk_model.example',
new Definition(
'AKK\ModelBundle\Example',
array(
new Reference('service_id'),
"plain_value",
new Parameter('parameter_name'),
)
)
);
*/
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
namespace AppBundle\Controller; namespace AppBundle\Controller;
use AKK\ModelBundle\Repository\Detail\RepositoryImpl;
use Doctrine\DBAL\Connection;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
...@@ -11,11 +13,14 @@ class DefaultController extends Controller ...@@ -11,11 +13,14 @@ class DefaultController extends Controller
/** /**
* @Route("/", name="homepage") * @Route("/", name="homepage")
*/ */
public function indexAction(Request $request) public function indexAction(Request $request, Connection $connection)
{ {
// replace this example code with whatever you need // replace this example code with whatever you need
$repo = new RepositoryImpl($connection);
$repo->select('sqlite_master');
return $this->render('default/index.html.twig', [ return $this->render('default/index.html.twig', [
'base_dir' => realpath($this->getParameter('kernel.project_dir')).DIRECTORY_SEPARATOR, 'base_dir' => realpath($this->getParameter('kernel.project_dir')).DIRECTORY_SEPARATOR,
'thing' => $connection->fetchAll('SELECT name FROM sqlite_master')
]); ]);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment