Skip to content

Commit

Permalink
Release/v0.2.0 (#127)
Browse files Browse the repository at this point in the history
* fix(BodyData): Added default body data (#118)

* Update dependencies

* Add default value to body data

* feat(Migrations): Implemented db migrations (#119)

* Install doctrine migrations package

* Add migrations configuration

* Add migrations folder

* Update usefull commands

* Generates initial migration

* Load all migrations

* Update readme

* Update pr template

* Add foreign keys

* Rename workflow

* Move cache up

* Move checkout

* Release/v0.1.1 (#120) (#121)

* fix(BodyData): Added default body data (#118)

* Update dependencies

* Add default value to body data

* feat(Migrations): Implemented db migrations (#119)

* Install doctrine migrations package

* Add migrations configuration

* Add migrations folder

* Update usefull commands

* Generates initial migration

* Load all migrations

* Update readme

* Update pr template

* Add foreign keys

* Rename workflow

* Move cache up

* Move checkout

* Bump version

* Remove empty line

* feat(Created): Added created column (#122)

* Add created column

* Generate migration

* Add created column

* Generate migration

* Update dependencies

* Sort by created date

* Fix/rename users table (#123)

* Add migrations generate command

* Rename table

* Generate migration

* Fix migration

* Fix migration

* Fix ascii convertion (#125)

* feat(Menu): Implemented menu (#126)

* Update dependencies

* Add menu entity

* Add menu item entity

* Fix anotations

* Fix anotation

* Add DateTime type

* Generate migration

* Add menu controller

* Update return structure

* Bump version
  • Loading branch information
pchalupa authored Mar 10, 2021
1 parent edb524a commit f9f3988
Show file tree
Hide file tree
Showing 9 changed files with 580 additions and 127 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "stacha/back-end",
"type": "project",
"description": "Back-end for our applications.",
"version": "0.1.2",
"version": "0.2.0",
"license": "MIT",
"authors": [
{
Expand Down
226 changes: 113 additions & 113 deletions composer.lock

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions src/Controller/Menu.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace App\Controller;

use App\Controller\Base;
use App\Lib\Middleware\RouteFactory;
use Exception;

final class Menu extends Base
{
/**
* Register routes to router
*
* @param \App\Lib\Middleware\Router $router
* @return void
*/
public function registerRoutes(\App\Lib\Middleware\Router $router): void
{
$router->register(RouteFactory::fromConstants(1, "GET", "@^(?<version>[0-9]+)/menu/(?<id>[0-9]+)$@", "getOneById", array("id")));
}

/**
* Gets one menu by ID
*
* @param int $id
* @return \App\Model\Entity\Menu
*/
public function getOneById(int $id): \App\Model\Entity\Menu
{
$menu = $this->entityManager->getRepository('App\Model\Entity\Menu')->findOneBy(array('id' => $id));

if ($menu instanceof \App\Model\Entity\Menu) {
$items = [];
foreach ($menu->getItems() as $item) {
array_push($items, array('title' => $item->getTitle(), 'target' => $item->getTarget(), "updated" => $menu->getUpdated(), 'created' => $menu->getCreated(), "state" => $menu->getState()));
}

$this->view->render(["title" => $menu->getTitle(), "items" => $items, "updated" => $menu->getUpdated(), 'created' => $menu->getCreated(), "state" => $menu->getState()]);

return $menu;
} else {
throw new Exception("Menu with ID:" . $id . " can not be founded!", 404);
}
}
}
28 changes: 16 additions & 12 deletions src/Lib/Util/Input.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,23 @@ class Input
*/
public static function toAscii(string $input): string
{
$input = preg_replace('#[^\x09\x0A\x0D\x20-\x7E\xA0-\x{2FF}\x{370}-\x{10FFFF}]#u', '', $input) ?? "";
$input = (string)preg_replace('#[^\x09\x0A\x0D\x20-\x7E\xA0-\x{2FF}\x{370}-\x{10FFFF}]#u', '', $input);
$input = strtr($input, '`\'"^~', "\x01\x02\x03\x04\x05");
$input = (string)iconv('UTF-8', 'ASCII//TRANSLIT', $input);
$input = strtr(
$input,
"\xa5\xa3\xbc\x8c\xa7\x8a\xaa\x8d\x8f\x8e\xaf\xb9\xb3\xbe\x9c\x9a\xba\x9d\x9f\x9e"
. "\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3"
. "\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8"
. "\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf8\xf9\xfa\xfb\xfc\xfd\xfe\x96",
"ALLSSSSTZZZallssstzzzRAAAALCCCEEEEIIDDNNOOOOxRUUUUYTsraaaalccceeeeiiddnnooooruuuuyt-"
);
$input = str_replace(array('`', "'", '"', '^', '~'), '', $input);
return (string)strtr($input, "\x01\x02\x03\x04\x05", '`\'"^~');
if (ICONV_IMPL === 'glibc') {
$input = @iconv('UTF-8', 'WINDOWS-1250//TRANSLIT', $input); // intentionally @
$input = strtr(
(string)$input,
"\xa5\xa3\xbc\x8c\xa7\x8a\xaa\x8d\x8f\x8e\xaf\xb9\xb3\xbe\x9c\x9a\xba\x9d\x9f\x9e"
. "\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3"
. "\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8"
. "\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf8\xf9\xfa\xfb\xfc\xfd\xfe\x96",
"ALLSSSSTZZZallssstzzzRAAAALCCCEEEEIIDDNNOOOOxRUUUUYTsraaaalccceeeeiiddnnooooruuuuyt-"
);
} else {
$input = @iconv('UTF-8', 'ASCII//TRANSLIT', $input); // intentionally @
}
$input = str_replace(array('`', "'", '"', '^', '~'), '', (string)$input);
return strtr($input, "\x01\x02\x03\x04\x05", '`\'"^~');
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Model/Entity/Gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class Gallery
* @param string $title
* @param string $description
* @param string $alias
* @param bool $state
*/
public function __construct(string $title = "", string $description = "", string $alias = "", bool $state = true)
{
Expand Down
173 changes: 173 additions & 0 deletions src/Model/Entity/Menu.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
<?php

declare(strict_types=1);

namespace App\Model\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\PersistentCollection;
use DateTime;

/**
* @ORM\Entity
* @ORM\Table(name="menu")
*/
class Menu
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
* @var int
*/
protected $id;

/**
* @ORM\Column(type="string", length=512)
* @var string
*/
protected $title;

/**
* @ORM\OneToMany(targetEntity="MenuItem", mappedBy="menu")
* @var PersistentCollection<MenuItem>
*/
protected $items;

/**
* @ORM\Column(type="datetime", nullable=false)
* @ORM\Version
* @var DateTime
*/
protected $updated;

/**
* @ORM\Column(type="datetime", nullable=false)
* @var DateTime
*/
protected $created;

/**
* @ORM\Column(type="boolean")
* @var boolean
*/
protected $state;

/**
* @param string $title
* @param bool $state
*/
public function __construct(string $title = "", bool $state = true)
{
$this->setTitle($title);
$this->setCreated(new DateTime("now"));
$this->setState($state);
}

/**
* Sets title
*
* @param string $title
* @return self
*/
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}

/**
* Sets updated date
*
* @return self
*/
public function setUpdated(): self
{
$this->updated = new DateTime("now");
return $this;
}

/**
* Sets created date
*
* @param DateTime $created
* @return self
*/
public function setCreated(DateTime $created): self
{
$this->created = $created;
return $this;
}

/**
* Sets state
*
* @param boolean $state
* @return self
*/
public function setState(bool $state): self
{
$this->state = $state;
return $this;
}

/**
* Return ID
*
* @return integer
*/
public function getId(): int
{
return $this->id;
}

/**
* Returns title
*
* @return string
*/
public function getTitle(): string
{
return $this->title;
}

/**
* Returns menu items associated to menu entity
*
* @return PersistentCollection<MenuItem>
*/
public function getItems(): PersistentCollection
{
return $this->items;
}

/**
* Returns updated date
*
* @return DateTime
*/
public function getUpdated(): DateTime
{
return $this->updated;
}

/**
* Returns created date
*
* @return DateTime
*/
public function getCreated(): DateTime
{
return $this->created;
}

/**
* Returns state
*
* @return boolean
*/
public function getState(): bool
{
return $this->state;
}
}
Loading

0 comments on commit f9f3988

Please sign in to comment.