Closure PHP Class Code Examples

This page contains top rated real world PHP examples of class Closure extracted from open source projects. You can rate examples to help us improve the quality of examples

Example #1
Show file File: SystemMailer.php Project: sgomez/SystemMailBundle
1
 /**
  * Sends out the system message
  *
  * Examples:
  * <code>
  *  // sends out AppBundle/Resources/emails/registration/confirmUser.xml.twig
  *  $systemMailer->send('App:registration/confirmUser', ['user' => $user]);
  *
  *  // force locale of mail
  *  $systemMailer->send('App:info-mail', ['user' => $user], 'de');
  *
  *  // attach file to mail
  *  $systemMailer->send('App:message-with-pdf', [], null, function (\Swift_Message $message) {
  *     $message->attach(\Swift_Attachment::fromPath('my-document.pdf'))
  *  });
  * </code>
  *
  * @param string   $name            The email to send out, format: YourBundle:emailXmlTemplateName
  * @param array    $parameters      The parameters passed to your email template xml
  * @param string   $locale          Overwrite default locale of session
  * @param callable $messageModifier Pass Closure to modify message before it is send (to attach files i.e.)
  */
 public function send($name, $parameters = [], $locale = null, \Closure $messageModifier = null)
 {
     $mailDefinition = $this->provider->fetchMailDefinition($name, $parameters);
     $parsedMessage = $this->parser->parseMailDefinition($mailDefinition, $locale ?: $this->locale);
     $this->handleDefaults($parsedMessage);
     $this->mailer->send($parsedMessage, $messageModifier);
 }
Example #2
Show file File: WebDriverCoordinates.php Project: DGCarramona/php-webdriver
0
 public function __construct($on_screen, Closure $in_view_port, Closure $on_page, $auxiliary)
 {
     $this->onScreen = $on_screen;
     $this->inViewPort = $in_view_port;
     $this->onPage = $on_page;
     $this->auxiliary = $auxiliary;
 }
Example #3
Show file File: Metadata.php Project: Maksold/platform
0
 /**
  * {@inheritdoc}
  */
 public function all(\Closure $filter = null)
 {
     if ($filter) {
         return array_filter($this->options, $filter);
     }
     return $this->options;
 }
Example #4
Show file File: AbstractQueryTranslatorTest.php Project: wookieb/query-object
0
 private function useCustomListenerForEvent($eventName, \Closure $listener)
 {
     $this->object->getEventDispatcher()->addListener($eventName, function () use($listener) {
         $this->customListenerCalled = true;
         call_user_func_array($listener, func_get_args());
     });
 }
Example #5
Show file File: ReflectionCaster.php Project: christengc/wheel
0
 public static function castClosure(\Closure $c, array $a, Stub $stub, $isNested)
 {
     $prefix = Caster::PREFIX_VIRTUAL;
     $c = new \ReflectionFunction($c);
     $stub->class = 'Closure';
     // HHVM generates unique class names for closures
     $a = static::castFunctionAbstract($c, $a, $stub, $isNested);
     if (isset($a[$prefix . 'parameters'])) {
         foreach ($a[$prefix . 'parameters'] as &$v) {
             $param = $v;
             $v = array();
             foreach (static::castParameter($param, array(), $stub, true) as $k => $param) {
                 if ("" === $k[0]) {
                     $v[substr($k, 3)] = $param;
                 }
             }
             unset($v['position'], $v['isVariadic'], $v['byReference'], $v);
         }
     }
     if ($f = $c->getFileName()) {
         $a[$prefix . 'file'] = $f;
         $a[$prefix . 'line'] = $c->getStartLine() . ' to ' . $c->getEndLine();
     }
     $prefix = Caster::PREFIX_DYNAMIC;
     unset($a['name'], $a[$prefix . '0'], $a[$prefix . 'this'], $a[$prefix . 'parameter'], $a[Caster::PREFIX_VIRTUAL . 'extra']);
     return $a;
 }
Example #6
Show file File: helpers.php Project: codixor/support
0
 function closure_dump(Closure $c)
 {
     $str = 'function (';
     $r = new ReflectionFunction($c);
     $params = array();
     foreach ($r->getParameters() as $p) {
         $s = '';
         if ($p->isArray()) {
             $s .= 'array ';
         } else {
             if ($p->getClass()) {
                 $s .= $p->getClass()->name . ' ';
             }
         }
         if ($p->isPassedByReference()) {
             $s .= '&';
         }
         $s .= '$' . $p->name;
         if ($p->isOptional()) {
             $s .= ' = ' . var_export($p->getDefaultValue(), TRUE);
         }
         $params[] = $s;
     }
     $str .= implode(', ', $params);
     $str .= '){' . PHP_EOL;
     $lines = file($r->getFileName());
     for ($l = $r->getStartLine(); $l < $r->getEndLine(); $l++) {
         $str .= $lines[$l];
     }
     return $str;
 }
Example #7
Show file File: Writer.php Project: hilmysyarif/phpv8
0
 /**
  * Register a new callback handler for when
  * a log event is triggered.
  *
  * @param  \Closure  $callback
  * @return void
  *
  * @throws \RuntimeException
  */
 public function listen(Closure $callback)
 {
     if (!isset($this->dispatcher)) {
         throw new \RuntimeException("Events dispatcher has not been set.");
     }
     $this->dispatcher->listen('illuminate.log', $callback);
 }
Example #8
Show file File: Writer.php Project: davidhemphill/framework
0
 /**
  * Register a new callback handler for when a log event is triggered.
  *
  * @param  \Closure  $callback
  * @return void
  *
  * @throws \RuntimeException
  */
 public function listen(Closure $callback)
 {
     if (!isset($this->dispatcher)) {
         throw new RuntimeException('Events dispatcher has not been set.');
     }
     $this->dispatcher->listen('illuminate.log', $callback);
 }
Example #9
Show file File: Builder.php Project: davidhemphill/framework
0
 /**
  * Create a new command set with a Closure.
  *
  * @param  string  $table
  * @param  \Closure|null  $callback
  * @return \Illuminate\Database\Schema\Blueprint
  */
 protected function createBlueprint($table, Closure $callback = null)
 {
     if (isset($this->resolver)) {
         return call_user_func($this->resolver, $table, $callback);
     }
     return new Blueprint($table, $callback);
 }
Example #10
Show file File: ModelListAssociation.php Project: ablyler/phan
0
 /**
  * @param string $table_name
  * The table storing the primary key association
  *
  * @param string $target_model_name
  * The name of the target model class
  *
  * @param \Closure $read_closure
  * A closure that accepts a map from keys to models
  * that are to be handled by the source model
  *
  * @param \Closure $write_closure
  * A closure that returns an array mapping string keys
  * to model objects that will be written.
  */
 public function __construct(string $table_name, string $target_model_name, \Closure $read_closure, \Closure $write_closure)
 {
     $schema = new Schema($table_name, [new Column('id', Column::TYPE_INT, true, true), new Column('source_pk', 'STRING'), new Column('target_pk', 'STRING')]);
     /*
     $schema->addCreateQuery(
         "CREATE UNIQUE INDEX IF NOT EXISTS {$table_name}_source_pk_value ON `$table_name` "
         . " (source_pk, value)"
     );
     */
     parent::__construct($schema, $read_closure, $write_closure);
     $this->target_model_name = $target_model_name;
 }
Example #11
Show file File: QueryBuilderHandler.php Project: atiarda/pixie
0
 /**
  * @param          $event
  * @param string   $table
  * @param callable $action
  *
  * @return void
  */
 public function registerEvent($event, $table = ':any', \Closure $action)
 {
     if ($table != ':any') {
         $table = $this->addTablePrefix($table, false);
     }
     return $this->connection->getEventHandler()->registerEvent($event, $table, $action);
 }
Example #12
Show file File: VerifyCsrfToken.php Project: berkapavel/Laravel5-Time-Tracker-Project-manager
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if ('testing' !== app()->environment()) {
         return parent::handle($request, $next);
     }
     return $next($request);
 }
Example #13
Show file File: fake-index.php Project: JBZoo/CrossCMS
0
 /**
  * @param Closure $callback
  * @return mixed
  */
 public function init(\Closure $callback)
 {
     if ($this->_coverage) {
         $this->_coverage->start($this->_covHash, true);
     }
     return $callback();
 }
Example #14
Show file File: BackendAuthentication.php Project: kidaa30/magento2-platformsh
0
 /**
  * Replace standard admin login form with HTTP Basic authentication
  *
  * @param AbstractAction $subject
  * @param callable $proceed
  * @param RequestInterface $request
  * @return ResponseInterface
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function aroundDispatch(AbstractAction $subject, \Closure $proceed, RequestInterface $request)
 {
     $resource = isset($this->aclResources[$request->getControllerName()]) ? isset($this->aclResources[$request->getControllerName()][$request->getActionName()]) ? $this->aclResources[$request->getControllerName()][$request->getActionName()] : $this->aclResources[$request->getControllerName()] : null;
     $type = $request->getParam('type');
     $resourceType = isset($this->aclResources[$type]) ? $this->aclResources[$type] : null;
     if (!$resource || !$resourceType) {
         return parent::aroundDispatch($subject, $proceed, $request);
     }
     $session = $this->_auth->getAuthStorage();
     // Try to login using HTTP-authentication
     if (!$session->isLoggedIn()) {
         list($login, $password) = $this->httpAuthentication->getCredentials();
         try {
             $this->_auth->login($login, $password);
         } catch (AuthenticationException $e) {
             $this->logger->critical($e);
         }
     }
     // Verify if logged in and authorized
     if (!$session->isLoggedIn() || !$this->authorization->isAllowed($resource) || !$this->authorization->isAllowed($resourceType)) {
         $this->httpAuthentication->setAuthenticationFailed('RSS Feeds');
         return $this->_response;
     }
     return parent::aroundDispatch($subject, $proceed, $request);
 }
Example #15
Show file File: VerifyCsrfToken.php Project: Insantani/SourceTree-diovi
0
 public function handle($request, Closure $next)
 {
     if (!$request->is("api/*")) {
         return parent::handle($request, $next);
     }
     return $next($request);
 }
Example #16
Show file File: Manager.php Project: andrewhowdencom/m2onk8s
0
 /**
  * Processes list of operations
  *
  * @param callable $beforeCallback
  * @param callable $afterCallback
  * @return void
  */
 public function process(\Closure $beforeCallback = null, \Closure $afterCallback = null)
 {
     /** @var OperationInterface $operation */
     foreach ($this->operationsList as $operation) {
         if (is_callable($beforeCallback)) {
             $beforeCallback($operation);
         }
         $operation->doOperation();
         if (is_callable($afterCallback)) {
             $afterCallback($operation);
         }
     }
     $this->operationsList = [];
 }
Example #17
Show file File: RouteAccess.php Project: ICHydro/anaconda
0
 /**
  * @param $route
  * @param callable $callback
  * @return null|mixed
  */
 public static function can($route, \Closure $callback = null, \Closure $failCallback = null, $attributes = [])
 {
     if (is_array($route)) {
         $route = (array) $route;
         $key = json_encode($route);
         $route = static::normalizeRoute($route[0]);
     } else {
         $key = $route;
     }
     if (isset($callback)) {
         $key .= spl_object_hash($callback);
     }
     if (isset($failCallback)) {
         $key .= spl_object_hash($failCallback);
     }
     $key .= json_encode($attributes);
     $key = md5($key);
     if (!isset(static::$_accessCache[$key])) {
         self::$_accessCache[$key] = false;
         $parts = \Yii::$app->createController($route);
         if ($parts) {
             /**
              * @var $controller Controller
              */
             list($controller, $actionID) = $parts;
             if (!$actionID) {
                 $actionID = 'index';
             }
             $tmpLoginUrl = Yii::$app->user->loginUrl;
             Yii::$app->user->loginUrl = null;
             try {
                 $modules = $controller->getModules();
                 if ($modules && !$modules[count($modules) - 1]->beforeAction(new Action($actionID, $controller))) {
                     throw new \Exception('not valid');
                 }
                 if ($controller->beforeAction(new Action($actionID, $controller))) {
                     if (isset($callback)) {
                         self::$_accessCache[$key] = $callback();
                     } else {
                         self::$_accessCache[$key] = true;
                     }
                 }
             } catch (\Exception $e) {
                 if (isset($failCallback)) {
                     self::$_accessCache[$key] = $failCallback();
                 }
             }
             Yii::$app->user->loginUrl = $tmpLoginUrl;
         }
     }
     return self::$_accessCache[$key];
 }
Example #18
Show file File: Blueprint.php Project: pin-cnx/orientdb-laravel-5
0
 /**
  * Create a new schema blueprint.
  *
  * @param  string   $table
  * @param  \Closure  $callback
  * @return void
  */
 public function __construct($table, Closure $callback = null)
 {
     $this->table = $table;
     if (!is_null($callback)) {
         $callback($this);
     }
 }
Frequently Used Methods