Returns an instance of the app as a component

@param bool $bUseCache Whether to use the cache or not

@return Component
188217
public static function getApp($bUseCache = true): Component
    {
        //  If we have already fetched this data then don't get it again
        if ($bUseCache && isset(static::$aCache['APP'])) {
            return static::$aCache['APP'];
        }

        // --------------------------------------------------------------------------

        $sComposer = @file_get_contents(NAILS_APP_PATH . 'composer.json');

        if (empty($sComposer)) {
            ErrorHandler::halt('Failed to get app configuration; could not load composer.json');
        }

        $oComposer = @json_decode($sComposer);

        if (empty($oComposer)) {
            ErrorHandler::halt('Failed to get app configuration; could not decode composer.json');
        }

        $aComposer = (array) $oComposer;
        $aNails    = !empty($oComposer->extra->nails) ? (array) $oComposer->extra->nails : [];
        $oOut      = new Component(
            (object) [
                'slug'        => 'app',
                'name'        => 'app',
                'description' => ArrayHelper::getFromArray('description', $aNails, ArrayHelper::getFromArray('description', $aComposer)),
                'homepage'    => ArrayHelper::getFromArray('homepage', $aNails, ArrayHelper::getFromArray('homepage', $aComposer)),
                'authors'     => ArrayHelper::getFromArray('authors', $aNails, ArrayHelper::getFromArray('authors', $aComposer)),
                'extra'       => (object) [
                    'nails' => (object) [
                        'namespace'  => '\\App\\',
                        'moduleName' => ArrayHelper::getFromArray('moduleName', $aNails, ''),
                        'data'       => ArrayHelper::getFromArray('data', $aNails, null),
                        'autoload'   => ArrayHelper::getFromArray('autoload', $aNails, null),
                    ],
                ],
            ],
            NAILS_APP_PATH,
            './',
            true
        );

        // --------------------------------------------------------------------------

        if ($bUseCache) {
            static::$aCache['APP'] = $oOut;
        }

        return $oOut;
    }
625150
public function useCacheIfPossible($useCache = true)
    {
        if ($useCache && is_readable($this->cacheFileName)) {
            $fileTime   = filemtime($this->pathToImage);
            $cacheTime  = filemtime($this->cacheFileName);

            if ($fileTime <= $cacheTime) {
                if ($this->useCache) {
                    if ($this->verbose) {
                        $this->log("Use cached file.");
                        $this->log("Cached image filesize: " . filesize($this->cacheFileName) . " bytes.");
                    }
                    $this->output($this->cacheFileName, $this->outputFormat);
                } else {
                    $this->log("Cache is valid but ignoring it by intention.");
                }
            } else {
                $this->log("Original file is modified, ignoring cache.");
            }
        } else {
            $this->log("Cachefile does not exists or ignoring it.");
        }

        return $this;
    }
31318
protected function marshall(QtiComponent $component)
    {
        $element = static::getDOMCradle()->createElement($component->getQtiClassName());

        $this->setDOMElementAttribute($element, 'shape', QtiShape::getNameByConstant($component->getShape()));
        $this->setDOMElementAttribute($element, 'coords', $component->getCoords());
        $this->setDOMElementAttribute($element, 'mappedValue', $component->getMappedValue());

        return $element;
    }
1037725
public function getCacheBusterFactory()
    {
        if (null === $this->cacheBusterFactory) {
            $this->cacheBusterFactory = function ($helper) {
                return new CacheBusterDecorator($helper);
            };
        }
        return $this->cacheBusterFactory;
    }
1250998
public function query(QueryBuilderCache $queryBuilderCache)
    {
        // Reconnect the connection in case isn't connected yet.
        $this->reconnect();

        $result = false;
        $queryStatement = new QueryStatement($queryBuilderCache);

        $startTime = microtime(true);

        // Run the query for real
        if ($this->disableQueryExecution === false) {
            $rows = $this->platformQueryHandler($queryStatement);
            $result = new Result($rows);

            if ($this->transactionInProgress) {
                $this->transactionStatus = ($queryStatement->hasErrors() ? false : true);
            }
        }

        $queryStatement->setDuration($startTime);

        $this->queriesCache[] = $queryStatement;

        if ($queryStatement->hasErrors()) {
            if ($this->debugEnabled) {
                throw new RuntimeException($queryStatement->getLatestErrorMessage(),
                    $queryStatement->getLatestErrorCode());
            }

            if ($this->transactionInProgress) {
                $this->transactionStatus = false;
                $this->transactionInProgress = false;
            }

            return false;
        }

        return $result;
    }
179569
public function cache(Store $cache = null)
    {
        $cache = $cache ?: $this->resolve(CacheRepository::class)->getStore();

        if ($this->usesCachedClipboard()) {
            $this->guard->getClipboard()->setCache($cache);

            return $this;
        }

        return $this->setClipboard(new CachedClipboard($cache));
    }
43461
protected function marshall(QtiComponent $component)
    {
        $element = self::getDOMCradle()->createElement('col');

        if ($component->getSpan() !== 1) {
            $this->setDOMElementAttribute($element, 'span', $component->getSpan());
        }

        $this->fillElement($element, $component);

        return $element;
    }
4279
public function get($key = null, $cache_cb = null, &$cas_token = null)
    {

        if (isset($this->cacheListing [$key])) {
            return parent::get($key, $cache_cb, $cas_token);
        }

        return false;
    }
267474
public function get_tables($usecache=true) {
        if ($usecache and $this->tables !== null) {
            return $this->tables;
        }
        $this->tables = array();
        $prefix = str_replace('_', '\\_', $this->prefix);
        $sql = "SHOW TABLES LIKE '$prefix%'";
        $this->query_start($sql, null, SQL_QUERY_AUX);
        $result = $this->mysqli->query($sql);
        $this->query_end($result);
        $len = strlen($this->prefix);
        if ($result) {
            while ($arr = $result->fetch_assoc()) {
                $tablename = reset($arr);
                $tablename = substr($tablename, $len);
                $this->tables[$tablename] = $tablename;
            }
            $result->close();
        }

        // Add the currently available temptables
        $this->tables = array_merge($this->tables, $this->temptables->get_temptables());
        return $this->tables;
    }
398367
private function createXcache():Xcache
    {
        /** @var IConfig $config */
        $config = $this->di->getShared('config');
        /** @var IApp $app */
        $app = $this->di->getShared('app');
        $lifetime = (int)$config->get($this->getName() . '.lifetime', 3600);
        $frontCache = new FrontData([
            "lifetime" => $lifetime
        ]);
        return new Xcache($frontCache, ['prefix' => $app->getAppId()]);

    }
186111
public static function getInstance(Application $app, $sbasid, $sbas_coll, $dmin, $dmax)
    {
        $cache_id = 'feed_' . md5($sbasid . '_' . $sbas_coll . '_' . $dmin . '_' . $dmax);

        try {
            $result = $app->getApplicationBox()->get_data_from_cache($cache_id);
            $result->setApplication($app);

            return $result;
        } catch (\Exception $e) {

        }
        $tmp = new self($app, $sbasid, $sbas_coll, $dmin, $dmax);

        $app->getApplicationBox()->set_data_to_cache($tmp, $cache_id);

        return $tmp;
    }
659191
public function getCache()
    {
        if ($this->cache) {
            return $this->cache;
        }

        if (property_exists($this, 'app') && $this->app instanceof ServiceContainer
            && isset($this->app['cache']) && $this->app['cache'] instanceof CacheInterface) {
            return $this->cache = $this->app['cache'];
        }

        return $this->cache = $this->createDefaultCache();
    }
993622
protected static function get(string $component, bool $forInstance = false)
    {
        //读取具体组件
        $component = strtoupper($component);
        if (array_key_exists($component, self::$lists)) {
            $Class = self::$lists[$component][0];
            if ($forInstance) {
                if (!is_object($Class)) {
                    $Class = new $Class;
                }
            } else {
                if (is_object($Class)) {
                    $Class = get_class($Class);
                }
            }
            return $Class;
        }
        throw new Exception("$component does not exist!"); //没有注册则抛出异常
    }
1367238
public function getComponent (string $key)
    {
        $components = $this->getComponents();

        return array_key_exists($key, $components)
            ? $components[$key]
            : null;
    }
909330
protected function marshall(QtiComponent $component)
    {
        $element = static::getDOMCradle()->createElement($component->getQtiClassName());

        $this->setDOMElementAttribute($element, 'baseType', BaseType::getNameByConstant($component->getBaseType()));
        self::setDOMElementValue($element, $component->getValue());

        return $element;
    }
389971
public function getCache($key) {
        if (!$this->__cacheEnabled) {
            return null;
        }

        $key = $this->createCacheKey($key);

        if ($this->hasCache($key)) {
            return $this->_cache[$key];
        }

        return null;
    }
344273
public function get($cache = null)
    {
        if (is_null($cache)) {
            $cache = $this->getDefaultCache();
        }

        if ($cache instanceof CacheItemPoolInterface) {
            return $cache;
        }
        if ($cache instanceof CacheInterface) {
            return $cache;
        }

        foreach ($this->callbacks as $callBack) {
            $result = call_user_func($callBack, $cache);
            if ($result instanceof CacheItemPoolInterface) {
                return $result;
            }
            if ($result instanceof CacheInterface) {
                return $result;
            }
        }

        throw new InvalidArgumentException(Message::INVALID_CACHE_ADAPTER);
    }