-
-
Notifications
You must be signed in to change notification settings - Fork 154
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
Showing
13 changed files
with
452 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,5 @@ | |
/symfony.lock | ||
|
||
/.phpunit.result.cache | ||
|
||
src/Bundle/test/src/Tests/Tmp/ |
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
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,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- | ||
This file is part of the Sylius package. | ||
(c) Paweł Jędrzejewski | ||
For the full copyright and license information, please view the LICENSE | ||
file that was distributed with this source code. | ||
--> | ||
|
||
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
<services> | ||
<service id="sylius.maker.resource" class="Sylius\Component\Resource\Symfony\Maker\MakeResource"> | ||
<tag name="maker.command" /> | ||
</service> | ||
</services> | ||
</container> |
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,31 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Entity\Tests\Tmp\Entity; | ||
|
||
use App\Repository\Tests\Tmp\Entity\BookRepository; | ||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
#[ORM\Entity(repositoryClass: BookRepository::class)] | ||
class Book | ||
{ | ||
#[ORM\Id] | ||
#[ORM\GeneratedValue] | ||
#[ORM\Column] | ||
private ?int $id = null; | ||
|
||
public function getId(): ?int | ||
{ | ||
return $this->id; | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
src/Bundle/test/src/Repository/Tests/Tmp/Entity/BookRepository.php
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,77 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Repository\Tests\Tmp\Entity; | ||
|
||
use App\Entity\Tests\Tmp\Entity\Book; | ||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; | ||
use Doctrine\Persistence\ManagerRegistry; | ||
|
||
/** | ||
* @extends ServiceEntityRepository<Book> | ||
* | ||
* @method Book|null find($id, $lockMode = null, $lockVersion = null) | ||
* @method Book|null findOneBy(array $criteria, array $orderBy = null) | ||
* @method Book[] findAll() | ||
* @method Book[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) | ||
*/ | ||
class BookRepository extends ServiceEntityRepository | ||
{ | ||
public function __construct(ManagerRegistry $registry) | ||
{ | ||
parent::__construct($registry, Book::class); | ||
} | ||
|
||
public function save(Book $entity, bool $flush = false): void | ||
{ | ||
$this->getEntityManager()->persist($entity); | ||
|
||
if ($flush) { | ||
$this->getEntityManager()->flush(); | ||
} | ||
} | ||
|
||
public function remove(Book $entity, bool $flush = false): void | ||
{ | ||
$this->getEntityManager()->remove($entity); | ||
|
||
if ($flush) { | ||
$this->getEntityManager()->flush(); | ||
} | ||
} | ||
|
||
// /** | ||
// * @return Book[] Returns an array of Book objects | ||
// */ | ||
// public function findByExampleField($value): array | ||
// { | ||
// return $this->createQueryBuilder('b') | ||
// ->andWhere('b.exampleField = :val') | ||
// ->setParameter('val', $value) | ||
// ->orderBy('b.id', 'ASC') | ||
// ->setMaxResults(10) | ||
// ->getQuery() | ||
// ->getResult() | ||
// ; | ||
// } | ||
|
||
// public function findOneBySomeField($value): ?Book | ||
// { | ||
// return $this->createQueryBuilder('b') | ||
// ->andWhere('b.exampleField = :val') | ||
// ->setParameter('val', $value) | ||
// ->getQuery() | ||
// ->getOneOrNullResult() | ||
// ; | ||
// } | ||
} |
55 changes: 55 additions & 0 deletions
55
src/Bundle/test/src/Sylius/Resource/Tests/Tmp/Sylius/Resource/BookResource.php
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,55 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Sylius\Resource\Tests\Tmp\Sylius\Resource; | ||
|
||
use Sylius\Component\Resource\Metadata\Create; | ||
use Sylius\Component\Resource\Metadata\Delete; | ||
use Sylius\Component\Resource\Metadata\Index; | ||
use Sylius\Component\Resource\Metadata\Resource; | ||
use Sylius\Component\Resource\Metadata\Show; | ||
use Sylius\Component\Resource\Metadata\Update; | ||
use Sylius\Component\Resource\Model\ResourceInterface; | ||
use Symfony\Component\Uid\AbstractUid; | ||
|
||
#[Resource] | ||
#[Index( | ||
// grid: Tests\Tmp\Sylius\Resource\BookGrid::class, | ||
)] | ||
#[Create( | ||
// processor: CreateTests\Tmp\Sylius\Resource\BookProcessor::class, | ||
)] | ||
#[Update( | ||
// provider: Tests\Tmp\Sylius\Resource\BookItemProvider::class, | ||
// processor: UpdateTests\Tmp\Sylius\Resource\BookProcessor::class, | ||
)] | ||
#[Delete( | ||
// provider: Tests\Tmp\Sylius\Resource\BookItemProvider::class, | ||
// processor: DeleteTests\Tmp\Sylius\Resource\BookProcessor::class, | ||
)] | ||
#[Show( | ||
// template: 'tests\tmp\sylius\resource\book/show.html.twig', | ||
// provider: Tests\Tmp\Sylius\Resource\BookItemProvider::class, | ||
)] | ||
final class BookResource implements ResourceInterface | ||
{ | ||
public function __construct( | ||
public ?AbstractUid $id = null, | ||
) { | ||
} | ||
|
||
public function getId(): ?string | ||
{ | ||
return $this->id?->__toString(); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/Component/Symfony/Bundle/Resources/config/skeleton/Resource.tpl.php
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,50 @@ | ||
<?= "<?php\n" ?> | ||
|
||
namespace <?= $namespace; ?>; | ||
|
||
use Sylius\Component\Resource\Metadata\Create; | ||
use Sylius\Component\Resource\Metadata\Delete; | ||
use Sylius\Component\Resource\Metadata\Index; | ||
use Sylius\Component\Resource\Metadata\Resource; | ||
use Sylius\Component\Resource\Metadata\Show; | ||
use Sylius\Component\Resource\Metadata\Update; | ||
use Sylius\Component\Resource\Model\ResourceInterface; | ||
use Symfony\Component\Uid\AbstractUid; | ||
|
||
#[Resource] | ||
#[Index( | ||
// grid: <?= $class_name_without_suffix ?>Grid::class, | ||
)] | ||
#[Create( | ||
// processor: Create<?= $class_name_without_suffix ?>Processor::class, | ||
)] | ||
#[Update( | ||
// provider: <?= $class_name_without_suffix ?>ItemProvider::class, | ||
// processor: Update<?= $class_name_without_suffix ?>Processor::class, | ||
)] | ||
#[Delete( | ||
// provider: <?= $class_name_without_suffix ?>ItemProvider::class, | ||
// processor: Delete<?= $class_name_without_suffix ?>Processor::class, | ||
)] | ||
#[Show( | ||
// template: '<?= $show_template_dir ?>/show.html.twig', | ||
// provider: <?= $class_name_without_suffix ?>ItemProvider::class, | ||
)] | ||
final class <?= $class_name ?> implements ResourceInterface | ||
{ | ||
<?php if (class_exists(Symfony\Component\Uid\AbstractUid::class)) : ?> | ||
public function __construct( | ||
public ?AbstractUid $id = null, | ||
) { | ||
} | ||
<?php endif; ?> | ||
|
||
public function getId(): ?string | ||
{ | ||
<?php if (class_exists(Symfony\Component\Uid\AbstractUid::class)) : ?> | ||
return $this->id?->__toString(); | ||
<?php else : ?> | ||
throw new \LogicException('TODO: Implement getId method'); | ||
<?php endif; ?> | ||
} | ||
} |
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,85 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Component\Resource\Symfony\Maker; | ||
|
||
use Symfony\Bundle\MakerBundle\ConsoleStyle; | ||
use Symfony\Bundle\MakerBundle\DependencyBuilder; | ||
use Symfony\Bundle\MakerBundle\Generator; | ||
use Symfony\Bundle\MakerBundle\InputConfiguration; | ||
use Symfony\Bundle\MakerBundle\Maker\AbstractMaker; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
|
||
final class MakeResource extends AbstractMaker | ||
{ | ||
public static function getCommandName(): string | ||
{ | ||
return 'make:resource'; | ||
} | ||
|
||
public static function getCommandDescription(): string | ||
{ | ||
return 'Creates a Resource class'; | ||
} | ||
|
||
public function configureCommand(Command $command, InputConfiguration $inputConfig): void | ||
{ | ||
$command | ||
->setDescription(self::getCommandDescription()) | ||
->addArgument('class', InputArgument::OPTIONAL, 'Class name of the resource to create') | ||
->addOption('namespace', null, InputOption::VALUE_REQUIRED, 'Customize the namespace for generated resource', 'Sylius\\Resource') | ||
; | ||
} | ||
|
||
public function configureDependencies(DependencyBuilder $dependencies): void | ||
{ | ||
} | ||
|
||
public function interact(InputInterface $input, ConsoleStyle $io, Command $command): void | ||
{ | ||
} | ||
|
||
public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator): void | ||
{ | ||
$class = $input->getArgument('class'); | ||
|
||
$namespace = $input->getOption('namespace'); | ||
$namespace = \trim($namespace, '\\'); | ||
|
||
$resourceClassDetails = $generator->createClassNameDetails( | ||
$class, | ||
$namespace, | ||
'Resource', | ||
); | ||
|
||
if (\str_ends_with($class, 'Resource')) { | ||
$class = \mb_substr($class, 0, -\strlen('Resource')); | ||
} | ||
|
||
$generator->generateClass( | ||
$resourceClassDetails->getFullName(), | ||
__DIR__ . '/../Bundle/Resources/config/skeleton/Resource.tpl.php', | ||
[ | ||
'class_name_without_suffix' => $class, | ||
'show_template_dir' => \strtolower($class), | ||
], | ||
); | ||
|
||
$generator->writeChanges(); | ||
|
||
$this->writeSuccessMessage($io); | ||
} | ||
} |
Oops, something went wrong.