本文整理匯總了PHP中Injector類的典型用法代碼示例。如果您正苦於以下問題:PHP Injector類的具體用法?PHP Injector怎麽用?PHP Injector使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Injector類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getAuthenticator
protected function getAuthenticator()
{
$injector = new Injector();
$auth = new RESTfulAPI_TokenAuthenticator();
$injector->inject($auth);
return $auth;
}
示例2: getSerializer
protected function getSerializer()
{
$injector = new Injector();
$serializer = new RESTfulAPI_BasicSerializer();
$injector->inject($serializer);
return $serializer;
}
開發者ID:helpfulrobot,項目名稱:colymba-silverstripe-restfulapi,代碼行數:7,代碼來源:RESTfulAPI_BasicSerializer_Test.php
示例3: getQueryHandler
protected function getQueryHandler()
{
$injector = new Injector();
$qh = new RESTfulAPI_DefaultQueryHandler();
$injector->inject($qh);
return $qh;
}
示例4: injected
function injected()
{
$injector = new Injector(array('ServiceA', 'ServiceB', 'ServiceC', 'ServiceD', 'ServiceE'));
for ($i = 0; $i < ITERATIONS; $i++) {
$obj = $injector->instantiate('MyObject');
$obj->doSomething();
}
}
示例5: testProxyClass
public function testProxyClass()
{
$config = array(array('class' => 'TestServiceForProxy', 'id' => 'TestServiceForProxy'), array('class' => 'TestAspectBean', 'id' => 'PreCallTest'), array('class' => 'TestAspectBean', 'id' => 'PostCallTest'), array('src' => dirname(dirname(dirname(__FILE__))) . '/services/AopProxyService.php', 'id' => 'TestService', 'properties' => array('proxied' => '#$TestServiceForProxy', 'beforeCall' => array('calculate' => '#$PreCallTest'), 'afterCall' => array('calculate' => '#$PostCallTest'))));
$injector = new Injector($config);
$test = $injector->get('TestService');
$this->assertEqual('AopProxyService', get_class($test));
$this->assertEqual(10, $test->calculate(5));
$aspect1 = $injector->get('PreCallTest');
$this->assertEqual(5, $aspect1->data['calculatepre']);
$aspect2 = $injector->get('PostCallTest');
$this->assertEqual(10, $aspect2->data['calculatepost']);
$this->assertNotEqual($aspect1, $aspect2);
}
示例6: loadContext
/**
* Load the application context
* @return ApplicationContext
*/
protected function loadContext($config)
{
$loader = ContextLoaderFactory::getLoader($config);
$context = $loader->load($config);
$injector = new Injector($context);
foreach ($context->getResources() as $resource) {
$injector->inject($resource);
}
foreach ($context->getResources() as $resource) {
if ($resource instanceof InitializingBean) {
$resource->afterPropertiesSet();
}
}
PiconApplication::get()->getContextLoadListener()->onContextLoaded($context);
}
示例7: iAmLoggedInWithPermissions
/**
* Creates a member in a group with the correct permissions.
* Example: Given I am logged in with "ADMIN" permissions
*
* @Given /^I am logged in with "([^"]*)" permissions$/
*/
function iAmLoggedInWithPermissions($permCode)
{
if (!isset($this->cache_generatedMembers[$permCode])) {
$group = \Group::get()->filter('Title', "{$permCode} group")->first();
if (!$group) {
$group = \Injector::inst()->create('Group');
}
$group->Title = "{$permCode} group";
$group->write();
$permission = \Injector::inst()->create('Permission');
$permission->Code = $permCode;
$permission->write();
$group->Permissions()->add($permission);
$member = \DataObject::get_one('Member', sprintf('"Email" = \'%s\'', "{$permCode}@example.org"));
if (!$member) {
$member = \Injector::inst()->create('Member');
}
// make sure any validation for password is skipped, since we're not testing complexity here
$validator = \Member::password_validator();
\Member::set_password_validator(null);
$member->FirstName = $permCode;
$member->Surname = "User";
$member->Email = "{$permCode}@example.org";
$member->PasswordEncryption = "none";
$member->changePassword('Secret!123');
$member->write();
$group->Members()->add($member);
\Member::set_password_validator($validator);
$this->cache_generatedMembers[$permCode] = $member;
}
return new Step\Given(sprintf('I log in with "%s" and "%s"', "{$permCode}@example.org", 'Secret!123'));
}
示例8: connect
public function connect()
{
if (!($member = Member::currentUser())) {
/** @var stdClass $params */
$params = $this->getAccessToken($this->request->getVar('code'));
// member is not currently logged into SilverStripe. Look up
// for a member with the UID which matches first.
$member = Member::get()->filter(array("VkUID" => $params->user_id))->first();
if (!$member) {
// see if we have a match based on email. From a
// security point of view, users have to confirm their
// email address in facebook so doing a match up is fine
$email = $params->email;
if ($email) {
$member = Member::get()->filter(array('Email' => $email))->first();
}
}
if (!$member) {
$member = Injector::inst()->create('Member');
$member->syncVkDetails($this->getUserInfo());
}
}
$member->logIn(true);
// redirect the user to the provided url, otherwise take them
// back to the route of the website.
if ($url = Session::get(VkControllerExtension::SESSION_REDIRECT_URL_FLAG)) {
return $this->redirect($url);
} else {
return $this->redirect(Director::absoluteBaseUrl());
}
}
示例9: run
/**
* @return void
*/
public function run()
{
try {
$batch_size = 100;
$init_time = time();
$summit = null;
if (isset($_GET['batch_size'])) {
$batch_size = intval(trim(Convert::raw2sql($_GET['batch_size'])));
echo sprintf('batch_size set to %s', $batch_size) . PHP_EOL;
}
if (isset($_GET['summit_id'])) {
$summit = Summit::get()->byID(intval($_GET['summit_id']));
}
if (is_null($summit)) {
throw new Exception('summit_id is not valid!');
}
$manager = Injector::inst()->get('SpeakerSecondBreakoutAnnouncementSenderManager');
if (!$manager instanceof ISpeakerSecondBreakoutAnnouncementSenderManager) {
return;
}
$processed = $manager->send($summit, $batch_size);
$finish_time = time() - $init_time;
echo 'processed records ' . $processed . ' - time elapsed : ' . $finish_time . ' seconds.';
} catch (Exception $ex) {
SS_Log::log($ex->getMessage(), SS_Log::ERR);
}
}
示例10: mockFactory
/**
* @test
* @profile
* @ignore(ignoreUntilFixed)
*/
public function mockFactory()
{
$mockException = Mock_Factory::mock('Components\\Test_Exception', array('test/unit/case/mock', 'Mocked Exception.'));
$mockExceptionDefault = Mock_Factory::mock('Components\\Test_Exception');
$mockRunner = Mock_Factory::mock('Components\\Test_Runner');
$mockListener = Mock_Factory::mock('Components\\Test_Listener');
$mockListener->when('onInitialize')->doReturn(true);
$mockListener->when('onExecute')->doReturn(true);
$mockListener->when('onTerminate')->doNothing();
assertTrue($mockListener->onExecute($mockRunner));
assertTrue($mockListener->onInitialize($mockRunner));
$mockLL->onTerminate($mockRunner);
assertEquals('test/unit/case/mock', $mockException->getNamespace());
assertEquals('Mocked Exception.', $mockException->getMessage());
assertEquals('test/exception', $mockExceptionDefault->getNamespace());
assertEquals('Test exception.', $mockExceptionDefault->getMessage());
$mockBindingModule = Mock_Factory::mock('Components\\Binding_Module');
$mockBindingModule->when('bind')->doAnswer(function (Binding_Module $self_, $type_) {
echo "Bound {$type_}\r\n";
return $self_->bind($type_);
});
$mockBindingModule->when('configure')->doAnswer(function (Binding_Module $self_) {
$self_->bind('Components\\Test_Runner')->toInstance(Test_Runner::get());
$self_->bind(Integer::TYPE)->toInstance(22)->named('boundInteger');
});
$injector = Injector::create($mockBindingModule);
assertSame(Test_Runner::get(), $injector->resolveInstance('Components\\Test_Runner'));
assertEquals(22, $injector->resolveInstance(Integer::TYPE, 'boundInteger'));
}
示例11: adapter
/**
* @return MailingListAdapter
*/
public static function adapter()
{
if (!isset(self::$adapter)) {
self::$adapter = Injector::inst()->get(self::config()->default_adapter_class);
}
return self::$adapter;
}
示例12: controller_for
/**
* Get the appropriate {@link CatalogueProductController} or
* {@link CatalogueProductController} for handling the relevent
* object.
*
* @param $object Either Product or Category object
* @param string $action
* @return CatalogueController
*/
protected static function controller_for($object, $action = null)
{
if ($object->class == 'CatalogueProduct') {
$controller = "CatalogueProductController";
} elseif ($object->class == 'CatalogueCategory') {
$controller = "CatalogueCategoryController";
} else {
$ancestry = ClassInfo::ancestry($object->class);
while ($class = array_pop($ancestry)) {
if (class_exists($class . "_Controller")) {
break;
}
}
// Find the controller we need, or revert to a default
if ($class !== null) {
$controller = "{$class}_Controller";
} elseif (ClassInfo::baseDataClass($object->class) == "CatalogueProduct") {
$controller = "CatalogueProductController";
} elseif (ClassInfo::baseDataClass($object->class) == "CatalogueCategory") {
$controller = "CatalogueCategoryController";
}
}
if ($action && class_exists($controller . '_' . ucfirst($action))) {
$controller = $controller . '_' . ucfirst($action);
}
return class_exists($controller) ? Injector::inst()->create($controller, $object) : $object;
}
示例13: createMockYouTubeService
/**
* @param $methods
* @param null $responseWill
* @return mixed
*/
protected function createMockYouTubeService($methods, $responseWill = null)
{
if (!is_array($methods)) {
$methods = [$methods];
}
if (!$responseWill) {
$responseWill = $this->returnSelf();
}
$methodMap = [];
foreach ($methods as $methodName => $callback) {
if (is_numeric($methodName)) {
$methodName = $callback;
}
$expects = is_callable($callback) ? $callback($this) : $this->any();
$methodMap[$methodName] = $expects;
}
$mockResponse = $this->getMockBuilder('GuzzleHttp\\Stream\\Stream')->setMethods(['getBody', 'getContents'])->disableOriginalConstructor()->getMock();
$mockResponse->expects($this->any())->method('getBody')->will($this->returnSelf());
$mockResponse->expects($this->any())->method('getContents')->will($responseWill);
$mockService = $this->getMockBuilder('SummitVideoYouTubeService')->setConstructorArgs([Injector::inst()->get('SummitVideoHTTPClient')])->setMethods(array_keys($methodMap))->getMock();
foreach ($methodMap as $methodName => $expects) {
$mockService->expects($expects)->method($methodName)->will($this->returnValue($mockResponse));
}
return $mockService;
}
示例14: add_to_class
static function add_to_class($class, $extensionClass, $args = null)
{
if (method_exists($class, 'extraDBFields')) {
$extraStaticsMethod = 'extraDBFields';
} else {
$extraStaticsMethod = 'extraStatics';
}
$statics = Injector::inst()->get($extensionClass, true, $args)->{$extraStaticsMethod}($class, $extensionClass);
if ($statics) {
Deprecation::notice('3.1.0', "{$extraStaticsMethod} deprecated. Just define statics on your extension, or use add_to_class");
// TODO: This currently makes extraStatics the MOST IMPORTANT config layer, not the least
foreach (self::$extendable_statics as $key => $merge) {
if (isset($statics[$key])) {
if (!$merge) {
Config::inst()->remove($class, $key);
}
Config::inst()->update($class, $key, $statics[$key]);
}
}
// TODO - remove this
DataObject::$cache_has_own_table[$class] = null;
DataObject::$cache_has_own_table_field[$class] = null;
}
parent::add_to_class($class, $extensionClass, $args);
}
示例15: manualUpdateCMSFields
/**
* This should be updateCMSFields and configured to be called last but configuration
* priority does not seem to work to force this to be the last loaded/called extension.
*
* For now will call via extend.manualUpdate with the field list in ArtisanModel.getCMSFields
*
* @param FieldList $fields
*/
public function manualUpdateCMSFields(FieldList $fields)
{
// $formFields = $fields->dataFields();
$formFields = $fields->VisibleFields();
$selectorFieldName = parent::get_config_setting('selector_field_name');
$hiddenCSSClass = parent::get_config_setting('hidden_css_class');
$provider = Injector::inst()->get('AdaptableFormMetaDataProvider');
$defaultFieldNames = $provider->getDefaultFieldNames();
// keep track of fields we have encountered in the spec, other fields will be hidden,
// we can initialise this to defaultFieldNames as we don't want to hide these ever
$handled = array_combine($defaultFieldNames, $defaultFieldNames);
// we want to get the form so we can remove fields later
$form = null;
$metaData = $provider->getMetaData();
// the master list of content types by field name
$this->contentTypes = [];
foreach ($metaData as $contentType => $fieldSpec) {
if (isset($fieldSpec['FormFields'])) {
$fieldDefinitions = $fieldSpec['FormFields'];
$specFields = array_merge($fieldDefinitions, $defaultFieldNames);
$this->processFieldList($formFields, $contentType, $selectorFieldName, $specFields, $defaultFieldNames, $handled);
}
}
$this->hideUnhandled($formFields, $handled, $hiddenCSSClass);
}