Ejemplo n.º 1
0
<?php

define('LYSINE_REQUEST_CLASS', '\\Test\\Mock\\Request');
define('LYSINE_RESPONSE_CLASS', '\\Test\\Mock\\Response');
require __DIR__ . '/../vendor/autoload.php';
\Lysine\Service\Manager::getInstance()->importConfig(require __DIR__ . '/Fixture/config/services.php');
Ejemplo n.º 2
0
 /**
  * 获得存储服务连接实例
  *
  * @return IService
  * @throws \RuntimeException Data class没有配置存储服务
  */
 public function getService()
 {
     $service = $this->getOption('service');
     return \Lysine\Service\Manager::getInstance()->get($service);
 }
Ejemplo n.º 3
0
<?php

require __DIR__ . '/../src/loader.php';
\Lysine\Service\Manager::getInstance()->importConfig(array('master' => array('class' => '\\Lysine\\Service\\DB\\Mysql', 'dsn' => 'mysql:host=192.168.1.2;dbname=foo', 'user' => 'dev', 'password' => 'abc'), 'slave' => array('class' => '\\Lysine\\Service\\DB\\Mysql', 'dsn' => 'mysql:host=192.168.1.3;dbname=foo', 'user' => 'dev', 'password' => 'abc'), 'cache' => array('class' => 'Lysine\\Service\\Redis', 'host' => '192.168.1.4', 'database' => 1, 'timeout' => 3, 'persistent_id' => 'cache')));
class Topic extends \Lysine\DataMapper\Data
{
    protected static $mapper = '\\TopicMapper';
    protected static $service = 'slave';
    protected static $collection = 'tipic';
    protected static $attributes = array('topic_id' => array('type' => 'integer', 'primary_key' => true, 'auto_generate' => true), 'subject' => array('type' => 'string'), 'content' => array('type' => 'string'), 'create_time' => array('type' => 'datetime', 'refuse_update' => true, 'default' => 'now'));
    public static function select()
    {
        return static::getMapper()->select();
    }
}
class TopciMapper extends \Lysine\DataMapper\DBMapper
{
    public function __construct($class)
    {
        parent::__construct($class);
        $this->onEvent(static::AFTER_INSERT_EVENT, function ($data) {
            $this->setStatus($data->id(), 'at_master');
        });
        $this->onEvent(static::AFTER_UPDATE_EVENT, function ($data) {
            $this->setStatus($data->id(), 'at_master');
        });
        $this->onEvent(static::AFTER_DELETE_EVENT, function ($data) {
            $this->setStatus($data->id(), 'deleted');
        });
    }
    public function selectMaster()
Ejemplo n.º 4
0
 function service($name, $args = null)
 {
     if ($args !== null) {
         $args = array_slice(func_get_args(), 1);
     }
     return \Lysine\Service\Manager::getInstance()->get($name, $args);
 }