Ejemplo n.º 1
0
 /**
  * Factory to construct the logger and one or more writers
  * based on the configuration array
  *
  * @param array|Miao_Config Array or instance of Miao_Config
  * @return Miao_Log
  */
 public static function factory($config = array())
 {
     if (!is_array($config) || empty($config)) {
         throw new Miao_Log_Exception('Configuration must be an array');
     }
     $log = new Miao_Log();
     if (!is_array(current($config))) {
         $log->addWriter(current($config));
     } else {
         foreach ($config as $writer) {
             $log->addWriter($writer);
         }
     }
     return $log;
 }
Ejemplo n.º 2
0
 public function getLog()
 {
     if (empty($this->_log)) {
         $logFilename = Miao_Config::Main()->get('paths.logs') . '/pdo_log';
         $this->_log = Miao_Log::easyFactory($logFilename);
     }
     return $this->_log;
 }
Ejemplo n.º 3
0
 /**
  *
  * @return the $_logObj
  */
 public function getLogObj()
 {
     if (!$this->_log) {
         $debugMode = $this->getDebugMode();
         $logFilename = $this->_logFilename;
         $log = Miao_Log::easyFactory($logFilename, false, $debugMode ? Miao_Log::DEBUG : Miao_Log::ERR);
         $this->_log = $log;
     }
     return $this->_log;
 }
Ejemplo n.º 4
0
 /**
  *
  * @param Miaox_PDO $pdo
  * @param Miao_Log $log
  */
 public function __construct(Miaox_PDO $pdo, Miao_Log $log = null)
 {
     if (!$log) {
         $this->_log = Miao_Log::easyFactory('');
     } else {
         $this->_log = $log;
     }
     $this->_pdo = $pdo;
     $this->_pdo->setLog($log);
     $this->_init();
 }
Ejemplo n.º 5
0
 /**
  *
  *
  * @param unknown_type $jarFilename
  * @param array $options
  */
 public function __construct($jarFilename = '', Miao_Log $log = null)
 {
     if (empty($jarFilename)) {
         $jarFilename = Miao_Path::getDefaultInstance()->getModuleRoot(__CLASS__) . '/data/compiler.jar';
     }
     if (is_null($log)) {
         $log = Miao_Log::easyFactory('', '');
     }
     parent::__construct($log);
     $this->setJarFilename($jarFilename);
 }
Ejemplo n.º 6
0
 public function testLog()
 {
     $sourceDir = Miao_PHPUnit::getSourceFolder(__CLASS__);
     $filename = $sourceDir . '/unittest_log';
     $log = Miao_Log::easyFactory($filename);
     $msg = 'Hello world';
     $log->err($msg);
     $content = file_get_contents($filename);
     $this->assertTrue(!empty($content));
     unlink($filename);
 }
Ejemplo n.º 7
0
 /**
  *
  * @dataProvider providerTestMinify
  */
 public function testMinify($fileList, $dstFilename, $options, $actualFilename, $exceptionName = '')
 {
     if (!empty($exceptionName)) {
         $this->setExpectedException($exceptionName);
     }
     $log = Miao_Log::easyFactory($this->_moduleRoot . '/' . 'test_minify_log', false);
     $obj = new Miaox_Compress_Driver_ClosureCompiler('', $log);
     $obj->minify($fileList, $dstFilename, $options);
     $this->assertFileEquals($dstFilename, $actualFilename);
     unlink($dstFilename);
 }
Ejemplo n.º 8
0
 /**
  *
  * @dataProvider providerTestMergeFile
  */
 public function testMergeFile($files, $actualFilename, $exceptionName = '')
 {
     $log = Miao_Log::easyFactory($this->_tmpDir . '/' . 'test_merge_file_log');
     $obj = new Miaox_Compress_Driver($log);
     foreach ($files as &$file) {
         $file = $this->_sourceDir . $file;
     }
     $outpuFilename = $this->_tmpDir . '/total';
     $actualFilename = $this->_sourceDir . $actualFilename;
     $obj->mergeFiles($files, $outpuFilename);
     $this->assertFileEquals($outpuFilename, $actualFilename);
 }
Ejemplo n.º 9
0
 public function testFileMode()
 {
     $sourceDir = Miao_PHPUnit::getSourceFolder(__CLASS__);
     $filename = $sourceDir . '/unittest_log';
     $log = Miao_Log::easyFactory($filename);
     $msg = 'Hello world';
     $log->err($msg);
     $expected = '0666';
     $actual = substr(sprintf('%o', fileperms($filename)), -4);
     $this->assertEquals($expected, $actual);
     unlink($filename);
 }
Ejemplo n.º 10
0
 /**
  *
  * @dataProvider providerTestMinify
  */
 public function testMinify($fileList, $dstFilename, $options, $actualFilename, $exceptionName = '')
 {
     //$this->markTestSkipped( 'Miaox_Compress_Driver_Yui_Test test skipped, because work long time' );
     if (!empty($exceptionName)) {
         $this->setExpectedException($exceptionName);
     }
     $log = Miao_Log::easyFactory($this->_moduleRoot . '/' . 'test_minify_log', false);
     $obj = new Miaox_Compress_Driver_Yui('', $log);
     $obj->minify($fileList, $dstFilename, $options);
     $this->assertFileEquals($dstFilename, $actualFilename);
     unlink($dstFilename);
 }
Ejemplo n.º 11
0
 public function mergeFiles(array $files, $outpuFilename)
 {
     assert(is_array($files) && !empty($files));
     $message = sprintf('MINIFY: start mergeFiles to "%s"', $outpuFilename);
     $this->_log->info($message);
     if (file_exists($outpuFilename)) {
         unlink($outpuFilename);
     }
     $shell = $this->_getShell();
     foreach ($files as $filename) {
         if (!file_exists($filename) || !is_readable($filename)) {
             $message = sprintf('MINIFY ERROR: File not found "%s"', $filename);
             $this->_log->crit($message);
             throw new Miaox_Compress_Driver_Exception($message);
         }
         $command = sprintf('cat "%s" >> "%s"', $filename, $outpuFilename);
         $returnVal = 0;
         $shell->exec($command, $returnVal, false);
     }
     $message = sprintf('MINIFY: end mergeFiles');
     $this->_log->info($message);
     return $outpuFilename;
 }
Ejemplo n.º 12
0
 protected function _pdo(array $config)
 {
     assert(array_key_exists('dsn', $config));
     assert(array_key_exists('username', $config));
     assert(array_key_exists('password', $config));
     if (isset($config['logFilename'])) {
         $verbose = isset($config['logVerbose']) ? $config['logVerbose'] : false;
         $log = Miao_Log::easyFactory($config['logFilename'], $verbose);
     }
     $dsn = $config['dsn'];
     $user = $config['username'];
     $pass = $config['password'];
     $options = isset($config['options']) ? $options : array();
     $pdo = new Miaox_PDO($dsn, $user, $pass, $options);
     $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     $pdo->setLog($log);
     return $pdo;
 }
Ejemplo n.º 13
0
 private function _info($message)
 {
     $this->_log->debug($message);
 }
Ejemplo n.º 14
0
 /**
  * Обертка для Miao_Log
  * @param $str
  * @param int $priority
  */
 private function _log($str, $priority = Miao_Log::DEBUG)
 {
     if (!is_null($this->_miaoLog)) {
         $this->_miaoLog->log($str, $priority);
     }
 }
Ejemplo n.º 15
0
        require_once __DIR__ . '/bootstrap.php';
    } else {
        if (file_exists($bootstrap) && is_readable($bootstrap)) {
            require_once $bootstrap;
        } else {
            $msg = sprintf('Invalid param --bootstrap, file (%s) not found or is not readable', $bootstrap);
            throw new Exception($msg);
        }
    }
}
try {
    $bootstrap = '';
    $opts = getopt('', array('bootstrap:'));
    extract($opts);
    includeBootstrap($bootstrap);
    $log = Miao_Log::easyFactory('', true);
    $message = 'Run script: ' . __FILE__;
    $log->debug($message);
    $message = sprintf('Params: %s', print_r($opts, true));
    $log->debug($message);
    $config = Miaox_Acs_Instance::getConfig();
    $config['log']['verbose'] = true;
    $adapter = Miaox_Acs_Instance::adapter($config);
    $builder = new Miaox_Acs_Adapter_Db_Builder($adapter);
    $builder->run();
} catch (Exception $ex) {
    echo "\n";
    echo "Error!\n";
    echo $ex->getMessage();
    echo "\n\n";
}
Ejemplo n.º 16
0
            $msg = sprintf('Invalid param --bootstrap, file (%s) not found or is not readable', $bootstrap);
            throw new Exception($msg);
        }
    }
}
$action = '';
$userName = '';
$verbose = false;
$withTemplate = null;
$remainingArgs = array();
$bootstrap = '';
try {
    $data = parseOpts();
    extract($data);
    includeBootstrap($bootstrap);
    $log = Miao_Log::easyFactory(null, $verbose);
    $author = isset($_SERVER['USER']) ? $_SERVER['USER'] : '';
    $console = new Miao_Console($remainingArgs[0], $author, $log);
    $console->createTemplate($withTemplate);
    if ($action == 'cp' || $action == 'ren') {
        if (!isset($remainingArgs[1])) {
            help();
        }
        $console->{$action}($remainingArgs[1]);
    } else {
        $console->{$action}();
    }
} catch (Exception $ex) {
    echo "\n";
    echo "Console error!\n";
    echo $ex->getMessage();