Пример #1
0
 /**
  * You cannot create an instance of Schema class
  * directly
  *
  * @param $model
  */
 private function __construct($model)
 {
     $this->_pointer = $model;
     if (class_exists(get_class($this->_pointer))) {
         $reflectionClass = new \ReflectionClass(get_class($this->_pointer));
         /*
         | We will set the database connection name here
         */
         if (property_exists($this->_pointer, 'database')) {
             $reflectionProperty = $reflectionClass->getProperty('database');
             $reflectionProperty->setAccessible(true);
             $this->database = $reflectionProperty->getValue($this->_pointer);
         } else {
             $this->database = Connection::getDefaultConnection();
         }
         /*
         | We will set the primary key of the table schema
         */
         if (property_exists($this->_pointer, 'primaryKey')) {
             $reflectionPropertyKey = $reflectionClass->getProperty('primaryKey');
             $reflectionPropertyKey->setAccessible(true);
             $this->primaryKey = $reflectionPropertyKey->getValue($this->_pointer);
         }
         /*
         | Set database connection name
         */
         $this->setConn($this->database);
         if (!property_exists($this->_pointer, 'tableName')) {
             $this->tableName = Inflector::tabilize(get_class($this->_pointer));
         }
     }
     // $this->config = Connection::getConfiguration();
 }
Пример #2
0
 private function setModelAttributes($model)
 {
     $this->setModelClass(Inflector::getClassNameFromNamespace($model));
     if (!property_exists($model, 'tableName') || is_null($this->tableName)) {
         $this->setTableName(Inflector::tabilize($this->getModelClass()));
     }
     if (!property_exists($model, 'database') || is_null($this->database)) {
         $this->setDatabase(Connection::getDefaultConnection());
     } else {
         $this->setDatabase($this->database);
     }
     if (is_null($this->getDatabase())) {
         throw new \InvalidArgumentException("Please specify database name in your model. " . get_called_class());
     }
     $this->setPrimarykey();
 }
Пример #3
0
 /**
  * @param $input
  * @return mixed
  */
 private function getDatabase($input)
 {
     return $input->getArgument('database') != '' ? $input->getArgument('database') : Connection::getDefaultConnection();
 }
Пример #4
0
 public function getDefaultDatabaseConnection()
 {
     return Connection::getDefaultConnection();
 }