Skip to content

Commit

Permalink
Merge branch 'release/v1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxes3 committed Mar 25, 2024
2 parents 989f754 + 0ad8aa4 commit 2229434
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:
- uses: shivammathur/setup-php@2cb9b829437ee246e9b3cac53555a39208ca6d28
with:
php-version: '8.1'
php-version: '8.2'
- uses: actions/checkout@v2
- name: Install Dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
vendor/
var/
composer.lock
.phpunit.result.cache
.phpunit.result.cache
31 changes: 14 additions & 17 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,32 @@
"type": "symfony-bundle",
"description": "Extends whatwedo crud bundle with history view from auditor-bundle",
"license": "MIT",
"minimum-stability": "stable",
"minimum-stability": "dev",
"prefer-stable": true,
"authors": [
{
"name": "whatwedo GmbH",
"email": "[email protected]"
}
],
"require": {
"php": ">=8.1",
"symfony/security-bundle": "^6.0",
"damienharper/auditor-bundle": "^5.2.1",
"symfony/form": "^6.0",
"php": ">=8.2",
"symfony/security-bundle": "^6.4|^7.0",
"damienharper/auditor-bundle": "dev-master",
"symfony/form": "^6.4|^7.0",
"whatwedo/twig-bootstrap-icons": "^v1.1.1",
"araise/table-bundle": "^1.0.0",
"araise/core-bundle": "^1.0.0",
"araise/crud-bundle": "^1.0.0",
"araise/search-bundle": "^3.0.0"
"araise/table-bundle": "^1.1",
"araise/core-bundle": "^1.1",
"araise/crud-bundle": "^1.1",
"araise/search-bundle": "^3.1"
},
"require-dev": {
"symfony/phpunit-bridge": "^v6.0",
"symfony/phpunit-bridge": "^7.0",
"zenstruck/foundry": "^v1.24.1",
"symfony/yaml": "^v6.0",
"whatwedo/php-coding-standard": "dev-develop",
"symfony/yaml": "^7.0",
"whatwedo/php-coding-standard": "^1.2.4",
"symfony/test-pack": "^1.0.10",
"mhujer/breadcrumbs-bundle": "dev-master",
"araise/table-bundle": "dev-develop as 1.0.0",
"araise/core-bundle": "dev-develop as 1.0.0",
"araise/crud-bundle": "dev-develop as 1.0.0",
"araise/search-bundle": "dev-develop as 3.0.0",
"mhujer/breadcrumbs-bundle": "^1.5.9",
"phpstan/phpstan": "^1.10"
},
"autoload": {
Expand Down
12 changes: 3 additions & 9 deletions src/EventSubscriber/AuditTriggerSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,15 @@

namespace whatwedo\CrudHistoryBundle\EventSubscriber;

use Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface;
use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Event\OnFlushEventArgs;
use Doctrine\ORM\Events;
use whatwedo\CrudHistoryBundle\Entity\AuditManyToOneTriggerInterface;

final class AuditTriggerSubscriber implements EventSubscriberInterface
#[AsDoctrineListener(event: Events::onFlush)]
final class AuditTriggerSubscriber
{
public function getSubscribedEvents(): array
{
return [
Events::onFlush,
];
}

public function onFlush(OnFlushEventArgs $args): void
{
$entityManager = $args->getObjectManager();
Expand Down
2 changes: 1 addition & 1 deletion src/Model/HistoryItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(Entry $entry, string $entityFqcn)
{
$this->entry = $entry;
$this->class = ClassUtils::getRealClass($entityFqcn);
$this->date = new \DateTimeImmutable($entry->getCreatedAt());
$this->date = is_string($entry->getCreatedAt()) ? new \DateTimeImmutable($entry->getCreatedAt()) : $entry->getCreatedAt();
}

public function getEntry(): Entry
Expand Down
15 changes: 5 additions & 10 deletions src/Routing/CrudHistoryLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct(
parent::__construct();
}

public function load($resource, $type = null): RouteCollection
public function load(mixed $resource, ?string $type = null): RouteCollection
{
if ($this->isLoaded) {
throw new \RuntimeException('Do not add the "whatwedo_crud" loader twice');
Expand All @@ -40,11 +40,9 @@ public function load($resource, $type = null): RouteCollection
]
);

switch ($capability) {
case HistoryPage::HISTORY:
$route->setPath($route->getPath().'{id}/history');
$route->setRequirement('id', '\d+');
break;
if ($capability == HistoryPage::HISTORY) {
$route->setPath($route->getPath().'{id}/history');
$route->setRequirement('id', '\d+');
}

$routes->add($definition::getRoutePrefix().'_'.$capability->toRoute(), $route);
Expand All @@ -57,10 +55,7 @@ public function load($resource, $type = null): RouteCollection
return $routes;
}

/**
* @return bool
*/
public function supports($resource, $type = null)
public function supports(mixed $resource, ?string $type = null): bool
{
return $type === 'whatwedo_crud_history';
}
Expand Down
50 changes: 20 additions & 30 deletions tests/App/Entity/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,58 +6,48 @@

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use whatwedo\CrudHistoryBundle\Entity\AuditTriggerInterface;
use whatwedo\CrudHistoryBundle\Entity\AuditTriggerTrait;
use whatwedo\CrudHistoryBundle\Tests\App\Repository\CompanyRepository;

/**
* @ORM\Table(name="company")
* @ORM\Entity(repositoryClass="whatwedo\CrudHistoryBundle\Tests\App\Repository\CompanyRepository")
*/
#[ORM\Table(name: 'company')]
#[ORM\Entity(repositoryClass: CompanyRepository::class)]
class Company implements AuditTriggerInterface
{
use AuditTriggerTrait;

/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
#[ORM\Column(type: Types::INTEGER)]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
private ?int $id = null;

/**
* @ORM\Column(type="string")
* @Assert\NotBlank
* @Assert\NotNull()
*/
#[ORM\Column(type: Types::STRING)]
#[Assert\NotBlank]
#[Assert\NotNull]
private ?string $name = null;

/**
* @ORM\Column(type="string")
* @Assert\NotBlank
* @Assert\NotNull()
*/
#[ORM\Column(type: Types::STRING)]
#[Assert\NotBlank]
#[Assert\NotNull]
private ?string $city = null;

/**
* @ORM\Column(type="string")
* @Assert\NotBlank
* @Assert\NotNull()
*/
#[ORM\Column(type: Types::STRING)]
#[Assert\NotBlank]
#[Assert\NotNull]
private ?string $country = null;

/**
* @ORM\Column(type="string")
* @Assert\NotBlank
* @Assert\NotNull()
*/
#[ORM\Column(type: Types::STRING)]
#[Assert\NotBlank]
#[Assert\NotNull]
private ?string $taxIdentificationNumber = null;

/**
* @var Collection|array<Contact> One Member has Many Departments
* @ORM\OneToMany (targetEntity="Contact", mappedBy="company")
*/
#[ORM\OneToMany(mappedBy: 'company', targetEntity: Contact::class)]
private $contacts;

public function __construct()
Expand Down
27 changes: 11 additions & 16 deletions tests/App/Entity/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,30 @@

namespace whatwedo\CrudHistoryBundle\Tests\App\Entity;

use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use whatwedo\CrudHistoryBundle\Entity\AuditManyToOneTriggerInterface;
use whatwedo\CrudHistoryBundle\Tests\App\Repository\ContactRepository;

/**
* @ORM\Table(name="contact")
* @ORM\Entity(repositoryClass="whatwedo\CrudHistoryBundle\Tests\App\Repository\ContactRepository")
*/
#[ORM\Table(name: 'contact')]
#[ORM\Entity(repositoryClass: ContactRepository::class)]
class Contact implements \Stringable, AuditManyToOneTriggerInterface
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
#[ORM\Column(type: Types::INTEGER)]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
private ?int $id = null;

/**
* @ORM\Column(type="string", length=50)
* @Assert\NotBlank
* @Assert\NotNull()
*/
#[ORM\Column(type: Types::STRING, length: 50)]
#[Assert\NotBlank]
#[Assert\NotNull]
private ?string $name = null;

/**
* Many Groups have Many Members.
*
* @ORM\ManyToOne(targetEntity="Company", inversedBy="contacts")
*/
#[ORM\ManyToOne(targetEntity: Company::class, inversedBy: 'contacts')]
private Company $company;

public function __construct(Company $company)
Expand Down
24 changes: 10 additions & 14 deletions tests/App/Entity/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,23 @@

namespace whatwedo\CrudHistoryBundle\Tests\App\Entity;

use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use whatwedo\CrudHistoryBundle\Tests\App\Repository\PersonRepository;

/**
* @ORM\Table(name="person")
* @ORM\Entity(repositoryClass="whatwedo\CrudHistoryBundle\Tests\App\Repository\PersonRepository")
*/
#[ORM\Table(name: 'person')]
#[ORM\Entity(repositoryClass: PersonRepository::class)]
class Person
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
#[ORM\Column(type: Types::INTEGER)]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
private ?int $id = null;

/**
* @ORM\Column(type="string")
* @Assert\NotBlank
* @Assert\NotNull()
*/
#[ORM\Column(type: Types::STRING)]
#[Assert\NotBlank]
#[Assert\NotNull]
private ?string $name = null;

public function getId(): ?int
Expand Down
3 changes: 2 additions & 1 deletion tests/App/config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ doctrine:
orm:
default_entity_manager: default
auto_generate_proxy_classes: true
enable_lazy_ghost_objects: true
entity_managers:
default:
connection: default
Expand All @@ -21,7 +22,7 @@ doctrine:
mappings:
App:
is_bundle: false
type: annotation
type: attribute
dir: '%kernel.project_dir%/Entity'
prefix: 'whatwedo\CrudHistoryBundle\Tests\App\Entity'
alias: App
4 changes: 2 additions & 2 deletions tests/App/config/routes/annotations.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
controllers:
resource: ../../../../src/Controller/
type: annotation
type: attribute

kernel:
resource: ../../Kernel.php
type: annotation
type: attribute

0 comments on commit 2229434

Please sign in to comment.