Compile the migration stub.

@param $nameView
@return string
@throws \Illuminate\Contracts\Filesystem\FileNotFoundException
497453
protected function compileViewStub($nameView)
    {
        $stub = $this->files->get(__DIR__ . '/../stubs/html_assets/'.$nameView.'.stub');

        if($nameView == 'show'){
            // show.blade.php
            $this->replaceName($stub)
                ->replaceSchemaShow($stub);

        } elseif($nameView == 'edit'){
            // edit.blade.php
            $this->replaceName($stub)
                ->replaceSchemaEdit($stub);

        } elseif($nameView == 'create'){
            // edit.blade.php
            $this->replaceName($stub)
                ->replaceSchemaCreate($stub);

        } else {
            // index.blade.php
            $this->replaceName($stub)
                ->replaceSchemaIndex($stub);
        }



        return $stub;
    }
1287884
public function compileTemplateSource()
    {
        if (!$this->source->recompiled) {
            $this->properties['file_dependency'] = array();
            if ($this->source->components) {
                // for the extends resource the compiler will fill it
                // uses real resource for file dependency
                // $source = end($this->source->components);
                // $this->properties['file_dependency'][$this->source->uid] = array($this->source->filepath, $this->source->timestamp, $source->type);
            } else {
                $this->properties['file_dependency'][$this->source->uid] = array($this->source->filepath, $this->source->timestamp, $this->source->type);
            }
        }
        // compile locking
        if ($this->smarty->compile_locking && !$this->source->recompiled) {
            if ($saved_timestamp = $this->compiled->timestamp) {
                touch($this->compiled->filepath);
            }
        }
        // call compiler
        try {
            $code = $this->compiler->compileTemplate($this);
        }
        catch (Exception $e) {
            // restore old timestamp in case of error
            if ($this->smarty->compile_locking && !$this->source->recompiled && $saved_timestamp) {
                touch($this->compiled->filepath, $saved_timestamp);
            }
            throw $e;
        }
        // compiling succeded
        if (!$this->source->recompiled && $this->compiler->write_compiled_code) {
            // write compiled template
            $_filepath = $this->compiled->filepath;
            if ($_filepath === false) {
                throw new SmartyException('getCompiledFilepath() did not return a destination to save the compiled template to');
            }
            Smarty_Internal_Write_File::writeFile($_filepath, $code, $this->smarty);
            $this->compiled->exists = true;
            $this->compiled->isCompiled = true;
        }
        // release compiler object to free memory
        unset($this->compiler);
    }
58849
private function bakeViewsConfig(string $name) : void
    {
        $options = [
            'path' => Configure::read('CsvMigrations.modules.path') . $name . DS . 'views' . DS,
            'ext' => 'json'
        ];

        $this->bake('add.dist', 'Module/views/add', [], '', $options);
        $this->bake('edit.dist', 'Module/views/edit', [], '', $options);
        $this->bake('index.dist', 'Module/views/index', [], '', $options);
        $this->bake('view.dist', 'Module/views/view', [], '', $options);
    }
51163
function load($name): string {
    if (!isset($this->views[$name])) {
      $cacheKey = [__CLASS__, $name];
      $viewRenderer = $this->viewRenderer;

      /** @var \yii\caching\Cache $cache */
      $cache = $viewRenderer->cache;
      if ($viewRenderer->enableCaching && $cache->exists($cacheKey))
        $output = $cache->get($cacheKey);
      else {
        $path = FileHelper::localize($this->findViewFile($name));
        if (!is_file($path)) throw new InvalidCallException("The view file '$path' does not exist.");

        $output = @file_get_contents($path);
        if ($viewRenderer->enableCaching) $cache->set($cacheKey, $output, $viewRenderer->cachingDuration);
      }

      $this->views[$name] = $output;
    }

    return $this->views[$name];
  }
622481
protected function findNamespacedView($name)
    {
        // Extract the $view and the $namespace parts
        list($namespace, $view) = $this->parseNamespaceSegments($name);

        $paths = $this->addThemeNamespacePaths($namespace);

        // Find and return the view
        return $this->findInPaths($view, $paths);
    }
1241448
public function copyMigration($name, $template)
    {
        $migrations = $this->getMigrations();

        // Check name not exists
        foreach ($migrations as $migration) {
            if (strtolower($name) == strtolower($migration['name'])) {
                throw new \RuntimeException(
                    'Migration: <info>' . $name . "</info> has exists. \nFile at: <info>" .
                    $migration['path'] . '</info>'
                );
            }
        }

        $date = gmdate('YmdHis');

        $file = $date . '_' . ucfirst($name) . '.php';

        $tmpl = file_get_contents($template);

        $tmpl = SimpleTemplate::render($tmpl, ['version' => $date, 'className' => ucfirst($name)]);

        // Get file path
        $filePath = $this->get('path') . '/' . $file;

        if (is_file($filePath)) {
            throw new \RuntimeException(sprintf('File already exists: %s', $filePath));
        }

        // Write it
        File::write($filePath, $tmpl);

        $this->out()->out('Migration version: <info>' . $file . '</info> created.');
        $this->out('File path: <info>' . realpath($filePath) . '</info>');
    }
201783
public function migrate($version = null)
    {
        $migrations     = $this->getMigrations();
        $versions       = $this->getVersions();
        $currentVersion = $this->getCurrentVersion();

        if (!count($migrations)) {
            throw new \RuntimeException('No migrations found.');
        }

        if ($version === null) {
            $version = max(array_merge($versions, array_keys(iterator_to_array($migrations))));
        } else {
            if ($version != 0 && empty($migrations[$version])) {
                throw new \RuntimeException('Version is not valid.');
            }
        }

        // Prepare SQL logs
        if (is_file($this->getLogFile())) {
            File::delete($this->getLogFile());
        }

        Folder::create(dirname($this->getLogFile()));

        $queryLogStream = new Stream($this->getLogFile(), Stream::MODE_WRITE_ONLY_FROM_END);
        $logListener = function (Event $event) use ($queryLogStream) {
            $queryLogStream->write($event['query'] . ";\n\n");
        };
        Ioc::getDispatcher()->listen('onMigrationAfterQuery', $logListener);

        $direction = ($version > $currentVersion) ? AbstractMigration::UP : AbstractMigration::DOWN;

        $migrations = iterator_to_array($migrations);

        $count = 0;

        try {
            if ($direction === AbstractMigration::DOWN) {
                krsort($migrations);

                foreach ($migrations as $migration) {
                    if ($migration['version'] <= $version) {
                        break;
                    }

                    if (in_array($migration['version'], $versions)) {
                        $this->executeMigration($migration, AbstractMigration::DOWN);
                    }

                    $count++;
                }
            }

            ksort($migrations);

            foreach ($migrations as $migration) {
                if ($migration['version'] > $version) {
                    break;
                }

                if (!in_array($migration['version'], $versions, true)) {
                    $this->executeMigration($migration, AbstractMigration::UP);
                }

                $count++;
            }
        } catch (\PDOException $e) {
            $queryLogStream->write("-- ERROR: {$e->getMessage()}\n" . $this->db->getQuery());

            throw $e;
        }

        Ioc::getDispatcher()->removeListener($logListener);

        if (!$count) {
            $this->out('No change.');
        }
    }
1313418
public function call($name, $data = null, $nest = null)
    {

        //Merge data
        if (!is_null($data)) {
            $this->data = array_merge($this->data, $data);
        }

        if (!$this->exists($name, $nest)) {
            throw new ViewNotFoundException($name);
        } else {
            $data = $this->exists($name, $nest);

            $this->path = $data['path'];
            $this->engine = $data['engine'];
            $this->nest = $nest;
        }

        $nameSegments = dot($name);

        $this->name = $this->setName($nameSegments);

        return $this;
    }
1105815
public function actionView($name = '')
    {
        if ($name == '') {
            $name = yii::$app->getRequest()->getPathInfo();
        }
        $model = Article::findOne(['type' => Article::SINGLE_PAGE, 'sub_title' => $name]);
        if (empty($model)) {
            throw new NotFoundHttpException('None page named ' . $name);
        }
        return $this->render('view', [
            'model' => $model,
        ]);
    }
1292822
public function package($name)
    {
        if (starts_with($name, 'src')) {
            $name = str_replace('src/', '', $name);
        }
        $basePath   = rtrim($this->app->make('path.base'), '/');
        $vendorPath = "{$basePath}/src";
        $paths      = [
            "{$vendorPath}/{$name}/resources/database/migrations/",
            "{$vendorPath}/{$name}/database/migrations/",
            "{$vendorPath}/{$name}/migrations/",
        ];
        foreach ($paths as $path) {
            if ($this->app->make('files')->isDirectory($path)) {
                $this->run($path);
            }
        }
        $seeds = [
            "{$vendorPath}/{$name}/resources/database/seeds/",
            "{$vendorPath}/{$name}/database/seeds/",
            "{$vendorPath}/{$name}/seeds/",
        ];
        $this->seed($name, $seeds);
    }
864302
public function compile($name = 'teleport.phar')
    {
        $this->cleanse($name);

        $this->getVersion();

        echo "building {$name} version {$this->version} ({$this->versionDate})" . PHP_EOL;

        $phar = $this->preparePhar($name);

        $this->addSrc($phar);

        $this->addTpl($phar);

        $this->addAutoload($phar);

        $this->addDependencies($phar);

        $this->addTeleportBin($phar);

        $phar->setStub($this->getStub());

        $this->addLicense($phar);

        $this->writePhar($phar);

        unset($phar);
    }
1335123
private function create_package_migration($name) {
		list($packagename, $name) = explode('/', $name);

		$skeleton_packages = \Skeleton\Core\Skeleton::get_all();
		$package = null;
		foreach ($skeleton_packages as $skeleton_package) {
			if ($skeleton_package->name == $packagename) {
				$package = $skeleton_package;
			}
		}

		if ($package === null) {
			throw new \Exception('Package ' . $packagename . ' not found');
		}

		if (!file_exists($package->migration_path)) {
			mkdir($package->migration_path);
		}

		$name = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $name);

		$datetime = date('Ymd_His');
		$filename = $datetime . '_' . strtolower($name) . '.php';
		$classname = 'Migration_' . $datetime . '_' . ucfirst($name);

		$namespace_parts = explode('-', $package->name);
		foreach ($namespace_parts as $key => $namespace_part) {
			$namespace_parts[$key] = ucfirst($namespace_part);
		}
		$namespace = implode('\\', $namespace_parts);

		$template = file_get_contents(__DIR__ . '/../template/migration.php');
		$template = str_replace('%%namespace%%', 'namespace ' . $namespace . ';' . "\n", $template);
		$template = str_replace('%%classname%%', $classname, $template);
		file_put_contents($package->migration_path . '/' . $filename, $template);
		return $package->migration_path . '/' . $filename;
	}
12940
protected function replaceClass($stub, $name)
    {
        $class = str_replace($this->getNamespace($name).'\\', '', $name);
        $view = $this->getViewName();

        $stub = str_replace('DummyClass', $class, $stub);

        return str_replace('DummyTemplate', 'admin.dashboard.'.$view, $stub);
    }
1030870
public function getFile($name)
    {
        if ($file = $this->resolveFile($name)) {
            return $file;
        } else {
            $components = $this->parseResource($name);
            throw new \RuntimeException(sprintf('Template "%s" not found in directories "%s"', $components['file'], implode('", "', $components['dirs'])));
        }
    }
814289
public function lastModified($name)
    {
        if (! $this->files->exists($name)) {
            throw new FileNotFoundException("$name does not exist");
        }
        return $this->files->lastModified($name);
    }
1134698
protected static function _buildTransport($name)
    {
        if (!isset(static::$_config[$name])) {
            throw new InvalidArgumentException(
                sprintf('The "%s" transport configuration does not exist', $name)
            );
        }

        if (is_array(static::$_config[$name]) && empty(static::$_config[$name]['className'])) {
            throw new InvalidArgumentException(
                sprintf('Transport config "%s" is invalid, the required `className` option is missing', $name)
            );
        }

        static::getRegistry()->load($name, static::$_config[$name]);
    }
839014
public static function findTemplate (\Twig_Loader_Filesystem $filesystem, $name)
    {
        $name = self::normalizeName($name);
        self::validateName($name);
        list($namespace, $shortname) = self::parseName($name);
        $paths = $filesystem->getPaths($namespace);
        if (empty($paths)) {
            throw new Twig_Error_Loader(sprintf('There are no registered paths for namespace "%s".', $namespace));
        }
        foreach ($paths as $path) {
            if (is_file($path . '/' . $shortname)) {
                if (false !== $realpath = realpath($path . '/' . $shortname)) {
                    return $realpath;
                }
                return $path . '/' . $shortname;
            }
        }
        throw new Twig_Error_Loader(sprintf('Unable to find template "%s" (looked into: %s).', $name, implode(', ', $paths)));
    }