protected function getOriginDb(OutputInterface $output, $now)
    {
        $url = $this->getContainer()->getParameter('anime_db.ani_db.import_titles');

        if (($path = parse_url($url, PHP_URL_PATH)) === false) {
            throw new \InvalidArgumentException('Failed parse URL: '.$url);
        }

        /* @var Filesystem $fs */
        $fs = $this->getContainer()->get('filesystem');
        $filename = sys_get_temp_dir().'/'.pathinfo($path, PATHINFO_BASENAME);

        if (!$fs->exists($filename) || filemtime($filename) + self::CACHE_LIFE_TIME < $now) {
            /* @var $downloader \AnimeDb\Bundle\AppBundle\Service\Downloader */
            $downloader = $this->getContainer()->get('anime_db.downloader');
            $tmp = tempnam(sys_get_temp_dir(), 'ani_db_titles');
            if (!$downloader->download($url, $tmp, true)) {
                $fs->remove($tmp);
                throw new \RuntimeException('Failed to download the titles database');
            }
            $fs->rename($tmp, $filename, true);
            $output->writeln('The titles database is loaded');
        }

        return $filename;
    }
protected function getOriginDb(OutputInterface $output, $now)
    {
        $url = $this->getContainer()->getParameter('anime_db.ani_db.import_titles');

        if (($path = parse_url($url, PHP_URL_PATH)) === false) {
            throw new \InvalidArgumentException('Failed parse URL: '.$url);
        }

        /* @var Filesystem $fs */
        $fs = $this->getContainer()->get('filesystem');
        $filename = sys_get_temp_dir().'/'.pathinfo($path, PATHINFO_BASENAME);

        if (!$fs->exists($filename) || filemtime($filename) + self::CACHE_LIFE_TIME < $now) {
            /* @var $downloader \AnimeDb\Bundle\AppBundle\Service\Downloader */
            $downloader = $this->getContainer()->get('anime_db.downloader');
            $tmp = tempnam(sys_get_temp_dir(), 'ani_db_titles');
            if (!$downloader->download($url, $tmp, true)) {
                $fs->remove($tmp);
                throw new \RuntimeException('Failed to download the titles database');
            }
            $fs->rename($tmp, $filename, true);
            $output->writeln('The titles database is loaded');
        }

        return $filename;
    }
protected function getOriginDb ( OutputInterface $ output , $ now ) { $ url = $ this -> getContainer ( ) -> getParameter ( 'anime_db.ani_db.import_titles' ) ; if ( ( $ path = parse_url ( $ url , PHP_URL_PATH ) ) === false ) { throw new \ InvalidArgumentException ( 'Failed parse URL: ' . $ url ) ; } /* @var Filesystem $fs */ $ fs = $ this -> getContainer ( ) -> get ( 'filesystem' ) ; $ filename = sys_get_temp_dir ( ) . '/' . pathinfo ( $ path , PATHINFO_BASENAME ) ; if ( ! $ fs -> exists ( $ filename ) || filemtime ( $ filename ) + self :: CACHE_LIFE_TIME < $ now ) { /* @var $downloader \AnimeDb\Bundle\AppBundle\Service\Downloader */ $ downloader = $ this -> getContainer ( ) -> get ( 'anime_db.downloader' ) ; $ tmp = tempnam ( sys_get_temp_dir ( ) , 'ani_db_titles' ) ; if ( ! $ downloader -> download ( $ url , $ tmp , true ) ) { $ fs -> remove ( $ tmp ) ; throw new \ RuntimeException ( 'Failed to download the titles database' ) ; } $ fs -> rename ( $ tmp , $ filename , true ) ; $ output -> writeln ( 'The titles database is loaded' ) ; } return $ filename ; }
Get original db file.

Download the original db if need and cache it in a system temp dir

@throws \InvalidArgumentException
@throws \RuntimeException

@param OutputInterface $output
@param int $now

@return string
Get original db file .