-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Adrian Miu
committed
Feb 24, 2020
1 parent
e550593
commit ea08185
Showing
7 changed files
with
116 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Sirius\Orm\Relation; | ||
|
||
use Sirius\Orm\Helpers\Str; | ||
use Sirius\Orm\Mapper; | ||
use Sirius\Orm\Orm; | ||
|
||
class RelationBuilder { | ||
|
||
/** | ||
* @var Orm | ||
*/ | ||
protected $orm; | ||
|
||
public function __construct(Orm $orm) | ||
{ | ||
$this->orm = $orm; | ||
} | ||
|
||
public function newRelation(Mapper $nativeMapper, $name, $options): Relation | ||
{ | ||
$foreignMapper = $options[RelationConfig::FOREIGN_MAPPER]; | ||
if ($this->orm->has($foreignMapper)) { | ||
if (! $foreignMapper instanceof Mapper) { | ||
$foreignMapper = $this->orm->get($foreignMapper); | ||
} | ||
} | ||
$type = $options[RelationConfig::TYPE]; | ||
$relationClass = __NAMESPACE__ . '\\' . Str::className($type); | ||
|
||
if (! class_exists($relationClass)) { | ||
throw new \InvalidArgumentException("{$relationClass} does not exist"); | ||
} | ||
|
||
return new $relationClass($name, $nativeMapper, $foreignMapper, $options); | ||
} | ||
} |