/** * @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()); }
/** * 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(); }
/** * @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); } }
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')); } }
/** * Creates a new WURFL Configuration object from $configFilePath * * @param string $configFilePath Complete filename of configuration file * * @throws \InvalidArgumentException */ public function __construct($configFilePath) { if (!file_exists($configFilePath)) { throw new \InvalidArgumentException('The configuration file ' . $configFilePath . ' does not exist.'); } $this->configFilePath = $configFilePath; $this->configurationFileDir = dirname($this->configFilePath); $configLoader = new ConfigLoader($this->configFilePath); $this->initialize($configLoader->all()); }
/** * @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()); }
/** * @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; }
/** * 继承原来的load方法,实现级联系统的配置文件自动加载 * * @param array|string $path 缓存文件路径,同时也是缓存的key * @param bool $reload * @return static */ public static function load($path, $reload = false) { if (!is_array($path)) { $path = [$path]; } $cacheKey = md5(json_encode($path)); // 如果有缓存并且可以不重新加载,那么就直接返回 if (!$reload && isset(self::$_pathCache[$cacheKey])) { return self::$_pathCache[$cacheKey]; } $finalPath = []; foreach ($path as $_path) { foreach (self::$_configPaths as $includePath) { // 检测和包含带下面后缀的文件 $files = [$includePath . $_path . '.php', $includePath . $_path . '-local.php']; foreach ($files as $file) { if (strpos($file, '*') === false) { if (is_file($file)) { $finalPath[] = $file; } } else { $finalPath[] = $file; } } } } return self::$_pathCache[$cacheKey] = parent::load($finalPath); }
/** * 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)); } }
public function __construct($configFile) { try { $this->config = Config::load($configFile); } catch (Exception $e) { throw new FeatureTogglerException($e->getMessage()); } }
public function __construct() { $conf = Config::load(CONFPATH . 'redis.php'); $redis = new Redis($conf['host'], $conf['port']); $this->redis = $redis; $this->redis->auth('rensheng'); $this->redis->select($conf['db']); }
public function __construct($config = 'mqtt.php', $host = '127.0.0.1', $port = '1883') { $conf = Config::load(CONFPATH . $config); $host = $conf['host'] ? $conf['host'] : $host; $port = $conf['port'] ? $conf['port'] : $port; $this->mq = new \Mosquitto\client(); $this->mq->connect($host, $port, 5); }
/** {@inheritdoc} */ public function __construct($paths = []) { if (empty($paths)) { $this->data = $this->getDefaults(); } else { !is_array($paths) || !is_string(key($paths)) ? parent::__construct($paths) : ($this->data = array_replace_recursive($this->getDefaults(), $paths)); } }
/** * Just hardcoded path to config. */ public function __construct() { $io = new IO(); if (file_exists($io->configurationPath)) { parent::__construct($io->configurationPath); } else { parent::__construct($io->configurationReferencePath); } }
public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN') { $this->app_dir = realpath(__DIR__ . '/../'); try { $this->app_conf = Config::load([$this->app_dir . '/config/general.ini', $this->app_dir . '/config/record_types.ini', $this->app_dir . '/config/excluded_record_types.ini']); } catch (\Exception $e) { print "\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\nPlease check your configuration files. You must create a valid\n'general.ini' (you can use the supplied 'general.ini.template')\nfile with your Netsuite credentials in order to run this tool.\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"; exit(1); } parent::__construct($name, $version); }
public function __construct() { if (defined('PHPUNIT_BETASYNTAX_TESTSUITE') == true) { $basepath = __DIR__ . '/../../tests/config/'; } else { $basepath = (string) app()->getBasePath() . '/config/'; } $this->conf['app'] = Conf::load($basepath . 'app.php'); $this->conf['db'] = Conf::load($basepath . 'db.php'); $this->conf['email'] = Conf::load($basepath . 'email.php'); $this->conf['mounts'] = Conf::load($basepath . 'mounts.php'); }
/** * @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)); }
public function setUp() { $conf = Config::load(CONFPATH . 'socket.php'); $this->socket = new Socket($conf['host'], $conf['port'], $conf['type'], $conf['long']); if (!$this->socket->connect()) { $error = 'socket connect error'; my_log('/data/log/cronJob/doJob.log', $error); exit; } my_log('/data/log/cronJob/doJob.log', '123'); $this->redis = new RedisModel(); $this->redis->selectDB(0); }
/** * 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; } } }
public function run() { if (isset($_SESSION[$this->app->config->get('auth.session')])) { $this->app->auth = $this->app->user->where('id', $_SESSION[$this->app->config->get('auth.session')])->first(); } //create language cookie if (!isset($_COOKIE[$this->app->config->get('lang.language')])) { $this->app->setcookie($this->app->config->get('lang.language'), 'en-us', Carbon::parse('+1 week')->timestamp); $language = Config::load(INC_ROOT . "/app/lang/en-us.php"); } else { $lang = $this->app->getCookie($this->app->config->get('lang.language')); $language = Config::load(INC_ROOT . "/app/lang/{$lang}.php"); } $this->app->lang = $language->get('lang'); $this->checkRememberMe(); $this->app->view()->appendData(['auth' => $this->app->auth, 'baseUrl' => $this->app->config->get('app.url'), 'lang' => $this->app->lang]); }
/** * Create a Manager instance using config * * @param $path * @return static * @throws \Exception */ public static function factory($path) { $pools = array(); try { if (file_exists($path)) { $config = Config::load($path); foreach ($config->get('workers', array()) as $worker) { $count = array_key_exists('count', $worker) ? $worker['count'] : null; $options = array_key_exists('options', $worker) ? $worker['options'] : array(); $pool = new Pool($count); $pool->add(new Worker(new Process(new Command($worker['path'], $options)))); $pools[] = $pool; } } } catch (\Exception $e) { throw $e; } $instance = new static($pools); return $instance; }
use alexander\Helpers\Hash; use alexander\Validation\Validator; use alexander\Middleware\BeforeMiddleware; use alexander\Middleware\CsrfMiddleware; use alexander\Mail\Mailer; session_cache_limiter(false); session_start(); // only for tutorial ini_set('display_errors', 'On'); define('INC_ROOT', dirname(__DIR__)); require INC_ROOT . '/vendor/autoload.php'; $app = new Slim(['mode' => file_get_contents(INC_ROOT . '/mode.php'), 'view' => new Twig(), 'templates.path' => INC_ROOT . '/app/views']); $app->add(new BeforeMiddleware()); $app->add(new CsrfMiddleware()); $app->configureMode($app->config('mode'), function () use($app) { $app->config = Config::load(INC_ROOT . "/app/config/" . substr($app->mode, 0, strlen($app->mode) - 1) . ".php"); }); require 'database.php'; require 'filters.php'; require 'routes.php'; $app->auth = false; // $user = new \alexander\user\user; $app->container->set('user', function () { return new User(); }); $app->container->singleton('hash', function () use($app) { return new Hash($app->config); }); $app->container->singleton('validation', function () use($app) { return new Validator($app->user, $app->hash, $app->auth); });
public function config() { if (!$this->config) { $this->config = \Noodlehaus\Config::load($this->app_path . DIRECTORY_SEPARATOR . 'modvert.yml'); } return $this->config; }
<?php /** * app/bootstrap.php * * @author Zangue <*****@*****.**> */ use Slim\Slim; use Noodlehaus\Config; //session_cache_limiter(false); //session_start(); ini_set('display_errors', 'On'); // Require all PHP dependencies using the composer autoloader require ROOT . DS . 'vendor' . DS . 'autoload.php'; require ROOT . DS . CORE_DIR . DS . 'Router.php'; require ROOT . DS . CORE_DIR . DS . 'Model' . DS . 'Model.php'; require ROOT . DS . CORE_DIR . DS . 'Model' . DS . 'ErrorModel.php'; require ROOT . DS . CORE_DIR . DS . 'Controller' . DS . 'Controller.php'; require ROOT . DS . CORE_DIR . DS . 'Controller' . DS . 'ErrorController.php'; require ROOT . DS . CORE_DIR . DS . 'View' . DS . 'View.php'; require APP_DIR . DS . 'Controller' . DS . 'AppController.php'; require APP_DIR . DS . 'Model' . DS . 'AppModel.php'; // Instantiate a new Slim Application $app = new Slim(['mode' => 'development', 'templates.path' => VIEW_ROOT]); // Some more things can be done here. Eg, add a custom middleware // $app->add(new MyMiddleware()); // Load configuration $app->configureMode($app->config('mode'), function () use($app) { $app->config = Config::load(APP_DIR . DS . "Config" . DS . "{$app->mode}.php"); });
<?php // All file paths relative to root chdir(dirname(__DIR__)); require 'vendor/autoload.php'; session_start(); //simulate customer login $_SESSION['customer_id'] = 1; use Noodlehaus\Config; $conf = Config::load('app/boot/settings.yaml'); $settings = $conf->get('settings', []); // Instantiate Slim $app = new \Slim\App(['settings' => $settings]); //require 'app/model/AuthService.php'; require 'app/model/PlacesService.php'; require 'app/boot/dependencies.php'; require 'app/boot/middleware.php'; // Register the routes require 'app/src/routes.php'; $app->run();
require '../vendor/autoload.php'; require 'core/Middleware.php'; use Noodlehaus\Config; use Helge\Framework\Session; use Helge\Framework\Authentication; use Symfony\Component\Translation\Translator; use Symfony\Component\Translation\MessageSelector; use Symfony\Bridge\Twig\Extension\TranslationExtension; // Start session Session::start(); Session::cacheLimiter("nocache"); // Instantiate and setup Slim application instance $app = new \Slim\Slim(array('view' => new \Slim\Views\Twig(), 'templates.path' => '../app/views', 'cookies.encrypt' => true, 'cookies.secret_key' => "pCAyyIHcGmZ9kT1yzsA8YuhNt64oNPvSOBHHUhQYuamRjYKFrQujaLMjTlhS", 'cookies.cipher' => MCRYPT_RIJNDAEL_256, 'cookies.cipher_mode' => MCRYPT_MODE_CBC, 'log.enabled' => true, 'log.level' => \Slim\Log::WARN, 'log.writer' => new \Slim\Logger\DateTimeFileWriter(array('path' => "../log/")))); // Load the ini config file $app->container->set("config", Config::load('../app/config.ini')); // Set the default timezone from config date_default_timezone_set($app->config->get("localization.timezone")); // If debugging is enabled we show all errors if ($app->config->get("development.debugging")) { error_reporting(E_ALL); ini_set("display_errors", "on"); } else { ini_set("display_errors", "off"); } // Create a translator instance $app->container->set("translator", new Translator($app->config->get("localization.language"), new MessageSelector())); $app->translator->setFallbackLocales(['nb_NO']); $app->translator->addLoader('php', new \Symfony\Component\Translation\Loader\PhpFileLoader()); // Include require all route files in the routes directory $languages = glob("../app/lang/*.php");
/** * @return Config * @throws \Exception */ public static function getConfig() { return Config::load(static::$configs); }
use Codecourse\User\User; use Codecourse\Mail\Mailer; use Codecourse\Helpers\Hash; use Codecourse\Validation\Validator; use Codecourse\Middleware\BeforeMiddleware; use Codecourse\Middleware\CsrfMiddleware; session_cache_limiter(false); session_start(); ini_set('display_errors', 'On'); define('INC_ROOT', dirname(__DIR__)); require INC_ROOT . '../vendor/autoload.php'; $app = new Slim(['mode' => file_get_contents(INC_ROOT . '/mode.php'), 'view' => new Twig(), 'templates.path' => INC_ROOT . '/app/views']); $app->add(new BeforeMiddleware()); $app->add(new CsrfMiddleware()); $app->configureMode($app->config('mode'), function () use($app) { $app->config = Config::load(INC_ROOT . "/app/config/development.php"); }); require 'database.php'; require 'filters.php'; require 'routes.php'; $app->auth = false; // the user is initially unauthenticated $app->container->set('user', function () { return new User(); }); $app->container->singleton('hash', function () use($app) { return new Hash($app->config); }); $app->container->singleton('validation', function () use($app) { return new Validator($app->user, $app->hash, $app->auth); });
use Slim\Views\Twig; use Slim\Views\TwigExtension; use Noodlehaus\Config; use Myproject\User\User; use Myproject\Helpers\Hash; use Myproject\Validation\Validator; use Myproject\Middleware\BeforeMiddleware; session_cache_limiter(false); session_start(); ini_set('display_errors', 'On'); define(INC_ROOT, dirname(__DIR__)); require INC_ROOT . '/vendor/autoload.php'; $app = new Slim(['mode' => file_get_contents(INC_ROOT . '/mode.php'), 'view' => new Twig(), 'templates.path' => INC_ROOT . '/app/views']); $app->add(new BeforeMiddleware()); $app->configureMode($app->config('mode'), function () use($app) { $app->config = Config::load(INC_ROOT . "/app/config/{$app->mode}.php"); }); require 'database.php'; require 'routes.php'; $app->auth = false; $app->container->set('user', function () { return new User(); }); $app->container->singleton('hash', function () use($app) { return new Hash($app->config); }); $app->container->singleton('validation', function () use($app) { return new Validator($app->user); }); $view = $app->view; $view->parserOptions = ['debug' => $app->config->get('twig.debug')];
/** * @param EntityManager $entityManager * @param Config $config */ public function __construct(EntityManager $entityManager, Config $config) { $this->entityManager = $entityManager; $this->jwtConfig = $config->get('authentication.jwt'); }