Skip to content

Commit

Permalink
ObjectProperty: Modified model loader
Browse files Browse the repository at this point in the history
Changes:
- Changed `modelLoader()` visibility from private to protected
- Added support for retrieving a specific model loader from `modelLoader()`
  • Loading branch information
mcaskill committed May 9, 2017
1 parent e1d9061 commit 3b28e5c
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/Charcoal/Property/ObjectProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class ObjectProperty extends AbstractProperty implements SelectablePropertyInter
*
* @var ModelLoader[]
*/
private static $modelLoaders = [];
protected static $modelLoaders = [];

/**
* Store the factory instance for the current class.
Expand Down Expand Up @@ -743,16 +743,16 @@ protected function renderObjPattern($obj, $pattern = null)
*
* Loads the object from the cache store or from the storage source.
*
* @param mixed $id Object id.
* @param mixed $objId Object id.
* @return ModelInterface
*/
protected function loadObject($id)
protected function loadObject($objId)
{
if ($id instanceof ModelInterface) {
return $id;
if ($objId instanceof ModelInterface) {
return $objId;
}

$obj = $this->modelLoader()->load($id);
$obj = $this->modelLoader()->load($objId);
if (!$obj->id()) {
return null;
} else {
Expand All @@ -761,11 +761,21 @@ protected function loadObject($id)
}

/**
* Retrieve the model loader.
*
* @param string $objType The object type.
* @return ModelLoader
*/
private function modelLoader()
protected function modelLoader($objType = null)
{
$objType = $this->objType();
if ($objType === null) {
$objType = $this->objType();
} elseif (!is_string($objType)) {
throw new InvalidArgumentException(
'Object type must be a string.'
);
}

if (isset(self::$modelLoaders[$objType])) {
return self::$modelLoaders[$objType];
}
Expand Down

0 comments on commit 3b28e5c

Please sign in to comment.