/** * Executes index action * * @param sfRequest $request A request object */ public function executeIndex(sfWebRequest $request) { $params = $request->getParameter('phone'); $form = new CallbackForm(); if ($request->isMethod('post')) { $phone = $params; try { if (empty($obj)) { $obj = new Callback(); $obj->setPhone($phone)->save(); } } catch (Exception $e) { } $contacts = UserPeer::getAllContact(); $backEmail = $contacts->getEmail(); $message = "Телефон: " . $phone . "<br/>"; // почта, на которую придет письмо $mail_to = $backEmail; // тема письма $subject = "Заказ звонка"; // заголовок письма $headers = "Content-type: text/html; charset=utf-8\r\n"; // кодировка письма // отправляем письмо mail($mail_to, $subject, $message, $headers); } $this->form = $form; }
/** * Test that an exception is thrown when an invalid class is given * * @expectedException InvalidArgumentException */ public function testInvalidCallbackMatch() { $route = new \Psecio\Invoke\RouteContainer('/foo/bar', ['callback' => 'BadClass::test1']); $this->data->setRoute($route); $cb = new Callback([]); $cb->evaluate($this->data); }
/** * Initialize */ public function init() { parent::init(); foreach (cogear()->gears as $gear) { if (is_array($gear->access)) { foreach ($gear->access as $rule => $rights) { $name = $gear->gear . '.' . $rule; // Array of user roles if (is_array($rights)) { if (in_array(role(), $rights)) { $this->rights->{$name} = TRUE; } else { $this->rights->{$name} = FALSE; } } else { if (is_string($rights)) { $callback = new Callback(array($gear, $rights)); if ($callback->check()) { $this->rights->{$name} = $callback; } } elseif (is_bool($rights)) { $this->rights->{$name} = $rights; } } } } } }
/** * @return IPresenterResponse */ public function run(PresenterRequest $request) { $this->request = $request; $httpRequest = $this->context->getByType('IHttpRequest'); if (!$httpRequest->isAjax() && ($request->isMethod('get') || $request->isMethod('head'))) { $refUrl = clone $httpRequest->getUrl(); $url = $this->context->router->constructUrl($request, $refUrl->setPath($refUrl->getScriptPath())); if ($url !== NULL && !$httpRequest->getUrl()->isEqual($url)) { return new RedirectResponse($url, IHttpResponse::S301_MOVED_PERMANENTLY); } } $params = $request->getParameters(); if (!isset($params['callback'])) { return; } $params['presenter'] = $this; $callback = new Callback($params['callback']); $response = $callback->invokeArgs(PresenterComponentReflection::combineArgs($callback->toReflection(), $params)); if (is_string($response)) { $response = array($response, array()); } if (is_array($response)) { if ($response[0] instanceof SplFileInfo) { $response = $this->createTemplate('FileTemplate')->setParameters($response[1])->setFile($response[0]); } else { $response = $this->createTemplate('Template')->setParameters($response[1])->setSource($response[0]); } } if ($response instanceof ITemplate) { return new TextResponse($response); } else { return $response; } }
/** * * @return type */ public function render() { if ($this->callback) { $callback = new Callback($this->callback); if ($callback->check()) { $this->options->values = $callback->run(array($this->form)); } } $this->prepareOptions(); $code[] = HTML::open_tag('select', $this->options); foreach ($this->values as $key => $value) { $attributes = array(); if ($this->value instanceof Core_ArrayObject) { $this->value = $this->value->toArray(); } if (is_array($this->value)) { if (in_array($key, $this->value)) { $attributes['selected'] = 'selected'; } } elseif ($key == $this->value) { $attributes['selected'] = 'selected'; } $attributes['value'] = $key; $code[] = HTML::paired_tag('option', $value, $attributes); } $code[] = HTML::close_tag('select'); $code = implode("\n", $code); if ($this->wrapper) { $tpl = new Template($this->wrapper); $tpl->assign($this->options); $tpl->code = $code; $code = $tpl->render(); } return $code; }
/** * @param Callback * @param string * @return Callback */ public static function create(Callback $callback, $className) { $factory = new self(); $factory->callback = $callback->getNative(); $factory->className = $className; return Callback::create($factory, 'call'); }
/** * */ public function testConvertsACallbackIntoAnObserver() { $subject = $this->getMockForAbstractClass('\\SplSubject'); $callback = $this->getMockForAbstractClass('\\MetaborStd\\CallbackInterface'); $callback->expects($this->once())->method('__invoke')->with($subject); $observer = new Callback($callback); $observer->update($subject); }
/** * Magic __call method * * @param string $name * @param array $array */ public function __call($name, $args) { $callback = new Callback(array(cogear(), $name)); if ($callback->check()) { return $callback->run($args); } return NULL; }
/** * @param $transactionName * @param callable $function */ public static function after($transactionName, callable $function) { $callback = new Callback($function, $transactionName); $transactionName = $callback->getName(); if (!array_key_exists($transactionName, self::$afterHooks)) { self::$afterHooks[$transactionName] = []; } self::$afterHooks[$transactionName][] = $callback; }
/** * Magic __call method * * @param string $name * @param array $args * @return mixed */ public function __call($name, $args) { if (is_object($this->object)) { $callback = new Callback(array($this->object, $name)); if ($callback->check()) { return $callback->run($args); } } return parent::__call($name, $args); }
/** * Преобразуем строку действия в реальный callback * * @param string $action * @return Callback */ public function parseAction($action) { if (preg_match('#^(\\w+)\\((.+)\\)$#', $action, $matches)) { $action = $matches[1]; $matches[2] = str_replace(' ', '', $matches[2]); $args = explode(',', $matches[2]); $callback = new Callback(array($this->image, $action)); $callback->setArgs($args); return $callback; } return NULL; }
public function testCallback() { $called = false; $callback = function () use(&$called) { $called = true; return 'bar'; }; $filter = new Callback($callback); $result = $filter->filter('foo'); $this->assertTrue($called); $this->assertEquals('bar', $result); }
/** * Add callback request to DB * * @param $data * @return bool */ public function add($data) { if (!$data) { return false; } $model = new Callback(); $model->setAttributes($data); if ($model->save()) { $this->sendNotification($model); return true; } return false; }
/** * @expectedException Respect\Validation\Exceptions\OneOfException */ public function testShortcutInvalid() { $valid1 = new Callback(function () { return false; }); $valid2 = new Callback(function () { return false; }); $valid3 = new Callback(function () { return false; }); $o = $valid1->addOr($valid2, $valid3); $this->assertFalse($o->validate('any')); $this->assertFalse($o->assert('any')); }
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; }
public function render() { if ($this->callback) { $callback = Callback::prepare($this->callback); is_callable($callback) && $this->setValues(call_user_func($callback)); } $this->getAttributes(); $code[] = HTML::open_tag('select', $this->attributes); foreach ($this->values as $key => $value) { $attributes = array(); if ($key == $this->value) { $attributes['selected'] = 'selected'; } $attributes['value'] = $key; $code[] = HTML::paired_tag('option', $value, $attributes); } $code[] = HTML::close_tag('select'); $code = implode("\n", $code); if ($this->wrapper) { $tpl = new Template($this->wrapper); $tpl->assign($this->attributes); $tpl->code = $code; $code = $tpl->render(); } return $code; }
/** * @return \Venne\Security\Login\LoginControl */ protected function createComponentSignInForm() { $form = $this->loginControlFactory->create(); $form->onSuccess[] = $this->formSuccess; $form->onError[] = $this->formError; return $form; }
/** * @param $id * @return Callback * @throws CHttpException */ public function loadModel($id) { $model = Callback::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, Yii::t('CallbackModule.callback', 'Page not found!')); } return $model; }
/** * * @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; }
public function getContent() { if (!is_array($content = Callback::decode($this->log_content))) { throw new Exception('Callback failed!'); } if (count($content) > self::MaxSearchResults) { $content = array_slice($content, 0, self::MaxSearchResults); } return $content; }
/** * @return array|bool */ public function checkSelf() { $messages = []; $callbacksCount = Callback::model()->new()->count(); if (!$callbacksCount) { return false; } $messages[WebModule::CHECK_NOTICE][] = ['type' => WebModule::CHECK_NOTICE, 'message' => Yii::t('CallbackModule.callback', 'New requests: {count}', ['{count}' => CHtml::link($callbacksCount, ['/callback/callbackBackend/index', 'Callback[status]' => Callback::STATUS_NEW])])]; return $messages; }
/** * * @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; }
private function addMovieAttributes($arr_infos) { foreach ($arr_infos as $key => $value) { if (is_array($value)) { $value = Callback::encode($value); } $attr = new MovieAttributes(); $attr->code = $key; $attr->value = utf8_encode($value); $attr->movie_id = $this->id; $attr->save(); } }
/** * Logs message or exception to file and sends email notification. * @param string|array * @param int one of constant INFO, WARNING, ERROR (sends email), CRITICAL (sends email) * @return bool was successful? */ public function log($message, $priority = self::INFO) { if (!is_dir($this->directory)) { throw new DirectoryNotFoundException("Directory '{$this->directory}' is not found or is not directory."); } if (is_array($message)) { $message = implode(' ', $message); } $res = error_log(trim($message) . PHP_EOL, 3, $this->directory . '/' . strtolower($priority) . '.log'); if (($priority === self::ERROR || $priority === self::CRITICAL) && $this->email && $this->mailer && @filemtime($this->directory . '/email-sent') + self::$emailSnooze < time() && @file_put_contents($this->directory . '/email-sent', 'sent')) { Callback::create($this->mailer)->invoke($message, $this->email); } return $res; }
public function testParseTemplateCreated() { $xml = <<<EOS \t\t\t<callback> \t\t\t\t<callback-type>Template</callback-type> \t\t\t\t<guid>dl3jsdf9850dfkl3-dfl2</guid> \t\t\t\t<status>created</status> \t\t\t\t<created-at>2009-11-05 16:36:08 -0800</created-at> \t\t\t</callback> EOS; $callback = Callback::parse($xml); $this->assertTrue($callback->isTemplate()); $this->assertTrue($callback->isCreated()); $this->assertEquals('dl3jsdf9850dfkl3-dfl2', $callback->guid); }
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 __destruct() { parent::__destruct(); unset($this->_name); }
/** @param int */ private function handleLazy($key) { $object = call_user_func($this->lazy[$key][0]); if (!$object instanceof IListener) { $cb = Callback::create($this->lazy[$key][0]); throw new BadReturnException(array(NULL, __CLASS__ . " lazy factory {$cb}()", 'Orm\\IListener', $object)); } $types = $this->lazy[$key][1]; foreach (self::$instructions as $e => $m) { if (isset($types[$e])) { if ($object instanceof $m[0]) { $this->listeners[$e][$types[$e]] = array(true, array($object, $m[1])); } else { throw new InvalidArgumentException(ExceptionHelper::format(array($this, Callback::create($this->lazy[$key][0]), $m[0], $object), "%c1 lazy factory %s2() must return %s3; '%v4' given.")); } } else { if ($object instanceof $m[0]) { throw new InvalidArgumentException(ExceptionHelper::format(array($this, Callback::create($this->lazy[$key][0]), $m[0], $object), "%c1 lazy factory %s2() returns not expected %s3; '%v4'.")); } } } unset($this->lazy[$key]); }