public function isAuthenticated() { if (($ret = parent::isAuthenticated()) === FALSE) { return FALSE; } if (($identity = $this->getIdentity()) === NULL) { return FALSE; } if ($identity instanceof UserEntity) { if (!isset($this->logins[$this->session->id][$identity->id])) { $this->logins[$this->session->id][$identity->id] = (bool) $this->loginRepository->findOneBy(array('user' => $identity->id, 'sessionId' => $this->session->id)); } return $this->logins[$this->session->id][$identity->id]; } else { if ($this->checkConnection->invoke()) { try { if (!isset($this->logins[$this->session->id][-1])) { $this->logins[$this->session->id][-1] = (bool) $this->loginRepository->findOneBy(array('user' => NULL, 'sessionId' => $this->session->id)); if (!$this->logins[$this->session->id][-1]) { $this->setAuthenticated(TRUE); } } return TRUE; } catch (DBALException $e) { } } } return $ret; }
/** * * @param string|array $method * @param mixed $var,... * @return string */ public function callback($method) { // Get all passed variables $variables = func_get_args(); $variables[0] = $this->_array; $this->_array = Callback::invoke($method, $variables); return $this; }
/** * * @param string $uri */ public function execute_uri($uri) { $method = $this->_router->find($uri); if (strpos($method, '::') !== FALSE) { Callback::invoke($method, array($this)); } else { $this->{$method}(); } return $this; }
/** * Sign in form component factory. * * @return Form */ protected function createComponentSignInForm() { $form = $this->form->invoke(); $form->onSuccess[] = $this->formSuccess; $form->onError[] = $this->formError; if ($this->reset['enabled']) { $form->setResetEmail($this->reset['emailSubject'], $this->reset['emailText'], $this->reset['emailSender'], $this->reset['emailFrom']); } return $form; }
public function authenticate(array $credentials) { if ($this->checkConnection->invoke()) { $data = $this->getData(); try { /** @var $user \CmsModule\Pages\Users\UserEntity */ $user = $this->userRepository->createQueryBuilder('a')->join('a.socialLogins', 's')->where('s.type = :type AND s.uniqueKey = :key')->setParameter('type', $this->getType())->setParameter('key', $data['id'])->getQuery()->getSingleResult(); } catch (\Doctrine\ORM\NoResultException $e) { } if (!isset($user) || !$user) { throw new AuthenticationException($this->translator->translate('User does not exist.'), self::INVALID_CREDENTIAL); } return new Identity($user->email, $user->getRoles()); } }
/** * Returns mPDF object * @return mPDFExtended */ public function getMPDF() { if (!$this->mPDF instanceof mPDF) { if ($this->createMPDF instanceof \Nette\Callback and $this->createMPDF->isCallable()) { $mpdf = $this->createMPDF->invoke($this); if (!$mpdf instanceof \mPDF) { throw new \Nette\InvalidStateException("Callback function createMPDF must return mPDF object!"); } $this->mPDF = $mpdf; } else { throw new \Nette\InvalidStateException("Callback createMPDF is not callable or is not instance of Nette\\Callback!"); } } return $this->mPDF; }
public function testShouldReturnCallableReturnOnInvokeMethod() { $expectedReturn = 42; $argumentParserMock = $this->getMock('PHPFluent\\Callback\\ArgumentParser\\ArgumentParserInterface'); $callback = new Callback(function () use($expectedReturn) { return $expectedReturn; }, $argumentParserMock); $argumentParserMock->expects($this->any())->method('parse')->will($this->returnValue(array())); $actualReturn = $callback->invoke(); $this->assertSame($expectedReturn, $actualReturn); }
/** * * @param string $field * @param mixed $value * @param array $rules * @return mixed */ public function field($field, $value, array $rules = NULL) { if (Kohana::$profiling === TRUE) { $benchmark = Profiler::start('Filter field', $field); } if (empty($rules)) { $rules = Arr::path($this->_rules, $field . '.rules', array()); } // Bind the field name and model so they can be used in the filter method $_bound = array(':field' => $field, ':filter' => $this); foreach ($rules as $filter) { // Value needs to be bound inside the loop so we are always using the // version that was modified by the filters that already ran $_bound[':value'] = $value; $params = array(':value'); foreach ($params as $key => $param) { if (is_string($param) and array_key_exists($param, $_bound)) { // Replace with bound value $params[$key] = $_bound[$param]; } } $value = Callback::invoke($filter, $params); } if (isset($benchmark)) { Profiler::stop($benchmark); } return $value; }
/** * * @param string $field * @param array $attributes * @return string */ public function field($field, array $attributes = NULL) { $field_data = Arr::get($this->form_columns(), $field); if ($field_data === NULL) { $field_data = array('type' => Arr::path($this->_table_columns, $field . '.data_type')); } $field_name = $field; if (Arr::get($field_data, 'free') !== TRUE) { $value = $this->get($field); } else { $value = NULL; } if (isset($attributes['prefix'])) { $field_name = $attributes['prefix'] . "[{$field_name}]"; unset($attributes['prefix']); } $attributes['id'] = $this->object_name() . '_' . $field; if (isset($attributes['choices'])) { $field_data['choices'] = $attributes['choices']; unset($attributes['choices']); } if (isset($attributes['multiply'])) { $field_data['multiply'] = TRUE; $field_name .= '[]'; unset($attributes['multiply']); } if (!empty($field_data['choices'])) { $choices = Callback::invoke($field_data['choices']); } $input = NULL; if (isset($attributes['class']) and !is_array($attributes['class'])) { $attributes['class'] = array($attributes['class']); } if (is_callable($field_data['type'])) { $input = call_user_func($field_data['type'], $this, $field, $attributes); } else { if (is_array($field_data['type'])) { $input = Callback::invoke_function($field_data['type'], array($this, $field, $attributes)); } else { switch ($field_data['type']) { case 'textarea': case 'text': $attributes['rows'] = 3; $input = Form::textarea($field_name, $value, $attributes); break; case 'select': $input = Form::select($field_name, $choices, $value, $attributes); break; case 'checkbox': $default = Arr::get($field_data, 'value', 1); $input = Form::label(NULL, Form::checkbox($field_name, $default, $default == $value, $attributes) . ' ' . $this->label($field, NULL, TRUE)); break; case 'password': $input = Form::password($field_name, NULL, $attributes); break; default: $input = Form::input($field_name, $value, $attributes); break; } } } return $input; }
protected function createComponent($name) { return $this->factory->invoke($name, $this); }
/** * * @param Model_Widget_Decorator | View $widget * @param string $field * @param mixed $value * @return \Context */ public function inject($widget, $field, $value) { if ($widget instanceof Model_Widget_Decorator or $widget instanceof View) { if (!empty($field)) { $method = "set_{$field}"; if (method_exists($widget, $method)) { Callback::invoke(array($widget, $method), array($value)); unset($method); } else { $widget->{$field} = $value; } } } return $this; }