Skip to content

Commit f9f3988

Browse files
authored
Release/v0.2.0 (#127)
* 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
1 parent edb524a commit f9f3988

File tree

9 files changed

+580
-127
lines changed

9 files changed

+580
-127
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "stacha/back-end",
33
"type": "project",
44
"description": "Back-end for our applications.",
5-
"version": "0.1.2",
5+
"version": "0.2.0",
66
"license": "MIT",
77
"authors": [
88
{

composer.lock

Lines changed: 113 additions & 113 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Controller/Menu.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Controller;
6+
7+
use App\Controller\Base;
8+
use App\Lib\Middleware\RouteFactory;
9+
use Exception;
10+
11+
final class Menu extends Base
12+
{
13+
/**
14+
* Register routes to router
15+
*
16+
* @param \App\Lib\Middleware\Router $router
17+
* @return void
18+
*/
19+
public function registerRoutes(\App\Lib\Middleware\Router $router): void
20+
{
21+
$router->register(RouteFactory::fromConstants(1, "GET", "@^(?<version>[0-9]+)/menu/(?<id>[0-9]+)$@", "getOneById", array("id")));
22+
}
23+
24+
/**
25+
* Gets one menu by ID
26+
*
27+
* @param int $id
28+
* @return \App\Model\Entity\Menu
29+
*/
30+
public function getOneById(int $id): \App\Model\Entity\Menu
31+
{
32+
$menu = $this->entityManager->getRepository('App\Model\Entity\Menu')->findOneBy(array('id' => $id));
33+
34+
if ($menu instanceof \App\Model\Entity\Menu) {
35+
$items = [];
36+
foreach ($menu->getItems() as $item) {
37+
array_push($items, array('title' => $item->getTitle(), 'target' => $item->getTarget(), "updated" => $menu->getUpdated(), 'created' => $menu->getCreated(), "state" => $menu->getState()));
38+
}
39+
40+
$this->view->render(["title" => $menu->getTitle(), "items" => $items, "updated" => $menu->getUpdated(), 'created' => $menu->getCreated(), "state" => $menu->getState()]);
41+
42+
return $menu;
43+
} else {
44+
throw new Exception("Menu with ID:" . $id . " can not be founded!", 404);
45+
}
46+
}
47+
}

src/Lib/Util/Input.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,23 @@ class Input
1717
*/
1818
public static function toAscii(string $input): string
1919
{
20-
$input = preg_replace('#[^\x09\x0A\x0D\x20-\x7E\xA0-\x{2FF}\x{370}-\x{10FFFF}]#u', '', $input) ?? "";
20+
$input = (string)preg_replace('#[^\x09\x0A\x0D\x20-\x7E\xA0-\x{2FF}\x{370}-\x{10FFFF}]#u', '', $input);
2121
$input = strtr($input, '`\'"^~', "\x01\x02\x03\x04\x05");
22-
$input = (string)iconv('UTF-8', 'ASCII//TRANSLIT', $input);
23-
$input = strtr(
24-
$input,
25-
"\xa5\xa3\xbc\x8c\xa7\x8a\xaa\x8d\x8f\x8e\xaf\xb9\xb3\xbe\x9c\x9a\xba\x9d\x9f\x9e"
26-
. "\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3"
27-
. "\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8"
28-
. "\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf8\xf9\xfa\xfb\xfc\xfd\xfe\x96",
29-
"ALLSSSSTZZZallssstzzzRAAAALCCCEEEEIIDDNNOOOOxRUUUUYTsraaaalccceeeeiiddnnooooruuuuyt-"
30-
);
31-
$input = str_replace(array('`', "'", '"', '^', '~'), '', $input);
32-
return (string)strtr($input, "\x01\x02\x03\x04\x05", '`\'"^~');
22+
if (ICONV_IMPL === 'glibc') {
23+
$input = @iconv('UTF-8', 'WINDOWS-1250//TRANSLIT', $input); // intentionally @
24+
$input = strtr(
25+
(string)$input,
26+
"\xa5\xa3\xbc\x8c\xa7\x8a\xaa\x8d\x8f\x8e\xaf\xb9\xb3\xbe\x9c\x9a\xba\x9d\x9f\x9e"
27+
. "\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3"
28+
. "\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8"
29+
. "\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf8\xf9\xfa\xfb\xfc\xfd\xfe\x96",
30+
"ALLSSSSTZZZallssstzzzRAAAALCCCEEEEIIDDNNOOOOxRUUUUYTsraaaalccceeeeiiddnnooooruuuuyt-"
31+
);
32+
} else {
33+
$input = @iconv('UTF-8', 'ASCII//TRANSLIT', $input); // intentionally @
34+
}
35+
$input = str_replace(array('`', "'", '"', '^', '~'), '', (string)$input);
36+
return strtr($input, "\x01\x02\x03\x04\x05", '`\'"^~');
3337
}
3438

3539
/**

src/Model/Entity/Gallery.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class Gallery
7979
* @param string $title
8080
* @param string $description
8181
* @param string $alias
82+
* @param bool $state
8283
*/
8384
public function __construct(string $title = "", string $description = "", string $alias = "", bool $state = true)
8485
{

src/Model/Entity/Menu.php

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Model\Entity;
6+
7+
use Doctrine\ORM\Mapping as ORM;
8+
use Doctrine\ORM\PersistentCollection;
9+
use DateTime;
10+
11+
/**
12+
* @ORM\Entity
13+
* @ORM\Table(name="menu")
14+
*/
15+
class Menu
16+
{
17+
/**
18+
* @ORM\Id
19+
* @ORM\Column(type="integer")
20+
* @ORM\GeneratedValue
21+
* @var int
22+
*/
23+
protected $id;
24+
25+
/**
26+
* @ORM\Column(type="string", length=512)
27+
* @var string
28+
*/
29+
protected $title;
30+
31+
/**
32+
* @ORM\OneToMany(targetEntity="MenuItem", mappedBy="menu")
33+
* @var PersistentCollection<MenuItem>
34+
*/
35+
protected $items;
36+
37+
/**
38+
* @ORM\Column(type="datetime", nullable=false)
39+
* @ORM\Version
40+
* @var DateTime
41+
*/
42+
protected $updated;
43+
44+
/**
45+
* @ORM\Column(type="datetime", nullable=false)
46+
* @var DateTime
47+
*/
48+
protected $created;
49+
50+
/**
51+
* @ORM\Column(type="boolean")
52+
* @var boolean
53+
*/
54+
protected $state;
55+
56+
/**
57+
* @param string $title
58+
* @param bool $state
59+
*/
60+
public function __construct(string $title = "", bool $state = true)
61+
{
62+
$this->setTitle($title);
63+
$this->setCreated(new DateTime("now"));
64+
$this->setState($state);
65+
}
66+
67+
/**
68+
* Sets title
69+
*
70+
* @param string $title
71+
* @return self
72+
*/
73+
public function setTitle(string $title): self
74+
{
75+
$this->title = $title;
76+
return $this;
77+
}
78+
79+
/**
80+
* Sets updated date
81+
*
82+
* @return self
83+
*/
84+
public function setUpdated(): self
85+
{
86+
$this->updated = new DateTime("now");
87+
return $this;
88+
}
89+
90+
/**
91+
* Sets created date
92+
*
93+
* @param DateTime $created
94+
* @return self
95+
*/
96+
public function setCreated(DateTime $created): self
97+
{
98+
$this->created = $created;
99+
return $this;
100+
}
101+
102+
/**
103+
* Sets state
104+
*
105+
* @param boolean $state
106+
* @return self
107+
*/
108+
public function setState(bool $state): self
109+
{
110+
$this->state = $state;
111+
return $this;
112+
}
113+
114+
/**
115+
* Return ID
116+
*
117+
* @return integer
118+
*/
119+
public function getId(): int
120+
{
121+
return $this->id;
122+
}
123+
124+
/**
125+
* Returns title
126+
*
127+
* @return string
128+
*/
129+
public function getTitle(): string
130+
{
131+
return $this->title;
132+
}
133+
134+
/**
135+
* Returns menu items associated to menu entity
136+
*
137+
* @return PersistentCollection<MenuItem>
138+
*/
139+
public function getItems(): PersistentCollection
140+
{
141+
return $this->items;
142+
}
143+
144+
/**
145+
* Returns updated date
146+
*
147+
* @return DateTime
148+
*/
149+
public function getUpdated(): DateTime
150+
{
151+
return $this->updated;
152+
}
153+
154+
/**
155+
* Returns created date
156+
*
157+
* @return DateTime
158+
*/
159+
public function getCreated(): DateTime
160+
{
161+
return $this->created;
162+
}
163+
164+
/**
165+
* Returns state
166+
*
167+
* @return boolean
168+
*/
169+
public function getState(): bool
170+
{
171+
return $this->state;
172+
}
173+
}

0 commit comments

Comments
 (0)