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
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
language: php

php:
- 7.0
- 7.1
- 7.2

branches:
only:
- master
- develop
- /^v\d+\.\d+\.\d+$/
- /^d+\.\d+$/

cache:
directories:
Expand Down
18 changes: 14 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,32 @@
}
],
"require": {
"php": "^7.1",
"symfony/property-access": "^3.0|^4.0"
},
"require-dev": {
"doctrine/orm": "^2.4,>=2.4.5",
"phpunit/phpunit": "^6.3",
"phpunit/phpunit": "^7.0",
"friendsofphp/php-cs-fixer": "^2.7",
"phpmd/phpmd": "^2.6"
"phpmd/phpmd": "^2.6",
"phpstan/phpstan": "^0.9.2",
"symfony/var-dumper": "^4.0",
"symfony/yaml": "^4.0"
},
"suggest": {
"doctrine/orm": "^2.4,>=2.4.5",
"webonyx/graphql-php": "^0.0,>=0.9"
},
"autoload": {
"psr-4": { "Xsolve\\Associate\\": "lib" }
"psr-4": {
"Xsolve\\Associate\\": "lib",
"Xsolve\\LegacyAssociate\\": "legacyLib"
}
},
"autoload-dev": {
"psr-4": { "Xsolve\\AssociateTests\\": "tests" }
"psr-4": {
"Xsolve\\AssociateTests\\": "tests",
"Xsolve\\LegacyAssociateTests\\": "legacyTests"
}
}
}
96 changes: 96 additions & 0 deletions draft-1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

$sources = [$source1, $source2, $source3];
$path = ['bar', 'baz'];

$targets = $collector->getTargets($sources, $path);

$sourcesToTargetsMap = $collector->getSourcesToTargetsMap($sources, $path);
$targets1 = $sourcesToTargetsMap->get([$source1]);
$targets1And2 = $sourcesToTargetsMap->get([$source1, $source2]);

$targetIds = $collector->getTargetIds($sources, $path);

$sourcesToTargetIdsMap = $collector->getSourcesToTargetIdsMap($sources, $path);
$targetIds1 = $sourcesToTargetIdsMap->get([$source1]);
$targetIds1And2 = $sourcesToTargetIdsMap->get([$source1, $source2]);

// Need to specify strategy for final objects - if they should be fully loaded or if proxies are enough.

$doctrineOrmAssociationPath = $doctrineOrmAssociationPathBuilder
->associate('bar')
->aliasAs('bars')
->loadFull()
->associate('baz')
->aliasAs('bazs')
->create();

$doctrineOrmAssociationPath = $doctrineOrmAssociationPathBuilder
->associate('bar')
->associate('baz')
->create();

// Equivalent to
$doctrineOrmAssociationPath = new DoctrineOrmAssociationPath([
(new DoctrineOrmAssociation('bar'))
->setAlias('bars')
->setLoadMode(DoctrineOrmAssociationLoad::FULL),
(new DoctrineOrmAssociation('baz'))
->setLoadMode(DoctrineOrmAssociationLoad::PROXY),
]);

$doctrineOrmEntitiesSource = (new DoctrineOrmEntitiesSource([$foo1, $foo2, $foo3]))
->declareEntityClass(Foo::class);

$targets = $associate
->getAdapter('doctrine')
->getTargets($doctrineOrmEntitiesSource, $doctrineOrmAssociationPath);

$bazs = $targets->getAll();

// Complete usage for prefetching with simplified facad, diverging paths.
$associateDoctrineOrmFetcher->fetch(
$foos,
Foo::class,
[
['foo', [
['bar'],
['baz' , 'qux'],
]],
['qux'],
]
);


// .foo.bar
// .baz.qux
// .qux
//
$doctrineOrmAssociationPathBuilder
->diverge()
->associate('foo')
->diverge()
->associate('bar')
->endDiverge()
->diverge()
->associate('baz')
->associate('qux')
->endDiverge()
->endDiverge()
->diverge()
->associate('qux')
->endDiverge();

// .foo.bar.baz.qux
// .qux
//
$doctrineOrmAssociationPathBuilder
->associate('foo')
->associate('bar')
->diverge()
->associate('baz')
->associate('qux')
->endDiverge()
->diverge()
->associate('qux')
->endDiverge();
14 changes: 14 additions & 0 deletions draft-2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

$fooIds = [$fooId1, $fooId2, $fooId3]; // Or any other iterable.
$foos = [$foo1, $foo2, $foo3]; // Or any other iterable.

// Only ids are given for entities, entity class has to be declared.
$source = new DoctrineOrmIdentifiersSource($fooIds, Foo::class);

// Entity class not declared, will be determined based on entities and metadata.
// Entities can be fully loaded or just unitialized proxies.
$source = new DoctrineOrmEntitiesSource($foos);

// Entity class declared, will be checked (or not?) and compared with metadata.
$source = new DoctrineOrmEntityiesSource($foos, Foo::class);
119 changes: 119 additions & 0 deletions example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?php

require_once __DIR__ . '/vendor/autoload.php';

class Foo
{
/**
* @var Bar|null
*/
protected $bar;

/**
* @param Bar|null $bar
*/
public function __construct(Bar $bar = null)
{
$this->bar = $bar;
}

/**
* @return Bar|null
*/
public function getBar()
{
return $this->bar;
}
}

class Bar
{
/**
* @var Baz[]
*/
public $bazs;

/**
* @param Baz[] $bazs
*/
public function __construct(array $bazs)
{
$this->bazs = $bazs;
}
}

class Baz
{
/**
* @var string
*/
protected $text;

/**
* @param string $text
*/
public function __construct(string $text)
{
$this->text = $text;
}

/**
* @return string
*/
public function getText(): string
{
return $this->text;
}

/**
* @return string[]
*/
public function getWords(): array
{
return explode(' ', $this->text);
}

/**
* @return array
*/
public function getTextStats(): array
{
return ['wordCount' => count($this->getWords())];
}
}

$foos = [
$foo1 = new Foo(
$bar1 = new Bar([
$baz1 = new Baz('lorem ipsum'),
$baz2 = new Baz('dolor'),
])
),
$foo2 = new Foo(
$bar2 = new Bar([
$baz1,
$baz3 = new Baz('sit amet malef'),
$baz4 = new Baz('dolor sit'),
])
),
$foo3 = new Foo(),
];

$facade = new \Xsolve\Associate\Facade();
$basicCollector = $facade->getBasicCollector();

$bars = $basicCollector->collect($foos, ['bar']);
var_dump($bars);
die;

$bazs = $basicCollector->collect($foos, ['bar', 'bazs']);
var_dump($bazs);

$texts = $basicCollector->collect($foos, ['bar', 'bazs', 'text']);
var_dump($texts);

$words = $basicCollector->collect($foos, ['bar', 'bazs', 'words']);
var_dump($words);

$wordCounts = $basicCollector->collect($foos, ['bar', 'bazs', 'textStats', '[wordCount]']);
var_dump($wordCounts);
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Xsolve\Associate\AssociationCollecting;
namespace Xsolve\LegacyAssociate\AssociationCollecting;

interface AssociationCollectingStrategyInterface
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace Xsolve\Associate\AssociationCollecting;
namespace Xsolve\LegacyAssociate\AssociationCollecting;

use Xsolve\Associate\CollectionTraversal\CollectionTraversalStrategyInterface;
use Xsolve\Associate\ObjectCollection\ObjectCollectionInterface;
use Xsolve\Associate\ObjectCollection\UniqueObjectCollection;
use Xsolve\LegacyAssociate\CollectionTraversal\CollectionTraversalStrategyInterface;
use Xsolve\LegacyAssociate\ObjectCollection\ObjectCollectionInterface;
use Xsolve\LegacyAssociate\ObjectCollection\UniqueObjectCollection;
use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\PropertyAccess\PropertyAccessor;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace Xsolve\Associate\AssociationCollecting;
namespace Xsolve\LegacyAssociate\AssociationCollecting;

use Xsolve\Associate\Loader\DoctrineOrmEntityLoader;
use Xsolve\Associate\Metadata\AssociationMetadataWrapper;
use Xsolve\Associate\Metadata\ClassMetadataWrapper;
use Xsolve\Associate\Metadata\MetadataWrapperProvider;
use Xsolve\LegacyAssociate\Loader\DoctrineOrmEntityLoader;
use Xsolve\LegacyAssociate\Metadata\AssociationMetadataWrapper;
use Xsolve\LegacyAssociate\Metadata\ClassMetadataWrapper;
use Xsolve\LegacyAssociate\Metadata\MetadataWrapperProvider;

class DoctrineOrmAssociationCollectingStrategy extends BasicAssociationCollectingStrategy
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Xsolve\Associate\AssociationPath;
namespace Xsolve\LegacyAssociate\AssociationPath;

class AssociationPath
{
Expand Down Expand Up @@ -113,7 +113,7 @@ public static function compare(self $associationPath1, self $associationPath2):
return $comparison;
}

$i += 1;
++$i;
}

throw new \Exception();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Xsolve\Associate\AssociationPath;
namespace Xsolve\LegacyAssociate\AssociationPath;

class AssociationPathsCollection
{
Expand Down Expand Up @@ -97,7 +97,7 @@ protected function sortUniqueAssociatedPaths(array $associationPaths): array
$uniqueAssociationPaths[] = $associationPaths[$i];
}

$i += 1;
++$i;
}

return $uniqueAssociationPaths;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Xsolve\Associate\BufferedCollector;
namespace Xsolve\LegacyAssociate\BufferedCollector;

use Xsolve\Associate\AssociationPath\AssociationPath;
use Xsolve\LegacyAssociate\AssociationPath\AssociationPath;

class BufferedCollect
{
Expand All @@ -22,8 +22,8 @@ class BufferedCollect
protected $associatedEntities;

/**
* @param array $objects
* @param string[] $associationNames
* @param array $objects
* @param string[] $associationNames
*/
public function __construct(
array $objects,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace Xsolve\Associate\BufferedCollector;
namespace Xsolve\LegacyAssociate\BufferedCollector;

use Xsolve\Associate\CollectorInterface;
use Xsolve\Associate\Metadata\MetadataWrapperProvider;
use Xsolve\Associate\ObjectCollection\UniqueObjectCollection;
use Xsolve\LegacyAssociate\CollectorInterface;
use Xsolve\LegacyAssociate\Metadata\MetadataWrapperProvider;
use Xsolve\LegacyAssociate\ObjectCollection\UniqueObjectCollection;

class BufferedCollector implements BufferedCollectorInterface
{
Expand Down
Loading