This repository has been archived by the owner on Aug 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e1bfa3e
commit 1db2615
Showing
19 changed files
with
369 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
services: | ||
smart_parameter.parameter_provider: | ||
class: Smart\ParameterBundle\Provider\ParameterProvider | ||
public: true | ||
arguments: | ||
- '@Doctrine\ORM\EntityManagerInterface' | ||
|
||
Smart\ParameterBundle\Provider\ParameterProvider: | ||
public: false | ||
alias: smart_parameter.parameter_provider |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
includes: | ||
- vendor/phpstan/phpstan-symfony/extension.neon | ||
- vendor/phpstan/phpstan-symfony/rules.neon | ||
- vendor/phpstan/phpstan-doctrine/extension.neon | ||
- vendor/phpstan/phpstan-doctrine/rules.neon | ||
|
||
parameters: | ||
checkMissingIterableValueType: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
namespace Smart\ParameterBundle\Entity; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @author Mathieu Ducrot <[email protected]> | ||
* | ||
* @ORM\Table(name="smart_parameter") | ||
* @ORM\Entity(repositoryClass="Smart\ParameterBundle\Repository\ParameterRepository") | ||
*/ | ||
class Parameter | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\GeneratedValue(strategy="AUTO") | ||
* @ORM\Column(name="id", type="integer") | ||
*/ | ||
private int $id; | ||
|
||
/** | ||
* @ORM\Column(name="code", type="string", nullable=false, unique=true) | ||
*/ | ||
private string $code; | ||
|
||
/** | ||
* @ORM\Column(name="value", type="text", nullable=false) | ||
*/ | ||
private string $value; | ||
|
||
/** | ||
* @ORM\Column(name="help", type="text", nullable=true) | ||
*/ | ||
private ?string $help; | ||
|
||
public function __toString() | ||
{ | ||
return (string) $this->getCode(); | ||
} | ||
|
||
public function getId(): ?int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getCode(): string | ||
{ | ||
return $this->code; | ||
} | ||
|
||
/** | ||
* @param string $code | ||
*/ | ||
public function setCode(string $code): void | ||
{ | ||
$this->code = $code; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getValue(): string | ||
{ | ||
return $this->value; | ||
} | ||
|
||
/** | ||
* @param string $value | ||
*/ | ||
public function setValue(string $value): void | ||
{ | ||
$this->value = $value; | ||
} | ||
|
||
/** | ||
* @return string|null | ||
*/ | ||
public function getHelp(): ?string | ||
{ | ||
return $this->help; | ||
} | ||
|
||
/** | ||
* @param string|null $help | ||
*/ | ||
public function setHelp(?string $help): void | ||
{ | ||
$this->help = $help; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace Smart\ParameterBundle\Provider; | ||
|
||
use Doctrine\ORM\EntityManagerInterface; | ||
use Doctrine\ORM\EntityNotFoundException; | ||
use Smart\ParameterBundle\Entity\Parameter; | ||
|
||
/** | ||
* @author Mathieu Ducrot <[email protected]> | ||
*/ | ||
class ParameterProvider | ||
{ | ||
private EntityManagerInterface $entityManager; | ||
private array $parameters; | ||
|
||
public function __construct(EntityManagerInterface $entityManager) | ||
{ | ||
$this->entityManager = $entityManager; | ||
$this->parameters = []; | ||
} | ||
|
||
/** | ||
* Get a Parameter instance | ||
* | ||
* @throws EntityNotFoundException | ||
*/ | ||
public function get(string $code): Parameter | ||
{ | ||
if (isset($this->parameters[$code])) { | ||
return $this->parameters[$code]; | ||
} | ||
|
||
$parameter = $this->entityManager->getRepository(Parameter::class)->findOneBy(['code' => $code]); | ||
|
||
if ($parameter == null) { | ||
throw new EntityNotFoundException("The parameter with code \"$code\" was not found."); | ||
} | ||
$this->parameters[$code] = $parameter; | ||
|
||
return $parameter; | ||
} | ||
|
||
/** | ||
* Get a Parameter value | ||
*/ | ||
public function getValue(string $code): string | ||
{ | ||
return $this->get($code)->getValue(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace Smart\ParameterBundle\Repository; | ||
|
||
use Doctrine\ORM\EntityRepository; | ||
use Smart\ParameterBundle\Entity\Parameter; | ||
|
||
/** | ||
* @author Mathieu Ducrot <[email protected]> | ||
* | ||
* @extends \Doctrine\ORM\EntityRepository<Parameter> | ||
*/ | ||
class ParameterRepository extends EntityRepository | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Smart\ParameterBundle\Tests; | ||
|
||
use Liip\TestFixturesBundle\Test\FixturesTrait; | ||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | ||
|
||
/** | ||
* @author Mathieu Ducrot <[email protected]> | ||
*/ | ||
abstract class AbstractWebTestCase extends WebTestCase | ||
{ | ||
use FixturesTrait; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
self::bootKernel(); | ||
|
||
// Empty load to guarantee that the base will always be available | ||
$this->loadFixtureFiles([]); | ||
} | ||
|
||
protected function getFixtureDir(): string | ||
{ | ||
return __DIR__ . '/fixtures'; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace Smart\ParameterBundle\Tests; | ||
|
||
use Psr\Log\NullLogger; | ||
use Symfony\Component\Config\Loader\LoaderInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\HttpKernel\Kernel; | ||
|
||
/** | ||
* Kernel used by PHPUnit to ease services testing | ||
* | ||
* @author Mathieu Ducrot <[email protected]> | ||
*/ | ||
class AppKernel extends Kernel | ||
{ | ||
public function registerBundles() | ||
{ | ||
return [ | ||
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(), | ||
new \Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), | ||
new \Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(), | ||
new \DAMA\DoctrineTestBundle\DAMADoctrineTestBundle(), | ||
new \Liip\TestFixturesBundle\LiipTestFixturesBundle(), | ||
new \Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle(), | ||
new \Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle(), | ||
new \Smart\ParameterBundle\SmartParameterBundle(), | ||
]; | ||
} | ||
|
||
public function registerContainerConfiguration(LoaderInterface $loader): void | ||
{ | ||
$loader->load(__DIR__ . '/config_test.yml'); | ||
} | ||
|
||
// https://github.com/dmaicher/doctrine-test-bundle/blob/master/tests/Functional/app/AppKernel.php | ||
protected function build(ContainerBuilder $container): void | ||
{ | ||
// remove logger info | ||
$container->register('logger', NullLogger::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.