-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- ResultSet\PrototypeStrategy sub-package moved to Object\PrototypeStrategy - Tests adapted - ResultSet\PrototypeStrategy\Service\ServiceLocatorStrategyFactory leaved in place (for backward compatibility) but deprecated (it'll be removed soon) - DateTimeStrategy revisited
- Loading branch information
Showing
12 changed files
with
249 additions
and
135 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
94 changes: 94 additions & 0 deletions
94
library/Object/PrototypeStrategy/Service/ServiceLocatorStrategyFactory.php
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,94 @@ | ||
<?php | ||
/** | ||
* Matryoshka | ||
* | ||
* @link https://github.com/matryoshka-model/matryoshka | ||
* @copyright Copyright (c) 2014-2015, Ripa Club | ||
* @license http://opensource.org/licenses/BSD-2-Clause Simplified BSD License | ||
*/ | ||
namespace Matryoshka\Model\Object\PrototypeStrategy\Service; | ||
|
||
use Matryoshka\Model\Object\PrototypeStrategy\ServiceLocatorStrategy; | ||
use Zend\ServiceManager\FactoryInterface; | ||
use Zend\ServiceManager\ServiceLocatorInterface; | ||
|
||
/** | ||
* Class ServiceLocatatorStrategyFactory | ||
*/ | ||
class ServiceLocatorStrategyFactory implements FactoryInterface | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $configKey = 'matryoshka-object-servicelocatorstrategy'; | ||
|
||
/** | ||
* Config | ||
* @var array | ||
*/ | ||
protected $config; | ||
|
||
/** | ||
* Create service | ||
* | ||
* @param ServiceLocatorInterface $serviceLocator | ||
* @return mixed | ||
*/ | ||
public function createService(ServiceLocatorInterface $serviceLocator) | ||
{ | ||
$config = $this->getConfig($serviceLocator); | ||
|
||
if (isset($config['service_locator'])) { | ||
$objectServiceLocator = $serviceLocator->get($config['service_locator']); | ||
} else { | ||
$objectServiceLocator = $serviceLocator->has('Matryoshka\Model\Object\ObjectManager') ? | ||
$serviceLocator->get('Matryoshka\Model\Object\ObjectManager') | ||
: $serviceLocator; | ||
} | ||
|
||
$strategy = new ServiceLocatorStrategy($objectServiceLocator); | ||
|
||
if (isset($config['type_field'])) { | ||
$strategy->setTypeField($config['type_field']); | ||
} | ||
|
||
if (isset($config['validate_object'])) { | ||
$strategy->setValidateObject($config['validate_object']); | ||
} | ||
|
||
if (isset($config['clone_object'])) { | ||
$strategy->setCloneObject($config['clone_object']); | ||
} | ||
|
||
return $strategy; | ||
} | ||
|
||
/** | ||
* Get model configuration, if any | ||
* | ||
* @param ServiceLocatorInterface $serviceLocator | ||
* @return array | ||
*/ | ||
protected function getConfig(ServiceLocatorInterface $serviceLocator) | ||
{ | ||
if ($this->config !== null) { | ||
return $this->config; | ||
} | ||
|
||
if (!$serviceLocator->has('Config')) { | ||
$this->config = []; | ||
return $this->config; | ||
} | ||
|
||
$config = $serviceLocator->get('Config'); | ||
if (!isset($config[$this->configKey]) | ||
|| !is_array($config[$this->configKey]) | ||
) { | ||
$this->config = []; | ||
return $this->config; | ||
} | ||
|
||
$this->config = $config[$this->configKey]; | ||
return $this->config; | ||
} | ||
} |
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
Oops, something went wrong.