Gets all service resources (storage and databases) based on RBAC

@param array $manifest
@param array $allServices
@param bool  $fullTree
15646
private function getAllowedServiceResources(&$manifest, $allServices, $fullTree)
    {
        if (!empty($allServices)) {
            // Get list of active services with type for group lookup
            foreach ($allServices as $service) {
                $serviceName = array_get($service, 'name');
                $serviceId = array_get($service, 'id');
                if (Session::allowsServiceAccess($serviceName, Session::getRequestor())) {
                    try {
                        $service = ServiceManager::getService($serviceName);
                        if ($service->isActive()) {
                            $typeInfo = $service->getServiceTypeInfo();
                            switch ($typeInfo->getGroup()) {
                                case ServiceTypeGroups::FILE:
                                    $this->getAllowedStoragePaths($manifest, $serviceName, $serviceId, $fullTree);
                                    break;
                                case ServiceTypeGroups::DATABASE:
                                    $this->getAllowedDatabaseResources($manifest, $serviceName);
                                    break;
                            }
                        } else {
                            \Log::warning('Excluding inactive service:' . $serviceName . ' from manifest.');
                        }
                    } catch (\Exception $e) {
                        // Error occurred. Flag it, Log and let go.
                        $manifest['service'][$serviceName][static::REACHABLE_FLAG] = false;
                        \Log::alert('Failed to include service:' .
                            $serviceName .
                            ' in manifest due to error:' .
                            $e->getMessage());
                    }
                }
            }
        }
    }
520604
public function getExportStorageService($default = null)
    {
        $storage = array_get($this->manifest, 'storage', $default);

        if (is_array($storage)) {
            $name = array_get($storage, 'name', array_get($storage, 'id', $default));
            if (is_numeric($name)) {
                return ServiceManager::getServiceNameById($name);
            }

            return $name;
        }

        return $storage;
    }
776251
public function checkQuery($fullUrlWithQuery,$active=null,$inactive=null)
    {
        $this->setReturnValue($active,$inactive);

        if (is_array($fullUrlWithQuery)) {
            $result = call_user_func_array(array($this,'queryIsDeeply'), $fullUrlWithQuery);
        } else {
            $result = $this->queryIsDeeply($fullUrlWithQuery);   
        }

        return $result ? $this->activeValue : $this->inActiveValue;
    }
686369
function getAll(name, deploy, fn, single) {
  getTree(name, deploy, function(err, tree) {
    if (err) return fn(err);
    var acc = [];
    flatten(tree, acc);
    if (acc.length === 0) return fn(null);
    if (single && acc.length === 1) return fn(null, acc[0]);
    fn(err, acc);
  });
}
41114
private function getSubresourceData($identifiers, array $attributes, array $context)
    {
        if (null === $this->subresourceDataProvider) {
            throw new RuntimeException('Subresources not supported');
        }

        return $this->subresourceDataProvider->getSubresource($attributes['resource_class'], $identifiers, $attributes['subresource_context'] + $context, $attributes['subresource_operation_name']);
    }
1220735
public function all($fields = [], $sorted = true, $sortBy = 'cn', $sortByDirection = 'asc')
    {
        $namingContext = $this->getConfigurationNamingContext();

        if ($namingContext) {
            $search = $this->adldap->search()
                ->setDn($namingContext)
                ->select($fields)
                ->where('objectCategory', '=', $this->serverObjectCategory);

            if ($sorted) {
                $search->sortBy($sortBy, $sortByDirection);
            }

            return $search->get();
        }

        return false;
    }
1230094
public function getBreadcrumbs(HasNodeInterface $page, $full = false)
    {
        $key = sprintf('%s:%d:%d', ClassLookup::getClass($page), $page->getId(), $full);
        if ($this->cache->contains($key)) {
            return $this->cache->fetch($key);
        }

        $nodeTranslation = $this->nodeVersions->getNodeTranslationFor($page);

        if (null === $nodeTranslation) {
            throw new \RuntimeException(sprintf('Cant find node for %s:%d page', get_class($page), $page->getId()));
        }

        $lang = $nodeTranslation->getLang();
        $breadcrumbs = $this->breadCrumbsService->getNodePath($nodeTranslation->getNode());

        $parents = (new ArrayCollection($breadcrumbs))
            ->filter(function (Node $node) use ($full) { return $full || false === $node->isHiddenFromNav(); })
            ->map(function (Node $node) use ($lang) { return $node->getNodeTranslation($lang, true); })
            ->map(function (NodeTranslation $nt) { return $this->nodeTranslationToCategory($nt); })
            ->toArray();

        $this->cache->save($key, $parents);

        return $parents;
    }
541836
public function getResource($uri, $expanded = false)
    {
        if (!$expanded)
            $url = self::makeUrl(null, $uri);
        else
            $url = self::makeUrl(null, $uri, true);

        // If getting the root folder, we must use repository.folder+json
        if ($uri == "/")
            $type = "application/repository.folder+json";
        else
            $type = "application/repository.file+json";

        $response = $this->service->makeRequest($url, array(200, 204), 'GET', null, true, 'application/json', $type);

        $data = $response['body'];
        $headers = $response['headers'];
        $content_type = array_values(preg_grep("#repository\.(.*)\+#", $headers));
        preg_match("#repository\.(.*)\+#", $content_type[0], $resource_type);

        $class = RESOURCE_NAMESPACE . '\\' . ucfirst($resource_type[1]);
        if (class_exists($class) && is_subclass_of($class, RESOURCE_NAMESPACE . '\\Resource')) {
            return $class::createFromJSON(json_decode($data, true), $class);
        } else {
            return Resource::createFromJSON(json_decode($data, true));
        }
    }
457254
public function getManifestOnly($systemOnly = false, $fullTree = false)
    {
        $this->data['system']['role'] = $this->getAllResources('system', 'role', ['fields' => 'id,name']);
        $this->data['system']['service'] =
            $this->getAllResources('system', 'service', ['fields' => 'id,name'], null, false);
        // Keeping a separate copy of all services to fetch exportable resources for each services.
        $allServices = $this->data['system']['service'];
        $this->data['system']['app'] = $this->getAllResources('system', 'app', ['fields' => 'id,name']);
        $this->data['system']['user'] =
            $this->getAllResources('system', 'user', ['fields' => 'id,email,username,first_name,last_name']);
        $this->data['system']['admin'] =
            $this->getAllResources('system', 'admin', ['fields' => 'id,email,username,first_name,last_name']);
        $this->data['system']['custom'] = $this->getAllResources('system', 'custom');
        $this->data['system']['cors'] = $this->getAllResources('system', 'cors', ['fields' => 'id,path']);
        $this->data['system']['email_template'] = $this->getAllResources('system', 'email_template',
            ['fields' => 'id,name']);
        $this->data['system']['event_script'] = $this->getAllResources('system', 'event_script', ['fields' => 'name']);
        $this->data['system']['lookup'] = $this->getAllResources('system', 'lookup', ['fields' => 'id,name']);

        /* Check for paid limits class */
        if (class_exists(\DreamFactory\Core\Limit\ServiceProvider::class)) {
            $this->data['system']['limit'] = $this->getAllResources('system', 'limit', ['fields' => 'id,name']);
        }

        $manifest = $this->package->getManifestHeader();
        $this->getAllowedSystemResources($manifest);

        // If system/service is not allowed for the user then remove it from output array.
        if (!Session::checkServicePermission(Verbs::GET, 'system', 'service', Session::getRequestor(), false)) {
            unset($manifest['service']['system']['service']);
            if(empty($manifest['service']['system'])){
                unset($manifest['service']['system']);
            }
        }

        if (false === $systemOnly) {
            $this->getAllowedServiceResources($manifest, $allServices, $fullTree);
        }

        return $manifest;
    }
781951
public function executeFull()
    {
        $storeIds = array_keys($this->storeManager->getStores());

        foreach ($storeIds as $storeId) {
            $dimension = $this->dimensionFactory->create(['name' => 'scope', 'value' => $storeId]);
            $this->indexerHandler->cleanIndex([$dimension]);
            $this->indexerHandler->saveIndex([$dimension], $this->fullAction->rebuildStoreIndex($storeId));
        }
    }
940627
public function getEntity($full_name)
    {
        $filePath = path_join($this->path, Util::toFileName($full_name, '.dat'));
        $data = $this->fs->get($filePath);
        return unserialize($data);
    }
1160909
public function getLinks($all = false)
    {
        $links = [];

        $this->getLinksByTagAttribute("link", "href", $links);
        $this->getLinksByTagAttribute("a", "href", $links);
        $this->getLinksByTagAttribute("script", "src", $links);
        $this->getLinksByTagAttribute("iframe", "src", $links);
        $this->getLinksByTagAttribute("img", "src", $links);

        //get all string started with http
        $regexUrl = '/[">\s]+((http|https|ftp|ftps)\:\/\/(.*?))["<\s]+/';
        $urls     = null;
        if (preg_match_all($regexUrl, $this->html, $urls) > 0) {
            $matches = $urls[1];
            foreach ($matches as $url) {
                if (filter_var($url, FILTER_VALIDATE_URL)) {
                    $links[$url] = $url;
                }
            }
        }

        if ($all) {
            //get all params which can be a url
            $regexParam = '/["](.*?)["]/';
            $params     = [];
            if (preg_match_all($regexParam, $this->html, $params) > 0) {
                $urls = $params[1];
                foreach ($urls as $url) {
                    $url = trim($url);
                    if ((strpbrk($url, "/.") !== false) && (strpbrk($url, " ") === false)) {
                        $links[$url] = $url;
                    }
                }
            }
        }

        foreach ($links as $link) {
            $url = parse_url($link);
            if (!((isset($url['host']) && isset($url['scheme'])) || (isset($url['path'])))) {
                unset($links[$link]);
            }
        }

        return $links;
    }
1016290
public function purge_children($requirefulltree) {
        $this->children = array();
        $this->fulltree = ($requirefulltree || $this->fulltree);
        $this->loaded   = false;
        //break circular dependencies - this helps PHP 5.2
        while($this->category_cache) {
            array_pop($this->category_cache);
        }
        $this->category_cache = array();
    }
301319
private function getManifestComponentModuleIndex($manifest, $componentId)
    {
        $manifest = is_array($manifest)
            ? $manifest
            : $this->getManifest($manifest);

        $modules = array_filter($manifest['modules'], function ($module) use ($componentId) {
            return ($module['id'] === $componentId);
        });

        return array_keys($modules)[0];
    }
138428
protected static function resolveFullUrl($entities = [], $params = [])
    {
        $uri = static::getUri();

        if (!empty($entities)) {
            if (is_array($entities)) {
                $entities = implode('/', $entities) . '/';
            }

            if (!is_scalar($entities)) {
                throw new InvalidQueryException();
            }

            $uri .= $entities;
        }

        if (!empty($params)) {
            $uri .= '?' . http_build_query($params);
        }

        return $uri;
    }
843353
protected function find($scheme, $file, $array, $absolute, $all)
    {
        if (!isset($this->schemes[$scheme])) {
            throw new \InvalidArgumentException("Invalid resource {$scheme}://");
        }

        $results = $array ? [] : false;
        foreach ($this->schemes[$scheme] as $prefix => $paths) {
            if ($prefix && strpos($file, $prefix) !== 0) {
                continue;
            }

            // Remove prefix from filename.
            $filename = '/' . trim(substr($file, \strlen($prefix)), '\/');

            foreach ($paths as $path) {
                if (\is_array($path)) {
                    // Handle scheme lookup.
                    $relPath = trim($path[1] . $filename, '/');
                    $found = $this->find($path[0], $relPath, $array, $absolute, $all);
                    if ($found) {
                        if (!$array) {
                            return $found;
                        }
                        $results = array_merge($results, $found);
                    }
                } else {
                    // TODO: We could provide some extra information about the path to remove preg_match().
                    // Check absolute paths for both unix and windows
                    if (!$path || !preg_match('`^/|\w+:`', $path)) {
                        // Handle relative path lookup.
                        $relPath = trim($path . $filename, '/');
                        $fullPath = $this->base . '/' . $relPath;
                    } else {
                        // Handle absolute path lookup.
                        $fullPath = rtrim($path . $filename, '/');
                        if (!$absolute) {
                            throw new \RuntimeException("UniformResourceLocator: Absolute stream path with relative lookup not allowed ({$prefix})", 500);
                        }
                    }

                    if ($all || file_exists($fullPath)) {
                        $current = $absolute ? $fullPath : $relPath;
                        if (!$array) {
                            return $current;
                        }
                        $results[] = $current;
                    }
                }
            }
        }

        return $results;
    }
358957
public function process_resource($manifestroot, &$fname, $folder) {
        $file = empty($folder) ? $manifestroot.'/'.$fname : $manifestroot.'/'.$folder.'/'.$fname;
        if (!file_exists($file) && $this->throwonerror) {
            throw new Exception('The file doesnt exist!');
        }

        GetDepFiles($manifestroot, $fname, $this->folder, $this->files);
        array_unshift($this->files, $folder.$fname);
        $this->init_empty_new();
        $this->href             = $folder.$fname;
        $this->identifierref    = $folder.$fname;
        $this->filename         = $fname;
        $this->isempty          = false;
        $this->folder           = $folder;
    }