本文整理汇总了PHP中lithium\core\Libraries类的典型用法代码示例。如果您正苦于以下问题:PHP Libraries类的具体用法?PHP Libraries怎么用?PHP Libraries使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Libraries类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: template
/**
* 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.");
}
开发者ID:fedeisas,项目名称:lithium,代码行数:38,代码来源:Compiler.php
示例2: _tempFileWithContents
protected function _tempFileWithContents($contents)
{
$path = Libraries::get(true, 'resources') . '/tmp/' . uniqid() . '.php';
$this->_files[] = $path;
file_put_contents($path, $contents);
return $path;
}
开发者ID:raisinbread,项目名称:li3_qa,代码行数:7,代码来源:DocumentedTest.php
示例3: add
/**
* Add a tests to the group
*
* @param string $test
* @param string $options
* @return array
*/
public function add($test = null, $options = array())
{
$callback = function ($test) {
if (empty($test)) {
return array();
}
if (is_object($test) && $test instanceof \lithium\test\Unit) {
return array(get_class($test));
}
if (is_string($test)) {
if ($test[0] != '\\') {
$test = "lithium\\tests\\cases\\{$test}";
}
if (preg_match("/Test/", $test)) {
return array($test);
}
$parts = array_filter(explode("\\", $test));
$library = array_shift($parts);
$test = Libraries::find($library, array('recursive' => true, 'path' => '/' . join('/', $parts), 'filter' => '/cases|intergration|functional/'));
return (array) $test;
}
return (array) $test;
};
if (is_array($test)) {
foreach ($test as $t) {
$this->_items = array_filter(array_merge($this->_items, $callback($t)));
}
return $this->_items;
}
return $this->_items = array_merge($this->_items, $callback($test));
}
开发者ID:kdambekalns,项目名称:framework-benchs,代码行数:38,代码来源:Group.php
示例4: get
/**
* Read the configuration or access the connections you have set up.
*
* Usage:
* {{{
* // Gets the names of all available configurations
* $configurations = Connections::get();
*
* // Gets the configuration array for the connection named 'db'
* $config = Connections::get('db', array('config' => true));
*
* // Gets the instance of the connection object, configured with the settings defined for
* // this object in Connections::add()
* $dbConnection = Connections::get('db');
*
* // Gets the connection object, but only if it has already been built.
* // Otherwise returns null.
* $dbConnection = Connections::get('db', array('autoCreate' => false));
* }}}
*
* @param string $name The name of the connection to get, as defined in the first parameter of
* `add()`, when the connection was initially created.
* @param array $options Options to use when returning the connection:
* - `'autoCreate'`: If `false`, the connection object is only returned if it has
* already been instantiated by a previous call.
* - `'config'`: If `true`, returns an array representing the connection's internal
* configuration, instead of the connection itself.
* @return mixed A configured instance of the connection, or an array of the configuration used.
*/
public static function get($name = null, array $options = array())
{
static $mockAdapter;
$defaults = array('config' => false, 'autoCreate' => true);
$options += $defaults;
if ($name === false) {
if (!$mockAdapter) {
$class = Libraries::locate('data.source', 'Mock');
$mockAdapter = new $class();
}
return $mockAdapter;
}
if (!$name) {
return array_keys(static::$_configurations);
}
if (!isset(static::$_configurations[$name])) {
return null;
}
if ($options['config']) {
return static::_config($name);
}
$settings = static::$_configurations[$name];
if (!isset($settings[0]['object'])) {
if (!$options['autoCreate']) {
return null;
}
}
return static::adapter($name);
}
开发者ID:djordje,项目名称:li3_filemanager,代码行数:58,代码来源:Locations.php
示例5: testCustomConfiguration
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);
}
开发者ID:niel,项目名称:lithium,代码行数:31,代码来源:PhpTest.php
示例6: find
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;
}
开发者ID:bruensicke,项目名称:radium,代码行数:28,代码来源:Widgets.php
示例7: testConfig
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));
}
开发者ID:tmaiaroto,项目名称:li3_facebook,代码行数:35,代码来源:FacebookProxyTest.php
示例8: setUp
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();
}
开发者ID:nilamdoc,项目名称:KYCGlobal,代码行数:7,代码来源:ResourcesValidatorTest.php
示例9: config
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;
}
开发者ID:brandonwestcott,项目名称:li3_varnish,代码行数:25,代码来源:Varnish.php
示例10: file
/**
* 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;
}
开发者ID:raisinbread,项目名称:li3_less,代码行数:37,代码来源:Less.php
示例11: _init
/**
* Perform initialization.
*
* @return void
*/
protected function _init()
{
Object::_init();
$type = isset($this->_config['type']) ? $this->_config['type'] : null;
if ($type === 'text') {
$h = function ($data) {
return $data;
};
} else {
$encoding = 'UTF-8';
if ($this->_message) {
$encoding =& $this->_message->charset;
}
$h = function ($data) use(&$encoding) {
return htmlspecialchars((string) $data, ENT_QUOTES, $encoding);
};
}
$this->outputFilters += compact('h') + $this->_config['outputFilters'];
foreach (array('loader', 'renderer') as $key) {
if (is_object($this->_config[$key])) {
$this->{'_' . $key} = $this->_config[$key];
continue;
}
$class = $this->_config[$key];
$config = array('view' => $this) + $this->_config;
$path = 'adapter.template.mail';
$instance = Libraries::instance($path, $class, $config);
$this->{'_' . $key} = $instance;
}
}
开发者ID:atelierdisko,项目名称:li3_mailer,代码行数:35,代码来源:Mail.php
示例12: tearDown
public function tearDown()
{
$_SERVER = $this->_backup['_SERVER'];
chdir($this->_backup['cwd']);
Libraries::add('app', $this->_backup['app']);
$this->_cleanUp();
}
开发者ID:kdambekalns,项目名称:framework-benchs,代码行数:7,代码来源:CreateTest.php
示例13: __construct
/**
* 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);
}
开发者ID:unionofrad,项目名称:lithium,代码行数:15,代码来源:Cookie.php
示例14: __construct
/**
* 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);
}
开发者ID:fedeisas,项目名称:lithium,代码行数:26,代码来源:File.php
示例15: tearDown
public function tearDown()
{
$_SERVER = $this->_backup['_SERVER'];
chdir($this->_backup['cwd']);
Libraries::remove('library_test');
unset($this->library, $this->request);
}
开发者ID:Nys,项目名称:lithium,代码行数:7,代码来源:LibraryTest.php
示例16: flush
/**
*
*/
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!');
}
开发者ID:unionofrad,项目名称:li3_twig,代码行数:28,代码来源:Twig.php
示例17: testDeliverLogToDir
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);
}
开发者ID:globus40000,项目名称:li3_mailer,代码行数:26,代码来源:DebugTest.php
示例18: setUp
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'));
}
开发者ID:newmight2015,项目名称:Blockchain-2,代码行数:7,代码来源:GettextTest.php
示例19: _init
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;
}
开发者ID:JacopKane,项目名称:li3_pecl_oauth,代码行数:7,代码来源:ClientController.php
示例20: view
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');
}
开发者ID:unionofrad,项目名称:li3_bot,代码行数:25,代码来源:LogsController.php
注:本文中的lithium\core\Libraries类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论