コード例 #1
0
ファイル: File.php プロジェクト: nnevala/zf-boilerplate
 /**
  * Authenticate and return an auth result
  *
  * @return phpRack_Runner_Auth_Result
  * @see phpRack_Adapters_Auth_Abstract::authenticate()
  */
 public function authenticate()
 {
     /**
      * @see phpRack_Adapters_File
      */
     require_once PHPRACK_PATH . '/Adapters/File.php';
     $file = phpRack_Adapters_File::factory($this->_options['htpasswd'])->getFileName();
     $fileContent = file($file);
     foreach ($fileContent as $line) {
         list($login, $password) = explode(':', $line, 2);
         /* Just to make sure we don't analyze some whitespace */
         $login = trim($login);
         $password = trim($password);
         if ($login == $this->_request['login'] && $password == $this->_request['hash']) {
             return $this->_validated(true);
         }
     }
     return $this->_validated(false, 'Invalid login credentials provided');
 }
コード例 #2
0
ファイル: Disc.php プロジェクト: nnevala/zf-boilerplate
 /**
  * Show directory structure
  *
  * @param string Relative path, in relation to the location of {@link PHPRACK_PATH} file
  * @param array List of options
  * @return $this
  */
 public function showDirectory($dir, array $options = array())
 {
     require_once PHPRACK_PATH . '/Adapters/File.php';
     $dir = phpRack_Adapters_File::factory($dir)->getFileName();
     if (!file_exists($dir)) {
         $this->_failure("Directory '{$dir}' is absent");
         return $this;
     }
     $this->_log("Directory tree '" . realpath($dir) . "':");
     // Create our file iterator
     require_once PHPRACK_PATH . '/Adapters/Files/DirectoryFilterIterator.php';
     $iterator = phpRack_Adapters_Files_DirectoryFilterIterator::factory($dir);
     if (array_key_exists('exclude', $options)) {
         $iterator->setExclude($options['exclude']);
     }
     if (array_key_exists('maxDepth', $options)) {
         $iterator->setMaxDepth($options['maxDepth']);
     }
     $this->_log(implode("\n", $this->_convertDirectoriesToLines($iterator, $dir)));
     return $this;
 }
コード例 #3
0
ファイル: File.php プロジェクト: nnevala/zf-boilerplate
 /**
  * Check whether the filename is a directory
  *
  * @param string File name to check
  * @return $this
  */
 public function isDir($fileName)
 {
     $fileName = phpRack_Adapters_File::factory($fileName)->getFileName();
     clearstatcache();
     if (is_dir($fileName)) {
         $this->_success("File '{$fileName}' is a directory");
     } else {
         $this->_failure("File '{$fileName}' is not a directory");
     }
     return $this;
 }
コード例 #4
0
ファイル: Php.php プロジェクト: tpc2/phprack
 /**
  * Check files in directory have correct php syntax.
  *
  * Possible options are:
  *
  * <code>
  * class MyTest extends phpRack_Test {
  *   public function testCodeValidity() {
  *     $this->assert->php->lint(
  *       '/home/myproject/php', // path to PHP files
  *       array(
  *         'extensions' => 'php,phtml', // comma-separated list of extensions to parse
  *         'exclude' => array('/\.svn/'), // list of RegExps to exclude
  *         'verbose' => true, // show detailed log, with one file per line
  *       )
  *     );
  *   }
  * }
  * </code>
  *
  * @param string Directory path to check
  * @param array List of options
  * @return $this
  */
 public function lint($dir, array $options = array())
 {
     require_once PHPRACK_PATH . '/Adapters/File.php';
     $dir = phpRack_Adapters_File::factory($dir)->getFileName();
     if (!file_exists($dir)) {
         $this->_failure("Directory '{$dir}' does not exist");
         return $this;
     }
     // Create our file iterator
     require_once PHPRACK_PATH . '/Adapters/Files/DirectoryFilterIterator.php';
     $iterator = phpRack_Adapters_Files_DirectoryFilterIterator::factory($dir);
     if (!empty($options['exclude'])) {
         $iterator->setExclude($options['exclude']);
     }
     if (!empty($options['extensions'])) {
         $iterator->setExtensions($options['extensions']);
     }
     $lintCommand = 'php -l';
     $valid = $invalid = 0;
     foreach ($iterator as $file) {
         $file = realpath($file->getPathname());
         $command = $lintCommand . ' ' . escapeshellarg($file) . ' 2>&1';
         /**
          * @see phpRack_Adapters_Shell_Command
          */
         require_once PHPRACK_PATH . '/Adapters/Shell/Command.php';
         $output = phpRack_Adapters_Shell_Command::factory($command)->run();
         if (preg_match('#^No syntax errors detected#', $output)) {
             if (!empty($options['verbose'])) {
                 $this->_success("File '{$file}' is valid");
             }
             $valid++;
         } else {
             $this->_failure("File '{$file}' is NOT valid:");
             $this->_log($output);
             $invalid++;
         }
     }
     // notify phpRack about success in the test
     if (!$invalid) {
         $this->_success("{$valid} files are LINT-valid");
     }
     $this->_log(sprintf('%d files LINT-checked, among them: %d valid and %d invalid', $valid + $invalid, $valid, $invalid));
     return $this;
 }