获取同步

@param Context $context
请求上下文对象
@return Miner
197977
public function getSync(Context $context = null)
    {
        $activeConfig = $this->config['mysql'][$this->active];
        $client = $this->getDBQueryBuilder($context);
        if ($client->getPdoConnection() === null) {
            return $client->pdoConnect($activeConfig);
        } else {
            return $client;
        }
    }
1295868
protected function mergeContextHeaders($context)
    {
        $headers = $this->headers->asArray();
        
        if($context === null ) {
            return $headers;
        }
        
        $cookieUpdates = $context->cookies()->updates();
        if(empty($cookieUpdates)) {
            return $headers;
        }
        
        $cookieHeaders = array();
        foreach($cookieUpdates as $update) {
            $cookieHeaders[] = $update->asHeader();
        }
        
        foreach($headers as $name => $value) {
            if(strtolower($name) === 'set-cookie') {
                foreach($cookieHeaders as $header) {
                    $headers[$name][] = $header;
                }
                return $headers;
            }
        }
        
        $headers['Set-Cookie'] = $cookieHeaders;
        return $headers;
    }
1027282
public function setContext($context)
    {
        if ($context instanceof Context) {
            $context = [$context];
        }

        if ($context instanceof \ArrayObject || is_array($context) || $context instanceof \Iterator) {
            foreach ($context as $key => $value) {
                if (!$value instanceof Context) {
                    if (is_int($key) && is_array($value) && array_key_exists('key', $value) && array_key_exists('value', $value)) {
                        $contextData = ['key' => $value['key'], 'value' => $value['value']];
                        if (isset($value['id'])) {
                            $contextData['id'] = $value['id'];
                        }
                    } else {
                        $contextData = ['key' => $key, 'value' => $value];
                    }
                    $value = new Context($contextData);
                }

                $value->setNotification($this);
                $this->contexts->add($value);
            }
        }

        return $this;
    }
998761
public function loadContext($context)
    {

        $now = time();
        $context->created = $now;
        $context->updated = $now;

        return true;

    }
400416
public function getContextLocale($context)
    {
        return isset($this->contextLocales[$context]) ? $this->contextLocales[$context] : null;
    }
878208
public function addContext($context = [])
    {
        if (!$context || empty($context)) {
            return $this;
        }
        $this->nestContext($context);
        $this->sanitizeContext($context);
        $this->context = array_merge($this->context, $context);

        return $this;
    }
1087665
public function getProvidersByContext($context)
    {
        $providers = array();
        
        foreach($this->providers[$context] as $providerId) {
            $providers[] = $this->container->get($providerId);
        }
        
        return $providers;
    }
91823
public function fireEvents($context)
    {
        if (!isset($context['__env'])) {
            return $context;
        }

        /** @var \Illuminate\View\Factory $factory */
        $env  = $context['__env'];
        $viewName = $this->name ?: $this->getTemplateName();

        $view = new View(
            $env,
            $env->getEngineResolver()->resolve('twig'),
            $viewName,
            null,
            $context
        );
        $env->callCreator($view);
        $env->callComposer($view);
        return $view->getData();
    }
747486
public function setContext(Context $context)
    {
        $this->context = $context;

        if (empty($this->parameters['secret'])) {
            $this->parameters['secret'] = $context->getSecret();
        }

        return $this;
    }
1311175
protected static function ctxHasCurrentAccount(ContextInterface $context): bool
    {
        /** @var AccountManagerInterface $manager */
        $container = static::ctxGetContainer($context);
        $manager   = $container->get(AccountManagerInterface::class);
        $account   = $manager->getAccount();

        return $account !== null;
    }
253306
final public function filterByContext(array $context)
    {
        if ($context !== $this->withContext) {
            $this->withContext = $context;
            $this->consumer = null;
        }
        
        return $this;
    }
179037
protected static function cache_add(context $context) {
        if (isset(self::$cache_contextsbyid[$context->id])) {
            // already cached, no need to do anything - this is relatively cheap, we do all this because count() is slow
            return;
        }

        if (self::$cache_count >= CONTEXT_CACHE_MAX_SIZE) {
            $i = 0;
            foreach(self::$cache_contextsbyid as $ctx) {
                $i++;
                if ($i <= 100) {
                    // we want to keep the first contexts to be loaded on this page, hopefully they will be needed again later
                    continue;
                }
                if ($i > (CONTEXT_CACHE_MAX_SIZE / 3)) {
                    // we remove oldest third of the contexts to make room for more contexts
                    break;
                }
                unset(self::$cache_contextsbyid[$ctx->id]);
                unset(self::$cache_contexts[$ctx->contextlevel][$ctx->instanceid]);
                self::$cache_count--;
            }
        }

        self::$cache_contexts[$context->contextlevel][$context->instanceid] = $context;
        self::$cache_contextsbyid[$context->id] = $context;
        self::$cache_count++;
    }
1060847
public function createQuery($context = 'list')
    {
        /** @var QueryBuilder $query */
        $query = parent::createQuery($context);

        /** @var User $user */
        $user = $this->getConfigurationPool()->getContainer()->get('security.token_storage')->getToken()->getUser();

        if ($this->isGranted('ROLE_SUPER_ADMIN')) {
            return $query;
        }

        $query->leftJoin($query->getRootAliases()[0] . '.userGroups', 'ug');

        $query->andWhere('ug.id = :group_id');
        $query->setParameter('group_id', $user->getGroups());

        return $query;
    }
498171
protected static function construct(ExecutionContext $exeContext = null): Executor
    {
        $executorReflection = new \ReflectionClass(Executor::class);
        /** @var Executor $executor */
        $executor = $executorReflection->newInstanceWithoutConstructor();

        if ($exeContext !== null) {
            $constructor = $executorReflection->getConstructor();
            $constructor->setAccessible(true);
            $constructor->invoke($executor, $exeContext);
        }

        return $executor;
    }
932562
public function getSecurity($context)
    {
        if (array_key_exists($context, $this->instances))
        {
            return $this->instances[$context];
        }

        $configuration = $this->getConfigurationFor($context);
        $this->addPermissionsFactoryListener($context);

        return $this->instances[$context] = $this->getSecurityFactory()->create($context, $configuration);
    }
1257069
protected function prepareContextStack($context = null)
    {
        $stack = new Mustache_Context();

        $helpers = $this->mustache->getHelpers();
        if (!$helpers->isEmpty()) {
            $stack->push($helpers);
        }

        if (!empty($context)) {
            $stack->push($context);
        }

        return $stack;
    }
965374
public function begin(Context $context = null)
    {
        $this->getDBQueryBuilder($context)->go(null, 'begin');
        
        return $this;
    }