setLogger() 공개 메소드

public setLogger ( Psr\Log\LoggerInterface $logger ) : GrepGenerator
$logger Psr\Log\LoggerInterface
리턴 GrepGenerator
예제 #1
0
    /**
     * tests running the generation of a grep command
     *
     * @group generator
     * @group sourcetest
     */
    public function testRun()
    {
        $mockLogger = $this->getMock('\\Monolog\\Logger', array(), array(), '', false);
        self::assertSame($this->object, $this->object->setLogger($mockLogger));
        $mockBrowscap = $this->getMock('\\phpbrowscap\\Browscap', array(), array(), '', false);
        $tmpfile = tempnam(sys_get_temp_dir(), 'browscaptest');
        $in = <<<HERE
; comment

test
HERE;
        file_put_contents($tmpfile, $in);
        self::assertNull($this->object->run($mockBrowscap, $tmpfile, GrepCommand::MODE_UNMATCHED));
        unlink($tmpfile);
    }
예제 #2
0
    /**
     * tests running the generation of a grep command
     *
     * @group generator
     * @group sourcetest
     */
    public function testRun()
    {
        $logger = $this->createMock(\Monolog\Logger::class);
        self::assertSame($this->object, $this->object->setLogger($logger));
        $mockBrowscap = $this->createMock(\BrowscapPHP\Browscap::class);
        $tmpfile = tempnam(sys_get_temp_dir(), 'browscaptest');
        $in = <<<HERE
; comment

test
HERE;
        file_put_contents($tmpfile, $in);
        self::assertNull($this->object->run($mockBrowscap, $tmpfile, GrepCommand::MODE_UNMATCHED));
        unlink($tmpfile);
    }
예제 #3
0
 /**
  * Executes the current command.
  *
  * This method is not abstract because you can use this class
  * as a concrete class. In this case, instead of defining the
  * execute() method, you set the code to execute by passing
  * a Closure to the setCode() method.
  *
  * @param InputInterface  $input  An InputInterface instance
  * @param OutputInterface $output An OutputInterface instance
  *
  * @throws \Exception
  * @return null|integer null or 0 if everything went fine, or an error code
  *
  * @see    setCode()
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $inputFile = $input->getArgument('inputFile');
     $mode = $input->getOption('mode');
     if (!in_array($mode, array(self::MODE_MATCHED, self::MODE_UNMATCHED))) {
         throw new \Exception('Mode must be "matched" or "unmatched"');
     }
     if (!file_exists($inputFile)) {
         throw new \Exception('Input File "' . $inputFile . '" does not exist, or cannot access');
     }
     $cacheDir = sys_get_temp_dir() . '/browscap-grep/' . microtime(true) . '/';
     if (!file_exists($cacheDir)) {
         mkdir($cacheDir, 0777, true);
     }
     $debug = $input->getOption('debug');
     $loggerHelper = new LoggerHelper();
     $this->logger = $loggerHelper->create($debug);
     $iniFile = $input->getArgument('iniFile');
     if (!$iniFile || !file_exists($iniFile)) {
         $this->logger->info('iniFile Argument not set or invalid - creating iniFile from resources');
         $iniFile = $cacheDir . 'full_php_browscap.ini';
         $buildGenerator = new BuildGenerator($input->getOption('resources'), $cacheDir);
         $writerCollectionFactory = new FullPhpWriterFactory();
         $writerCollection = $writerCollectionFactory->createCollection($this->logger, $cacheDir);
         $buildGenerator->setLogger($this->logger)->setCollectionCreator(new CollectionCreator())->setWriterCollection($writerCollection);
         $buildGenerator->run($input->getArgument('version'), false);
     }
     $generator = new GrepGenerator();
     $browscap = new Browscap($cacheDir);
     $browscap->localFile = $iniFile;
     $generator->setLogger($this->logger)->run($browscap, $inputFile, $mode);
     $this->logger->info('Grep done.');
 }