By name:
embed:lithium\tests\cases\core\LibrariesTest::testLibraryConfigAccess(1-1)
With no parameters, to return all configuration for all libraries:
embed:lithium\tests\cases\core\LibrariesTest::testLibraryConfigAccess(22-22)
By list of names with a key to extract:
embed:lithium\tests\cases\core\LibrariesTest::testLibraryConfigAccess(34-34)
With no name, and a key to extract, to return a key/value array, where the library name is
the key, and the $key value is the value:
embed:lithium\tests\cases\core\LibrariesTest::testLibraryConfigAccess(37-37)
By containing class name:
embed:lithium\tests\cases\core\LibrariesTest::testLibraryConfigAccess(45-45)
public static get ( mixed $name = null, string $key = null ) : mixed | ||
$name | mixed | Either the name of a library added in `Libraries::add()`, an array of library names, or a fully-namespaced class name (see usage examples above). |
$key | string | Optional key name. If `$name` is set and is the name of a valid library (or an array of valid libraries), returns the given named configuration key, i.e. `'path'`, `'webroot'` or `'resources'`. |
Résultat | mixed | A configuation array for one or more libraries, or a string value if `$key` is specified and `$name` is a string, or a library name (string) if `$name` is a fully-namespaced class name. |
/** * Compiles a template and writes it to a cache file, which is used for inclusion. * * @param string $file The full path to the template that will be compiled. * @param array $options Options for compilation include: * - `path`: Path where the compiled template should be written. * - `fallback`: Boolean indicating that if the compilation failed for some * reason (e.g. `path` is not writable), that the compiled template * should still be returned and no exception be thrown. * @return string The compiled template. */ public static function template($file, array $options = array()) { $cachePath = Libraries::get(true, 'resources') . '/tmp/cache/templates'; $defaults = array('path' => $cachePath, 'fallback' => false); $options += $defaults; $stats = stat($file); $oname = basename(dirname($file)) . '_' . basename($file, '.php'); $oname .= '_' . ($stats['ino'] ?: hash('md5', $file)); $template = "template_{$oname}_{$stats['mtime']}_{$stats['size']}.php"; $template = "{$options['path']}/{$template}"; if (file_exists($template)) { return $template; } $compiled = static::compile(file_get_contents($file)); if (is_writable($cachePath) && file_put_contents($template, $compiled) !== false) { foreach (glob("{$options['path']}/template_{$oname}_*.php", GLOB_NOSORT) as $expired) { if ($expired !== $template) { unlink($expired); } } return $template; } if ($options['fallback']) { return $file; } throw new TemplateException("Could not write compiled template `{$template}` to cache."); }
protected function _tempFileWithContents($contents) { $path = Libraries::get(true, 'resources') . '/tmp/' . uniqid() . '.php'; $this->_files[] = $path; file_put_contents($path, $contents); return $path; }
public function testCustomConfiguration() { $config = array( 'session.name' => 'awesome_name', 'session.cookie_lifetime' => 1200, 'session.cookie_domain' => 'awesome.domain', 'session.save_path' => Libraries::get(true, 'resources') . '/tmp/', 'somebad.configuration' => 'whoops' ); $adapter = new Php($config); $result = ini_get('session.name'); $this->assertEqual($config['session.name'], $result); $result = ini_get('session.cookie_lifetime'); $this->assertEqual($config['session.cookie_lifetime'], (integer) $result); $result = ini_get('session.cookie_domain'); $this->assertEqual($config['session.cookie_domain'], $result); $result = ini_get('session.cookie_secure'); $this->assertFalse($result); $result = ini_get('session.cookie_httponly'); $this->assertTrue($result); $result = ini_get('session.save_path'); $this->assertEqual($config['session.save_path'], $result); $result = ini_get('somebad.configuration'); $this->assertFalse($result); }
public function testConfig() { $oldConfig = Libraries::get('li3_facebook'); Libraries::remove('li3_facebook'); Libraries::add('li3_facebook'); FacebookProxy::$_autoConfigure = false; FacebookProxy::__init(); $this->assertEqual(FacebookProxy::config(), array(), 'config should be empty.'); $this->assertEqual(FacebookProxy::config(array()), array(), 'config should be empty.'); //check ignoring FacebookProxy::reset(); $result = FacebookProxy::config(array('foo')); $this->assertTrue($result, array(), 'config should return true'); $this->assertIdentical(FacebookProxy::config(), array(), 'config should be empty'); //check ingoring vs. existing but unset associations FacebookProxy::reset(); $result = FacebookProxy::config(array('appId')); $this->assertTrue($result, array(), 'config should return true'); $this->assertIdentical(FacebookProxy::config(), array(), 'config should be empty'); //check valid Settings FacebookProxy::reset(); $sampleConfig = array('appId' => 'hello'); $result = FacebookProxy::config($sampleConfig); $this->assertTrue($result, 'config should return true'); $this->assertIdentical(FacebookProxy::config(), $sampleConfig, 'config should not be empty'); //check vs. complete Settings FacebookProxy::reset(); $result = FacebookProxy::config($this->_mockDefaults); $this->assertTrue($result, 'config should return true'); $this->assertIdentical(FacebookProxy::config(), $this->_mockDefaults, 'config should not be empty'); Libraries::remove('li3_facebook'); Libraries::add('li3_facebook', $oldConfig); //FaceBookProxy::foo(); //die(print_r(array($result,FacebookProxy::config()),true)); }
public function testDeliverLogToDir() { $path = realpath(Libraries::get(true, 'resources') . '/tmp/tests'); $this->skipIf(!is_writable($path), "Path `{$path}` is not writable."); $log = $path . DIRECTORY_SEPARATOR . 'mails'; if (!is_dir($log)) { mkdir($log); } $glob = $log . DIRECTORY_SEPARATOR . '*.mail'; $oldresults = glob($glob); $options = array('to' => 'foo@bar', 'subject' => 'test subject'); $message = new Message($options); $debug = new Debug(); $format = 'short'; $delivered = $debug->deliver($message, compact('log', 'format')); $this->assertTrue($delivered); $results = array_diff(glob($glob), $oldresults); $this->assertEqual(1, count($results)); $resultFile = current($results); $result = file_get_contents($resultFile); $pattern = '\\[[\\d:\\+\\-T]+\\]'; $info = ' Sent to foo@bar with subject `test subject`.\\n'; $expected = '/^' . $pattern . $info . '$/'; $this->assertPattern($expected, $result); unlink($resultFile); }
/** * Get content of file, parse it with lessc and return formatted css * * @todo allow for css-file name only, and search it in all avail. webroots * @param string $file full path to file * @param array $options Additional options to control flow of method * - header - controls, whether to prepend a header * - cache - controls, whether to cache the result * - cachePath - Where to cache files, defaults to * resources/tmp/cache * @return string|boolean generated css, false in case of error */ public static function file($file, array $options = array()) { $defaults = array('header' => true, 'cache' => true, 'cachePath' => Libraries::get(true, 'resources') . '/tmp/cache', 'cacheKey' => Inflector::slug(str_replace(array(LITHIUM_APP_PATH, '.less'), array('', '.css'), $file))); $options += $defaults; $css_file = $options['cachePath'] . '/' . $options['cacheKey']; if (file_exists($css_file) && filemtime($css_file) >= filemtime($file)) { return file_get_contents($css_file); } if (!file_exists($file)) { return false; } try { $less = static::_getLess($file); $output = $less->parse(); } catch (Exception $e) { $output = "/* less compiler exception: {$e->getMessage()} */"; } if ($options['header']) { $output = static::_prependHeader($output); } if ($options['cache']) { file_put_contents($css_file, $output); } return $output; }
protected function _init() { parent::_init(); $this->_config = (array) Libraries::get('li3_pecl_oauth'); $this->_config += array('host' => $this->request->env('SERVER_NAME'), 'oauth_callback' => $this->request->env('SERVER_NAME') . '/oauth/client', 'namespace' => 'li3_pecl_oauth', 'redirect_success' => 'Client::index', 'redirect_failed' => array('Client::index', 'args' => array('failed' => true))); return Consumer::config($this->_config) ? true : false; }
/** * Constructor. * * Takes care of setting appropriate configurations for this object. * * @param array $config Optional configuration parameters. * @return void */ public function __construct(array $config = array()) { if (empty($config['name'])) { $config['name'] = basename(Libraries::get(true, 'path')) . 'cookie'; } parent::__construct($config + $this->_defaults); }
/** * Constructor. * * @see lithium\util\String::insert() * @param array $config Settings used to configure the adapter. Available options: * - `'path'` _string_: The directory to write log files to. Defaults to * `<app>/resources/tmp/logs`. * - `'timestamp'` _string_: The `date()`-compatible timestamp format. Defaults to * `'Y-m-d H:i:s'`. * - `'file'` _\Closure_: A closure which accepts two parameters: an array * containing the current log message details, and an array containing the `File` * adapter's current configuration. It must then return a file name to write the * log message to. The default will produce a log file name corresponding to the * priority of the log message, i.e. `"debug.log"` or `"alert.log"`. * - `'format'` _string_: A `String::insert()`-compatible string that specifies how * the log message should be formatted. The default format is * `"{:timestamp} {:message}\n"`. * @return void */ public function __construct(array $config = array()) { $defaults = array('path' => Libraries::get(true, 'resources') . '/tmp/logs', 'timestamp' => 'Y-m-d H:i:s', 'file' => function ($data, $config) { return "{$data['priority']}.log"; }, 'format' => "{:timestamp} {:message}\n"); parent::__construct($config + $defaults); }
public static function find(array $options = array()) { $defaults = array('collect' => true); $options += $defaults; $data = array(); $libs = Libraries::get(null, 'path'); $recursive = true; foreach ($libs as $lib => $path) { $result = array(); $path .= '/views/widgets'; $files = StaticContents::available(compact('path', 'recursive')); if (!$files) { continue; } $temp = array_keys(Set::flatten($files, array('separator' => '/'))); foreach ($temp as $key => $value) { if (strpos($value, 'admin.') !== false) { continue; } if (strpos($value, 'inc.') !== false) { continue; } $result[$key] = str_replace('.html.php', '', $value); } $data[$lib] = $result; } return $data; }
public function setUp() { $this->_backup['catalogConfig'] = Catalog::config(); Catalog::reset(); Catalog::config(array('lithium' => array('adapter' => 'Php', 'path' => Libraries::get('lithium', 'path') . '/g11n/resources/php'))); Validator::__init(); }
public function index() { $title = 'Testing Leaderboard'; $options = Libraries::get('li3_leaderboard'); $data = StatsPresenter::find('all', $options); return compact('data', 'title'); }
/** * */ public function flush() { $this->_header(); $success = false; $config = Libraries::get('app'); $dir = TwigAdapter::cachePath(); $trash = $config['resources'] . self::PATH_TO_REMOVE; $this->out('Starting cache flush.'); if (!is_dir($dir)) { return $this->error('Cache folder not found... exiting.'); } $this->out('Cache folder found : ' . $dir); if (is_dir($trash)) { $this->out('Old trash folder found (previous command failure possible), deleting it...'); $this->_rrmdir($trash); } $this->out('Moving cache folder to temporary location...'); rename($dir, $trash); $this->out('Deleting temporary cache location...'); $success = $this->_rrmdir($trash); if (!$success) { return $this->error('Error while deleting Twig template cache.'); } return $this->out('Success!'); }
public function setUp() { $this->_path = $path = Libraries::get(true, 'resources') . '/tmp/tests'; mkdir("{$this->_path}/en/LC_MESSAGES", 0755, true); mkdir("{$this->_path}/de/LC_MESSAGES", 0755, true); $this->adapter = new MockGettext(compact('path')); }
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; }
/** * Class initializer. Parses template and sets up params that need to be filled. * * @return void */ protected function _init() { parent::_init(); $this->library = $this->library ?: true; $defaults = array('prefix' => null, 'path' => null); $this->_library = (array) Libraries::get($this->library) + $defaults; }
public function view() { $date = $this->request->date; $channel = '#' . $this->request->channel; $year = date('Y', strtotime($date)); if (!in_array($channel, LogMessages::channels())) { throw new Exception('Unknown channel.'); } $baseUrl = array('library' => 'li3_bot', 'controller' => 'logs'); $breadcrumbs[] = array('title' => 'Channel Logs', 'url' => $baseUrl + array('action' => 'channels')); $breadcrumbs[] = array('title' => $channel, 'url' => null); $breadcrumbs[] = array('title' => $year, 'url' => array('library' => 'li3_bot', 'controller' => 'logs', 'action' => 'index', 'channel' => ltrim($channel, '#')) + compact('year')); $breadcrumbs[] = array('title' => date('m/d', strtotime($date)), 'url' => null); $messages = LogMessages::day($channel, $date); $previous = date('Y-m-d', strtotime($date) - 60 * 60 * 24); $next = date('Y-m-d', strtotime($date) + 60 * 60 * 24); if (!LogMessages::hasDay($channel, $previous)) { $previous = null; } if (!LogMessages::hasDay($channel, $next)) { $next = null; } $rewriters = Libraries::get('li3_bot', 'rewriters'); return compact('channel', 'messages', 'date', 'breadcrumbs', 'previous', 'next', 'rewriters'); }
/** * Skip the test if the default File adapter read/write path is not read/write-able. * * @return void */ public function skip() { $this->configuration['path'] = Libraries::get(true, 'resources') . '/tmp/tests'; $directory = new SplFileInfo($this->configuration['path']); $accessible = $directory->isDir() && $directory->isReadable() && $directory->isWritable(); $message = 'The File filesystem adapter path does not have the proper permissions.'; $this->skipIf(!$accessible, $message); }
/** * Finds a library for given path. * * @return string|void The library's name on success. */ protected function _library($path) { foreach (Libraries::get() as $name => $library) { if (strpos($path, $library['path']) === 0) { return $name; } } }
public function setUp() { $this->_path = Libraries::get(true, 'resources') . '/tmp/tests'; $template1 = '<' . '?php echo $foo; ?' . '>'; $template2 = '<' . '?php echo $this["foo"]; ?' . '>'; file_put_contents("{$this->_path}/template1.html.php", $template1); file_put_contents("{$this->_path}/template2.html.php", $template2); }
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']; }
public function testError() { $base = Libraries::get(true, 'resources') . '/tmp/tests'; $this->skipIf(!is_writable($base), "Path `{$base}` is not writable."); $response = new Response(array('error' => fopen($this->streams['error'], 'w+'))); $this->assertInternalType('resource', $response->error); $this->assertEqual(2, $response->error('ok')); $this->assertEqual('ok', file_get_contents($this->streams['error'])); }
/** * Set the testPath and check if it is writable (skip if not). */ public function skip() { $path = Libraries::get(true, 'resources'); if (is_writable($path) && !is_dir("{$path}/tmp/tests")) { mkdir("{$path}/tmp/tests", 0777, true); } $this->_testPath = "{$path}/tmp/tests"; $this->skipIf(!is_writable($this->_testPath), "Path `{$this->_testPath}` is not writable."); }
public function testCheckBasicIsFalse() { $http = new MockHttp(array('method' => 'basic', 'users' => array('gwoo' => 'li3'))); $result = $http->check($this->request); $this->assertEmpty($result); $basic = basename(Libraries::get(true, 'path')); $expected = array('WWW-Authenticate: Basic realm="' . $basic . '"'); $result = $http->headers; $this->assertEqual($expected, $result); }
/** * Renders the sitemap response based on the received request and configuration * @param object $request The request object * @throws Exception * @return object Response */ public static function render($request) { $config = Libraries::get('li3_sitemap'); $sitemap = Sitemap::generate($config); $viewOptions = Sitemap::configureView($request, $config); $response = new Response(compact('request')); $view = new View(array('paths' => array('element' => '{:library}/views/elements/{:template}.{:type}.php', 'template' => '{:library}/views/{:controller}/{:template}.{:type}.php', 'layout' => '{:library}/views/layouts/{:layout}.{:type}.php'))); $response->body = $view->render('all', compact('sitemap'), $viewOptions); return $response; }
/** * Create reCAPTCHA challenge field * If you pass `$options` or you have set `'options'` key on library adding * create `RecaptchaOptions` object to configure look and feel of your * challenge field. * * Example: * {{{ * $this->challenge(array('theme' => 'white')); * }}} * * @param array $options `'key' => 'value'` pairs to be converted to javascript * object as `RecaptchaOptions` * @see https://developers.google.com/recaptcha/docs/customization * @return string Rendered reCAPTCHA challenge field template */ public function challenge(array $options = array()) { $config = Libraries::get('li3_recaptcha', 'keys'); $src = $this->_context->request()->scheme . '://www.google.com/recaptcha/api'; $errorpart = ''; if (static::$error) { $errorpart = '&error=' . static::$error; } return $this->_render(__METHOD__, 'challenge', array('config' => $this->_recaptchaOptions($options), 'src' => $src, 'publickey' => $config['public'], 'errorpart' => $errorpart)); }
public function testShouldRunSetsLibraryConfig() { $config = $this->selfConfig; unset($config['shouldRun']); Libraries::add('li3_newrelic', $this->selfConfig); $result = NewrelicMock::shouldRun(); $config = Libraries::get('li3_newrelic'); $this->assertArrayHasKey('shouldRun', $config); $this->assertInternalType('bool', $result); }
function __construct($options = null) { if ($options == null) { $options = Libraries::get('li3_upload_progress')['config']; } $this->options = array('script_url' => '/', 'upload_dir' => Libraries::get(true, 'path') . '/webroot/img/original/', 'upload_url' => '/img/original/', 'img_name' => uniqid('img') . '.jpg', 'param_name' => 'files', 'delete_type' => 'DELETE', 'max_file_size' => null, 'min_file_size' => 1, 'accept_file_types' => '/.+$/i', 'max_number_of_files' => null, 'max_width' => null, 'max_height' => null, 'min_width' => 1, 'min_height' => 1, 'discard_aborted_uploads' => true, 'orient_image' => false, 'image_versions' => array('pequenas' => array('upload_dir' => Libraries::get(true, 'path') . '/webroot/img/projectos/pequenas/', 'upload_url' => '/img/paginas/', 'max_width' => 125, 'max_height' => 75), 'grandes' => array('upload_dir' => Libraries::get(true, 'path') . '/webroot/img/projectos/grandes/', 'upload_url' => '/img/paginas/', 'max_width' => 635, 'max_height' => 381))); if ($options) { $this->options = array_replace_recursive($this->options, $options); } }
protected function _init() { parent::_init(); $this->_library = isset($this->request->library) ? $this->request->library : true; $this->_library = Libraries::get($this->_library); $this->_path = $this->_library['path'] . '/resources/migration'; $this->_migrations = $this->_getMigrations($this->_path); if (isset($this->request->params['connection'])) { $this->_options['connection'] = $this->request->params['connection']; } }
/** * * 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(); }