コード例 #1
0
    public static function __init() {
    /**
	 * The following code will append a library Page model's $_schema and
	 * $validates properites to this Page model. $_schema can never be changed,
	 * only extended. $validates can be changed and extended, but if default
	 * field rules are left out, they will be used from this parent model.
	*/
	$class =  __CLASS__;
	
        /*
        $extended_schema = static::_object()->_schema;
        
	// Loop through and ensure no one forgot to set the form key		
	foreach($extended_schema as $k => $v) {
		$extended_schema[$k] += array('form' => array('position' => 'default'));
	}
	// Append extended schema
	$class::_object()->_schema += $extended_schema;
        */
        
	// Use the library Page model's validation rules combined with the default (but the library gets priority) this way the default rules can be changed, but if left out will still be used (to help make things nicer)
	$class::_object()->validates = static::_object()->validates += $class::_object()->validates;
	// Same for the search schema, the library gets priority, but combine them.
	$class::_object()->search_schema = static::_object()->search_schema += $class::_object()->search_schema;
	
	// Replace any set display name for context
	$class::_object()->display_name = static::_object()->display_name;
	
	// Lock the schema so values that aren't part of it can't be saved to the db.
	self::meta('locked', true);
        
        parent::__init();
    }
コード例 #2
0
 public static function __init()
 {
     static::_isBase(__CLASS__, true);
     parent::__init();
     self::_addRelations();
     self::_connectionFilters();
 }
コード例 #3
0
 public static function __init(array $options = array())
 {
     parent::__init($options);
     $self = static::_instance();
     $self->_finders['count'] = function ($self, $params, $chain) use(&$query, &$classes) {
         $db = Connections::get($self::meta('connection'));
         $records = $db->read('SELECT count(*) as count FROM posts', array('return' => 'array'));
         return $records[0]['count'];
     };
     Post::applyFilter('save', function ($self, $params, $chain) {
         $post = $params['record'];
         if (!$post->id) {
             $post->created = date('Y-m-d H:i:s');
         } else {
             $post->modified = date('Y-m-d H:i:s');
         }
         $params['record'] = $post;
         return $chain->next($self, $params, $chain);
     });
     Validator::add('isUniqueTitle', function ($value, $format, $options) {
         $conditions = array('title' => $value);
         // If editing the post, skip the current psot
         if (isset($options['values']['id'])) {
             $conditions[] = 'id != ' . $options['values']['id'];
         }
         // Lookup for posts with same title
         return !Post::find('first', array('conditions' => $conditions));
     });
 }
コード例 #4
0
ファイル: Deploy.php プロジェクト: nervetattoo/li3_apps
 /**
  * Override _init to ensure MongoDb indexes
  */
 public static function __init()
 {
     parent::__init();
     $collection = static::connection()->connection->{static::meta('source')};
     $collection->ensureIndex(array('index' => 1));
     $collection->ensureIndex(array('app' => 1));
 }
コード例 #5
0
ファイル: Message.php プロジェクト: nervetattoo/li3_backbone
 /**
  * Override _init to ensure MongoDb indexes
  */
 public static function __init()
 {
     parent::__init();
     $collection = static::connection()->connection->{static::meta('source')};
     $collection->ensureIndex(array('created' => -1, 'username' => 1));
     $collection->ensureIndex(array('tags' => 1));
 }
コード例 #6
0
ファイル: App.php プロジェクト: nervetattoo/li3_apps
 /**
  * Override _init to ensure MongoDb indexes
  */
 public static function __init()
 {
     parent::__init();
     $collection = static::connection()->connection->{static::meta('source')};
     $collection->ensureIndex(array('path' => 1), array('unique' => true));
     $collection->ensureIndex(array('repo' => 1), array('unique' => true));
     $collection->ensureIndex(array('title' => 1));
 }
コード例 #7
0
ファイル: Model.php プロジェクト: nateabele/li3_behaviors
	public static function __init() {
		static::_isBase(__CLASS__, true);
		parent::__init();
		$class = get_called_class();

		if (!static::_isBase($class) && $behaviors = static::_object()->_actsAs) {
			Behaviors::apply($class, $behaviors);
		}
	}
コード例 #8
0
ファイル: Base.php プロジェクト: notomato/li3_activitystreams
 public static function __init()
 {
     parent::__init();
     static::applyFilter('create', function ($self, $params, $chain) {
         if (empty($params['data']['id'])) {
             $params['data']['id'] = String::uuid();
         }
         return $chain->next($self, $params, $chain);
     });
 }
コード例 #9
0
ファイル: TestModel.php プロジェクト: alkemann/AL13
 public static function __init($options = array())
 {
     $self = static::_instance();
     if (!isset($self->_meta['source'])) {
         $model = get_class($self);
         $tmp = explode('\\', $model);
         $modelName = end($tmp);
         $self->_meta['source'] = \lithium\util\Inflector::tableize($modelName);
     }
     parent::__init($options);
 }
コード例 #10
0
 public static function __init()
 {
     parent::__init();
     $class = __CLASS__;
     Validator::add('modelIsSet', function ($value, $format, $options) use($class) {
         if (isset($options['model']) && ($options['model'] = $class)) {
             return true;
         }
         return false;
     });
 }
コード例 #11
0
ファイル: File.php プロジェクト: nervetattoo/li3_start
 /**
  * Override _init to ensure MongoDb indexes
  */
 public static function __init()
 {
     parent::__init();
     static::finder('slug', function ($self, $params, $chain) {
         $params['options']['conditions'] = array('slug' => $params['options']['conditions']['_id']);
         $data = $chain->next($self, $params, $chain);
         $data = is_object($data) ? $data->rewind() : $data;
         return $data ?: null;
     });
     $collection = static::connection()->connection->{static::meta('source')};
     $collection->ensureIndex(array('title' => 1));
 }
コード例 #12
0
ファイル: Post.php プロジェクト: rudiedirkx/MyLithium
 public static function __init(array $options = array())
 {
     parent::__init($options);
     $self = static::_object();
     #		$self = static::_instance(__CLASS__);
     #var_dump($self);
     $self->_finders['count'] = function ($self, $params, $chain) use(&$query, &$classes) {
         $db = Connections::get($self::meta('connection'));
         $records = $db->read('SELECT count(*) as count FROM posts', array('return' => 'array'));
         return $records[0]['count'];
     };
 }
コード例 #13
0
ファイル: BaseModel.php プロジェクト: tmaiaroto/li3b_core
 public static function __init()
 {
     $class = __CLASS__;
     // Note: If any of the following properties are not set in any extended model,
     // they will be picked up from this base model.
     $class::_object()->search_schema = static::_object()->search_schema += $class::_object()->search_schema;
     $class::_object()->url_field = static::_object()->url_field;
     $class::_object()->url_separator = static::_object()->url_separator;
     // Future compatibility.
     if (method_exists('\\lithium\\data\\Model', '__init')) {
         parent::__init();
     }
 }
コード例 #14
0
 public function testClassInitialization()
 {
     $expected = MockPost::instances();
     MockPost::__init();
     $this->assertEqual($expected, MockPost::instances());
     Model::__init();
     $this->assertEqual($expected, MockPost::instances());
     $this->assertEqual('mock_posts', \lithium\tests\mocks\data\MockPost::meta('source'));
     MockPost::__init(array('source' => 'post'));
     $this->assertEqual('post', MockPost::meta('source'));
     MockPost::__init(array('source' => false));
     $this->assertIdentical(false, MockPost::meta('source'));
     MockPost::__init(array('source' => null));
     $this->assertIdentical('mock_posts', MockPost::meta('source'));
 }
コード例 #15
0
 public static function __init(array $options = array())
 {
     parent::__init($options);
     $self = static::_instance();
     Comment::applyFilter('save', function ($self, $params, $chain) {
         $comment = $params['record'];
         if (!$comment->id) {
             $comment->created = date('Y-m-d h:i:s');
         } else {
             $comment->modified = date('Y-m-d h:i:s');
         }
         $params['record'] = $comment;
         return $chain->next($self, $params, $chain);
     });
     Validator::add('validName', '/^[A-Za-z0-9\'\\s]+$/');
 }
コード例 #16
0
ファイル: Model.php プロジェクト: rich97/li3_tree
	/**
	 * init
	 * 
	 * init Tree Callback Methods
	 */
	public static function __init() {
		parent::__init();
		
		$class = get_called_class();
		static::$_tree_config[$class] = array_merge(static::$_tree_defaults, static::$_tree_config);
		
		static::applyFilter('save', function($self,$params,$chain){
        	if($self::beforeSave($self,$params)){
	        	$chain->next($self,$params,$chain);
        	}
        });
        
        static::applyFilter('delete', function($self,$params,$chain){
        	if($self::beforeDelete($self,$params)){
	        	$chain->next($self,$params,$chain);
        	}
        });
	}
コード例 #17
0
ファイル: MockBase.php プロジェクト: rmarscher/lithium
 public static function __init()
 {
     static::_isBase(__CLASS__, true);
     parent::__init();
 }
コード例 #18
0
ファイル: Asset.php プロジェクト: nateabele/Minerva-Plugin
 public static function __init() {
     self::$fields += static::$fields;
     self::$validate += static::$validate;
     
     parent::__init();
 }