Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"doctrine/collections": "^1.6",
"doctrine/orm": "^2.6",
"doctrine/persistence": "^1.3 || ^2.1",
"setono/doctrine-object-manager-trait": "^1.0",
"symfony/property-access": "^4.4 || ^5.2",
"webmozart/assert": "^1.10"
},
Expand Down
3 changes: 2 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0"?>
<psalm
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
errorLevel="4"
errorLevel="1"
totallyTyped="true"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
Expand Down
24 changes: 22 additions & 2 deletions src/Batch/Batch.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,46 @@

namespace Setono\DoctrineORMBatcher\Batch;

use Doctrine\ORM\Query\Parameter;
use Doctrine\ORM\QueryBuilder;
use InvalidArgumentException;

abstract class Batch implements BatchInterface
class Batch implements BatchInterface
{
private array $data;

/** @var class-string */
protected string $class;

protected string $dql;

/**
* @var array<int, Parameter>
*/
protected array $parameters;

public function __construct(QueryBuilder $qb)
public function __construct(array $data, QueryBuilder $qb)
{
/** @var array<array-key, class-string> $rootEntities */
$rootEntities = $qb->getRootEntities();
if (0 === count($rootEntities)) {
throw new InvalidArgumentException('The number of root entities on the query builder must be one or more');
}

$this->data = $data;
$this->class = $rootEntities[0];
$this->dql = $qb->getDQL();
$this->parameters = $qb->getParameters()->toArray();
}

public function getData(): array
{
return $this->data;
}

/**
* @return class-string
*/
public function getClass(): string
{
return $this->class;
Expand All @@ -37,6 +54,9 @@ public function getDql(): string
return $this->dql;
}

/**
* @return array<int, Parameter>
*/
public function getParameters(): array
{
return $this->parameters;
Expand Down
2 changes: 2 additions & 0 deletions src/Batch/BatchInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

interface BatchInterface
{
public function getData(): array;

/**
* This is the root entity that can be used to get the entity manager from the manager registry.
*/
Expand Down
29 changes: 0 additions & 29 deletions src/Batch/CollectionBatch.php

This file was deleted.

10 changes: 0 additions & 10 deletions src/Batch/CollectionBatchInterface.php

This file was deleted.

Loading