Exemple #1
0
 static function safeWrite($file, $content, $perm = 0664)
 {
     lmb_assert_type($file, 'string', 'File name must be a string');
     lmb_assert_true($file, 'File name must be a string');
     self::mkdir(dirname($file));
     $tmp = self::generateTmpFile('_');
     $fh = fopen($tmp, 'w');
     if ($fh === false) {
         @unlink($tmp);
         throw new lmbFsException('could not open file for writing', array('file' => $file));
     }
     //just for safety
     @flock($fh, LOCK_EX);
     fwrite($fh, $content);
     @flock($fh, LOCK_UN);
     fclose($fh);
     if (lmbSys::isWin32() && file_exists($file)) {
         @unlink($file);
     }
     if (!@rename($tmp, $file)) {
         @unlink($tmp);
         throw new lmbFsException('could not move file', array('src' => $tmp, 'file' => $file));
     }
     @chmod($file, $perm);
     if (file_exists($tmp)) {
         @unlink($tmp);
     }
 }
 function testAssertTrue_CustomMessage()
 {
     $message = uniqid('lmb_assert_true');
     try {
         lmb_assert_true(false, $message);
     } catch (lmbInvalidArgumentException $e) {
         $this->assertPattern('/' . $message . '/', $e->getMessage());
     }
 }
 /**
  * @param string $name
  * @return lmbLog
  */
 function getLogFromConf($name)
 {
     lmb_assert_true($name);
     lmb_assert_type($name, 'string');
     if ($this->toolkit->hasConf('log')) {
         $conf = $this->toolkit->getConf('log');
         $log = $this->toolkit->createLog($conf['logs'][$name]);
     } else {
         $log = $this->toolkit->getDefaultLog();
     }
     return $log;
 }
 function _createDataSet()
 {
     $toolkit = lmbToolkit::instance();
     $conf = $toolkit->getConf('navigation');
     $role = $toolkit->getCmsUser()->getRoleType();
     lmb_assert_true($conf->has($role), "Navigation section for current user role not found");
     $data = $conf->get($role);
     if (is_array($data)) {
         return new lmbCollection($data);
     } else {
         return new lmbCollection();
     }
 }
 function __construct($limit_or_backtrace = null, $limit_or_offset = null, $offset = 0)
 {
     lmb_assert_true(!is_object($limit_or_backtrace), "Backtrace can't be a object");
     if (is_array($limit_or_backtrace)) {
         $this->backtrace = $limit_or_backtrace;
         $limit = $limit_or_offset;
     } else {
         $this->backtrace = debug_backtrace();
         $limit = $limit_or_backtrace;
         $offset = (int) $limit_or_offset + 1;
     }
     if (is_null($limit)) {
         $limit = count($this->backtrace) - $offset;
     }
     $this->backtrace = array_splice($this->backtrace, $offset, $limit);
 }