public function __construct(array $config) { if (!extension_loaded('memcached')) { throw Error::require_extension('memcached'); } $memcached = new \Memcached(); if (isset($config['servers'])) { $memcached->addServers($config['servers']); } else { list($host, $port) = \Lysine\array_get($config, 'server') ?: $this->default_server; $memcached->addServer($host, $port); } if (isset($config['life_time'])) { $this->life_time = $config['life_time']; } if (isset($config['prefix'])) { $this->setPrefix($config['prefix']); } if (isset($config['options'])) { foreach ($config['options'] as $key => $val) { $memcache->setOption($key, $val); } } $this->memcached = $memcached; }
public function __construct(array $config) { if (!extension_loaded('eaccelerator')) { throw Error::require_extension('eaccelerator'); } parent::__construct($config); }
/** * 订阅类的事件 * * @param string $class * @param string $event * @param callback $callback * @access public * @return void */ public function subscribe($class, $event, $callback) { if (!is_callable($callback)) { throw Error::not_callable('Events::subscribe() parameter 3'); } $class = strtolower(ltrim($class, '\\')); $this->subscribe[$class][$event][] = $callback; }
public function __construct($url = null) { if (!extension_loaded('curl')) { throw Error::require_extension('curl'); } if ($url) { $this->url = $url; } }
/** * 自定义类的autoloader * 会覆盖默认的autoloader * * @param callable $loader * @param boolean $throw * @param boolean $prepend * @access public * @return Lysine\MVC\Application */ public function setAutoloader($loader, $throw = true, $prepend = false) { if (!is_callable($loader)) { throw Error::not_callable('Application loader'); } spl_autoload_unregister(array($this, 'loadClass')); spl_autoload_register($loader, $throw, $prepend); return $this; }
<?php namespace Lysine\Storage\DB; use Lysine\Error; use Lysine\Storage; use Lysine\Storage\DB\Expr; use Lysine\Storage\DB\Select; if (!extension_loaded('pdo')) { throw Error::require_extension('pdo'); } /** * 数据库连接类接口 * 实现了此接口就可以在Lysine内涉及数据库操作的类里通用 * * @package DB * @author yangyi <*****@*****.**> */ interface IAdapter extends \Lysine\IStorage { /** * 连接数据库 * * @access public * @return 数据库连接对象 */ public function connect(); /** * 断开数据库 * * @access public
<?php namespace Lysine\Storage; use Lysine\Error; use Lysine\IStorage; use MongoCollection; if (!extension_loaded('mongo')) { throw Error::require_extension('mongo'); } /** * mongodb数据库连接 * * @package Storage * @uses Mongo * @uses Lysine\IStorage * @author yangyi <*****@*****.**> */ class Mongo extends \Mongo implements IStorage { /** * 构造函数 * * @param array $config * @access public * @return void */ public function __construct(array $config) { list($dsn, $options) = self::parseConfig($config); parent::__construct($dsn, $options);
<?php namespace Lysine\Storage\DB\Adapter; use Lysine\Error; use Lysine\Storage\DB; use Lysine\Storage\DB\Adapter; use Lysine\Storage\DB\Expr; if (!extension_loaded('pdo_mysql')) { throw Error::require_extension('pdo_mysql'); } class Mysql extends Adapter { /** * 开始事务 * * @access public * @return void */ public function begin() { $this->exec('SET AUTOCOMMIT = 0'); $this->exec('START TRANSACTION'); $this->in_transaction = true; } /** * 回滚事务 * * @access public * @return void */
<?php namespace Lysine\Utils\DOM; use Lysine\Error; if (!extension_loaded('dom')) { throw Error::require_extension('dom'); } class Document extends \DOMDocument { /** * xpath查询handle * * @var DOMXPath * @access private */ private $xpath_handle; /** * 构造函数 * * @param string $version * @param string $encoding */ public function __construct($version = '1.0', $encoding = 'utf-8') { parent::__construct($version, $encoding); // 把\Lysine\Utils\DOM\Element类注册为默认的Node class $this->registerNodeClass('DOMElement', '\\Lysine\\Utils\\DOM\\Element'); } /** * xpath查询
/** * 获得真正的视图文件名 * * @param string $file * @access protected * @return string */ protected function findFile($file) { $ext = $this->file_ext ?: 'php'; if (!is_file($file)) { // 不是绝对路径 $file = $this->view_dir . '/' . $file; } $pathinfo = pathinfo($file); if (!isset($pathinfo['extension']) || $pathinfo['extension'] != $ext) { $file .= '.' . $ext; } if (!($fullname = realpath($file))) { throw Error::file_not_found($file); } return $fullname; }