@param string $service
@param string $pattern

@return array
497906
protected function _getTables($service, $pattern = null)
    {
        /** @var \ManaPHP\DbInterface $db */
        $db = $this->_di->getShared($service);
        $tables = [];
        foreach ($db->getTables() as $table) {
            if ($pattern && !fnmatch($pattern, $table)) {
                continue;
            }
            $tables[] = $table;
        }

        sort($tables);

        return $tables;
    }
891331
protected function _getServices($services)
    {
        if ($services) {
            foreach ($services as $index => $service) {
                if (!$this->_di->has($service)) {
                    if ($this->_di->has($service . 'Mongodb')) {
                        $services[$index] = $service . 'Mongodb';
                    } elseif ($this->_di->has($service . '_mongodb')) {
                        $services[$index] = $service . '_mongodb';
                    } else {
                        $this->console->warn(['`:service` service is not exists: ignoring', 'service' => $service]);
                        unset($services[$index]);
                    }
                }
            }
        } else {
            $services = [];
            foreach ($this->configure->components as $service => $config) {
                $config = json_encode($config, JSON_UNESCAPED_SLASHES);
                if (preg_match('#mongodb://#', $config)) {
                    $services[] = $service;
                }
            }
        }

        return $services;
    }
524127
public function unsubscribe(...$pattern)
    {
        list($command, $channel, $subscribedChannels) = $this->__call('unsubscribe', $pattern);
        $this->subscribed = $subscribedChannels > 0;

        return [$command, $channel, $subscribedChannels];
    }
1248908
public function get(string $pattern, array $param): void
    {
        $this->call('get', $pattern, $param[0], $param[1], $param);
    }
1018146
protected static function transform(Pattern $pattern) {
        $result = [];
        $groups = [[$pattern]];

        while ($groups) {
            $children = array_shift($groups);
            $hasBranchPattern = false;
            foreach ($children as $c) {
                if ($c instanceof BranchPattern) {
                    $hasBranchPattern = true;
                    break;
                }
            }
            if ($hasBranchPattern) {
                /** @var BranchPattern $child */
                $child = null;
                foreach ($children as $key => $currentChild) {
                    if ($currentChild instanceof BranchPattern) {
                        $child = $currentChild;
                        unset($children[$key]);
                        break;
                    }
                }
                if ($child instanceof Either) {
                    foreach ($child->children as $c) {
                        $groups[] = array_merge([$c], $children);
                    }
                }
                else if ($child instanceof OneOrMore) {
                    $groups[] = array_merge($child->children, $child->children, $children);
                }
                else {
                    $groups[] = array_merge($child->children, $children);
                }
            }
            else {
                $result[] = $children;
            }
        }

        $rs = [];
        foreach ($result as $e) {
            $rs[] = new Required($e);
        }
        return new Either($rs);
    }
469671
public function parse($pattern)
    {
        //reset must be extracted
        $this->mustBeExtracted = array();
        //filter to lower and remove accentued
        $filteredPattern = mb_strtolower($this->remove_accents($pattern));

        $terms = $this->extractTerms($filteredPattern);
        $terms['_domain'] = $this->extractDomain($filteredPattern);
        $terms['_default'] = $this->extractDefault($filteredPattern);

        return $terms;
    }
1100982
public function scan($pattern = '*', $count = 100)
    {
        $client = $this->getConnection();
        $keys = [];

        foreach (new Keyspace($client->client(), $pattern) as $item) {
            $keys[] = $item;

            if (count($keys) == $count) {
                break;
            }
        }

        $script = <<<'LUA'
        local type = redis.call('type', KEYS[1])
        local ttl = redis.call('ttl', KEYS[1])

        return {KEYS[1], type, ttl}
LUA;

        return $client->pipeline(function (Pipeline $pipe) use ($keys, $script) {
            foreach ($keys as $key) {
                $pipe->eval($script, 1, $key);
            }
        });
    }
943207
public function transformPatternToRegex($pattern)
    {
        if (!isset($this->patternToRegexpCache[$pattern])) {
            $this->patternToRegexpCache[$pattern] = $this->transformPatternToRegexWithSupportedPolicy($pattern);
        }

        return $this->patternToRegexpCache[$pattern];
    }
1178960
public function parse($pattern, array $patterns = []) {
        return $this->matcher->parse(
            $pattern, $this->getPath(), $patterns
        );
    }
199191
public function getContainerStyleByPattern($pattern)
    {
        if ($pattern === null) {
            return array();
        }

        $nodeStyles = array();
        if (!empty($this->parent)) {
            $nodeStyles = $this->parent->getContainerStyleByPattern($pattern);
        }

        $keys = $this->pregGrepStyle($pattern);
        foreach ($keys as $key) {
            $nodeStyles = array_merge($nodeStyles, $this->containerStyles[$key]);
        }

        return $nodeStyles;
    }
497177
private function fieldsForService(string $service): array
    {
        switch ($service) {
            case self::CITY_EXTENDED_SERVICE:
                return [
                    'countryCode',
                    'regionCode',
                    'locality',
                    'postalCode',
                    'latitude',
                    'longitude',
                    'metroCode',
                    'areaCode',
                    'isp',
                    'organization',
                ];
            case self::OMNI_SERVICE:
                return [
                    'countryCode',
                    'countryName',
                    'regionCode',
                    'region',
                    'locality',
                    'latitude',
                    'longitude',
                    'metroCode',
                    'areaCode',
                    'timezone',
                    'continentCode',
                    'postalCode',
                    'isp',
                    'organization',
                    'domain',
                    'asNumber',
                    'netspeed',
                    'userType',
                    'accuracyRadius',
                    'countryConfidence',
                    'cityConfidence',
                    'regionConfidence',
                    'postalConfidence',
                    'error',
                ];
            default:
                throw new UnsupportedOperation(sprintf('Unknown MaxMind service %s', $service));
        }
    }
1152576
private static function getPattern(string $pattern)
    {
        $keywords = preg_split("/\\//", $pattern);
        $i = '0';
        $word = "";
        foreach ($keywords as $keyword) {
            $i++;
            if (preg_match("/:/i", $keyword)) {
                $word .= "([a-zA-Z0-9-._]+)";
            } else {
                $word .= $keyword;
            }
            if (count($keywords) != $i) {
                $word .= "/";
            }
        }

        return $word;
    }
62103
protected function parsePattern($pattern)
    {
        $patterns = explode(';', $pattern);
        if (!isset($patterns[1])) {
            // No explicit negative pattern was provided, construct it.
            $patterns[1] = '-' . $patterns[0];
        }
        return $patterns;
    }
843542
public function flushCache($pattern = null)
    {
        $keys = $this->getServiceKeys($pattern);

        array_map(function ($key) {
            $actualKey = $this->getFullKey($key);
            $this->log('flushing cache for '.get_class($this).' ('.$actualKey.')');

            CacheFacade::forget($actualKey);
        }, $keys);
    }
716084
public function pubSubChannels($pattern = null) {
        $payload = ['pubsub', 'channels'];

        if ($pattern !== null) {
            $payload[] = $pattern;
        }

        return $this->send($payload);
    }
1345872
private function getOptionByRegExpr(string $pattern): array
    {
        $purgedArgs = $this->getRawArgs(true);
        return preg_grep("/" . $pattern . "/", $purgedArgs);
    }
821092
public function actionIndex(string $pattern): Response
    {
        /** @var Response $response */
        $response = Craft::$app->getResponse();
        $jsonOptions = null;
        $pretty = false;
        $cache = false;
        $statusCode = 200;
        $statusText = null;

        try {
            $plugin = Plugin::getInstance();
            $config = $plugin->getEndpoint($pattern);
            $request = Craft::$app->getRequest();
            $siteId = Craft::$app->getSites()->getCurrentSite()->id;

            if (is_callable($config)) {
                $params = Craft::$app->getUrlManager()->getRouteParams();
                $config = $this->_callWithParams($config, $params);
            }

            if (is_array($config)) {
                // Merge in the defaults
                $config = array_merge($plugin->getDefaultResourceAdapterConfig(), $config);
            }

            // Before anything else, check the cache
            $cache = ArrayHelper::remove($config, 'cache', false);

            if ($cache) {
                $cacheKey = 'elementapi:'.$siteId.':'.$request->getPathInfo().':'.$request->getQueryStringWithoutPath();
                $cacheService = Craft::$app->getCache();

                if (($cachedContent = $cacheService->get($cacheKey)) !== false) {
                    // Set the JSON headers
                    (new JsonResponseFormatter())->format($response);

                    // Set the cached JSON on the response and return
                    $response->format = Response::FORMAT_RAW;
                    $response->content = $cachedContent;
                    return $response;
                }
            }

            // Extract config settings that aren't meant for createResource()
            $serializer = ArrayHelper::remove($config, 'serializer');
            $jsonOptions = ArrayHelper::remove($config, 'jsonOptions', JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
            $pretty = ArrayHelper::remove($config, 'pretty', false);
            $includes = ArrayHelper::remove($config, 'includes', []);
            $excludes = ArrayHelper::remove($config, 'excludes', []);

            // Generate all transforms immediately
            Craft::$app->getConfig()->getGeneral()->generateTransformsBeforePageLoad = true;

            // Get the data resource
            try {
                $resource = $plugin->createResource($config);
            } catch (\Throwable $e) {
                throw new NotFoundHttpException($e->getMessage() ?: Craft::t('element-api', 'Resource not found'), 0, $e);
            }

            // Load Fractal
            $fractal = new Manager();

            // Serialize the data
            if (!$serializer instanceof SerializerAbstract) {
                switch ($serializer) {
                    case 'dataArray':
                        $serializer = new DataArraySerializer();
                        break;
                    case 'jsonApi':
                        $serializer = new JsonApiSerializer();
                        break;
                    case 'jsonFeed':
                        $serializer = new JsonFeedV1Serializer();
                        break;
                    default:
                        $serializer = new ArraySerializer();
                }
            }

            $fractal->setSerializer($serializer);

            // Parse includes/excludes
            $fractal->parseIncludes($includes);
            $fractal->parseExcludes($excludes);

            $data = $fractal->createData($resource);

            // Fire a 'beforeSendData' event
            if ($this->hasEventHandlers(self::EVENT_BEFORE_SEND_DATA)) {
                $this->trigger(self::EVENT_BEFORE_SEND_DATA, new DataEvent([
                    'data' => $data,
                ]));
            }

            $data = $data->toArray();
        } catch (\Throwable $e) {
            $data = [
                'error' => [
                    'code' => $e instanceof HttpException ? $e->statusCode : $e->getCode(),
                    'message' => $e->getMessage(),
                ]
            ];
            $statusCode = $e instanceof HttpException ? $e->statusCode : 500;
            $statusText = $e->getMessage();
        }

        // Create a JSON response formatter with custom options
        $formatter = new JsonResponseFormatter([
            'encodeOptions' => $jsonOptions,
            'prettyPrint' => $pretty,
        ]);

        // Manually format the response ahead of time, so we can access and cache the JSON
        $response->data = $data;
        $formatter->format($response);
        $response->data = null;
        $response->format = Response::FORMAT_RAW;

        // Cache it?
        if ($cache) {
            if ($cache !== true) {
                $expire = ConfigHelper::durationInSeconds($cache);
            } else {
                $expire = null;
            }
            /** @noinspection PhpUndefinedVariableInspection */
            $cacheService->set($cacheKey, $response->content, $expire);
        }

        // Don't double-encode the data
        $response->format = Response::FORMAT_RAW;
        $response->setStatusCode($statusCode, $statusText);
        return $response;
    }