Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ services:
ports:
- "80:80"

node:
build:
dockerfile: node/Dockerfile
working_dir: /var/www/html
volumes:
- ../:/var/www/html
command: [ "tail", "-f", "/dev/null" ]

mysql:
image: mysql:8.0.29
environment:
Expand All @@ -29,11 +37,3 @@ services:
- "1000:8080"
depends_on:
- mysql

node:
build:
dockerfile: node/Dockerfile
working_dir: /var/www/html
volumes:
- ../:/var/www/html
command: [ "tail", "-f", "/dev/null" ]
2 changes: 0 additions & 2 deletions .docker/node/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
FROM node:18.17.0

WORKDIR /var/www/html
13 changes: 10 additions & 3 deletions .docker/php/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
FROM php:8.2-apache

# Change default Apache config
ENV APACHE_DOCUMENT_ROOT /var/www/html/www

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

# Enable .htaccess
RUN a2enmod rewrite

WORKDIR /var/www/html

# For managing PHP packages
COPY --from=composer /usr/bin/composer /usr/bin/composer

# Install base (from Docker) extensions
RUN docker-php-ext-install \
# For accessing databases in PHP
pdo \
pdo_mysql \
mysqli

# Install extra (from Debian) extensions
RUN apt-get update && apt-get -y install \
git
# For repository actions
git \
# For reading ZIP compressed archives (required by nextras/migrations)
zip
21 changes: 16 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
# run environment scripts
init\:env:
cd config && touch local.neon
make up
docker compose -f .docker/docker-compose.yml exec php composer install
docker compose -f .docker/docker-compose.yml exec php bin/console migration:reset
docker compose -f .docker/docker-compose.yml exec node npm install
docker compose -f .docker/docker-compose.yml exec node npm run build

# run containers scripts
up:
docker-compose -f .docker/docker-compose.yml up -d
docker compose -f .docker/docker-compose.yml up -d

build:
docker-compose -f .docker/docker-compose.yml up -d --build
docker compose -f .docker/docker-compose.yml up -d --build

down:
docker-compose -f .docker/docker-compose.yml down
docker compose -f .docker/docker-compose.yml down

# join container scripts
php:
docker-compose -f .docker/docker-compose.yml exec php bash;
docker compose -f .docker/docker-compose.yml exec php bash;

node:
docker-compose -f .docker/docker-compose.yml exec node bash;
docker compose -f .docker/docker-compose.yml exec node bash;
37 changes: 11 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,19 @@
# Snyt
## Snyt

website for restaurant with small CMS
Website for restaurant with small CMS

> more tech-info find in project's Wiki (tab in Github repository)
### Used technology

## Start project
- `Layouts` are designed in Adobe XDesign
- `Devops` is runned by [Docker](https://www.docker.com/) & Apache virtual server
- `Frontend` is coded in HTML stylesheet [Latte](https://latte.nette.org/cs/)
- `Backend` is programmed in [PHP](https://www.php.net/) framework [Nette](https://nette.org/cs/)
- `Database` is build by MYSQL with [Adminer](https://www.adminer.org/cs/) interface & [Dibi](https://dibiphp.com/cs/) (database layer)

- start containers
```
docker-compse up -d
```
### Start project

- join php container
```
docker exec php bash
```
Run this command in Terminal & open `localhost:80` in Browser

- install dependencies
```
composer install
make init:env
```

- add `local.neon` file to `config` folder
```neon
parameters:

database:
dsn: 'mysql:host=127.0.0.1;dbname=test'
user:
password:
```

- run `localhost:80` in your browser
19 changes: 0 additions & 19 deletions app/Model/BaseRepository.php

This file was deleted.

12 changes: 12 additions & 0 deletions app/Model/Factory/LoginFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace App\Model\Factory;

use App\Module\components\Login\LoginControl;

interface LoginFactory
{
public function create(): LoginControl;
}
10 changes: 10 additions & 0 deletions app/Model/Mapper/BaseListTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace App\Model\Mapper;

abstract class BaseListTable
{
public int $id;
}
21 changes: 21 additions & 0 deletions app/Model/Mapper/Event.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace App\Model\Mapper;

use App\Model\Mapper\Trait\CreatedAt;
use App\Model\Mapper\Trait\EditedAt;
use DateTime;

class Event extends BaseListTable
{
use CreatedAt;
use EditedAt;

public string $title;

public DateTime|null $event_time;

public string|null $event_place;
}
12 changes: 12 additions & 0 deletions app/Model/Mapper/Trait/CreatedAt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace App\Model\Mapper\Trait;

use DateTime;

trait CreatedAt
{
public DateTime $createdAt;
}
12 changes: 12 additions & 0 deletions app/Model/Mapper/Trait/EditedAt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace App\Model\Mapper\Trait;

use DateTime;

trait EditedAt
{
public DateTime $editedAt;
}
18 changes: 18 additions & 0 deletions app/Model/Mapper/User.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace App\Model\Mapper;

use App\Model\Mapper\Trait\CreatedAt;
use App\Model\Mapper\Trait\EditedAt;

class User extends BaseListTable
{
use CreatedAt;
use EditedAt;

public string $email;

public string $password;
}
86 changes: 86 additions & 0 deletions app/Model/Repository/BaseRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

declare(strict_types=1);

namespace App\Model\Repository;

use Dibi\Connection;
use Dibi\Row;
use ReflectionClass;

/**
* @template T of Row
*/
abstract class BaseRepository
{
protected string $tableName;

public function __construct(
protected Connection $dibi
) {
$reflect = new ReflectionClass($this);
$repositoryName = str_replace('Repository', '', $reflect->getShortName());

$this->tableName = strtolower($repositoryName);
}

/**
* @return T
*/
public function find(mixed $id): Row|null
{
$result = $this->dibi->query("
SELECT * FROM {$this->tableName} WHERE id=?
",
$id
);

return $result->fetch();
}

/**
* @return T
*/
public function findOneBy(array $criteria, array|null $orderBy = null): Row|null
{
$query = "SELECT * FROM {$this->tableName} WHERE %and";

if ($orderBy) {
$query = $query . " ORDER BY %by";
}

$arguments = [
$query,
$criteria
];

if ($orderBy) {
$arguments[] = $orderBy;
}

$result = $this->dibi->query(...$arguments);

return $result->fetch();
}

/**
* @return array<array-key, T>
*/
public function findAll(): array
{
$result = $this->dibi->query("
SELECT * FROM {$this->tableName}
");

return $result->fetchAll();
}

public function getAllCount(): int
{
$result = $this->dibi->query("
SELECT * FROM {$this->tableName}
");

return $result->getRowCount();
}
}
38 changes: 12 additions & 26 deletions app/Model/Repository/EventRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,23 @@

namespace App\Model\Repository;

use App\Model\BaseRepository;
use App\Model\Mapper\Event;

/**
* @extends BaseRepository<Event>
*/
class EventRepository extends BaseRepository
{
private const TABLE = 'event';

public function findAll(): array
{
$result = $this->getDibiConnection()
->select('*')
->from(self::TABLE);

return $result->fetchAssoc('id');
}

public function getAllCount(): int
{
$result = $this->getDibiConnection()
->select('COUNT(id)')
->from(self::TABLE);

return $result->fetchSingle();
}

public function findAllForPaginator(int $limit, int $offset): array
{
$result = $this->getDibiConnection()
->select('*')
->from(self::TABLE)
->limit($limit)
->offset($offset);
$result = $this->dibi->query("
SELECT * FROM {$this->tableName}
LIMIT ?
OFFSET ?
",
$limit,
$offset
);

return $result->fetchAssoc('id');
}
Expand Down
Loading