Subscription clause method
@param  string $key
@param  Closure $method
@param  string $model
@return void
186233
public function clause($key, $method, $model = null)
    {
        $query = null;

        if (! is_null($model)) {
            $appModel = app($model);
            $query = DB::table(app($model)->table);

            if ($this->inBillingCycle) {
                $customer = Customer::retrieve($this->user->meta->stripe_id);
                $stripeSubscription = $customer->subscriptions->retrieve($this->subscription->stripe_id);

                $currentPeriodStart = Carbon::createFromTimestamp($stripeSubscription->current_period_start)->format('Y-m-d h:i:s');
                $currentPeriodEnd = Carbon::createFromTimestamp($stripeSubscription->current_period_end)->format('Y-m-d h:i:s');

                $query = $appModel->where('created_at', '>=', $currentPeriodStart)->where('created_at', '<=', $currentPeriodEnd);
            }
        }

        $clause = $this->config['plans'][$this->subscription->stripe_plan][$key];

        return $method($this->user, $this->subscription, $clause, $query);
    }
937032
public function eagerlyResult(&$result, $relation, $subRelation, $closure)
    {
        $morphKey  = $this->morphKey;
        $morphType = $this->morphType;
        // 多态类型映射
        $model = $this->parseModel($result->{$this->morphType});

        $this->eagerlyMorphToOne($model, $relation, $result, $subRelation);
    }
874373
public function subscribe( $channels, Closure $callback, $connection = null, $method = 'subscribe' )
	{
		$loop = $this->connection( $connection )->pubSubLoop();

		call_user_func_array( [$loop, $method], (array) $channels );

		foreach ( $loop as $message )
		{
			if ( $message->kind === 'message' || $message->kind === 'pmessage' )
			{
				call_user_func( $callback, $message->payload, $message->channel );
			}
		}

		unset( $loop );
	}
458360
public function addMethod(Method $method): void
    {
        $this->methods[(string) $method->getFqsen()] = $method;
    }
914944
public function bind(string $class, string $method, Closure $closure)
  {
    if (!class_exists($class)) throw new ClassDoesNotExistException("Class {$class} does not exist");

    if (!in_array(
      Extendable::class,
      array_keys((new ReflectionClass($class))->getTraits()))
    ) {
      throw new CannotExtendClassException("Cannot extend \"{$class}::class\"");
    }

    return $class::bind($method, $closure);
  }
664683
public function join($table, $key, $operator = null, $value = null, $type = 'inner')
    {
        if (!$key instanceof \Closure) {
            $key = function ($joinBuilder) use ($key, $operator, $value) {
                $joinBuilder->on($key, $operator, $value);
            };
        }

        // Build a new JoinBuilder class, keep it by reference so any changes made
        // in the closure should reflect here
        $joinBuilder = $this->container->build('\\Pixie\\QueryBuilder\\JoinBuilder', array($this->connection));
        $joinBuilder = &$joinBuilder;
        // Call the closure with our new joinBuilder object
        $key($joinBuilder);
        $table = $this->addTablePrefix($table, false);
        // Get the criteria only query from the joinBuilder object
        $this->statements['joins'][] = compact('type', 'table', 'joinBuilder');

        return $this;
    }
435100
public function setMethod($method) {
        $methods = array(
            COMPLETION_AGGREGATION_ALL,
            COMPLETION_AGGREGATION_ANY,
        );

        if (in_array($method, $methods)) {
            $this->method = $method;
        } else {
            $this->method = COMPLETION_AGGREGATION_ALL;
        }
    }
1158126
public function hasRelatedKey($key, $model = false)
    {
        if (!$model) {
            $model = $this->model;
        }

        if (($methodBreaker = strpos($key, '.')) !== false) {
            $method = substr($key, 0, $methodBreaker);
            if (method_exists($model, $method)) {
                return true;
            }
        }

        return false;
    }
460735
public function inTransaction(Closure $closure): void
    {
        $connection = $this->getConnection();
        $connection->beginTransaction();
        try {
            $isOk = ($closure() === false ? null : true);
        } finally {
            $isCommitting = (isset($isOk) === true);
            try {
                $isCommitting === true ? $connection->commit() : $connection->rollBack();
            } /** @noinspection PhpRedundantCatchClauseInspection */ catch (ConEx | DBALException $exception) {
                throw new RepositoryException(
                    $isCommitting === true ? 'Failed to commit a transaction.' : 'Failed to rollback a transaction.',
                    0,
                    $exception
                );
            }
        }
    }
1203353
public function setMethod( $method )
	{
		if ( $method == $this->getMethod() ) { return; }

		$this->_values['method'] = (string) $method;
		$this->setModified();
	}
688149
public function forget($key)
    {
        if (strpos($key, '.') !== false) {
            $this->forgetSubKey($key);
        } else {
            $this->forgetByKey($key);
        }

        $this->resetLang();
    }
472693
public function setParameter($key, $parameter)
    {
        // If the object is null, an exception is thrown.
        if($this->getObject() === null) {
            throw new NullPointerException("The object cannot be null.");
        }

        // Let's get the key-method mapping.
        $mapping = $this->getKeyMethodMapping();

        // If the key is not mapped, an exception is thrown.
        if(!array_key_exists($key, $mapping)) {
            throw new ParameterNotFoundException("The $key parameter cannot be set with this setter.");
        }

        // Call the mapped setter method.
        $object   = $this->getObject();
        $method   = $mapping[$key];
        $callable = array($object, $method);
        call_user_func($callable, $parameter);
    }
345801
public function queueSubscribe($subject, $queue, \Closure $callback)
    {
        $sid = $this->randomGenerator->generateString(16);
        $msg = 'SUB '.$subject.' '.$queue.' '.$sid;
        $this->send($msg);
        $this->subscriptions[$sid] = $callback;
        return $sid;
    }
871557
public function withEntryFromClosure(string $key, \Closure $closure): self
    {
        $this->bindings[$key] = $closure;
        return $this;
    }
421103
public function handle($request, Closure $next, $model, $relation)
    {
        $model = 'App\\' . $model;
        $params = array_values( $request->route()->parameters() );
        // eğer ikinci yoksa dön
        if ( ! isset($params[1])) {
            return $next($request);
        }

        $model = is_numeric($params[0]) ? $model::findOrFail($params[0]) : $params[0];
        $relation_id = is_numeric($params[1]) ? $params[1] : $params[1]->id;

        // baum mu değil mi ona göre query oluşturulur
        // pagecategory baum olduğunda buna gerek yok
        $parent = '\\'. get_parent_class($model);
        $query = get_parent_class(new $parent) === 'Baum\Node' ? $model->descendantsAndSelf() : $model->query();
        $relationModel = $query->whereHas($relation, function($query) use($relation_id)
        {
            return $query->whereId($relation_id);
        })->get();

        if ( $relationModel->isEmpty() ) {
            abort(404);
        }

        return $next($request);
    }
287598
public function eagerlyResult(&$result, $relation, $subRelation, $closure)
    {
        $pk = $result->getPk();

        if (isset($result->$pk)) {
            $key   = $result->$pk;
            $where = [
                [$this->morphKey, '=', $key],
                [$this->morphType, '=', $this->type],
            ];
            $data = $this->eagerlyMorphToMany($where, $relation, $subRelation, $closure);

            if (!isset($data[$key])) {
                $data[$key] = [];
            }

            foreach ($data[$key] as &$relationModel) {
                $relationModel->setParent(clone $result);
                $relationModel->isUpdate(true);
            }

            $result->setRelation(Db::parseName($relation), $this->resultSetBuild($data[$key]));
        }
    }
673069
public function model($key, $class, Closure $callback = null)
    {
        $this->bind($key, function ($value) use ($class, $callback) {
            if ($value === null) {
                return null;
            }

            // For model binders, we will attempt to retrieve the models using the first
            // method on the model instance. If we cannot retrieve the models we'll
            // throw a not found exception otherwise we will return the instance.
            $instance = $this->container->make($class);

            if ($model = $instance->where($instance->getRouteKeyName(), $value)->first()) {
                return $model;
            }

            // If a callback was supplied to the method we will call that to determine
            // what we should do when the model is not found. This just gives these
            // developer a little greater flexibility to decide what will happen.
            if ($callback instanceof Closure) {
                return call_user_func($callback, $value);
            }

            throw new NotFoundHttpException;
        });
    }