Creates a new migration instance.
@param string $class the migration class name
@return \yii\db\Migration the migration instance
323023
protected function createMigration($class)
    {
        $query = new Query;
        $migrate = $query->select(['migrationPath'])
                ->from($this->migrationTable)
                ->where(['version' => $class])
                ->one();
        $filename = DIRECTORY_SEPARATOR . $class . '.php';
        if ($migrate && file_exists($migrate['migrationPath'] . $filename)) {
            $this->migrationPath = $migrate['migrationPath'];
        }

        $file = $this->migrationPath . $filename;
        require_once($file);

        return new $class(['db' => $this->db]);
    }
504728
private function _addMigrationRecord( $class )
    {
        $name = $this->db->prepareString( $class );
        $tm   = new \DateTime();
        $tm   = $tm->getTimestamp();
        
        // update migrations table with the new applied migration
        $query = "INSERT INTO $this->migrationTable 
                 ( migration_name, migration_date_applied ) VALUES ( ";
        
        $query .= "'$name', ";
        $query .= "$tm";
        
        $query .= " )";
        
        $this->db->lockTables( $this->migrationTable );
        
        $id = $this->db->insert( $query );
        
        if ( $this->verbose )
        {
            echo 'Migrating: ' . $class . PHP_EOL;
        }
        
        $this->db->unlockTables();
        
        return FALSE !== $id;
    }
194663
public function createCache($class, $args)
    {
        /** @var CacheInterface $cache */
        $reflection = new ReflectionClass($class);
        $cache = $reflection->newInstanceArgs($args);

        // Assign cache logger
        if ($this->logger && $cache instanceof LoggerAwareInterface) {
            $cache->setLogger($this->logger);
        }

        return $cache;
    }
1153892
public function createInstance(string $class)
    {
        $refClass = new \ReflectionClass($class);
        $args = [];
        if ($refClass->getConstructor()) {
            foreach ($refClass->getConstructor()->getParameters() as $parameter) {
                $name = Inflector::tableize(str_replace('_', '.', $parameter->getName()));
                $dependency = null;
                if ($parameter->getClass()) {
                    if ($this->container->has($parameter->getClass()->getName())) {
                        $dependency = $this->container->get($parameter->getClass()->getName());
                    } elseif ($this->container->has($name)) {
                        $dependency = $this->container->get($name);
                    }
                } elseif ($this->container->hasParameter($name)) {
                    $dependency = $this->container->getParameter($name);
                }
                $args[] = $dependency;
            }
        }

        return $refClass->newInstanceArgs($args);
    }
571168
private function newInstance($class)
    {
        $entity = $class->newInstance();

        if ($entity instanceof \Doctrine\Common\Persistence\ObjectManagerAware) {
            $entity->injectObjectManager($this->em, $class);
        }

        return $entity;
    }
497103
private function getModel($class)
    {
        $reflectionClass = new \ReflectionClass($class);
        $instance = $reflectionClass->newInstance();
        if (!($instance instanceof ModelInterface)) {
            throw new \Exception('This class is not supported');
        }

        return $instance;
    }
1169253
public static function newInstance($class, ...$args)
    {
        if(!isset(static::$classNameMap[$class]))
        {
            $ref = new \ReflectionClass($class);
            $className = static::getNewClassName($ref->getShortName());
            $tpl = static::getTpl($ref, $className);
            eval($tpl);
            static::$classNameMap[$class] = $className;
        }
        return new static::$classNameMap[$class](...$args);
    }
314246
private function createInstance(string $class, array $data)
    {
        $rule = $this->rules[$class];

        $reflectionClass = new \ReflectionClass($class);
        $object = $reflectionClass->newInstanceWithoutConstructor();
        $reflectionObject = new \ReflectionObject($object);

        foreach ($rule->getMap() as $property => $key) {
            $reflectionProperty = $reflectionObject->getProperty($property);
            $reflectionProperty->setAccessible(true);

            $constructor = $rule->getConstructor($property);

            $reflectionProperty->setValue($object, is_callable($constructor) ? $constructor($data[$key]) : $data[$key]);
        }

        return $object;
    }
468200
public static function newObject(string $class, array $args = [], $callGetClass = false)
    {
        $class = $callGetClass ? static::getClass($class) : $class;
        $rc = new \ReflectionClass($class);
        return $rc->newInstanceArgs($args);
    }
808004
protected function createContext(string $class): MappingContext
    {
        $definition = $this->definitionProvider->getDefinition($class);

        return new MappingContext($this, $definition);
    }
400505
public function newInstance($class = null, $options = [])
    {
        if ($class === null) {
            $class = get_class($this);
        } elseif ($class instanceof self) {
            $class = get_class($class);
        }

        if (is_string($class) && $class[0] != '\\') {
            $class = '\\'.$class;
        }

        if ($this->persistence) {
            return $this->persistence->add($class, $options);
        }

        return new $class($options);
    }
614790
private function createMigration(string $class, ContainerInterface $container): ?MigrationInterface
    {
        $migration = null;

        try {
            /** @var MigrationInterface $migration */
            $migration = new $class($container);
        } catch (Error $exception) {
            $this->getIO()->writeWarning("Migration `$class` not found." . PHP_EOL);
        }

        return $migration;
    }
1120635
protected static function createObject($class, ...$args)
    {
        if (!is_subclass_of($class, Record::class)) {
            throw new \InvalidArgumentException(sprintf('Class: %s is not sub class of ' . Record::class, $class));
        }

        // TODO: Make Record support set DB after construct.
        try {
            return new $class(...$args);
        } catch (\Exception $e) {
            if ($e instanceof \InvalidArgumentException || $e->getPrevious() instanceof \PDOException) {
                return new NullRecord();
            }

            throw $e;
        }
    }
113412
public function createInstance(string $class)
    {
        $reflection = new \ReflectionClass($class);

        // If the constructor has no parameters, there is no need to resolve them
        $constructor = $reflection->getConstructor();
        if (is_null($constructor)) {
            $this->instances[$class] = new $class;

            return new $class;
        }

        // Resolve the dependencies recursively
        $dependencies = $constructor->getParameters();
        $instances = $this->resolveDependencies($dependencies);

        $o = $reflection->newInstanceArgs($instances);
        $this->instances[$class] = $o;

        return $o;
    }
1180499
public function whenCreating($class)
    {
        if (!isset($this->args[$class])) {
            $this->args[$class] = new ClassMeta($class, $this);
        }

        return $this->args[$class];
    }
1246700
public static function createClass(
            $class,
            $data
            )
    {
        if (!class_exists($class)) {
            return null;
        }
        $ref = new \ReflectionClass($class);
        if ($ref->isAbstract()) {
            return null;
        }
        $store =  new $class($data);

        return $store;
    }
106398
public static function fromClass(string $class): self
    {
        /** @var \Colibri\Migration\Migration|string $class */
        $migration             = new self($class);
        $migration->hash       = $class::hash();
        $migration->name       = $class::name();
        $migration->createdAt  = $class::createdAt();
        $migration->migratedAt = $class::migratedAt();

        return $migration;
    }