コード例 #1
0
 function testaddFilterDirectory()
 {
     $sDir = PHP_Beautifier_Common::normalizeDir(dirname(__FILE__));
     $this->oBeaut->addFilterDirectory($sDir);
     $aDirs = $this->oBeaut->getFilterDirectories();
     $this->assertEquals(end($aDirs), $sDir);
 }
コード例 #2
0
 /**
  * getBatchEngine
  *
  * @access private
  * @return void
  */
 private function getBatchEngine()
 {
     $sCompress = $this->sCompress ? ucfirst($this->sCompress) : '';
     $sClass = $this->sOutputMode . $sCompress;
     $sClassEngine = 'PHP_Beautifier_Batch_Output_' . $sClass;
     $sClassFile = PHP_Beautifier_Common::normalizeDir(dirname(__FILE__)) . 'Batch/Output/' . $sClass . '.php';
     if (!file_exists($sClassFile)) {
         throw new Exception("Doesn't exists file definition for {$sClass} ({$sClassFile})");
     } else {
         include_once $sClassFile;
         if (!class_exists($sClassEngine)) {
             throw new Exception("{$sClassFile} exists, but {$sClassEngine} isn't defined");
         } else {
             return new $sClassEngine($this);
         }
     }
 }
コード例 #3
0
 /**
  * addHeaderComment
  *
  * @access public
  * @return void
  */
 function addHeaderComment()
 {
     if (!($sLicense = $this->getSetting('add_header'))) {
         return;
     }
     // if Header is a path, try to load the file
     if (file_exists($sLicense)) {
         $sDataPath = $sLicense;
     } else {
         $sDataPath = PHP_Beautifier_Common::normalizeDir(CODEFORMATTER_LIBPATH) . 'Beautifier/Licenses/' . $sLicense . '.txt';
     }
     if (file_exists($sDataPath)) {
         $sLicenseText = file_get_contents($sDataPath);
     } else {
         throw new Exception("Can't load license '" . $sLicense . "'");
     }
     $this->oBeaut->removeWhitespace();
     $this->oBeaut->addNewLine();
     $this->oBeaut->add($sLicenseText);
     $this->oBeaut->addNewLineIndent();
 }
コード例 #4
0
ファイル: Beautifier.php プロジェクト: kidaa30/yes
 /**
  * Add a filter directory
  * @param string path to directory
  * @throws Exception
  */
 public function addFilterDirectory($sDir)
 {
     $sDir = PHP_Beautifier_Common::normalizeDir($sDir);
     if (file_exists($sDir)) {
         array_push($this->aFilterDirs, $sDir);
     } else {
         throw new Exception_PHP_Beautifier_Filter("Path '{$sDir}' doesn't exists");
     }
 }
コード例 #5
0
ファイル: Common.php プロジェクト: bhirsch/voipdrupal-4.7-1.0
 /**
  * Return an array with the paths to save for an array of files
  * @param    array  Array of files (input)
  * @param    string Init path
  * @return   array  Array of files (output)
  */
 public static function getSavePath($aFiles, $sPath = './')
 {
     $sPath = PHP_Beautifier_Common::normalizeDir($sPath);
     // get the lowest denominator..
     $sPrevious = '';
     $iCut = 0;
     foreach ($aFiles as $i => $sFile) {
         $sFile = preg_replace("/^.*?#/", '', $sFile);
         $aFiles[$i] = $sFile;
         if (!$sPrevious) {
             $sPrevious = dirname($sFile);
             continue;
         }
         $aPreviousParts = explode("/", $sPrevious);
         $aCurrentParts = explode("/", dirname($sFile));
         for ($x = 0; $x < count($aPreviousParts); $x++) {
             if ($aPreviousParts[$x] != $aCurrentParts[$x]) {
                 $sPrevious = implode("/", array_slice($aPreviousParts, 0, $x));
             }
         }
     }
     $iCut = strlen($sPrevious);
     $aPathsOut = array();
     foreach ($aFiles as $sFile) {
         $sFileOut = preg_replace("/^(\\w:\\/|\\.\\/|\\/)/", "", substr($sFile, $iCut));
         $aPathsOut[] = $sPath . $sFileOut;
     }
     return $aPathsOut;
 }
コード例 #6
0
 /**
  * Search, inside a dir, for a file pattern using glob(* and ?)
  * 
  * @param mixed $sPath      Paht to the directory
  * @param mixed $bRecursive Set recursive to true or false
  *
  * @static
  * @access public
  * @return array path to file
  */
 public static function getFilesByGlob($sPath, $bRecursive = false)
 {
     if (!$bRecursive) {
         return glob($sPath);
     } else {
         $sDir = dirname($sPath) ? realpath(dirname($sPath)) : realpath('./');
         $sDir = PHP_Beautifier_Common::normalizeDir($sDir);
         $sDir = substr($sDir, 0, -1);
         // strip last slash
         $sGlob = basename($sPath);
         $dh = @opendir($sDir);
         if (!$dh) {
             throw new Exception("Cannot open directory '{$sPath}'");
         }
         $aMatches = glob($sDir . '/' . $sGlob);
         while ($entry = @readdir($dh)) {
             if ($entry == '.' or $entry == '..') {
                 continue;
             } elseif (is_dir($sDir . '/' . $entry)) {
                 $aMatches = array_merge($aMatches, PHP_Beautifier_Common::getFilesByGlob($sDir . '/' . $entry . '/' . $sGlob, true));
             }
         }
         return $aMatches;
     }
 }
コード例 #7
0
 function testgetFilesByGlob()
 {
     $sDir = PHP_Beautifier_Common::normalizeDir(dirname(__FILE__));
     $aExpected = array($sDir . 'BeautifierCommonTest.php');
     $this->assertEquals($aExpected, PHP_Beautifier_Common::getFilesByGlob($sDir . basename(__FILE__, '.php') . '.???', false));
 }