本文整理匯總了PHP中Auryn\Injector::define方法的典型用法代碼示例。如果您正苦於以下問題:PHP Injector::define方法的具體用法?PHP Injector::define怎麽用?PHP Injector::define使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Auryn\Injector
的用法示例。
在下文中一共展示了Injector::define方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: addToInjector
public function addToInjector(Injector $injector)
{
foreach ($this->shares as $share) {
$injector->share($share);
}
foreach ($this->aliases as $original => $alias) {
$injector->alias($original, $alias);
}
foreach ($this->definitions as $name => $args) {
$injector->define($name, $args);
}
foreach ($this->params as $param => $value) {
$injector->defineParam($param, $value);
}
foreach ($this->delegates as $param => $callable) {
$injector->delegate($param, $callable);
}
foreach ($this->prepares as $class => $callable) {
$injector->prepare($class, $callable);
}
}
示例2: setClassParameters
/**
* {@inheritdoc}
*/
public function setClassParameters($className, $arguments)
{
foreach ($arguments as $key => $value) {
unset($arguments[$key]);
$arguments[':' . $key] = $value;
}
$this->auryn->define($className, $arguments);
}
示例3: apply
/**
*
* {@inheritDoc}
*
* @see \Spark\Configuration\ConfigurationInterface::apply()
*/
public function apply(Injector $injector)
{
$host = $this->env['DB_HOST'];
$username = $this->env['DB_USERNAME'];
$password = $this->env['DB_PASSWORD'];
$name = $this->env['DB_DBNAME'];
$port = $this->env['DB_PORT'];
$dsn = "mysql:dbname={$name};host={$host};port={$port}";
$injector->define('PDO', [':dsn' => $dsn, ':username' => $username, ':passwd' => $password]);
$injector->define('FluentPDO', [':pdo' => $injector->make('PDO')]);
}
示例4: apply
/**
* Applies a configuration set to a dependency injector.
*
* @param Injector $injector
*/
public function apply(Injector $injector)
{
// JWT
$injector->define('Equip\\Auth\\Jwt\\Configuration', [':publicKey' => 'uhklzsdv89ywrahu', ':ttl' => 3600, ':algorithm' => 'HS256']);
$injector->alias('Equip\\Auth\\Jwt\\GeneratorInterface', 'Equip\\Auth\\Jwt\\FirebaseGenerator');
$injector->alias('Equip\\Auth\\Jwt\\ParserInterface', 'Equip\\Auth\\Jwt\\FirebaseParser');
// Tokens
$injector->alias(TokenExtractorInterface::class, TokenHeaderExtractor::class);
$injector->define(TokenHeaderExtractor::class, [':header' => 'Bearer']);
// Credentials
$injector->alias(CredentialsExtractorInterface::class, CredentialsBodyExtractor::class);
// Adapter
$injector->alias(AdapterInterface::class, JWTAdapter::class);
}
示例5: apply
/**
*
* {@inheritDoc}
*
* @see \Spark\Configuration\ConfigurationInterface::apply()
*/
public function apply(Injector $injector)
{
$injector->alias(ExtractorInterface::class, HeaderExtractor::class);
$injector->define(HeaderExtractor::class, [':header' => 'token']);
$injector->alias(\Spark\Auth\Credentials\ExtractorInterface::class, BodyExtractor::class);
$injector->alias(AdapterInterface::class, AuthAdapter::class);
}
示例6: apply
/**
* @inheritDoc
*/
public function apply(Injector $injector)
{
$injector->define(RelayBuilder::class, ['resolver' => 'Spark\\Resolver\\ResolverInterface']);
$injector->delegate('Relay\\Relay', function (RelayBuilder $builder, Middleware $queue) {
return $builder->newInstance($queue);
});
}
示例7: setMedoo
function setMedoo()
{
$injector = new Injector();
$injector->share('medoo');
$injector->define('medoo', [':options' => $this->databaseconfig]);
$this->medoodb = $injector->make('medoo');
}
示例8: apply
/**
* @inheritDoc
*/
public function apply(Injector $injector)
{
$injector->define(RelayBuilder::class, ['resolver' => ResolverInterface::class]);
$factory = function (RelayBuilder $builder, MiddlewareSet $queue) {
return $builder->newInstance($queue);
};
$injector->delegate(Relay::class, $factory);
}
示例9: apply
public function apply(Injector $injector)
{
//START: auth
$injector->alias(AdapterInterface::class, \trejeraos\SimpleServerMonitor\Auth\FooAdapter::class);
$injector->alias(AuthHandler::class, FooAuthHandler::class);
$injector->share(FooAuthHandler::class);
// get auth token
$injector->alias(TokenExtractorInterface::class, QueryExtractor::class);
$injector->define(QueryExtractor::class, [':parameter' => 'tok']);
// get auth credentials
$injector->alias(CredentialsExtractorInterface::class, BodyExtractor::class);
$injector->define(BodyExtractor::class, [':identifier' => 'user', ':password' => 'password']);
// share valid auth token class
$injector->share(\trejeraos\SimpleServerMonitor\Auth\ValidTokens::class);
//END: auth
// share global config class
$injector->share(\trejeraos\SimpleServerMonitor\Data\Configuration::class);
}
示例10: apply
/**
* @inheritDoc
*/
public function apply(Injector $injector)
{
$injector->define(Loader::class, [':filepaths' => $this->envfile]);
$injector->share(Env::class);
$injector->prepare(Env::class, function (Env $env, Injector $injector) {
$loader = $injector->make(Loader::class);
$values = $loader->parse()->toArray();
return $env->withValues($values);
});
}
示例11: registerRouterServices
private function registerRouterServices(Injector $injector)
{
$injector->share(RouteCollector::class);
$injector->define(RouteCollector::class, ['routeParser' => StdRouteParser::class, 'dataGenerator' => GcbGenerator::class]);
$injector->share(Router\FastRouteRouter::class);
$injector->define(Router\FastRouteRouter::class, ['collector' => RouteCollector::class, ':dispatcherCb' => function (array $data) use($injector) {
return $injector->make(GcbDispatcher::class, [':data' => $data]);
}]);
$injector->alias(Router\Router::class, Router\FastRouteRouter::class);
$injector->share(ResolverChain::class);
$injector->prepare(ResolverChain::class, function (ResolverChain $chain, Injector $injector) {
$chain->add($injector->make(ResponseResolver::class));
$chain->add($injector->make(CallableResolver::class));
$chain->add($injector->make(ControllerActionResolver::class));
});
$injector->share(InjectorExecutableResolver::class);
$injector->define(InjectorExecutableResolver::class, ['resolver' => ResolverChain::class]);
$injector->alias(HandlerResolver::class, InjectorExecutableResolver::class);
}
示例12: applyProviderConfig
private function applyProviderConfig(Injector $injector, array $env)
{
$config = [];
foreach ($env as $key => $value) {
list($provider, $key) = explode('_', strtolower($key), 2);
$key = $this->toCamelCase($key);
$config[$provider][$key] = $value;
}
$injector->define(__NAMESPACE__ . '\\ProviderConfig', [':config' => $config]);
}
示例13: apply
/**
* @inheritDoc
*/
public function apply(Injector $injector)
{
$injector->alias('Equip\\Auth\\Token\\ExtractorInterface', 'Equip\\Auth\\Token\\QueryExtractor');
$injector->define('Equip\\Auth\\Token\\QueryExtractor', [':parameter' => 'tk']);
$injector->alias('Equip\\Auth\\Credentials\\ExtractorInterface', 'Equip\\Auth\\Credentials\\BodyExtractor');
$injector->alias('Equip\\Auth\\AdapterInterface', 'Equip\\Project\\Auth\\Adapter');
$dir = dirname(dirname(__DIR__));
$dotenv = new Dotenv($dir);
$dotenv->load();
$dotenv->required(['DB_HOST', 'DB_NAME', 'DB_USER', 'DB_PASS']);
}
示例14: apply
/**
* Applies a configuration set to a dependency injector.
*
* @param Injector $injector
*/
public function apply(Injector $injector)
{
//Specify token parameter from query string
$injector->define(QueryExtractor::class, [':parameter' => 'al']);
//Use Query Extractor to grab auth token
$injector->alias(\Spark\Auth\Token\ExtractorInterface::class, QueryExtractor::class);
//Use Json Extractor to grab credentials
$injector->alias(\Spark\Auth\Credentials\ExtractorInterface::class, JsonExtractor::class);
//Specify custom auth adapter to use
$injector->alias(AdapterInterface::class, Adapter::class);
}
示例15: Injector
function testValidControllerActionResultsInRightCallback()
{
$handler = HandlerWithMethod::class . '#action';
$val = new \stdClass();
$val->action = null;
$injector = new Injector();
$injector->define(HandlerWithMethod::class, [':val' => $val]);
$resolver = new ControllerActionResolver($injector, $this->emitter);
$cb = $resolver->resolve($this->request, $handler);
$cb($this->getMock(ServerRequestInterface::class));
$this->assertSame('invoked', $val->action);
}