Example #1
0
    /**
     * Перегенерация файла модулей.
     * @return \yii\web\Response
     */
    public function actionWriteEnvGlobalFile()
    {
        $env = (string) \Yii::$app->request->get('env');
        if (!$env) {
            \Yii::$app->session->setFlash('error', \Yii::t('app', 'Not Specified Places to record'));
            return $this->redirect(\Yii::$app->request->getReferrer());
        }
        $content = <<<PHP
<?php
defined('YII_ENV') or define('YII_ENV', '{$env}');
PHP;
        $file = new File(APP_ENV_GLOBAL_FILE);
        if ($file->write($content)) {
            \Yii::$app->session->setFlash('success', \Yii::t('app', 'File successfully created and written'));
        } else {
            \Yii::$app->session->setFlash('error', \Yii::t('app', 'Failed to write file'));
        }
        return $this->redirect(\Yii::$app->request->getReferrer());
    }
Example #2
0
File: Cms.php Project: Liv1020/cms
    /**
     * Пройтись по всем расширениям уставноленным в проект, и сгенерировать конфиг файл.
     * @return bool
     */
    public function generateModulesConfigFile()
    {
        $configs = $this->findConfigFiles(['/config/main.php']);
        $configsConsole = $this->findConfigFiles(['/config/main-console.php']);
        if ($configs || $configsConsole) {
            $date = date("dd.mm.YY", time());
            $fileContent = <<<PHP
<?php
/**
 * Автоматически сгенерированные конфиг, можно просто удалить этот файл.
 *
 * @author Semenov Alexander <*****@*****.**>
 * @link http://skeeks.com/
 * @copyright 2010-2014 SkeekS (Sx)
 * @date {$date}
 * @since 1.0.0
 */
 return [

PHP;
            $fileContent .= "'web' => [\n";
            foreach ($configs as $filePach) {
                $fileContent .= "\"" . $filePach . "\", \n";
            }
            $fileContent .= "],\n";
            $fileContent .= "'console' => [\n";
            foreach ($configsConsole as $filePach) {
                $fileContent .= "\"" . $filePach . "\", \n";
            }
            $fileContent .= "]\n";
            $fileContent .= '];';
            $file = new File(AUTO_GENERATED_MODULES_FILE);
            $file->write($fileContent);
        }
        $file = new File(AUTO_GENERATED_MODULES_FILE);
        return $file->isExist();
    }
Example #3
0
    /**
     * Logs in a user using the provided username and password.
     *
     * @return boolean whether the user is logged in successfully
     */
    public function write()
    {
        if ($this->validate() && $this->hasConnect()) {
            $fileContent = <<<PHP
<?php
/**
 * @author Semenov Alexander <*****@*****.**>
 * @link http://skeeks.com/
 * @copyright 2010 SkeekS (СкикС)
 * @date 17.09.2015
 */
return [
    'class' => 'yii\\db\\Connection',
    'dsn' => 'mysql:host={$this->host};dbname={$this->dbname}',
    'username' => '{$this->username}',
    'password' => '{$this->password}',
    'charset' => '{$this->charset}',
    'enableSchemaCache' => true,
    'schemaCacheDuration' => 3600,
];

PHP;
            $file = new File(Yii::getAlias('@common/config/db.php'));
            $file->write($fileContent);
            if ($file->isExist()) {
                return true;
            }
            return false;
        } else {
            return false;
        }
    }