Init
This commit is contained in:
14
app/model/App.php
Normal file
14
app/model/App.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
final class App
|
||||
{
|
||||
|
||||
public const DESTINATION_FRONT_HOMEPAGE = ':Front:Home:';
|
||||
public const DESTINATION_ADMIN_HOMEPAGE = ':Admin:Home:';
|
||||
public const DESTINATION_SIGN_IN = ':Admin:Sign:in';
|
||||
public const DESTINATION_AFTER_SIGN_IN = self::DESTINATION_ADMIN_HOMEPAGE;
|
||||
public const DESTINATION_AFTER_SIGN_OUT = self::DESTINATION_FRONT_HOMEPAGE;
|
||||
|
||||
}
|
||||
25
app/model/Console/HelloCommand.php
Normal file
25
app/model/Console/HelloCommand.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Console;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class HelloCommand extends Command
|
||||
{
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->setName('hello');
|
||||
$this->setDescription('Hello world!');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$output->write('Hello world!');
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
8
app/model/Database/Entity/AbstractEntity.php
Normal file
8
app/model/Database/Entity/AbstractEntity.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Database\Entity;
|
||||
|
||||
abstract class AbstractEntity
|
||||
{
|
||||
|
||||
}
|
||||
33
app/model/Database/Entity/Attributes/TCreatedAt.php
Normal file
33
app/model/Database/Entity/Attributes/TCreatedAt.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Database\Entity\Attributes;
|
||||
|
||||
use App\Model\Utils\DateTime;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
trait TCreatedAt
|
||||
{
|
||||
|
||||
/**
|
||||
* @var DateTime
|
||||
* @ORM\Column(type="datetime", nullable=FALSE)
|
||||
*/
|
||||
protected $createdAt;
|
||||
|
||||
public function getCreatedAt(): DateTime
|
||||
{
|
||||
return $this->createdAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Doctrine annotation
|
||||
*
|
||||
* @ORM\PrePersist
|
||||
* @internal
|
||||
*/
|
||||
public function setCreatedAt(): void
|
||||
{
|
||||
$this->createdAt = new DateTime();
|
||||
}
|
||||
|
||||
}
|
||||
27
app/model/Database/Entity/Attributes/TId.php
Normal file
27
app/model/Database/Entity/Attributes/TId.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Database\Entity\Attributes;
|
||||
|
||||
trait TId
|
||||
{
|
||||
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Column(type="integer", nullable=FALSE)
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue
|
||||
*/
|
||||
private $id;
|
||||
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
|
||||
public function __clone()
|
||||
{
|
||||
$this->id = null;
|
||||
}
|
||||
|
||||
}
|
||||
33
app/model/Database/Entity/Attributes/TUpdatedAt.php
Normal file
33
app/model/Database/Entity/Attributes/TUpdatedAt.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Database\Entity\Attributes;
|
||||
|
||||
use App\Model\Utils\DateTime;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
trait TUpdatedAt
|
||||
{
|
||||
|
||||
/**
|
||||
* @var DateTime|NULL
|
||||
* @ORM\Column(type="datetime", nullable=TRUE)
|
||||
*/
|
||||
protected $updatedAt;
|
||||
|
||||
public function getUpdatedAt(): ?DateTime
|
||||
{
|
||||
return $this->updatedAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Doctrine annotation
|
||||
*
|
||||
* @ORM\PreUpdate
|
||||
* @internal
|
||||
*/
|
||||
public function setUpdatedAt(): void
|
||||
{
|
||||
$this->updatedAt = new DateTime();
|
||||
}
|
||||
|
||||
}
|
||||
48
app/model/Database/Entity/DictType.php
Normal file
48
app/model/Database/Entity/DictType.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model\Database\Entity;
|
||||
|
||||
use App\Model\Database\Entity\Attributes\TCreatedAt;
|
||||
use App\Model\Database\Entity\Attributes\TId;
|
||||
use App\Model\Database\Entity\Attributes\TUpdatedAt;
|
||||
use App\Model\Exception\Logic\InvalidArgumentException;
|
||||
use App\Model\Security\Identity;
|
||||
use App\Model\Utils\DateTime;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class DictType extends AbstractEntity
|
||||
{
|
||||
use TId;
|
||||
|
||||
public function __construct($short_name,$full_name)
|
||||
{
|
||||
$this->shortName = $short_name;
|
||||
$this->fullName = $full_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $shortName;
|
||||
|
||||
public function getShortName()
|
||||
{
|
||||
return $this->shortName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $fullName;
|
||||
|
||||
public function getFullName()
|
||||
{
|
||||
return $this->fullName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
76
app/model/Database/Entity/Dictionary.php
Normal file
76
app/model/Database/Entity/Dictionary.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model\Database\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use App\Model\Database\Entity\Attributes\TId;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class Dictionary extends AbstractEntity
|
||||
{
|
||||
|
||||
use Tid;
|
||||
|
||||
public function __construct($name,$fullname)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->fullName = $fullname;
|
||||
$this->translations = new \Doctrine\Common\Collections\ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="App\Model\Database\Entity\Translation", mappedBy="dictionary", cascade={"persist"})
|
||||
* @var Article[]|\Doctrine\Common\Collections\ArrayCollection
|
||||
*/
|
||||
protected $translations;
|
||||
|
||||
public function getTranslations()
|
||||
{
|
||||
return $this->translations;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Language", inversedBy="lang1_dicionaries")
|
||||
*/
|
||||
protected $lang1;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Language", inversedBy="lang2_dicionaries")
|
||||
*/
|
||||
protected $lang2;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $fullName;
|
||||
|
||||
public function setLang1($lang1)
|
||||
{
|
||||
$this->lang1 = $lang1;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setLang2($lang2)
|
||||
{
|
||||
$this->lang2 = $lang2;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
54
app/model/Database/Entity/Language.php
Normal file
54
app/model/Database/Entity/Language.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model\Database\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use App\Model\Database\Entity\Attributes\TId;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class Language extends AbstractEntity
|
||||
{
|
||||
|
||||
use Tid;
|
||||
|
||||
public function __construct($shortname,$name)
|
||||
{
|
||||
$this->shortName = $shortname;
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string",length=2, unique=true, options={"fixed" = true})
|
||||
*/
|
||||
protected $shortName;
|
||||
|
||||
public function getShortName()
|
||||
{
|
||||
return $this->shortName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string",length=32)
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/*
|
||||
* @ORM\OneToMany(targetEntity="Dictionary", mappedBy="language")
|
||||
*/
|
||||
protected $dictionaries1;
|
||||
|
||||
/*
|
||||
* @ORM\OneToMany(targetEntity="Dictionary", mappedBy="language")
|
||||
*/
|
||||
protected $dictionaries2;
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
46
app/model/Database/Entity/Pronunciation.php
Normal file
46
app/model/Database/Entity/Pronunciation.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model\Database\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use App\Model\Database\Entity\Attributes\TId;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class Pronunciation extends AbstractEntity
|
||||
{
|
||||
|
||||
use Tid;
|
||||
|
||||
public function __construct($type,$ipa,$filename=null)
|
||||
{
|
||||
$this->type = $type;
|
||||
$this->ipa = $ipa;
|
||||
$this->filename = $filename;
|
||||
$this->terms = new \Doctrine\Common\Collections\ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity="Term", mappedBy="pronunciations")
|
||||
*/
|
||||
private $terms;
|
||||
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="PronunciationType", inversedBy="pronunciations")
|
||||
*/
|
||||
protected $type;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string",nullable=true)
|
||||
*/
|
||||
protected $ipa;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", nullable=true)
|
||||
*/
|
||||
protected $filename;
|
||||
}
|
||||
|
||||
?>
|
||||
32
app/model/Database/Entity/PronunciationTypes.php
Normal file
32
app/model/Database/Entity/PronunciationTypes.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model\Database\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use App\Model\Database\Entity\Attributes\Tid;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class PronunciationType extends AbstractEntity
|
||||
{
|
||||
use Tid;
|
||||
|
||||
public function __construct($name,$fullName)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->fullName = $fullName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $fullName;
|
||||
}
|
||||
|
||||
?>
|
||||
32
app/model/Database/Entity/Suffix.php
Normal file
32
app/model/Database/Entity/Suffix.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model\Database\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use App\Model\Database\Entity\Attributes\TId;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class Suffix extends AbstractEntity
|
||||
{
|
||||
use Tid;
|
||||
|
||||
public function __construct($text)
|
||||
{
|
||||
$this->text = $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $text;
|
||||
|
||||
|
||||
public function getText()
|
||||
{
|
||||
return $this->text;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
42
app/model/Database/Entity/Term.php
Normal file
42
app/model/Database/Entity/Term.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model\Database\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use App\Model\Database\Entity\Attributes\TId;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(indexes={@ORM\Index(columns={"string1"}, flags={"fulltext"}),
|
||||
@ORM\Index(columns={"string2"}, flags={"fulltext"})})
|
||||
*/
|
||||
class Term extends AbstractEntity
|
||||
{
|
||||
|
||||
use Tid;
|
||||
|
||||
public function __construct(Dictionary $dictionary,$string)
|
||||
{
|
||||
$this->dictionary = $dictionary;
|
||||
$this->string1 = $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Dictionary", inversedBy="fullDict",cascade={"persist", "remove" })
|
||||
*/
|
||||
protected $dictionary;
|
||||
|
||||
/**
|
||||
* Get id
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
90
app/model/Database/Entity/TermFlag.php
Normal file
90
app/model/Database/Entity/TermFlag.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model\Database\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use App\Model\Database\Entity\Attributes\TId;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class TermFlag extends AbstractEntity
|
||||
{
|
||||
|
||||
use Tid;
|
||||
|
||||
public function __construct($id,$class,$language,$code,$description)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->class = $class;
|
||||
$this->language = $language;
|
||||
$this->code = $code;
|
||||
$this->description = $description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="WordClass", inversedBy="flags")
|
||||
*/
|
||||
protected $class;
|
||||
|
||||
public function getClass()
|
||||
{
|
||||
return $this->class;
|
||||
}
|
||||
|
||||
public function setClass($class)
|
||||
{
|
||||
$this->class = $class;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Language", inversedBy="flags")
|
||||
*/
|
||||
protected $language;
|
||||
|
||||
public function getLanguage()
|
||||
{
|
||||
return $this->language;
|
||||
}
|
||||
|
||||
public function setLanguage($language)
|
||||
{
|
||||
$this->language = $language;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $code;
|
||||
|
||||
public function getCode()
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
public function setCode($code)
|
||||
{
|
||||
$this->code = $code;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $description;
|
||||
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
public function setDescription($description)
|
||||
{
|
||||
$this->description = $description;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
77
app/model/Database/Entity/Translation.php
Normal file
77
app/model/Database/Entity/Translation.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model\Database\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use App\Model\Database\Entity\Attributes\TId;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class Translation extends AbstractEntity
|
||||
{
|
||||
|
||||
use Tid;
|
||||
|
||||
public function __construct($dictionary,$lang1,$lang2,$lang_name1,$lang_name2,$direction)
|
||||
{
|
||||
$this->dictionary = $dictionary;
|
||||
$this->lang1 = $lang1;
|
||||
$this->lang2 = $lang2;
|
||||
$this->lang_name1 = $lang_name1;
|
||||
$this->lang_name2 = $lang_name2;
|
||||
$this->direction = $direction;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Dictionary", inversedBy="translations")
|
||||
*/
|
||||
protected $dictionary;
|
||||
|
||||
public function getDictionary()
|
||||
{
|
||||
return $this->dictionary;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Language", inversedBy="translations1")
|
||||
*/
|
||||
protected $lang1;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Language", inversedBy="translations2")
|
||||
*/
|
||||
protected $lang2;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $lang_name1;
|
||||
|
||||
public function getLangName1()
|
||||
{
|
||||
return $this->lang_name1;
|
||||
}
|
||||
/**
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $lang_name2;
|
||||
|
||||
public function getLangName2()
|
||||
{
|
||||
return $this->lang_name2;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="smallint")
|
||||
*/
|
||||
protected $direction;
|
||||
|
||||
public function getDirection()
|
||||
{
|
||||
return $this->direction;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
205
app/model/Database/Entity/User.php
Normal file
205
app/model/Database/Entity/User.php
Normal file
@@ -0,0 +1,205 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Database\Entity;
|
||||
|
||||
use App\Model\Database\Entity\Attributes\TCreatedAt;
|
||||
use App\Model\Database\Entity\Attributes\TId;
|
||||
use App\Model\Database\Entity\Attributes\TUpdatedAt;
|
||||
use App\Model\Exception\Logic\InvalidArgumentException;
|
||||
use App\Model\Security\Identity;
|
||||
use App\Model\Utils\DateTime;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity(repositoryClass="App\Model\Database\Repository\UserRepository")
|
||||
* @ORM\Table(name="`user`")
|
||||
* @ORM\HasLifecycleCallbacks
|
||||
*/
|
||||
class User extends AbstractEntity
|
||||
{
|
||||
|
||||
public const ROLE_ADMIN = 'admin';
|
||||
public const ROLE_USER = 'user';
|
||||
|
||||
public const STATE_FRESH = 1;
|
||||
public const STATE_ACTIVATED = 2;
|
||||
public const STATE_BLOCKED = 3;
|
||||
|
||||
public const STATES = [self::STATE_FRESH, self::STATE_BLOCKED, self::STATE_ACTIVATED];
|
||||
|
||||
use TId;
|
||||
use TCreatedAt;
|
||||
use TUpdatedAt;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @ORM\Column(type="string", length=255, nullable=FALSE, unique=false)
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @ORM\Column(type="string", length=255, nullable=FALSE, unique=false)
|
||||
*/
|
||||
private $surname;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @ORM\Column(type="string", length=255, nullable=FALSE, unique=TRUE)
|
||||
*/
|
||||
private $email;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @ORM\Column(type="string", length=255, nullable=FALSE, unique=TRUE)
|
||||
*/
|
||||
private $username;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Column(type="integer", length=10, nullable=FALSE)
|
||||
*/
|
||||
private $state;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @ORM\Column(type="string", length=255, nullable=FALSE)
|
||||
*/
|
||||
private $password;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @ORM\Column(type="string", length=255, nullable=FALSE)
|
||||
*/
|
||||
private $role;
|
||||
|
||||
/**
|
||||
* @var DateTime|NULL
|
||||
* @ORM\Column(type="datetime", nullable=TRUE)
|
||||
*/
|
||||
private $lastLoggedAt;
|
||||
|
||||
public function __construct(string $name, string $surname, string $email, string $username, string $passwordHash)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->surname = $surname;
|
||||
$this->email = $email;
|
||||
$this->username = $username;
|
||||
$this->password = $passwordHash;
|
||||
|
||||
$this->role = self::ROLE_USER;
|
||||
$this->state = self::STATE_FRESH;
|
||||
}
|
||||
|
||||
public function changeLoggedAt(): void
|
||||
{
|
||||
$this->lastLoggedAt = new DateTime();
|
||||
}
|
||||
|
||||
public function getEmail(): string
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
public function getUsername(): string
|
||||
{
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
public function changeUsername(string $username): void
|
||||
{
|
||||
$this->username = $username;
|
||||
}
|
||||
|
||||
public function getLastLoggedAt(): ?DateTime
|
||||
{
|
||||
return $this->lastLoggedAt;
|
||||
}
|
||||
|
||||
public function getRole(): string
|
||||
{
|
||||
return $this->role;
|
||||
}
|
||||
|
||||
public function setRole(string $role): void
|
||||
{
|
||||
$this->role = $role;
|
||||
}
|
||||
|
||||
public function getPasswordHash(): string
|
||||
{
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
public function changePasswordHash(string $password): void
|
||||
{
|
||||
$this->password = $password;
|
||||
}
|
||||
|
||||
public function block(): void
|
||||
{
|
||||
$this->state = self::STATE_BLOCKED;
|
||||
}
|
||||
|
||||
public function activate(): void
|
||||
{
|
||||
$this->state = self::STATE_ACTIVATED;
|
||||
}
|
||||
|
||||
public function isActivated(): bool
|
||||
{
|
||||
return $this->state === self::STATE_ACTIVATED;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function getSurname(): string
|
||||
{
|
||||
return $this->surname;
|
||||
}
|
||||
|
||||
public function getFullname(): string
|
||||
{
|
||||
return $this->name . ' ' . $this->surname;
|
||||
}
|
||||
|
||||
public function rename(string $name, string $surname): void
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->surname = $surname;
|
||||
}
|
||||
|
||||
public function getState(): int
|
||||
{
|
||||
return $this->state;
|
||||
}
|
||||
|
||||
public function setState(int $state): void
|
||||
{
|
||||
if (!in_array($state, self::STATES)) {
|
||||
throw new InvalidArgumentException(sprintf('Unsupported state %s', $state));
|
||||
}
|
||||
|
||||
$this->state = $state;
|
||||
}
|
||||
|
||||
public function getGravatar(): string
|
||||
{
|
||||
return 'https://www.gravatar.com/avatar/' . md5($this->email);
|
||||
}
|
||||
|
||||
public function toIdentity(): Identity
|
||||
{
|
||||
return new Identity($this->getId(), [$this->role], [
|
||||
'email' => $this->email,
|
||||
'name' => $this->name,
|
||||
'surname' => $this->surname,
|
||||
'state' => $this->state,
|
||||
'gravatar' => $this->getGravatar(),
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
49
app/model/Database/Entity/WordClass.php
Normal file
49
app/model/Database/Entity/WordClass.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model\Database\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use App\Model\Database\Entity\Attributes\TId;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class WordClass extends AbstractEntity
|
||||
{
|
||||
|
||||
use Tid;
|
||||
|
||||
public function __construct($id,$name)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function setId($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
return $id;
|
||||
}
|
||||
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
28
app/model/Database/EntityManager.php
Normal file
28
app/model/Database/EntityManager.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Database;
|
||||
|
||||
use App\Model\Database\Repository\AbstractRepository;
|
||||
use Doctrine\Persistence\ObjectRepository;
|
||||
use Nettrine\ORM\EntityManagerDecorator;
|
||||
|
||||
class EntityManager extends EntityManagerDecorator
|
||||
{
|
||||
|
||||
use TRepositories;
|
||||
|
||||
/**
|
||||
* @param string $entityName
|
||||
* @return AbstractRepository<T>|ObjectRepository<T>
|
||||
* @internal
|
||||
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
|
||||
* @phpstan-template T of object
|
||||
* @phpstan-param class-string<T> $entityName
|
||||
* @phpstan-return ObjectRepository<T>
|
||||
*/
|
||||
public function getRepository($entityName): ObjectRepository
|
||||
{
|
||||
return parent::getRepository($entityName);
|
||||
}
|
||||
|
||||
}
|
||||
49
app/model/Database/Repository/AbstractRepository.php
Normal file
49
app/model/Database/Repository/AbstractRepository.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Database\Repository;
|
||||
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
|
||||
/**
|
||||
* @phpstan-template TEntityClass of object
|
||||
* @phpstan-extends EntityRepository<TEntityClass>
|
||||
*/
|
||||
abstract class AbstractRepository extends EntityRepository
|
||||
{
|
||||
|
||||
/**
|
||||
* Fetches all records like $key => $value pairs
|
||||
*
|
||||
* @param mixed[] $criteria
|
||||
* @param mixed[] $orderBy
|
||||
* @return mixed[]
|
||||
*/
|
||||
public function findPairs(?string $key, string $value, array $criteria = [], array $orderBy = []): array
|
||||
{
|
||||
if ($key === null) {
|
||||
$key = $this->getClassMetadata()->getSingleIdentifierFieldName();
|
||||
}
|
||||
|
||||
$qb = $this->createQueryBuilder('e')
|
||||
->select(['e.' . $value, 'e.' . $key])
|
||||
->resetDQLPart('from')
|
||||
->from($this->getEntityName(), 'e', 'e.' . $key);
|
||||
|
||||
foreach ($criteria as $k => $v) {
|
||||
if (is_array($v)) {
|
||||
$qb->andWhere(sprintf('e.%s IN(:%s)', $k, $k))->setParameter($k, array_values($v));
|
||||
} else {
|
||||
$qb->andWhere(sprintf('e.%s = :%s', $k, $k))->setParameter($k, $v);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($orderBy as $column => $order) {
|
||||
$qb->addOrderBy($column, $order);
|
||||
}
|
||||
|
||||
return array_map(function ($row) {
|
||||
return reset($row);
|
||||
}, $qb->getQuery()->getArrayResult());
|
||||
}
|
||||
|
||||
}
|
||||
38
app/model/Database/Repository/DictTypes.php
Normal file
38
app/model/Database/Repository/DictTypes.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
namespace App;
|
||||
|
||||
use Kdyby;
|
||||
use Nette;
|
||||
|
||||
class DictTypes extends Nette\Object
|
||||
{
|
||||
private $em;
|
||||
private $dicttypes;
|
||||
|
||||
public function __construct(Kdyby\Doctrine\EntityManager $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->dicttypes = $em->getRepository(DictType::class);
|
||||
}
|
||||
|
||||
public function find($value)
|
||||
{
|
||||
return $this->dicttypes->find($value);
|
||||
}
|
||||
|
||||
|
||||
public function findBy($criteria = [],$orderBy = [])
|
||||
{
|
||||
return $this->dicttypes->findBy($criteria,$orderBy);
|
||||
}
|
||||
|
||||
public function findPairs($criteria,$value,$orderBy,$key)
|
||||
{
|
||||
return $this->dicttypes->findPairs($criteria,$value,$orderBy,$key);
|
||||
}
|
||||
|
||||
public function findAssoc($criteria, $key = NULL)
|
||||
{
|
||||
return $this->dicttypes->findAssoc($criteria,$key);
|
||||
}
|
||||
}
|
||||
27
app/model/Database/Repository/Dictionaries.php
Normal file
27
app/model/Database/Repository/Dictionaries.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace App;
|
||||
|
||||
use Kdyby;
|
||||
use Nette;
|
||||
|
||||
class Dictionaries extends Nette\Object
|
||||
{
|
||||
private $em;
|
||||
private $dictionaries;
|
||||
|
||||
public function __construct(Kdyby\Doctrine\EntityManager $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->dictionaries = $em->getRepository(Dictionary::class);
|
||||
}
|
||||
|
||||
public function findAll($criteria = [],$orderBy = [])
|
||||
{
|
||||
return $this->dictionaries->findBy($criteria,$orderBy);
|
||||
}
|
||||
|
||||
public function findPairs($criteria,$value,$orderBy,$key)
|
||||
{
|
||||
return $this->dictionaries->findPairs($criteria,$value,$orderBy,$key);
|
||||
}
|
||||
}
|
||||
33
app/model/Database/Repository/Pronunciations.php
Normal file
33
app/model/Database/Repository/Pronunciations.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace App;
|
||||
|
||||
use Kdyby;
|
||||
use Nette;
|
||||
|
||||
class Pronunciations extends Nette\Object
|
||||
{
|
||||
private $em;
|
||||
private $pronunciations;
|
||||
|
||||
public function __construct(Kdyby\Doctrine\EntityManager $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->pronunciations = $em->getRepository(Pronunciation::class);
|
||||
}
|
||||
|
||||
public function find($value)
|
||||
{
|
||||
return $this->pronunciations->find($value);
|
||||
}
|
||||
|
||||
|
||||
public function findBy($criteria = [],$orderBy = [])
|
||||
{
|
||||
return $this->pronunciations->findBy($criteria,$orderBy);
|
||||
}
|
||||
|
||||
public function findPairs($criteria,$value,$orderBy,$key)
|
||||
{
|
||||
return $this->pronunciations->findPairs($criteria,$value,$orderBy,$key);
|
||||
}
|
||||
}
|
||||
37
app/model/Database/Repository/TermFlags.php
Normal file
37
app/model/Database/Repository/TermFlags.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
namespace App;
|
||||
|
||||
use Kdyby;
|
||||
use Nette;
|
||||
|
||||
class TermFlags extends Nette\Object
|
||||
{
|
||||
private $em;
|
||||
private $termFlags;
|
||||
|
||||
public function __construct(Kdyby\Doctrine\EntityManager $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->termFlags = $em->getRepository(TermFlag::class);
|
||||
}
|
||||
|
||||
public function find($value)
|
||||
{
|
||||
return $this->termFlags->find($value);
|
||||
}
|
||||
|
||||
public function findBy($criteria = [],$orderBy = [])
|
||||
{
|
||||
return $this->termFlags->findBy($criteria,$orderBy);
|
||||
}
|
||||
|
||||
public function findPairs($criteria,$value,$orderBy,$key)
|
||||
{
|
||||
return $this->termFlags->findPairs($criteria,$value,$orderBy,$key);
|
||||
}
|
||||
|
||||
public function findAssoc($criteria,$key)
|
||||
{
|
||||
return $this->termFlags->findAssoc($criteria,$key);
|
||||
}
|
||||
}
|
||||
46
app/model/Database/Repository/Terms.php
Normal file
46
app/model/Database/Repository/Terms.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
namespace App;
|
||||
|
||||
use Kdyby;
|
||||
use Nette;
|
||||
|
||||
class Terms extends Nette\Object
|
||||
{
|
||||
private $em;
|
||||
private $termsDao;
|
||||
private $terms;
|
||||
|
||||
public function __construct(Kdyby\Doctrine\EntityManager $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->terms = $em->getRepository(Term::class);
|
||||
$this->termsDao = $em->getDao(Term::class);
|
||||
}
|
||||
|
||||
public function findAll($criteria = [],$orderBy = [])
|
||||
{
|
||||
return $this->terms->findBy($criteria,$orderBy);
|
||||
}
|
||||
|
||||
public function findBy($criteria = [],$orderBy = [])
|
||||
{
|
||||
return $this->terms->findBy($criteria,$orderBy);
|
||||
}
|
||||
|
||||
public function find($id)
|
||||
{
|
||||
return $this->terms->find($id);
|
||||
}
|
||||
|
||||
|
||||
public function findPairs($criteria,$value,$orderBy,$key)
|
||||
{
|
||||
return $this->terms->findPairs($criteria,$value,$orderBy,$key);
|
||||
}
|
||||
|
||||
public function fetch($query)
|
||||
{
|
||||
return $this->termsDao->fetch($query);
|
||||
}
|
||||
|
||||
}
|
||||
33
app/model/Database/Repository/Translations.php
Normal file
33
app/model/Database/Repository/Translations.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace App;
|
||||
|
||||
use Kdyby;
|
||||
use Nette;
|
||||
|
||||
class Translations extends Nette\Object
|
||||
{
|
||||
private $em;
|
||||
private $translations;
|
||||
|
||||
public function __construct(Kdyby\Doctrine\EntityManager $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->translations = $em->getRepository(Translation::class);
|
||||
}
|
||||
|
||||
public function find($value)
|
||||
{
|
||||
return $this->translations->find($value);
|
||||
}
|
||||
|
||||
|
||||
public function findBy($criteria = [],$orderBy = [])
|
||||
{
|
||||
return $this->translations->findBy($criteria,$orderBy);
|
||||
}
|
||||
|
||||
public function findPairs($criteria,$value,$orderBy,$key)
|
||||
{
|
||||
return $this->translations->findPairs($criteria,$value,$orderBy,$key);
|
||||
}
|
||||
}
|
||||
22
app/model/Database/Repository/UserRepository.php
Normal file
22
app/model/Database/Repository/UserRepository.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Database\Repository;
|
||||
|
||||
use App\Model\Database\Entity\User;
|
||||
|
||||
/**
|
||||
* @method User|NULL find($id, ?int $lockMode = NULL, ?int $lockVersion = NULL)
|
||||
* @method User|NULL findOneBy(array $criteria, array $orderBy = NULL)
|
||||
* @method User[] findAll()
|
||||
* @method User[] findBy(array $criteria, array $orderBy = NULL, ?int $limit = NULL, ?int $offset = NULL)
|
||||
* @extends AbstractRepository<User>
|
||||
*/
|
||||
class UserRepository extends AbstractRepository
|
||||
{
|
||||
|
||||
public function findOneByEmail(string $email): ?User
|
||||
{
|
||||
return $this->findOneBy(['email' => $email]);
|
||||
}
|
||||
|
||||
}
|
||||
19
app/model/Database/TRepositories.php
Normal file
19
app/model/Database/TRepositories.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Database;
|
||||
|
||||
use App\Model\Database\Entity\User;
|
||||
use App\Model\Database\Repository\UserRepository;
|
||||
|
||||
/**
|
||||
* @mixin EntityManager
|
||||
*/
|
||||
trait TRepositories
|
||||
{
|
||||
|
||||
public function getUserRepository(): UserRepository
|
||||
{
|
||||
return $this->getRepository(User::class);
|
||||
}
|
||||
|
||||
}
|
||||
10
app/model/Exception/Logic/InvalidArgumentException.php
Normal file
10
app/model/Exception/Logic/InvalidArgumentException.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Exception\Logic;
|
||||
|
||||
use App\Model\Exception\LogicException;
|
||||
|
||||
final class InvalidArgumentException extends LogicException
|
||||
{
|
||||
|
||||
}
|
||||
8
app/model/Exception/LogicException.php
Normal file
8
app/model/Exception/LogicException.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Exception;
|
||||
|
||||
class LogicException extends \LogicException
|
||||
{
|
||||
|
||||
}
|
||||
10
app/model/Exception/Runtime/AuthenticationException.php
Normal file
10
app/model/Exception/Runtime/AuthenticationException.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Exception\Runtime;
|
||||
|
||||
use Nette\Security\AuthenticationException as NetteAuthenticationException;
|
||||
|
||||
final class AuthenticationException extends NetteAuthenticationException
|
||||
{
|
||||
|
||||
}
|
||||
10
app/model/Exception/Runtime/IOException.php
Normal file
10
app/model/Exception/Runtime/IOException.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Exception\Runtime;
|
||||
|
||||
use App\Model\Exception\RuntimeException;
|
||||
|
||||
final class IOException extends RuntimeException
|
||||
{
|
||||
|
||||
}
|
||||
10
app/model/Exception/Runtime/InvalidStateException.php
Normal file
10
app/model/Exception/Runtime/InvalidStateException.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Exception\Runtime;
|
||||
|
||||
use App\Model\Exception\RuntimeException;
|
||||
|
||||
final class InvalidStateException extends RuntimeException
|
||||
{
|
||||
|
||||
}
|
||||
8
app/model/Exception/RuntimeException.php
Normal file
8
app/model/Exception/RuntimeException.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Exception;
|
||||
|
||||
class RuntimeException extends \RuntimeException
|
||||
{
|
||||
|
||||
}
|
||||
35
app/model/Latte/FilterExecutor.php
Normal file
35
app/model/Latte/FilterExecutor.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Latte;
|
||||
|
||||
use Latte\Engine;
|
||||
|
||||
final class FilterExecutor
|
||||
{
|
||||
|
||||
/** @var Engine */
|
||||
private $latte;
|
||||
|
||||
public function __construct(Engine $latte)
|
||||
{
|
||||
$this->latte = $latte;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $args
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call(string $name, array $args)
|
||||
{
|
||||
return $this->latte->invokeFilter($name, $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get(string $name)
|
||||
{
|
||||
return $this->latte->invokeFilter($name, []);
|
||||
}
|
||||
|
||||
}
|
||||
30
app/model/Latte/Filters.php
Normal file
30
app/model/Latte/Filters.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Latte;
|
||||
|
||||
use Nette\Neon\Neon;
|
||||
use Nette\StaticClass;
|
||||
use Nette\Utils\Json;
|
||||
|
||||
final class Filters
|
||||
{
|
||||
|
||||
use StaticClass;
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
public static function neon($value): string
|
||||
{
|
||||
return Neon::encode($value, Neon::BLOCK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
public static function json($value): string
|
||||
{
|
||||
return Json::encode($value);
|
||||
}
|
||||
|
||||
}
|
||||
16
app/model/Latte/Macros.php
Normal file
16
app/model/Latte/Macros.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Latte;
|
||||
|
||||
use Latte\Compiler;
|
||||
use Latte\Macros\MacroSet;
|
||||
|
||||
final class Macros extends MacroSet
|
||||
{
|
||||
|
||||
public static function register(Compiler $compiler): void
|
||||
{
|
||||
$compiler = new static($compiler);
|
||||
}
|
||||
|
||||
}
|
||||
51
app/model/Latte/TemplateFactory.php
Normal file
51
app/model/Latte/TemplateFactory.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Latte;
|
||||
|
||||
use App\Model\Security\SecurityUser;
|
||||
use Nette\Application\UI\Control;
|
||||
use Nette\Bridges\ApplicationLatte\LatteFactory;
|
||||
use Nette\Bridges\ApplicationLatte\Template;
|
||||
use Nette\Bridges\ApplicationLatte\TemplateFactory as NetteTemplateFactory;
|
||||
use Nette\Caching\IStorage;
|
||||
use Nette\Http\IRequest;
|
||||
|
||||
final class TemplateFactory extends NetteTemplateFactory
|
||||
{
|
||||
|
||||
/** @var LatteFactory */
|
||||
private $latteFactory;
|
||||
|
||||
/** @var SecurityUser */
|
||||
private $user;
|
||||
|
||||
public function __construct(
|
||||
LatteFactory $latteFactory,
|
||||
IRequest $httpRequest,
|
||||
SecurityUser $user,
|
||||
IStorage $cacheStorage,
|
||||
string $templateClass = null
|
||||
)
|
||||
{
|
||||
parent::__construct($latteFactory, $httpRequest, $user, $cacheStorage, $templateClass);
|
||||
$this->latteFactory = $latteFactory;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
public function createTemplate(Control $control = null, string $class = null): Template
|
||||
{
|
||||
/** @var Template $template */
|
||||
$template = parent::createTemplate($control);
|
||||
|
||||
// Remove default $template->user for prevent misused
|
||||
unset($template->user);
|
||||
|
||||
// Assign new variables
|
||||
$template->_user = $this->user;
|
||||
$template->_template = $template;
|
||||
$template->_filters = new FilterExecutor($this->latteFactory->create());
|
||||
|
||||
return $template;
|
||||
}
|
||||
|
||||
}
|
||||
20
app/model/Latte/TemplateProperty.php
Normal file
20
app/model/Latte/TemplateProperty.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Latte;
|
||||
|
||||
use App\Model\Security\SecurityUser;
|
||||
use App\Modules\Base\BasePresenter;
|
||||
use App\UI\Control\BaseControl;
|
||||
use Nette\Bridges\ApplicationLatte\Template;
|
||||
|
||||
/**
|
||||
* @property-read SecurityUser $_user
|
||||
* @property-read BasePresenter $presenter
|
||||
* @property-read BaseControl $control
|
||||
* @property-read string $baseUri
|
||||
* @property-read string $basePath
|
||||
* @property-read array $flashes
|
||||
*/
|
||||
final class TemplateProperty extends Template
|
||||
{
|
||||
}
|
||||
55
app/model/Router/RouterFactory.php
Normal file
55
app/model/Router/RouterFactory.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Router;
|
||||
|
||||
use Nette\Application\Routers\Route;
|
||||
use Nette\Application\Routers\RouteList;
|
||||
|
||||
final class RouterFactory
|
||||
{
|
||||
|
||||
public function create(): RouteList
|
||||
{
|
||||
$router = new RouteList();
|
||||
|
||||
$this->buildMailing($router);
|
||||
$this->buildPdf($router);
|
||||
$this->buildAdmin($router);
|
||||
$this->buildFront($router);
|
||||
|
||||
return $router;
|
||||
}
|
||||
|
||||
protected function buildAdmin(RouteList $router): RouteList
|
||||
{
|
||||
$router[] = $list = new RouteList('Admin');
|
||||
$list[] = new Route('admin/<presenter>/<action>[/<id>]', 'Home:default');
|
||||
|
||||
return $router;
|
||||
}
|
||||
|
||||
protected function buildFront(RouteList $router): RouteList
|
||||
{
|
||||
$router[] = $list = new RouteList('Front');
|
||||
$list[] = new Route('<presenter>/<action>[/<id>]', 'Home:default');
|
||||
|
||||
return $router;
|
||||
}
|
||||
|
||||
protected function buildMailing(RouteList $router): RouteList
|
||||
{
|
||||
$router[] = $list = new RouteList('Mailing');
|
||||
$list[] = new Route('mailing/<presenter>/<action>[/<id>]', 'Home:default');
|
||||
|
||||
return $router;
|
||||
}
|
||||
|
||||
protected function buildPdf(RouteList $router): RouteList
|
||||
{
|
||||
$router[] = $list = new RouteList('Pdf');
|
||||
$list[] = new Route('pdf/<presenter>/<action>[/<id>]', 'Home:default');
|
||||
|
||||
return $router;
|
||||
}
|
||||
|
||||
}
|
||||
57
app/model/Security/Authenticator/UserAuthenticator.php
Normal file
57
app/model/Security/Authenticator/UserAuthenticator.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Security\Authenticator;
|
||||
|
||||
use App\Model\Database\Entity\User;
|
||||
use App\Model\Database\EntityManager;
|
||||
use App\Model\Exception\Runtime\AuthenticationException;
|
||||
use App\Model\Security\Passwords;
|
||||
use Nette\Security\Authenticator;
|
||||
use Nette\Security\IIdentity;
|
||||
|
||||
final class UserAuthenticator implements Authenticator
|
||||
{
|
||||
|
||||
/** @var EntityManager */
|
||||
private $em;
|
||||
|
||||
/** @var Passwords */
|
||||
private $passwords;
|
||||
|
||||
public function __construct(EntityManager $em, Passwords $passwords)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->passwords = $passwords;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $username
|
||||
* @param string $password
|
||||
* @throws AuthenticationException
|
||||
*/
|
||||
public function authenticate(string $username, string $password): IIdentity
|
||||
{
|
||||
$user = $this->em->getUserRepository()->findOneBy(['email' => $username]);
|
||||
|
||||
if (!$user) {
|
||||
throw new AuthenticationException('The username is incorrect.', self::IDENTITY_NOT_FOUND);
|
||||
} elseif (!$user->isActivated()) {
|
||||
throw new AuthenticationException('The user is not active.', self::INVALID_CREDENTIAL);
|
||||
} elseif (!$this->passwords->verify($password, $user->getPasswordHash())) {
|
||||
throw new AuthenticationException('The password is incorrect.', self::INVALID_CREDENTIAL);
|
||||
}
|
||||
|
||||
$user->changeLoggedAt();
|
||||
$this->em->flush();
|
||||
|
||||
return $this->createIdentity($user);
|
||||
}
|
||||
|
||||
protected function createIdentity(User $user): IIdentity
|
||||
{
|
||||
$this->em->flush();
|
||||
|
||||
return $user->toIdentity();
|
||||
}
|
||||
|
||||
}
|
||||
47
app/model/Security/Authorizator/StaticAuthorizator.php
Normal file
47
app/model/Security/Authorizator/StaticAuthorizator.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Security\Authorizator;
|
||||
|
||||
use App\Model\Database\Entity\User;
|
||||
use Nette\Security\Permission;
|
||||
|
||||
final class StaticAuthorizator extends Permission
|
||||
{
|
||||
|
||||
/**
|
||||
* Create ACL
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->addRoles();
|
||||
$this->addResources();
|
||||
$this->addPermissions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup roles
|
||||
*/
|
||||
protected function addRoles(): void
|
||||
{
|
||||
$this->addRole(User::ROLE_ADMIN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup resources
|
||||
*/
|
||||
protected function addResources(): void
|
||||
{
|
||||
$this->addResource('Admin:Home');
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup ACL
|
||||
*/
|
||||
protected function addPermissions(): void
|
||||
{
|
||||
$this->allow(User::ROLE_ADMIN, [
|
||||
'Admin:Home',
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
15
app/model/Security/Identity.php
Normal file
15
app/model/Security/Identity.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Security;
|
||||
|
||||
use Nette\Security\SimpleIdentity as NetteIdentity;
|
||||
|
||||
class Identity extends NetteIdentity
|
||||
{
|
||||
|
||||
public function getFullname(): string
|
||||
{
|
||||
return sprintf('%s %s', $this->data['name'] ?? '', $this->data['surname'] ?? '');
|
||||
}
|
||||
|
||||
}
|
||||
15
app/model/Security/Passwords.php
Normal file
15
app/model/Security/Passwords.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Security;
|
||||
|
||||
use Nette\Security\Passwords as NettePasswords;
|
||||
|
||||
final class Passwords extends NettePasswords
|
||||
{
|
||||
|
||||
public static function create(): Passwords
|
||||
{
|
||||
return new Passwords();
|
||||
}
|
||||
|
||||
}
|
||||
19
app/model/Security/SecurityUser.php
Normal file
19
app/model/Security/SecurityUser.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Security;
|
||||
|
||||
use App\Model\Database\Entity\User;
|
||||
use Nette\Security\User as NetteUser;
|
||||
|
||||
/**
|
||||
* @method Identity getIdentity()
|
||||
*/
|
||||
final class SecurityUser extends NetteUser
|
||||
{
|
||||
|
||||
public function isAdmin(): bool
|
||||
{
|
||||
return $this->isInRole(User::ROLE_ADMIN);
|
||||
}
|
||||
|
||||
}
|
||||
10
app/model/Utils/Arrays.php
Normal file
10
app/model/Utils/Arrays.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Utils;
|
||||
|
||||
use Nette\Utils\Arrays as NetteArrays;
|
||||
|
||||
final class Arrays extends NetteArrays
|
||||
{
|
||||
|
||||
}
|
||||
13
app/model/Utils/DateTime.php
Normal file
13
app/model/Utils/DateTime.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Utils;
|
||||
|
||||
use Nette\Utils\DateTime as ContributteDateTime;
|
||||
|
||||
/**
|
||||
* @method DateTime modifyClone(string $modify = '')
|
||||
*/
|
||||
final class DateTime extends ContributteDateTime
|
||||
{
|
||||
|
||||
}
|
||||
10
app/model/Utils/FileSystem.php
Normal file
10
app/model/Utils/FileSystem.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Utils;
|
||||
|
||||
use Contributte\Utils\FileSystem as ContributteFileSystem;
|
||||
|
||||
final class FileSystem extends ContributteFileSystem
|
||||
{
|
||||
|
||||
}
|
||||
10
app/model/Utils/Html.php
Normal file
10
app/model/Utils/Html.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Utils;
|
||||
|
||||
use Nette\Utils\Html as NetteHtml;
|
||||
|
||||
final class Html extends NetteHtml
|
||||
{
|
||||
|
||||
}
|
||||
10
app/model/Utils/Image.php
Normal file
10
app/model/Utils/Image.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Utils;
|
||||
|
||||
use Nette\Utils\Image as NetteImage;
|
||||
|
||||
class Image extends NetteImage
|
||||
{
|
||||
|
||||
}
|
||||
10
app/model/Utils/Strings.php
Normal file
10
app/model/Utils/Strings.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Utils;
|
||||
|
||||
use Contributte\Utils\Strings as ContributteStrings;
|
||||
|
||||
final class Strings extends ContributteStrings
|
||||
{
|
||||
|
||||
}
|
||||
10
app/model/Utils/Validators.php
Normal file
10
app/model/Utils/Validators.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Model\Utils;
|
||||
|
||||
use Contributte\Utils\Validators as ContributteValidators;
|
||||
|
||||
final class Validators extends ContributteValidators
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user