Newscoop\Services\FilesystemService::isReadable PHP Метод

isReadable() публичный статический Метод

Check if file is isReadable
public static isReadable ( string $fileName, boolean $message = true ) : boolean
$fileName string
$message boolean Show message
Результат boolean
    public static function isReadable($fileName, $message = true)
    {
        if (!is_readable($fileName)) {
            if ($message) {
                echo "\nThis script requires access to the file {$p_fileName}.\n";
                echo "Please run this script as a user with appropriate privileges.\n";
                echo "Most often this user is 'root'.\n\n";
            }
            return false;
        }
        return true;
    }

Usage Example

 /**
  * @see Console\Command\Command
  */
 protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
 {
     $this->em = $this->getApplication()->getKernel()->getContainer()->get('doctrine')->getManager();
     $etcDirectory = APPLICATION_PATH . '/../conf/';
     $notifierTemplate = '_events_notifier.tpl';
     $message = array();
     if (!FilesystemService::isReadable($etcDirectory . '/install_conf.php')) {
         exit;
     }
     // includes installation configuration file
     require_once $etcDirectory . '/install_conf.php';
     // includes campsite initialisation
     require_once APPLICATION_PATH . '/../include/campsite_init.php';
     if (!is_file($etcDirectory . '/database_conf.php')) {
         $output->writeln('Database configuration file is missing!');
         return;
     }
     $message['reply'] = $this->getReplyAddress();
     $autoId = $this->getAutoId();
     $logTimestamp = $autoId->getLogTimestamp();
     $logs = $this->em->getRepository('Newscoop\\Entity\\Log')->createQueryBuilder('l')->select('l, e, u')->leftJoin('l.eventId', 'e')->leftJoin('l.userId', 'u')->where('l.eventId = e.id')->andWhere('l.userId = u.id')->andWhere('e.notify = :notify')->andWhere('l.created > :logTimestamp')->getQuery()->setParameters(array('logTimestamp' => $logTimestamp, 'notify' => 'Y'))->getResult();
     if (count($logs) == 0) {
         return false;
     }
     $tpl = $this->initSmarty();
     $recipients = $this->getApplication()->getKernel()->getContainer()->getService('notification')->findRecipients();
     $lastTimestamp = null;
     if ($input->getOption('verbose')) {
         $output->writeln('<info>Number of found logs: ' . count($logs) . '.<info>');
     }
     foreach ($logs as $log) {
         $lastTimestamp = $log->getCreated();
         $tpl->assign('user_real_name', $log->getUser()->getFirstName());
         $tpl->assign('user_name', $log->getUser()->getUsername());
         $tpl->assign('user_email', $log->getUser()->getEmail());
         $tpl->assign('event_text', $log->getMessage());
         $tpl->assign('event_timestamp', $log->getCreated()->format('Y-m-d h:i:s'));
         $message['text'] = $tpl->fetch($notifierTemplate);
         if (count($recipients) <= 0) {
             if ($input->getOption('verbose')) {
                 $output->writeln('<error>There is no recipients.<error>');
             }
             continue;
         }
         $message['recipients'] = $recipients;
         $message['subject'] = $log->getEvent()->getName();
         $this->sendEmail($message);
         if ($input->getOption('verbose')) {
             $output->writeln('<info>Send message for event: ' . $log->getEvent()->getName() . '.<info>');
         }
     }
     if ($lastTimestamp != null) {
         $autoId->setLogTimestamp($lastTimestamp);
     }
     $this->em->flush();
 }
All Usage Examples Of Newscoop\Services\FilesystemService::isReadable