コード例 #1
0
 /**
  * @param string $rfcCode
  */
 public function notify($rfcCode)
 {
     $oldRfcPath = sprintf('%s/%s.html', $this->config->get('storagePath'), $rfcCode);
     try {
         // Build current RFC
         $currentRfc = $this->rfcService->getRfc($rfcCode);
     } catch (\InvalidArgumentException $e) {
         throw new \RuntimeException('Invalid RFC code, check rfc:list for valid codes');
     }
     if (!file_exists($oldRfcPath)) {
         file_put_contents($oldRfcPath, $currentRfc->getRawContent());
         $oldRfc = new \MikeyMike\RfcDigestor\Entity\Rfc();
     } else {
         try {
             // Get oldRfc
             $oldRfc = $this->rfcService->getRfcFromStorage($rfcCode);
         } catch (\InvalidArgumentException $e) {
             throw new \RuntimeException($e->getMessage());
         }
     }
     // Get diffs
     $diffs = $this->diffService->rfcDiff($currentRfc, $oldRfc);
     // Only send email if we have diffs
     if (count(array_filter($diffs)) === 0) {
         return;
     }
     foreach ($this->notifiers as $notifier) {
         $notifier->notify($currentRfc, $diffs);
     }
     file_put_contents($oldRfcPath, $currentRfc->getRawContent());
 }
コード例 #2
0
 /**
  * @param Rfc $rfc
  * @param array $voteDiff
  */
 public function notify(Rfc $rfc, array $voteDiff)
 {
     foreach ($this->emailSubscriberRepository->findAll() as $subscriber) {
         $email = $this->twig->render('rfc.twig', ['rfcName' => $rfc->getName(), 'details' => $voteDiff['details'], 'changeLog' => $voteDiff['changeLog'], 'voteDiffs' => $voteDiff['votes'], 'rfcVotes' => $rfc->getVotes(), 'unsubscribeUrl' => sprintf('%s/unsubscribe/%s', $this->config->get('app.url'), $subscriber->getUnsubscribeToken())]);
         $message = $this->mailer->createMessage()->setSubject(sprintf('%s updated!', $rfc->getName()))->setFrom('*****@*****.**')->setTo($subscriber->getEmail())->setBody($email, 'text/html');
         $this->mailer->send($message);
     }
 }
コード例 #3
0
ファイル: App.php プロジェクト: pmill/doctrine-rest-api
 /**
  * @param $autoloader
  * @param $configDirectory
  */
 public function __construct($autoloader, $configDirectory)
 {
     AnnotationRegistry::registerLoader([$autoloader, 'loadClass']);
     $this->config = new Config($configDirectory);
     $this->doctrine = new Doctrine($this->config->get('database'));
     $this->container = $this->setupContainer();
     $this->router = new Router($this->doctrine, $this->config->get('router'));
     $this->dispatcher = new Dispatcher($this->container);
     $this->response = new Response($this->doctrine->getAnnotationReader());
 }
コード例 #4
0
 /**
  * @return bool
  */
 public function isMaster()
 {
     if (false === $this->balancing) {
         return true;
     }
     $nodes = $this->config->get('worker_manager.monitoring.nodes');
     $masterName = null;
     foreach ($nodes as $node) {
         if ($node['name'] === $this->name || $this->actionFile->pingNode($node)) {
             $masterName = $node['name'];
             break;
         }
     }
     return $masterName === $this->name;
 }
コード例 #5
0
ファイル: Migration.php プロジェクト: cjp2600/bim-core
 /**
  * init bim applications
  * @throws \Exception
  */
 public static function init()
 {
     $conf = new Config(__DIR__ . "/config/commands.json");
     $console = new Console($conf->get("commands"));
     # run commands
     $console->run();
 }
コード例 #6
0
 public function registerSubmitScript()
 {
     if (\get_post_type(\get_the_id()) === 'landing-page') {
         $thankYou = new Config(__DIR__ . '/config/lang.json');
         wp_enqueue_script('landing-page', \plugin_dir_url(__FILE__) . 'landing-page.js', array('jquery', 'functions'), '', true);
         wp_localize_script('landing-page', 'thankYou', $thankYou->get((new LandingPage(\get_the_id()))->getLanguage() . '.thankyou'));
     }
 }
コード例 #7
0
ファイル: Application.php プロジェクト: Frenkz/streamlines
 /**
  * Register all of the configured providers.
  *
  * @return void
  */
 public function registerConfiguredProviders()
 {
     $providers = $this->config->get('app.providers');
     foreach ($providers as $service => $provider) {
         $config = [];
         $this->register(new $provider($config));
     }
 }
コード例 #8
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     if (posix_isatty(STDOUT)) {
         $output->writeln('<info>щ(ºДºщ) This command is pointless when not run on a cron</info>');
     }
     $currRfcList = $this->rfcService->getLists();
     $storageFile = sprintf('%s/rfcList.json', $this->config->get('storagePath'));
     if (!file_exists($storageFile)) {
         file_put_contents($storageFile, json_encode($currRfcList));
         return;
     }
     $prevRfcList = json_decode(file_get_contents($storageFile), true);
     $diffs = $this->diffService->listDiff($currRfcList, $prevRfcList);
     if (empty($diffs)) {
         file_put_contents($storageFile, json_encode($currRfcList));
         return;
     }
     $email = $this->twig->render('list.twig', ['changes' => $diffs]);
     $message = $this->mailer->createMessage()->setSubject('Some RFCs have moved!')->setFrom('*****@*****.**')->setTo($input->getArgument('email'))->setBody($email, 'text/html');
     $this->mailer->send($message);
     file_put_contents($storageFile, json_encode($currRfcList));
 }
コード例 #9
0
ファイル: Email.php プロジェクト: rwx-zwx-awx/SlimAppSkeleton
 /**
  * Sends an email via SMTP
  * @param string $to_email the email to send this message to
  * @param string $subject subject of the email
  * @param string $message the body of the email
  * @return bool if the message was sent or not
  */
 public function send($to_email, $subject, $message)
 {
     $from_name = $this->config->get("email.from_name");
     $from_email = $this->config->get("email.from_email");
     $mail_method = $this->config->get("email.method");
     if ($mail_method == "mail") {
         $headers = "From: {$from_name} <{$from_email}>\r\n";
         $headers .= "Reply-To: {$from_name} <{$from_email}>\r\n";
         $headers .= 'X-Mailer: PHP/' . phpversion();
         return mail($to_email, $subject, $message, $headers);
     } else {
         if ($mailMethod = "smtp") {
             try {
                 // Bool Flags
                 $this->mailer->isHTML($this->config->get("email.html"));
                 $this->mailer->isSMTP();
                 // SMTP Settings
                 $this->mailer->SMTPAuth = true;
                 $this->mailer->SMTPSecure = $this->config->get("email.secure");
                 // Authentication
                 $this->mailer->Host = $this->config->get("email.host");
                 $this->mailer->Username = $this->config->get("email.user");
                 $this->mailer->Password = $this->config->get("email.pass");
                 // Set Sender and Receiver
                 $this->mailer->setFrom($from_email, $from_name);
                 $this->mailer->addReplyTo($from_email, $from_name);
                 $this->mailer->addAddress($to_email);
                 // Subject and Body
                 $this->mailer->Subject = $subject;
                 $this->mailer->Body = $message;
                 // Return whether or not the message was sent
                 return $this->mailer->send();
             } catch (\phpmailerException $e) {
                 // Something failed, Let's puke out the error message
                 die($e->errorMessage());
             }
         } else {
             // Mail is disabled, let's just pretend we sent the mail
             // so we don't have to deal with scenario checking all over the place
             return true;
         }
     }
 }
コード例 #10
0
 /**
  * @param EntityManager $entityManager
  * @param Config $config
  */
 public function __construct(EntityManager $entityManager, Config $config)
 {
     $this->entityManager = $entityManager;
     $this->jwtConfig = $config->get('authentication.jwt');
 }
コード例 #11
0
 /**
  * Get a config value for a key
  * 
  * @param string $key 
  * @param null $default
  * @return array|mixed|null
  */
 public function get($key, $default = null)
 {
     return $this->config->get($key, $default);
 }
コード例 #12
0
 public function convertIcon($icon)
 {
     $icons = new Config(__DIR__ . '/config/icons.json');
     return '&#' . hexdec('f' . $icons->get($icon)) . ';';
 }
コード例 #13
0
ファイル: RemoteDriver.php プロジェクト: JasperGrimm/modvert2
 private function get($path)
 {
     $res = $this->client->get($this->config->get('stages.' . $this->stage)['remote_url'] . '?q=' . $path);
     return $res->json();
 }
コード例 #14
0
ファイル: app.php プロジェクト: shakyShane/php-rfc-digestor
use Openbuildings\Swiftmailer\CssInlinerPlugin;
$app = new Silex\Application();
$app['debug'] = true;
$app['config'] = function ($app) {
    // Get config files
    // Likely not platform agnostic
    $configs = [sprintf('%s/../config.json', realpath(__DIR__))];
    // Unix or Windows home path
    $homePath = strtolower(substr(PHP_OS, 0, 3)) === 'win' ? getenv('USERPROFILE') : getenv('HOME');
    $userConfigFile = sprintf('%s/.rfcdigestor.json', $homePath);
    if (file_exists($userConfigFile)) {
        $configs[] = $userConfigFile;
    }
    $config = new Config($configs);
    // Load configs and get storage path
    $storagePath = realpath(sprintf('%s/%s', __DIR__, $config->get('storagePath')));
    $templatePath = realpath(sprintf('%s/%s', __DIR__, $config->get('templatePath')));
    // Set config paths for future commands
    $config->set('storagePath', $storagePath);
    $config->set('templatePath', $templatePath);
    return $config;
};
$app->register(new Silex\Provider\TranslationServiceProvider(), array('translator.messages' => array()));
$app->register(new Silex\Provider\SessionServiceProvider());
$app->register(new FormServiceProvider());
$app->register(new Silex\Provider\ValidatorServiceProvider());
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => $app['config']->get('templatePath')));
$app['subscribe-form'] = $app['form.factory']->createBuilder('form')->add('email', 'text', ['attr' => ['placeholder' => 'Your email'], 'constraints' => [new Assert\Email(), new Assert\Callback(function ($email, ExecutionContextInterface $context) use($app) {
    $repo = $app['orm.em']->getRepository('MikeyMike\\RfcDigestor\\Entity\\Subscriber');
    if ($repo->findBy(['email' => $email])) {
        $context->addViolation("Email already used");