Skip to content

Commit

Permalink
[phalcon/incubator#971] Mass unification to collectionsManager
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeckerson committed Jul 9, 2023
1 parent 6cd967c commit 56478c8
Show file tree
Hide file tree
Showing 61 changed files with 106 additions and 114 deletions.
72 changes: 32 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Manager controls the initialization of collections, keeping record of relations
use Phalcon\Incubator\MongoDB\Mvc\Collection\Manager;

$di->set(
'collectionManager',
'collectionsManager',
function () {
return new Manager();
}
Expand Down Expand Up @@ -72,68 +72,60 @@ $robots = RobotsCollection::find();
echo "There are ", count($robots), "\n";

// How many mechanical robots are there?
$robots = RobotsCollection::find(
[
[
"type" => "mechanical",
],
]
);
$robots = RobotsCollection::find([
[
"type" => "mechanical",
],
]);

echo "There are ", count(robots), "\n";

// Get and print virtual robots ordered by name
$robots = RobotsCollection::findFirst(
[
[
"type" => "virtual"
],
"order" => [
"name" => 1,
],
]
);
$robots = RobotsCollection::findFirst([
[
"type" => "virtual",
],
"order" => [
"name" => 1,
],
]);

foreach ($robots as $robot) {
echo $robot->name, "\n";
echo $robot->name, "\n";
}

// Get first 100 virtual robots ordered by name
$robots = RobotsCollection::find(
[
[
"type" => "virtual",
],
"order" => [
"name" => 1,
],
"limit" => 100,
]
);
$robots = RobotsCollection::find([
[
"type" => "virtual",
],
"order" => [
"name" => 1,
],
"limit" => 100,
]);

foreach (RobotsCollection as $robot) {
echo $robot->name, "\n";
echo $robot->name, "\n";
}

$robot = RobotsCollection::findFirst(
[
[
"_id" => new ObjectId("45cbc4a0e4123f6920000002"),
],
]
);
$robot = RobotsCollection::findFirst([
[
"_id" => new ObjectId("45cbc4a0e4123f6920000002"),
],
]);

// Find robot by using \MongoDB\BSON\ObjectId object
$robot = RobotsCollection::findById(
new ObjectId("545eb081631d16153a293a66")
new ObjectId("545eb081631d16153a293a66")
);

// Find robot by using id as sting
$robot = RobotsCollection::findById("45cbc4a0e4123f6920000002");

// Validate input
if ($robot = RobotsCollection::findById($_POST["id"])) {
// ...
// ...
}
```

Expand Down
8 changes: 4 additions & 4 deletions src/Mvc/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ public static function findById($id): ?CollectionInterface
$className = static::class;
$collection = new $className();

if ($collection->getCollectionManager()->isUsingImplicitObjectIds($collection)) {
if ($collection->getCollectionsManager()->isUsingImplicitObjectIds($collection)) {
$objectId = new ObjectId($id);
} else {
$objectId = $id;
Expand All @@ -870,7 +870,7 @@ public static function findById($id): ?CollectionInterface
*
* @return ManagerInterface
*/
public function getCollectionManager(): ManagerInterface
public function getCollectionsManager(): ManagerInterface
{
return $this->collectionsManager;
}
Expand Down Expand Up @@ -1243,10 +1243,10 @@ public function unserialize($data): void
/**
* Gets the default collectionsManager service
*/
$manager = $container->getShared("collectionManager");
$manager = $container->getShared('collectionsManager');
if ($manager === null) {
throw new Exception(
"The injected service 'collectionManager' is not valid"
"The injected service 'collectionsManager' is not valid"
);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Mvc/Collection/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
* These components control the initialization of collections, keeping record of relations
* between the different collections of the application.
*
* A CollectionManager is injected to a collection via a Dependency Injector Container such as Phalcon\Di.
* A CollectionsManager is injected to a collection via a Dependency Injector Container such as Phalcon\Di.
*
* <code>
* $di = new \Phalcon\Di();
*
* $di->set(
* "collectionManager",
* "collectionsManager",
* function () {
* return new \Phalcon\Incubator\MongoDB\Mvc\Collection\Manager();
* }
Expand Down Expand Up @@ -181,7 +181,7 @@ public function initialize(CollectionInterface $collection): void
* If an EventsManager is available we pass to it every initialized collection
*/
if (is_object($this->eventsManager)) {
$this->eventsManager->fire('collectionManager:afterInitialize', $collection);
$this->eventsManager->fire('collectionsManager:afterInitialize', $collection);
}

$this->initialized[$className] = $collection;
Expand Down
4 changes: 2 additions & 2 deletions src/Mvc/Collection/ManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
* These components control the initialization of collections, keeping record of relations
* between the different collections of the application.
*
* A CollectionManager is injected to a collection via a Dependency Injector Container such as Phalcon\Di.
* A CollectionsManager is injected to a collection via a Dependency Injector Container such as Phalcon\Di.
*
* <code>
* $di = new \Phalcon\Di\Di();
*
* $di->set(
* "collectionManager",
* "collectionsManager",
* function() {
* return new \Phalcon\Incubator\Mvc\Collection\Manager();
* }
Expand Down
8 changes: 4 additions & 4 deletions tests/_data/fixtures/Traits/DiTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Phalcon\Di\Di;
use Phalcon\Di\DiInterface;
use Phalcon\Di\FactoryDefault;
use Phalcon\Incubator\MongoDB\Mvc\Collection\Manager as CollectionManager;
use Phalcon\Incubator\MongoDB\Mvc\Collection\Manager as CollectionsManager;

trait DiTrait
{
Expand Down Expand Up @@ -53,11 +53,11 @@ protected function resetDi()
}

/**
* Setup a new Collection Manager
* Set up a new Collection Manager
*/
protected function setDiCollectionManager()
protected function setDiCollectionsManager()
{
$this->container->setShared('collectionsManager', CollectionManager::class);
$this->container->setShared('collectionsManager', CollectionsManager::class);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/Collection/AggregateCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class AggregateCest
public function _before()
{
$this->setNewFactoryDefault();
$this->setDiCollectionManager();
$this->setDiCollectionsManager();
$this->setDiMongo();

$this->source = (new Robots())->getSource();
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/Collection/AppendMessageCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class AppendMessageCest
public function _before()
{
$this->setNewFactoryDefault();
$this->setDiCollectionManager();
$this->setDiCollectionsManager();
$this->setDiMongo();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/Collection/AssignCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class AssignCest
public function _before()
{
$this->setNewFactoryDefault();
$this->setDiCollectionManager();
$this->setDiCollectionsManager();
$this->setDiMongo();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/Collection/CloneResultCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class CloneResultCest
public function _before()
{
$this->setNewFactoryDefault();
$this->setDiCollectionManager();
$this->setDiCollectionsManager();
$this->setDiMongo();

$this->source = (new Robots)->getSource();
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/Collection/ConstructCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ConstructCest
public function _before()
{
$this->setNewFactoryDefault();
$this->setDiCollectionManager();
$this->setDiCollectionsManager();
$this->setDiMongo();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/Collection/CountCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class CountCest
public function _before()
{
$this->setNewFactoryDefault();
$this->setDiCollectionManager();
$this->setDiCollectionsManager();
$this->setDiMongo();

$this->source = (new Robots())->getSource();
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/Collection/CreateCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class CreateCest
public function _before()
{
$this->setNewFactoryDefault();
$this->setDiCollectionManager();
$this->setDiCollectionsManager();
$this->setDiMongo();

$this->source = (new Robots())->getSource();
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/Collection/DeleteCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class DeleteCest
public function _before()
{
$this->setNewFactoryDefault();
$this->setDiCollectionManager();
$this->setDiCollectionsManager();
$this->setDiMongo();

$this->source = (new Robots)->getSource();
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/Collection/Document/AssignCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class AssignCest
public function _before()
{
$this->setNewFactoryDefault();
$this->setDiCollectionManager();
$this->setDiCollectionsManager();
$this->setDiMongo();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/Collection/Document/ConstructCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ConstructCest
public function _before()
{
$this->setNewFactoryDefault();
$this->setDiCollectionManager();
$this->setDiCollectionsManager();
$this->setDiMongo();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class JsonSerializeCest
public function _before()
{
$this->setNewFactoryDefault();
$this->setDiCollectionManager();
$this->setDiCollectionsManager();
$this->setDiMongo();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class OffsetArrayAccessCest
public function _before()
{
$this->setNewFactoryDefault();
$this->setDiCollectionManager();
$this->setDiCollectionsManager();
$this->setDiMongo();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ReadWriteAttributeCest
public function _before()
{
$this->setNewFactoryDefault();
$this->setDiCollectionManager();
$this->setDiCollectionsManager();
$this->setDiMongo();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/Collection/Document/ToArrayCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ToArrayCest
public function _before()
{
$this->setNewFactoryDefault();
$this->setDiCollectionManager();
$this->setDiCollectionsManager();
$this->setDiMongo();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/Collection/FindByIdCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class FindByIdCest
public function _before()
{
$this->setNewFactoryDefault();
$this->setDiCollectionManager();
$this->setDiCollectionsManager();
$this->setDiMongo();

$this->source = (new Robots())->getSource();
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/Collection/FindCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class FindCest
public function _before()
{
$this->setNewFactoryDefault();
$this->setDiCollectionManager();
$this->setDiCollectionsManager();
$this->setDiMongo();

$this->source = (new Robots)->getSource();
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/Collection/FindFirstCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class FindFirstCest
public function _before()
{
$this->setNewFactoryDefault();
$this->setDiCollectionManager();
$this->setDiCollectionsManager();
$this->setDiMongo();

$this->source = (new Robots)->getSource();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,29 @@
use Phalcon\Incubator\MongoDB\Test\Fixtures\Mvc\Collections\Robots;
use Phalcon\Incubator\MongoDB\Test\Fixtures\Traits\DiTrait;

class GetCollectionManagerCest
class GetCollectionsManagerCest
{
use DiTrait;

public function _before()
{
$this->setNewFactoryDefault();
$this->setDiCollectionManager();
$this->setDiCollectionsManager();
$this->setDiMongo();
}

/**
* Tests Phalcon\Mvc\Collection :: getCollectionManager()
* Tests Phalcon\Mvc\Collection :: getCollectionsManager()
*
* @param IntegrationTester $I
* @since 2018-11-13
* @author Phalcon Team <team@phalcon.io>
*/
public function mvcCollectionGetCollectionManager(IntegrationTester $I)
public function mvcCollectionGetCollectionsManager(IntegrationTester $I)
{
$I->wantToTest('Mvc\Collection - getCollectionManager()');
$I->wantToTest('Mvc\Collection - getCollectionsManager()');

$robot = new Robots();
$I->assertTrue(is_subclass_of($robot->getCollectionManager(), ManagerInterface::class));
$I->assertTrue(is_subclass_of($robot->getCollectionsManager(), ManagerInterface::class));
}
}
Loading

0 comments on commit 56478c8

Please sign in to comment.