Skip to content

Commit

Permalink
feat: Change data table factory aware trait factory to protected, cha…
Browse files Browse the repository at this point in the history
…nge exceptions to bundle-specific ones
  • Loading branch information
Kreyu committed Feb 9, 2024
1 parent 7b54bce commit 777e947
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/DataTableFactoryAwareTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

namespace Kreyu\Bundle\DataTableBundle;

use Kreyu\Bundle\DataTableBundle\Exception\LogicException;
use Kreyu\Bundle\DataTableBundle\Type\DataTableType;
use Kreyu\Bundle\DataTableBundle\Type\DataTableTypeInterface;
use Symfony\Contracts\Service\Attribute\Required;

trait DataTableFactoryAwareTrait
{
private null|DataTableFactoryInterface $dataTableFactory = null;
protected ?DataTableFactoryInterface $dataTableFactory = null;

#[Required]
public function setDataTableFactory(?DataTableFactoryInterface $dataTableFactory): void
Expand All @@ -24,7 +25,7 @@ public function setDataTableFactory(?DataTableFactoryInterface $dataTableFactory
protected function createDataTable(string $type, mixed $query = null, array $options = []): DataTableInterface
{
if (null === $this->dataTableFactory) {
throw new \LogicException(sprintf('You cannot use the "%s" method on controller without data table factory.', __METHOD__));
throw new LogicException(sprintf('You cannot use the "%s" method on controller without data table factory.', __METHOD__));
}

return $this->dataTableFactory->create($type, $query, $options);
Expand All @@ -36,7 +37,7 @@ protected function createDataTable(string $type, mixed $query = null, array $opt
protected function createNamedDataTable(string $name, string $type, mixed $query = null, array $options = []): DataTableInterface
{
if (null === $this->dataTableFactory) {
throw new \LogicException(sprintf('You cannot use the "%s" method on controller without data table factory.', __METHOD__));
throw new LogicException(sprintf('You cannot use the "%s" method on controller without data table factory.', __METHOD__));
}

return $this->dataTableFactory->createNamed($name, $type, $query, $options);
Expand All @@ -45,7 +46,7 @@ protected function createNamedDataTable(string $name, string $type, mixed $query
protected function createDataTableBuilder(mixed $query = null, array $options = []): DataTableBuilderInterface
{
if (null === $this->dataTableFactory) {
throw new \LogicException(sprintf('You cannot use the "%s" method on controller without data table factory.', __METHOD__));
throw new LogicException(sprintf('You cannot use the "%s" method on controller without data table factory.', __METHOD__));
}

return $this->dataTableFactory->createBuilder(DataTableType::class, $query, $options);
Expand Down

0 comments on commit 777e947

Please sign in to comment.