Skip to content

Commit

Permalink
DEBUG ONLY: Revert "drop FactoryTrait"
Browse files Browse the repository at this point in the history
This reverts commit a7c8190.
  • Loading branch information
mvorisek committed Jun 4, 2020
1 parent a7c8190 commit a2ec463
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/DIContainerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public static function checkInstanceOf(object $object)// :static supported by PH
*/
public static function fromSeed($seed = [])// :static supported by PHP8+
{// @TODO move code from addTo here
return static::addTo(Shared::getFactory(), $seed, [], true);
return static::addTo(GlobalInternal::getDefaultFactory(), $seed, [], true);
}

/**
Expand All @@ -131,6 +131,6 @@ public static function fromSeed($seed = [])// :static supported by PHP8+
*/
public static function fromSeedWithCl($seed = [])// :static supported by PHP8+
{// @TODO move code from addTo here
return static::addToWithCl(Shared::getFactory(), $seed, [], true);
return static::addToWithCl(GlobalInternal::getDefaultFactory(), $seed, [], true);
}
}
31 changes: 31 additions & 0 deletions src/FactoryTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace atk4\core;

trait FactoryTrait
{
/**
* Check this property to see if trait is present in the object.
*
* @var bool
*/
public $_factoryTrait = true;

/**
* See \atk4\core\Factory::mergeSeeds().
*/
public function mergeSeeds($seed, $seed2, ...$more_seeds)
{
return GlobalInternal::getDefaultFactory()->mergeSeeds($seed, $seed2, $more_seeds);
}

/**
* See \atk4\core\Factory::factory().
*/
public function factory($seed, $defaults = []): object
{
return GlobalInternal::getDefaultFactory()->factory($seed, $defaults);
}
}
28 changes: 28 additions & 0 deletions src/GlobalInternal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace atk4\core;

class GlobalInternal
{
/** @var Factory */
private static $_defaultFactory;

private function __construct()
{
// zeroton
}

/**
* @return FactoryTrait
*/
public static function getDefaultFactory()
{
if (self::$_defaultFactory === null) {
self::$_defaultFactory = new Factory();
}

return self::$_defaultFactory;
}
}
28 changes: 0 additions & 28 deletions src/Shared.php

This file was deleted.

0 comments on commit a2ec463

Please sign in to comment.