Created
June 27, 2014 03:27
-
-
Save augustine-tran/f7839608f34d74a6da68 to your computer and use it in GitHub Desktop.
PhalconEye how injector api works
This file contains hidden or 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
/** | |
* Api container. | |
* | |
* @category PhalconEye | |
* @package Engine\Api | |
* @author Ivan Vorontsov <[email protected]> | |
* @copyright 2013-2014 PhalconEye Team | |
* @license New BSD License | |
* @link http://phalconeye.com/ | |
*/ | |
/** | |
* Get api from container. | |
* | |
* @param string $name Api name. | |
* @param array $arguments Api params. | |
* | |
* @return mixed | |
* @throws Exception | |
*/ | |
public function __call($name, $arguments) | |
{ | |
$apiClassName = sprintf('%s\Api\%s', ucfirst($this->_moduleName), ucfirst($name)); | |
$di = $this->getDI(); | |
if (!$di->has($apiClassName)) { | |
if (!class_exists($apiClassName)) { | |
throw new Exception(sprintf('Can not find Api with name "%s".', $name)); | |
} | |
$api = new $apiClassName($this->getDI(), $arguments); | |
$di->set($apiClassName, $api, true); | |
return $api; | |
} | |
return $di->get($apiClassName); | |
} | |
--------------------------- | |
Define: | |
class PyramidRepository extends AbstractApi { | |
public function getTeamUsers($teamId) { | |
return User::find(); | |
} | |
} | |
--------------------------- | |
Usage: | |
$arrUsers = $this->di->get('sourcing')->pyramidRepository()->getTeamUsers(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment