Example #1
0
 /**
  * Write the command to the local Icinga command file
  *
  * @param   IcingaCommand   $command
  * @param   int|null        $now
  *
  * @throws  ConfigurationError
  * @throws  CommandTransportException
  */
 public function send(IcingaCommand $command, $now = null)
 {
     if (!isset($this->path)) {
         throw new ConfigurationError('Can\'t send external Icinga Command. Path to the local command file is missing');
     }
     $commandString = $this->renderer->render($command, $now);
     Logger::debug('Sending external Icinga command "%s" to the local command file "%s"', $commandString, $this->path);
     try {
         $file = new File($this->path, $this->openMode);
         $file->fwrite($commandString . "\n");
     } catch (Exception $e) {
         $message = $e->getMessage();
         if ($e instanceof RuntimeException && ($pos = strrpos($message, ':')) !== false) {
             // Assume RuntimeException thrown by SplFileObject in the format: __METHOD__ . "({$filename}): Message"
             $message = substr($message, $pos + 1);
         }
         throw new CommandTransportException('Can\'t send external Icinga command to the local command file "%s": %s', $this->path, $message);
     }
 }
Example #2
0
 /**
  * @expectedException \Icinga\Exception\NotWritableError
  */
 public function testWhetherWritingToNonWritableFilesThrowsAnException()
 {
     $file = new File('/dev/null');
     $file->fwrite('test');
 }
Example #3
0
 /**
  * Write a message to the log
  *
  * @param string $message
  */
 protected function write($message)
 {
     $file = new File($this->file, 'a');
     $file->fwrite($message);
     $file->fflush();
 }
 /**
  * Recursively scan the given directory for translatable source files
  *
  * @param   string      $directory      The directory where to search for sources
  * @param   File        $file           The file where to write the results
  * @param   array       $blacklist      A list of directories to omit
  *
  * @throws  Exception                   In case the given directory is not readable
  */
 private function getSourceFileNames($directory, File $file)
 {
     $directoryHandle = opendir($directory);
     if (!$directoryHandle) {
         throw new IcingaException('Unable to read files from %s', $directory);
     }
     $subdirs = array();
     while (($filename = readdir($directoryHandle)) !== false) {
         $filepath = $directory . DIRECTORY_SEPARATOR . $filename;
         if (preg_match('@^[^\\.].+\\.(' . implode('|', $this->sourceExtensions) . ')$@', $filename)) {
             $file->fwrite($filepath . PHP_EOL);
         } elseif (is_dir($filepath) && !preg_match('@^(\\.|\\.\\.)$@', $filename)) {
             $subdirs[] = $filepath;
         }
     }
     closedir($directoryHandle);
     foreach ($subdirs as $subdir) {
         $this->getSourceFileNames($subdir, $file);
     }
 }