Load Resource Handler

@param  Smarty $smarty smarty object
@param  string $type   name of the resource

@throws SmartyException
@return Smarty_Resource Resource Handler
512252
public static function load(Smarty $smarty, $type)
    {
        // try smarty's cache
        if (isset($smarty->_cache['resource_handlers'][$type])) {
            return $smarty->_cache['resource_handlers'][$type];
        }

        // try registered resource
        if (isset($smarty->registered_resources[$type])) {
            return $smarty->_cache['resource_handlers'][$type] =
                $smarty->registered_resources[$type] instanceof Smarty_Resource ? $smarty->registered_resources[$type] :
                    new Smarty_Internal_Resource_Registered();
        }

        // try sysplugins dir
        if (isset(self::$sysplugins[$type])) {
            $_resource_class = 'Smarty_Internal_Resource_' . ucfirst($type);
            return $smarty->_cache['resource_handlers'][$type] = new $_resource_class();
        }

        // try plugins dir
        $_resource_class = 'Smarty_Resource_' . ucfirst($type);
        if ($smarty->loadPlugin($_resource_class)) {
            if (class_exists($_resource_class, false)) {
                return $smarty->_cache['resource_handlers'][$type] = new $_resource_class();
            } else {
                $smarty->registerResource($type,
                                          array("smarty_resource_{$type}_source", "smarty_resource_{$type}_timestamp",
                                                "smarty_resource_{$type}_secure", "smarty_resource_{$type}_trusted"));
                // give it another try, now that the resource is registered properly
                return self::load($smarty, $type);
            }
        }

        // try streams
        $_known_stream = stream_get_wrappers();
        if (in_array($type, $_known_stream)) {
            // is known stream
            if (is_object($smarty->security_policy)) {
                $smarty->security_policy->isTrustedStream($type);
            }
            return $smarty->_cache['resource_handlers'][$type] = new Smarty_Internal_Resource_Stream();
        }

        // TODO: try default_(template|config)_handler

        // give up
        throw new SmartyException("Unknown resource type '{$type}'");
    }
956457
public function import($resource, $prefix = '/', $type = null)
    {
        /** @var RouteCollection[] $collections */
        $collections = $this->load($resource, $type);

        // create a builder from the RouteCollection
        $builder = $this->createBuilder();

        foreach ($collections as $collection) {
            if (null === $collection) {
                continue;
            }

            foreach ($collection->all() as $name => $route) {
                $builder->addRoute($route, $name);
            }

            foreach ($collection->getResources() as $resource) {
                $builder->addResource($resource);
            }
        }

        // mount into this builder
        $this->mount($prefix, $builder);

        return $builder;
    }
110140
public function load($resource, $type = null)
    {
        if (!$resource instanceof ConfiguratorInterface) {
            throw new InvalidArgumentException('Resource must be configurator');
        }

        $this->container->addObjectResource($resource);
        $resource->load($this->container);
    }
349406
public static function load(Smarty $smarty, $type)
    {
        // try smarty's cache
        if (isset($smarty->_resource_handlers[$type])) {
            return $smarty->_resource_handlers[$type];
        }

        // try registered resource
        if (isset($smarty->registered_resources[$type])) {
            if ($smarty->registered_resources[$type] instanceof Smarty_Resource) {
                $smarty->_resource_handlers[$type] = $smarty->registered_resources[$type];
                // note registered to smarty is not kept unique!
                return $smarty->_resource_handlers[$type];
            }

            if (!isset(self::$resources['registered'])) {
                self::$resources['registered'] = new Smarty_Internal_Resource_Registered();
            }
            if (!isset($smarty->_resource_handlers[$type])) {
                $smarty->_resource_handlers[$type] = self::$resources['registered'];
            }

            return $smarty->_resource_handlers[$type];
        }

        // try sysplugins dir
        if (isset(self::$sysplugins[$type])) {
            if (!isset(self::$resources[$type])) {
                $_resource_class = 'Smarty_Internal_Resource_' . ucfirst($type);
                self::$resources[$type] = new $_resource_class();
            }

            return $smarty->_resource_handlers[$type] = self::$resources[$type];
        }

        // try plugins dir
        $_resource_class = 'Smarty_Resource_' . ucfirst($type);
        if ($smarty->loadPlugin($_resource_class)) {
            if (isset(self::$resources[$type])) {
                return $smarty->_resource_handlers[$type] = self::$resources[$type];
            }

            if (class_exists($_resource_class, false)) {
                self::$resources[$type] = new $_resource_class();

                return $smarty->_resource_handlers[$type] = self::$resources[$type];
            } else {
                $smarty->registerResource($type, array(
                    "smarty_resource_{$type}_source",
                    "smarty_resource_{$type}_timestamp",
                    "smarty_resource_{$type}_secure",
                    "smarty_resource_{$type}_trusted"
                ));

                // give it another try, now that the resource is registered properly
                return self::load($smarty, $type);
            }
        }

        // try streams
        $_known_stream = stream_get_wrappers();
        if (in_array($type, $_known_stream)) {
            // is known stream
            if (is_object($smarty->security_policy)) {
                $smarty->security_policy->isTrustedStream($type);
            }
            if (!isset(self::$resources['stream'])) {
                self::$resources['stream'] = new Smarty_Internal_Resource_Stream();
            }

            return $smarty->_resource_handlers[$type] = self::$resources['stream'];
        }

        // TODO: try default_(template|config)_handler

        // give up
        throw new SmartyException("Unkown resource type '{$type}'");
    }
1152192
public static function invalidLoadedCache(Smarty $smarty)
    {
        foreach ($smarty->template_objects as $tpl) {
            if (isset($tpl->cached)) {
                $tpl->cached->valid = false;
                $tpl->cached->processed = false;
            }
        }
    }
138452
public function load($resource, $type = null)
    {
        if (! is_file($resource)) {
            throw new InvalidArgumentException(sprintf('File "%s" is not a regular file.', $resource));
        }

        /* Checking file readability before hand to ensure getting its contents never fail. */
        if (! is_readable($resource)) {
            throw new InvalidArgumentException(sprintf('File "%s" is not readable.', $resource));
        }

        /* Explicitly reading file's content, because support for passing file names is deprecated since Symfony 2.8. */
        $content = file_get_contents($resource);
        $parsedYaml = Yaml::parse($content);

        if (! is_array($parsedYaml)) {
            throw new InvalidArgumentException(sprintf('Could not parse Yaml of file "%s"', $resource));
        }

        return $parsedYaml;
    }
1220887
public static function requestHandler($type)
    {
        if (! self::validateRequest($type)) {
            return false;
        }

        App::setCurrentID(self::$config['app']);

        self::loadRemoteComplements();

        switch (self::$config['request']) {
            case 'load-complements':
                self::complementsLoadRequest();
                break;
            case 'change-state':
                self::changeStateRequest();
                break;
            case 'install':
                self::installRequest();
                break;
            case 'update':
                self::installRequest(true);
                break;
            case 'uninstall':
                self::uninstallRequest();
                break;
            default:
                self::$errors[] = [
                    'message' => 'Unknown request: ' . self::$config['request'],
                ];
                echo json_encode(['errors' => self::$errors]);
                break;
        }

        if (empty(App::getOption('development-environment'))) {
            die;
        }
    }
308580
private function getHandler($type)
    {
        if (!isset(self::$typeHandlers[$type])) {
            throw new Exception("Unsupported PDO param type - " . $type);
        }

        return self::$typeHandlers[$type];
    }
1314448
public function import($resource, $type = null)
    {
        return $this->resolve($resource, $type)->load($resource, $type);
    }
498518
public function load($resource, $type = null)
    {
        $configValues = Yaml::parse(file_get_contents($resource));

        $processor = new Processor();
        $configuration = new SignalertConfiguration();
        $processedConfiguration = $processor->processConfiguration(
            $configuration,
            [$configValues]
        );

        return $processedConfiguration;
    }
1253385
public function load($resource, $type = null)
    {
        if (true === $this->loaded) {
            throw new \RuntimeException('Do not add the "shuwee_admin_extra" loader twice');
        }

        $routeCollection = new RouteCollection();
        foreach ($this->adminManager->getAdmins() as $alias => $admin) {
            // List
            $routeCollection->add(
                $this->routingHelper->getRouteName($admin, 'index'),
                $this->routingHelper->getRoute($admin, 'index', [], true)
            );

            // Create
            $routeCollection->add(
                $this->routingHelper->getRouteName($admin, 'create'),
                $this->routingHelper->getRoute($admin, 'create')
            );

            // Update
            $routeCollection->add(
                $this->routingHelper->getRouteName($admin, 'update'),
                $this->routingHelper->getRoute($admin, 'update', ['id'])
            );

            // Delete
            $routeCollection->add(
                $this->routingHelper->getRouteName($admin, 'delete'),
                $this->routingHelper->getRoute($admin, 'delete', ['id'])
            );

            // Toggle field
            $routeCollection->add(
                $this->routingHelper->getRouteName($admin, 'toggle'),
                $this->routingHelper->getRoute($admin, 'toggle', ['id', 'field', 'token']
                )
            );
        }

        $this->loaded = true;

        return $routeCollection;
    }
1069672
public function unregisterCacheResource($type)
    {
        if (isset($this->smarty->registered_cache_resources[$type])) {
            unset($this->smarty->registered_cache_resources[$type]);
        }
    }
839787
public static function load(string $file, ?string $type = null) : array
    {
        if (isset($type))
        {
            if (isset(self::$classMap[$type]))
            {
                $class = self::$classMap[$type];

                $data = $class::load($file);
            }
            else
            {
                throw new Exception(
                    "There is no registered handler for the specified type "
                    .$type
                );
            }
        }
        else
        {
            self::registerSymfonyYaml();

            foreach (self::$classMap as $ext => $class)
            {
                if (preg_match('/[.]'.preg_quote($ext, '/').'$/i', $file))
                {
                    $data = $class::load($file);
                    break;
                }
            }
        }

        if ( ! isset($data))
        {
            throw new OptionLoaderException(
                "File $file does not appear to be valid"
            );
        }

        return $data;
    }
193782
public function load($resource, $type = null): array
    {
        try {
            $path = $this->locator->locate($resource);
            $file = $this->filesystem->openFile($path);
            $configValues = $this->yamlParser->parse($file->getContents());

            return $configValues;
        } catch (FileLocatorFileNotFoundException $error) {
            return [];
        }
    }
878107
public function loadFile($type, $id) {
    $query = $this->connection->select('file_usage', 'n');
    $query->fields('n', array('fid'));
    $query->condition('n.module', 'site_commerce');
    $query->condition('n.type', $type);
    $query->condition('n.id', $id);
    $fid = $query->execute()->fetchField();
    $file = null;
    if ($fid) {
      $file = File::load($fid);
    }
    return $file;
  }
700816
public function invalidLoadedCache(Smarty $smarty)
    {
        $smarty->_cache['isCached'] = array();
        if (isset($smarty->ext->_subtemplate)) {
            $smarty->ext->_subtemplate->tplObjects = array();
        }
    }
7006
public function load($resource, $type = null)
    {
        if ($this->loaded) {
            throw new \RuntimeException('Do not add this loader twice');
        }

        $collection = new RouteCollection();

        foreach ($this->container->getParameter('smart_core_cms.modules') as $moduleName => $module) {
            $resource = $module['path'].'/Resources/config/routing_admin.yml';
            if (file_exists($resource)) {
                $importedRoutes = $this->import('@'.$moduleName.'ModuleBundle/Resources/config/routing_admin.yml', 'yaml');
                $importedRoutes->addPrefix($moduleName);

                $collection->addCollection($importedRoutes);
            }
        }

        return $collection;
    }