Skip to content
This repository was archived by the owner on Oct 20, 2023. It is now read-only.

Commit

Permalink
Correct driver config and versions for cake 4.x-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
rochamarcelo committed Aug 27, 2019
1 parent 3a133c0 commit d6dbe33
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions oven.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,12 @@ class Oven {
public $composerPath;
public $appDir = 'app';
public $versions = [
'~3.8.0' => '~3.8.0',
'~3.7.0' => '~3.7.0',
'~3.6.0' => '~3.6.0',
'~3.5.0' => '~3.5.0',
'4.x-dev' => '4.x-dev',
];
public $databaseDriverClasses = [
'mysql' => 'Cake\Database\Driver\Mysql',
'pgsql' => 'Cake\Database\Driver\Postgres',
'sqlite' => 'Cake\Database\Driver\Sqlite',
'mysql' => 'Mysql',
'pgsql' => 'Postgres',
'sqlite' => 'Sqlite',
];
public $minPhp = '7.2.0';
const DATASOURCE_REGEX = "/(\'Datasources'\s\=\>\s\[\n\s*\'default\'\s\=\>\s\[\n\X*\'__FIELD__\'\s\=\>\s\').*(\'\,)(?=\X*\'test\'\s\=\>\s)/";
Expand Down Expand Up @@ -103,7 +100,7 @@ public function getComposerSystemPath()
protected function _getAvailableVersions()
{
if (isset($_SESSION[self::VERSIONS_SESSION_KEY ]) && is_array($_SESSION[self::VERSIONS_SESSION_KEY ])) {
// return $_SESSION[self::VERSIONS_SESSION_KEY ];
return $_SESSION[self::VERSIONS_SESSION_KEY ];
}

if (!$package = json_decode(file_get_contents('https://packagist.org/packages/cakephp/cakephp.json'), true)) {
Expand All @@ -117,7 +114,7 @@ protected function _getAvailableVersions()
$tags = array_keys($package['package']['versions']);

$versions = ['4.x-dev' => '4.x-dev'];
$branches = ['3.8.', '3.7.', '3.6.', '3.5.'];
$branches = [];
foreach ($branches as $branch) {
if ($version = $this->_getLatestVersion($tags, $branch)) {
$versions['~' . $version] = $version;
Expand Down Expand Up @@ -165,11 +162,13 @@ protected function _getComposerPathFromQuery()

protected function _updateDatasourceConfig($path, $field, $value)
{
$config = file_get_contents($path);
if ($field === 'driver') {
$value = $this->databaseDriverClasses[$value];
$config = str_replace(['Driver\\Mysql', 'Mysql::class'], ["Driver\\$value", "$value::class"], $config);
} else {
$config = preg_replace(str_replace('__FIELD__', $field, Oven::DATASOURCE_REGEX), '${1}' . $value . '${2}', $config);
}
$config = file_get_contents($path);
$config = preg_replace(str_replace('__FIELD__', $field, Oven::DATASOURCE_REGEX), '${1}' . $value . '${2}', $config);

return file_put_contents($path, $config);
}
Expand Down

0 comments on commit d6dbe33

Please sign in to comment.