php lithium-core-Environment类(方法)实例源码

下面列出了php lithium-core-Environment 类(方法)源码代码实例,从而了解它的用法。

作者:brandonwestcot    项目:li3_varnis   
public static function config($name = null)
 {
     if (empty(self::$_config)) {
         $config = Libraries::get('li3_varnish');
         $env = Environment::get();
         if (isset($config[$env])) {
             $config += $config[$env];
             unset($config[$env]);
         }
         foreach ($config as $k => $v) {
             if (isset(self::$_defaults[$k]) && is_array(self::$_defaults[$k])) {
                 $config[$k] += self::$_defaults[$k];
             }
         }
         self::$_config = $config + self::$_defaults;
     }
     if (isset($name)) {
         if (isset(self::$_config[$name])) {
             return self::$_config[$name];
         } else {
             return null;
         }
     }
     return self::$_config;
 }

作者:robert-christophe    项目:li3_mandril   
/**
  * Return an instance of the Mandrill class.
  *
  * @return Mandrill Instance.
  */
 public static function getInstance()
 {
     // Detect when the PID of the current process has changed (from a fork, etc)
     // and force a reconnect to redis.
     $pid = getmypid();
     if (self::$pid !== $pid) {
         self::$mandrill = null;
         self::$pid = $pid;
     }
     if (!is_null(self::$mandrill)) {
         return self::$mandrill;
     }
     foreach (array_keys(self::$config) as $param) {
         if (Environment::get('mandrill.' . $param)) {
             self::$config[$param] = Environment::get('mandrill.' . $param);
         }
     }
     if (!self::$config['apikey']) {
         throw new Exception('missing Mandrill Configuration', 500);
     }
     try {
         self::$mandrill = new Mandrill(self::$config['apikey']);
     } catch (Exception $e) {
         return null;
     }
     return self::$mandrill;
 }

作者:nilamdo    项目:KYCGloba   
public function getkycinfo()
 {
     $email = strtolower($this->request->query['email']);
     $kycid = $this->request->query['kycid'];
     if (substr(Environment::get('locale'), 0, 2) == "en") {
         $locale = "en";
     } else {
         $locale = Environment::get('locale');
     }
     if ($email == "" || $kycid == "") {
         return $this->render(array('json' => array('success' => 0)));
     }
     $document = Documents::find('first', array('conditions' => array('email' => $email, 'email_code' => $kycid)));
     $encrypt = $document['hash'];
     //		print_r($function->decrypt($encrypt,CONNECTION_DB_KYC));
     if (count($document) == 1) {
         if ($emails['Verify']['Score'] >= 80) {
             return $this->render(array('json' => array('success' => 0, 'reason' => 'Aleredy KYC complete')));
         } else {
             return $this->render(array('json' => array('success' => 1, 'id' => $encrypt, 'locale' => $locale)));
         }
     } else {
         return $this->render(array('json' => array('success' => 0)));
     }
 }

作者:davidpersso    项目:li3_translat   
protected static function _config($model, Behavior $behavior, array $config, array $defaults)
 {
     $config += $defaults;
     if (!$config['locale']) {
         $config['locale'] = Environment::get('locale');
     }
     if (!$config['locales']) {
         $config['locales'] = array_keys(Environment::get('locales'));
     }
     if (!$config['strategy']) {
         $connection = get_class($model::connection());
         $config['strategy'] = $connection::enabled('arrays') ? 'nested' : 'inline';
     }
     if ($config['strategy'] === 'inline') {
         foreach ($config['fields'] as $field) {
             foreach ($config['locales'] as $locale) {
                 if ($locale === $config['locale']) {
                     continue;
                 }
                 if (!$model::hasField($field = static::_composeField($field, $locale))) {
                     throw new Exception("Model `{$model}` is missing translation field `{$field}`");
                 }
             }
         }
     }
     return $config;
 }

作者:josey    项目:li3_hierarch   
public function __construct($options = array())
 {
     $this->_library = Libraries::get('li3_hierarchy');
     $this->_cacheDir = $this->_library['path'] . '/resources/tmp/cache';
     $defaults['cache'] = Environment::get() == 'production' ? true : false;
     $this->_options = $this->_library + $defaults;
     $this->_cache = $this->_options['cache'];
 }

作者:nervetatto    项目:li3_twi   
/**
  * Constructor for this adapter - sets relevant default configurations for Twig to be used
  * when instantiating a new Twig_Environment and Twig_Loader_Filesystem.
  *
  * @param array $config Optional configuration directives.
  *        Please see http://www.twig-project.org/book/03-Twig-for-Developers for all
  *        available configuration keys and their description.
  *        There are 4 settings that is set
  *        - `cache`: Path to /resources/tmp/cache/templates/ where compiled templates will be stored
  *        - `auto_reload`: If Environment is not production, templates will be reloaded once edited
  *        - `base_template_class`: Overriden to the Template adapter, be carefull with changing this
  *        - `autoescape`: Set to false because the way we inject content is with full html that should not be escaped
  * @return void
  */
 public function __construct(array $config = array())
 {
     /**
      * TODO Change hardcoded LITHIUM_APP_PATH to be dynamic
      */
     $defaults = array('cache' => LITHIUM_APP_PATH . '/resources/tmp/cache/templates', 'auto_reload' => !Environment::is('production'), 'base_template_class' => 'li3_twig\\template\\view\\adapter\\Template', 'autoescape' => false);
     parent::__construct($config + $defaults);
 }

作者:davidpersso    项目:li3_translat   
public function testEnvironmentalDefaults()
 {
     $artist = Artists::create(['ja.name' => 'Richard Japper', 'ja.profile' => 'Dreaded Rasta Nihon', 'en.name' => 'Richard', 'en.profile' => 'Dreaded Rasta', 'something_else' => 'Something']);
     Environment::set('test', ['locales' => ['en' => 'English', 'es' => 'Espanol']]);
     $artist->_actsAs = ['Translatable' => ['default' => 'ja', 'fields' => ['name', 'profile']]];
     $this->assertTrue($artist->save());
     $artist = Artists::first();
 }

作者:unionofra    项目:lithiu   
protected function _init()
 {
     parent::_init();
     Environment::set($this->env);
     if (file_exists($this->_config['routes'])) {
         return require $this->_config['routes'];
     }
     $this->error("The routes file for this library doesn't exist or can't be found.");
 }

作者:nateabel    项目:li3_asseti   
/**
  * Configures this helper
  */
 public static function config($config = array())
 {
     $defaults = array('optimize' => Environment::get() == 'production', 'debug' => Environment::get() == 'development', 'stylesPath' => LITHIUM_APP_PATH . DIRECTORY_SEPARATOR . 'webroot' . DIRECTORY_SEPARATOR . 'css', 'scriptsPath' => LITHIUM_APP_PATH . DIRECTORY_SEPARATOR . 'webroot' . DIRECTORY_SEPARATOR . 'js', 'filters' => array());
     $config += $defaults;
     // Merge config
     static::$config = array_merge(static::$config, $config);
     // Configure filters
     static::registerFilters($config['filters']);
 }

作者:mdx-de    项目:li3_newreli   
/**
  *
  * Determines if we should run any `newrelic_` methods.
  *
  * If the configuration for the plugin `shouldRun` does not exist, set
  * a generic one.
  *
  * @return bool
  */
 public static function shouldRun()
 {
     if (!is_callable(Libraries::get('li3_newrelic', 'shouldRun'))) {
         $config = Libraries::get('li3_newrelic');
         $config['shouldRun'] = function () {
             return Environment::is('production') && extension_loaded('newrelic');
         };
         Libraries::add('li3_newrelic', $config);
     }
     return Libraries::get('li3_newrelic', 'shouldRun')->__invoke();
 }

作者:ncu    项目:sagalay   
/**
  * Auto run the help command.
  *
  * @param string $command Name of the command to return help about.
  * @return void
  */
 public function run($command = null)
 {
     $message = 'Lithium console started in the ' . Environment::get() . ' environment.';
     $message .= ' Use the --env=environment key to alter this.';
     $this->out($message);
     if (!$command) {
         $this->_renderCommands();
         return true;
     }
     if (!preg_match('/\\\\/', $command)) {
         $command = ucwords($command);
     }
     if (!($class = Libraries::locate('command', $command))) {
         $this->error("Command `{$command}` not found");
         return false;
     }
     $command = Inflector::classify($command);
     if (strpos($command, '\\') !== false) {
         $command = join('', array_slice(explode("\\", $command), -1));
     }
     $command = strtolower(Inflector::slug($command));
     $run = null;
     $methods = $this->_methods($class);
     $properties = $this->_properties($class);
     $info = Inspector::info($class);
     $this->out('USAGE', 'heading');
     if (isset($methods['run'])) {
         $run = $methods['run'];
         unset($methods['run']);
         $this->_renderUsage($command, $run, $properties);
     }
     foreach ($methods as $method) {
         $this->_renderUsage($command, $method);
     }
     if (!empty($info['description'])) {
         $this->nl();
         $this->_renderDescription($info);
         $this->nl();
     }
     if ($properties || $methods) {
         $this->out('OPTIONS', 'heading');
     }
     if ($run) {
         $this->_render($run['args']);
     }
     if ($methods) {
         $this->_render($methods);
     }
     if ($properties) {
         $this->_render($properties);
     }
     return true;
 }

作者:marian    项目:li3_doctrine   
/**
  * Create an entity manager
  *
  * @param array $params Parameters
  * @return object Entity manager
  * @filter
  */
 protected function createEntityManager()
 {
     $configuration = Setup::createAnnotationMetadataConfiguration([$this->_config['models']], Environment::is('development'), $this->_config['proxies'], isset($this->_config['cache']) ? call_user_func($this->_config['cache']) : null);
     $configuration->setProxyNamespace($this->_config['proxyNamespace']);
     $eventManager = new EventManager();
     $eventManager->addEventListener([Events::postLoad, Events::prePersist, Events::preUpdate], $this);
     $connection = $this->connectionSettings;
     $params = compact('connection', 'configuration', 'eventManager');
     return $this->_filter(__METHOD__, $params, function ($self, $params) {
         return EntityManager::create($params['connection'], $params['configuration'], $params['eventManager']);
     });
 }

作者:Robert-Christophe    项目:sit   
protected function _verify($request)
 {
     $config = Environment::get('service.recaptcha');
     $url = 'https://www.google.com/recaptcha/api/siteverify';
     $url .= '?secret=' . $config['secretKey'];
     $url .= '&response=' . $this->request->data['token'];
     $ch = curl_init($url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     $result = json_decode(curl_exec($ch), true);
     curl_close($ch);
     return $result['success'] === true;
 }

作者:josey    项目:li3_frontende   
public function _init()
 {
     parent::_init();
     $this->_config = Libraries::get('li3_frontender');
     $defaults = array('compress' => false, 'assets_root' => LITHIUM_APP_PATH . "/webroot", 'production' => Environment::get() == 'production', 'locations' => array('node' => '/usr/bin/node', 'coffee' => '/usr/bin/coffee'));
     $this->_config += $defaults;
     $this->_production = $this->_config['production'];
     // remove extra slash if it was included in the library config
     $this->_config['assets_root'] = substr($this->_config['assets_root'], -1) == "/" ? substr($this->_config['assets_root'], 0, -1) : $this->_config['assets_root'];
     $this->_paths['styles'] = $this->_config['assets_root'] . "/css/";
     $this->_paths['scripts'] = $this->_config['assets_root'] . "/js/";
 }

作者:servicerunne    项目:li3_kissmetric   
public function sendLoggedQueries()
 {
     if ($this->key) {
         KM::$key = $this->key;
     }
     if ($this->logdir) {
         KM::$log_dir = $this->logdir;
     }
     $this->header('Kissmetrics');
     $this->out(" - Using Environment: \t" . Environment::get());
     $this->out(" - Using log_dir: \t" . KM::$log_dir);
     $this->out("\nSending...");
     KM::send_logged_queries();
 }

作者:bruensick    项目:li3_resqu   
protected function setUp()
 {
     if (empty($this->host)) {
         $this->host = Environment::get('resque.host');
     }
     if (empty($this->host)) {
         $this->host = 'localhost';
     }
     if (empty($this->port)) {
         $this->port = Environment::get('resque.port');
     }
     if (empty($this->port)) {
         $this->port = 6379;
     }
     ResqueProxy::setBackend($this->host . ':' . $this->port);
     $this->queues = ResqueProxy::queues();
 }

作者:nashadala    项目:lithiu   
/**
  * Runs a test group or a specific test file based on the passed
  * parameters.
  *
  * @param string $group If set, this test group is run. If not set, a group test may
  *        also be run by passing the 'group' option to the $options parameter.
  * @param array $options Options array for the test run. Valid options are:
  *        - 'case': The fully namespaced test case to be run.
  *        - 'group': The fully namespaced test group to be run.
  *        - 'filters': An array of filters that the test output should be run through.
  * @return array A compact array of the title, an array of the results, as well
  *         as an additional array of the results after the $options['filters']
  *         have been applied.
  * @filter
  */
 public static function run($group = null, array $options = array())
 {
     $defaults = array('title' => $group, 'filters' => array(), 'reporter' => 'text');
     $options += $defaults;
     $isCase = is_string($group) && preg_match('/Test$/', $group);
     $items = $isCase ? array(new $group()) : (array) $group;
     $options['filters'] = Set::normalize($options['filters']);
     $group = static::_group($items);
     $report = static::_report($group, $options);
     return static::_filter(__FUNCTION__, compact('report'), function ($self, $params, $chain) {
         $environment = Environment::get();
         Environment::set('test');
         $params['report']->run();
         Environment::set($environment);
         return $params['report'];
     });
 }

作者:bruensick    项目:li3_resqu   
/**
  *
  * @return void
  */
 public static function __init()
 {
     $libraryConfig = Libraries::get('li3_resque');
     static::config($libraryConfig + static::$_defaults);
     if (Environment::get('resque.host')) {
         static::$_config['host'] = Environment::get('resque.host');
     }
     if (Environment::get('resque.port')) {
         static::$_config['port'] = Environment::get('resque.port');
     }
     if (!empty(static::$_config['host']) || !empty(static::$_config['port'])) {
         try {
             Resque::setBackend(static::$_config['host'] . ':' . static::$_config['port']);
         } catch (Exception $e) {
             throw new ConfigException('Could not connect to Resque server');
         }
     }
 }

作者:servicerunne    项目:li3_debu   
public static function terminate()
 {
     static::initSession();
     static::initAuth();
     static::$_data['end'] = microtime(true);
     static::$_data['environment'] = Environment::get();
     static::$_data['events.count'] = count(static::$_data['events']);
     static::$_data['db.count'] = count(static::$_data['db']);
     static::$_data['runtime'] = static::$_data['end'] - static::$_data['start'];
     static::$_data['memory.end'] = memory_get_usage(true);
     static::$_data['memory.usage'] = memory_get_peak_usage(true);
     static::$_data['log.count'] = count(static::$_data['log']);
     if (!Environment::is('production') && static::$_view) {
         try {
             echo static::$_view->render(array('element' => 'debug_bar'));
         } catch (\lithium\template\TemplateException $e) {
             $view = new View(array('paths' => array('element' => '{:library}/views/elements/{:template}.{:type}.php')));
             echo $view->render(array('element' => 'debug_bar'), array(), array('library' => 'li3_debug'));
         }
     }
 }

作者:ncu    项目:sagalay   
/**
  * Dispatches a request based on a request object (an instance of `lithium\console\Request`).
  *  If `$request` is `null`, a new request object is instantiated based on the value of the
  * `'request'` key in the `$_classes` array.
  *
  * @param object $request An instance of a request object with console request information.  If
  *        `null`, an instance will be created.
  * @param array $options
  * @return object The command action result which is an instance of `lithium\console\Response`.
  * @filter
  */
 public static function run($request = null, $options = array())
 {
     $defaults = array('request' => array());
     $options += $defaults;
     $classes = static::$_classes;
     $params = compact('request', 'options');
     return static::_filter(__FUNCTION__, $params, function ($self, $params) use($classes) {
         $request = $params['request'];
         $options = $params['options'];
         $router = $classes['router'];
         $request = $request ?: new $classes['request']($options['request']);
         $request->params = $router::parse($request);
         $params = $self::applyRules($request->params);
         Environment::set($request);
         try {
             $callable = $self::invokeMethod('_callable', array($request, $params, $options));
             return $self::invokeMethod('_call', array($callable, $request, $params));
         } catch (UnexpectedValueException $e) {
             return (object) array('status' => $e->getMessage() . "\n");
         }
     });
 }


问题


面经


文章

微信
公众号

扫码关注公众号