config() public static method

Configures the model for use. This method will set the Model::$_schema, Model::$_meta, Model::$_finders class attributes, as well as obtain a handle to the configured persistent storage connection.
public static config ( array $config = [] )
$config array Possible options are: - `meta`: Meta-information for this model, such as the connection. - `finders`: Custom finders for this model. - `query`: Default query parameters. - `schema`: A `Schema` instance for this model. - `classes`: Classes used by this model.
Ejemplo n.º 1
0
 public function testClassInitialization()
 {
     $expected = MockPost::instances();
     MockPost::config();
     $this->assertEqual($expected, MockPost::instances());
     Model::config();
     $this->assertEqual($expected, MockPost::instances());
     $this->assertEqual('mock_posts', MockPost::meta('source'));
     MockPost::config(array('meta' => array('source' => 'post')));
     $this->assertEqual('post', MockPost::meta('source'));
     MockPost::config(array('meta' => array('source' => false)));
     $this->assertIdentical(false, MockPost::meta('source'));
     MockPost::config(array('meta' => array('source' => null)));
     $this->assertIdentical('mock_posts', MockPost::meta('source'));
     MockPost::config();
     $this->assertEqual('mock_posts', MockPost::meta('source'));
     $this->assertTrue(MockPost::meta('connection'));
     MockPost::config(array('meta' => array('source' => 'toreset')));
     MockPost::reset();
     $this->assertEqual('mock_posts', MockPost::meta('source'));
     $this->assertFalse(MockPost::meta('connection'));
     MockPost::config(array('query' => array('with' => array('MockComment'), 'limit' => 10)));
     $expected = array('with' => array('MockComment'), 'limit' => 10, 'conditions' => null, 'fields' => null, 'order' => null, 'page' => null);
     $this->assertEqual($expected, MockPost::query());
     $finder = array('fields' => array('title', 'body'));
     MockPost::finder('myFinder', $finder);
     $result = MockPost::find('myFinder');
     $expected = $finder + array('order' => null, 'limit' => 10, 'conditions' => null, 'page' => null, 'with' => array('MockComment'), 'type' => 'read', 'model' => 'lithium\\tests\\mocks\\data\\MockPost');
     $this->assertEqual($expected, $result['options']);
     $finder = array('fields' => array('id', 'title'));
     MockPost::reset();
     $result = MockPost::finder('myFinder');
     $this->assertNull($result);
 }
Ejemplo n.º 2
0
 public function testClassInitialization()
 {
     $expected = MockPost::instances();
     MockPost::config();
     $this->assertEqual($expected, MockPost::instances());
     Model::config();
     $this->assertEqual($expected, MockPost::instances());
     $this->assertEqual('mock_posts', MockPost::meta('source'));
     MockPost::config(array('source' => 'post'));
     $this->assertEqual('post', MockPost::meta('source'));
     MockPost::config(array('source' => false));
     $this->assertIdentical(false, MockPost::meta('source'));
     MockPost::config(array('source' => null));
     $this->assertIdentical('mock_posts', MockPost::meta('source'));
     MockPost::config();
     $this->assertEqual('mock_posts', MockPost::meta('source'));
     $this->assertEqual('mock-source', MockPost::meta('connection'));
 }
Ejemplo n.º 3
0
 /**
  * Configures this model and the `Service` class.
  *
  * @see lithium\data\Model::config()
  * @param array $config
  * @return void
  */
 public static function config(array $config = array())
 {
     $defaults = array('meta' => array('service' => array('host' => 'en.gravatar.com')));
     $config = array_merge_recursive($defaults, $config);
     parent::config($config);
 }