/**
  * Tests tableLocator method
  *
  * @return void
  */
 public function testTableLocator()
 {
     $tableLocator = $this->subject->tableLocator();
     $this->assertSame(TableRegistry::locator(), $tableLocator);
     $newLocator = $this->getMock('Cake\\ORM\\Locator\\LocatorInterface');
     $subjectLocator = $this->subject->tableLocator($newLocator);
     $this->assertSame($newLocator, $subjectLocator);
 }
示例#2
0
 /**
  * Get the factory for the specified repository type.
  *
  * @param string $type The repository type to get the factory for.
  * @throws InvalidArgumentException If the specified repository type has no factory.
  * @return callable The factory for the repository type.
  */
 public static function get($type)
 {
     if (!isset(static::$_modelFactories['Table'])) {
         static::$_modelFactories['Table'] = [TableRegistry::locator(), 'get'];
     }
     if (!isset(static::$_modelFactories[$type])) {
         throw new InvalidArgumentException(sprintf('Unknown repository type "%s". Make sure you register a type before trying to use it.', $type));
     }
     return static::$_modelFactories[$type];
 }
示例#3
0
 /**
  * Sets the table locator.
  * If no parameters are passed, it will return the currently used locator.
  *
  * @param \Cake\ORM\Locator\LocatorInterface|null $tableLocator LocatorInterface instance.
  * @return \Cake\ORM\Locator\LocatorInterface
  */
 public function tableLocator(LocatorInterface $tableLocator = null)
 {
     if ($tableLocator !== null) {
         $this->_tableLocator = $tableLocator;
     }
     if (!$this->_tableLocator) {
         $this->_tableLocator = TableRegistry::locator();
     }
     return $this->_tableLocator;
 }
示例#4
0
 /**
  * Constructor. Looks at Session configuration information and
  * sets up the session model.
  *
  * @param array $config The configuration for this engine. It requires the 'model'
  * key to be present corresponding to the Table to use for managing the sessions.
  */
 public function __construct(array $config = [])
 {
     $tableLocator = isset($config['tableLocator']) ? $config['tableLocator'] : TableRegistry::locator();
     if (empty($config['model'])) {
         $config = $tableLocator->exists('Sessions') ? [] : ['table' => 'sessions'];
         $this->_table = $tableLocator->get('Sessions', $config);
     } else {
         $this->_table = $tableLocator->get($config['model']);
     }
     $this->_timeout = ini_get('session.gc_maxlifetime');
 }
 /**
  * Test that locator() method is returing TableLocator by default.
  *
  * @return void
  */
 public function testLocatorDefault()
 {
     $locator = TableRegistry::locator();
     $this->assertInstanceOf('Cake\\ORM\\Locator\\TableLocator', $locator);
 }