Ejemplo n.º 1
0
 /**
  * Gets a class name from the namespace by trimming out the namespace from the classname.
  *
  * @param $className
  * @param $namespace
  *
  * @return mixed
  *
  * @since 1.1.0
  *
  * @author Eddilbert Macharia (http://eddmash.com) <*****@*****.**>
  */
 public static function getNameFromNs($className, $namespace)
 {
     $className = static::getFormatNamespace($className, true, true);
     $namespace = static::getFormatNamespace($namespace, true, true);
     if (StringHelper::startsWith($className, $namespace)) {
         $className = substr($className, strlen($namespace));
     }
     return trim($className, '\\');
 }
Ejemplo n.º 2
0
 public function deconstruct()
 {
     $path = '';
     $alias = '';
     if (StringHelper::startsWith($this->getFullClassName(), 'Eddmash\\PowerOrm\\Migration\\Operation\\Model')) {
         $alias = 'modelOperation';
         $path = sprintf('Eddmash\\PowerOrm\\Migration\\Operation\\Model as %s', $alias);
     }
     if (StringHelper::startsWith($this->getFullClassName(), 'Eddmash\\PowerOrm\\Migration\\Operation\\Field')) {
         $alias = 'fieldOperation';
         $path = sprintf('Eddmash\\PowerOrm\\Migration\\Operation\\Field as %s', $alias);
     }
     return ['name' => sprintf('%1$s\\%2$s', $alias, $this->getShortClassName()), 'path' => $path, 'fullName' => $this->getFullClassName(), 'constructorArgs' => $this->getConstructorArgs()];
 }
Ejemplo n.º 3
0
 public static function run($config)
 {
     $baseDir = $config['baseDir'];
     if (strtolower(basename($baseDir)) === 'powerorm') {
         define('ENVIRONMENT', 'POWERORM_DEV');
     }
     // bootstrap the orm.
     require_once 'bootstrap.php';
     // load doctrine DBAL
     self::loadThirdParty();
     if (!StringHelper::startsWith(ENVIRONMENT, 'POWERORM_') && is_cli()) {
         new CI_Controller();
     }
 }
Ejemplo n.º 4
0
 /**
  * Returns the migration(s) which match the given prefix.
  *
  * @param $prefix
  *
  * @return mixed
  *
  * @throws AmbiguityError
  * @throws KeyError
  *
  * @since 1.1.0
  *
  * @author Eddilbert Macharia (http://eddmash.com) <*****@*****.**>
  */
 public function getMigrationByPrefix($prefix)
 {
     $migrations = [];
     foreach ($this->getMigrations() as $name => $migration) {
         $shortName = ClassHelper::getNameFromNs($name, BaseOrm::getMigrationsNamespace());
         if (StringHelper::startsWith($name, $prefix) || StringHelper::startsWith($shortName, $prefix)) {
             $migrations[] = $name;
         }
     }
     if (count($migrations) > 1) {
         throw new AmbiguityError(sprintf("There is more than one migration with the prefix '%s'", $prefix));
     } elseif (count($migrations) == 0) {
         throw new KeyError(sprintf("There no migrations with the prefix '%s'", $prefix));
     }
     return $migrations[0];
 }