本文整理匯總了PHP中Injector::inst方法的典型用法代碼示例。如果您正苦於以下問題:PHP Injector::inst方法的具體用法?PHP Injector::inst怎麽用?PHP Injector::inst使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Injector
的用法示例。
在下文中一共展示了Injector::inst方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getInjector
/**
* Retrieves the Injector instance
*
* @return \Injector
*/
protected function getInjector()
{
if ($this->injector === null) {
$this->injector = \Injector::inst();
}
return $this->injector;
}
示例2: authenticate
public static function authenticate($email, $password)
{
$authenticator = \Injector::inst()->get('ApiMemberAuthenticator');
if ($user = $authenticator->authenticate(['Password' => $password, 'Email' => $email])) {
return self::createSession($user);
}
}
示例3: getFixtureFactory
/**
* @return FixtureFactory
*/
public function getFixtureFactory()
{
if (!$this->fixtureFactory) {
$this->fixtureFactory = \Injector::inst()->create('BehatFixtureFactory');
}
return $this->fixtureFactory;
}
示例4: __construct
public function __construct()
{
$this->session = Injector::inst()->create('Session', array());
$this->controller = new Controller();
$this->controller->setSession($this->session);
$this->controller->pushCurrent();
}
示例5: 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;
}
示例6: updateItemEditForm
public function updateItemEditForm($form)
{
if ($id = $this->owner->request->getVar('ID')) {
Injector::inst()->get("CMSMain")->setCurrentPageID($id);
$form->Fields()->push(new HiddenField('ID', '', $id));
}
}
示例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: setUp
public function setUp()
{
parent::setUp();
// mock the real api
$this->api = $this->getMock('\\Acquia\\Pingdom\\PingdomApi', ['request'], ["user@test.com", "password", "token"]);
Injector::inst()->registerService($this->api, 'PingdomService');
}
示例9: 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());
}
}
示例10: getEditForm
public function getEditForm($id = null, $fields = null)
{
// TODO Duplicate record fetching (see parent implementation)
if (!$id) {
$id = $this->currentPageID();
}
$form = parent::getEditForm($id);
// TODO Duplicate record fetching (see parent implementation)
$record = $this->getRecord($id);
if ($record && !$record->canView()) {
return Security::permissionFailure($this);
}
$memberList = GridField::create('Members', false, Member::get(), $memberListConfig = GridFieldConfig_RecordEditor::create()->addComponent(new GridFieldButtonRow('after'))->addComponent(new GridFieldExportButton('buttons-after-left')))->addExtraClass("members_grid");
if ($record && method_exists($record, 'getValidator')) {
$validator = $record->getValidator();
} else {
$validator = Injector::inst()->get('Member')->getValidator();
}
$memberListConfig->getComponentByType('GridFieldDetailForm')->setValidator($validator);
$groupList = GridField::create('Groups', false, Group::get(), GridFieldConfig_RecordEditor::create());
$columns = $groupList->getConfig()->getComponentByType('GridFieldDataColumns');
$columns->setDisplayFields(array('Breadcrumbs' => singleton('Group')->fieldLabel('Title')));
$columns->setFieldFormatting(array('Breadcrumbs' => function ($val, $item) {
return Convert::raw2xml($item->getBreadcrumbs(' > '));
}));
$fields = new FieldList($root = new TabSet('Root', $usersTab = new Tab('Users', _t('SecurityAdmin.Users', 'Users'), $memberList, new LiteralField('MembersCautionText', sprintf('<p class="caution-remove"><strong>%s</strong></p>', _t('SecurityAdmin.MemberListCaution', 'Caution: Removing members from this list will remove them from all groups and the' . ' database')))), $groupsTab = new Tab('Groups', singleton('Group')->i18n_plural_name(), $groupList)), new HiddenField('ID', false, 0));
// Add import capabilities. Limit to admin since the import logic can affect assigned permissions
if (Permission::check('ADMIN')) {
$fields->addFieldsToTab('Root.Users', array(new HeaderField(_t('SecurityAdmin.IMPORTUSERS', 'Import users'), 3), new LiteralField('MemberImportFormIframe', sprintf('<iframe src="%s" id="MemberImportFormIframe" width="100%%" height="250px" frameBorder="0">' . '</iframe>', $this->Link('memberimport')))));
$fields->addFieldsToTab('Root.Groups', array(new HeaderField(_t('SecurityAdmin.IMPORTGROUPS', 'Import groups'), 3), new LiteralField('GroupImportFormIframe', sprintf('<iframe src="%s" id="GroupImportFormIframe" width="100%%" height="250px" frameBorder="0">' . '</iframe>', $this->Link('groupimport')))));
}
// Tab nav in CMS is rendered through separate template
$root->setTemplate('CMSTabSet');
// Add roles editing interface
if (Permission::check('APPLY_ROLES')) {
$rolesField = GridField::create('Roles', false, PermissionRole::get(), GridFieldConfig_RecordEditor::create());
$rolesTab = $fields->findOrMakeTab('Root.Roles', _t('SecurityAdmin.TABROLES', 'Roles'));
$rolesTab->push($rolesField);
}
$actionParam = $this->getRequest()->param('Action');
if ($actionParam == 'groups') {
$groupsTab->addExtraClass('ui-state-active');
} elseif ($actionParam == 'users') {
$usersTab->addExtraClass('ui-state-active');
} elseif ($actionParam == 'roles') {
$rolesTab->addExtraClass('ui-state-active');
}
$actions = new FieldList();
$form = Form::create($this, 'EditForm', $fields, $actions)->setHTMLID('Form_EditForm');
$form->addExtraClass('cms-edit-form');
$form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
// Tab nav in CMS is rendered through separate template
if ($form->Fields()->hasTabset()) {
$form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
}
$form->addExtraClass('center ss-tabset cms-tabset ' . $this->BaseCSSClasses());
$form->setAttribute('data-pjax-fragment', 'CurrentForm');
$this->extend('updateEditForm', $form);
return $form;
}
示例11: getStore
/**
* @return HybridSessionStore_Cookie
*/
protected function getStore()
{
$store = Injector::inst()->get('HybridSessionStore');
$store->setKey(uniqid());
$store->open(getTempFolder() . '/' . __CLASS__, 'SESSIONCOOKIE');
return $store;
}
示例12: process
public function process()
{
$nextTask = DevTaskRun::get_next_task();
if ($nextTask) {
//create task instance
$task = Injector::inst()->create($nextTask->Task);
//get params
$params = explode(' ', $nextTask->Params);
$paramList = array();
if ($params) {
foreach ($params as $param) {
$parts = explode('=', $param);
if (count($parts) === 2) {
$paramList[$parts[0]] = $parts[1];
}
}
}
echo 'Starting task ' . $task->getTitle() . "\n";
//remove so it doesn't get rerun
$nextTask->Status = 'Running';
$nextTask->write();
$request = new SS_HTTPRequest('GET', 'dev/tasks/' . $nextTask->Task, $paramList);
$task->run($request);
$nextTask->Status = 'Finished';
$nextTask->FinishDate = SS_Datetime::now()->getValue();
$nextTask->write();
echo 'Finished task ' . $task->getTitle() . "\n";
}
}
示例13: onAfterWrite
public function onAfterWrite()
{
$config = Config::inst();
$sitetreeclasses = $config->get('ImageEditCacheBust', 'SiteTree');
$dataobjectclasses = $config->get('ImageEditCacheBust', 'DataObject');
$stages = $config->get('ImageEditCacheBust', 'Stages');
if ($sitetreeclasses) {
// deal with SiteTree first
foreach ($sitetreeclasses as $clazz => $idfield) {
$instanceofclass = Injector::inst()->create($clazz);
$objectsWithImage = $instanceofclass::get()->filter($idfield, $this->owner->ID);
foreach ($objectsWithImage as $objectWithImage) {
foreach ($stages as $stage) {
$suffix = '_' . $stage;
$suffix = str_replace('_Stage', '', $suffix);
$sql = "UPDATE `SiteTree{$suffix}` SET LastEdited=NOW() where ID=" . $objectWithImage->ID;
DB::query($sql);
}
}
}
}
if ($dataobjectclasses) {
// deal with SiteTree first
foreach ($dataobjectclasses as $clazz => $idfield) {
$instanceofclass = Injector::inst()->create($clazz);
$objectsWithImage = $instanceofclass::get()->filter($idfield, $this->owner->ID);
foreach ($objectsWithImage as $objectWithImage) {
$sql = "UPDATE `{$clazz}` SET LastEdited=NOW() where ID=" . $objectWithImage->ID;
DB::query($sql);
}
}
}
}
開發者ID:helpfulrobot,項目名稱:weboftalent-imageeditpartialcachebust,代碼行數:33,代碼來源:ImageEditPartialCacheBustExtension.php
示例14: ProfiledMemberForm
/**
* Returns a form with fields from config.profiled_show_fields loaded from member.currentUser(). To work
* properly expects the current controller to be extended with ProfiledControllerExtension.
*
* @return ProfiledMemberForm
*/
public function ProfiledMemberForm($action)
{
$form = ProfiledMemberForm::create_for_action($action, Controller::curr(), null, null, null);
$member = Injector::inst()->get('ProfiledMemberClass');
$form->loadDataFrom($member::currentUser());
return $form;
}
示例15: updateEnabled
public function updateEnabled(&$enabled)
{
if ($enabled && Session::get("loggedInAs")) {
$this->checkAndConnectDB();
$enabled = !Injector::inst()->create('LeftAndMain')->canView();
}
}
開發者ID:helpfulrobot,項目名稱:gdmedia-silverstripe-frontend-admin,代碼行數:7,代碼來源:FrontEndAdminDynamicCacheExtension.php