Backend\Core\Ajax\Templates::processFile PHP Метод

processFile() приватный Метод

Process the content of the file.
private processFile ( string $file )
$file string The file to process.
    private function processFile($file)
    {
        $filesystem = new Filesystem();
        // if the files doesn't exists we can stop here
        if (!$filesystem->exists($file)) {
            return;
        }
        // fetch content from file
        $content = file_get_contents($file);
        $json = @json_decode($content, true);
        // skip invalid JSON
        if ($json === false || $json === null) {
            return;
        }
        // loop templates
        foreach ((array) $json as $template) {
            // skip items without a title
            if (!isset($template['title'])) {
                continue;
            }
            if (isset($template['file']) && $filesystem->exists(PATH_WWW . $template['file'])) {
                $template['html'] = file_get_contents(PATH_WWW . $template['file']);
            }
            // skip items without HTML
            if (!isset($template['html'])) {
                continue;
            }
            $image = '';
            if (isset($template['image'])) {
                // we have to remove the first slash, because that is set in the wrapper.
                // Otherwise the images don't work
                $image = ltrim($template['image'], '/');
            }
            $temp['title'] = $template['title'];
            $temp['description'] = isset($template['description']) ? $template['description'] : '';
            $temp['image'] = $image;
            $temp['html'] = $template['html'];
            // add the template
            $this->templates[] = $temp;
        }
    }