Commit abb34936 by Qiang Xue

use json format.

parent f16ef262
...@@ -193,7 +193,7 @@ abstract class Generator extends Model ...@@ -193,7 +193,7 @@ abstract class Generator extends Model
$attributes[] = 'template'; $attributes[] = 'template';
$path = $this->getStickyDataFile(); $path = $this->getStickyDataFile();
if (is_file($path)) { if (is_file($path)) {
$result = unserialize(file_get_contents($path)); $result = json_decode(file_get_contents($path), true);
if (is_array($result)) { if (is_array($result)) {
foreach ($stickyAttributes as $name) { foreach ($stickyAttributes as $name) {
if (isset($result[$name])) { if (isset($result[$name])) {
...@@ -218,7 +218,7 @@ abstract class Generator extends Model ...@@ -218,7 +218,7 @@ abstract class Generator extends Model
} }
$path = $this->getStickyDataFile(); $path = $this->getStickyDataFile();
@mkdir(dirname($path), 0755, true); @mkdir(dirname($path), 0755, true);
file_put_contents($path, serialize($values)); file_put_contents($path, json_encode($values));
} }
/** /**
...@@ -227,7 +227,7 @@ abstract class Generator extends Model ...@@ -227,7 +227,7 @@ abstract class Generator extends Model
*/ */
public function getStickyDataFile() public function getStickyDataFile()
{ {
return Yii::$app->getRuntimePath() . '/gii-' . Yii::getVersion() . '/' . str_replace('\\', '-', get_class($this)) . '.data'; return Yii::$app->getRuntimePath() . '/gii-' . Yii::getVersion() . '/' . str_replace('\\', '-', get_class($this)) . '.json';
} }
/** /**
......
...@@ -184,16 +184,16 @@ class BaseSecurity ...@@ -184,16 +184,16 @@ class BaseSecurity
public static function getSecretKey($name, $length = 32) public static function getSecretKey($name, $length = 32)
{ {
static $keys; static $keys;
$keyFile = Yii::$app->getRuntimePath() . '/keys.data'; $keyFile = Yii::$app->getRuntimePath() . '/keys.json';
if ($keys === null) { if ($keys === null) {
$keys = []; $keys = [];
if (is_file($keyFile)) { if (is_file($keyFile)) {
$keys = unserialize(file_get_contents($keyFile)); $keys = json_decode(file_get_contents($keyFile), true);
} }
} }
if (!isset($keys[$name])) { if (!isset($keys[$name])) {
$keys[$name] = static::generateRandomKey($length); $keys[$name] = static::generateRandomKey($length);
file_put_contents($keyFile, serialize($keys)); file_put_contents($keyFile, json_encode($keys));
} }
return $keys[$name]; return $keys[$name];
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment