Skip to content

Instantly share code, notes, and snippets.

@augustine-tran
Created June 27, 2014 03:27
Show Gist options
  • Save augustine-tran/f7839608f34d74a6da68 to your computer and use it in GitHub Desktop.
Save augustine-tran/f7839608f34d74a6da68 to your computer and use it in GitHub Desktop.
PhalconEye how injector api works
/**
* 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