Skip to content

Commit

Permalink
linux兼容与php5.4兼容
Browse files Browse the repository at this point in the history
  • Loading branch information
onanying committed Sep 6, 2017
1 parent c2b09f7 commit 2bbf204
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 15 deletions.
8 changes: 4 additions & 4 deletions mixphp/mix1/base/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ public function runAction($method, $action)
}
// 实例化控制器
$action = "{$this->controllerNamespace}\\{$action}";
$classFull = dirname($action);
$classPath = dirname($classFull);
$className = \Mix::$app->route->snakeToCamel(basename($classFull));
$method = \Mix::$app->route->snakeToCamel(basename($action), true);
$classFull = \mix\base\Route::dirname($action);
$classPath = \mix\base\Route::dirname($classFull);
$className = \mix\base\Route::snakeToCamel(\mix\base\Route::basename($classFull), true);
$method = \mix\base\Route::snakeToCamel(\mix\base\Route::basename($action), true);
$class = "{$classPath}\\{$className}Controller";
$method = "action{$method}";
try {
Expand Down
2 changes: 1 addition & 1 deletion mixphp/mix1/base/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Log extends Object
public $logRotate = self::ROTATE_DAY;

// 最大文件尺寸
public $maxFileSize = 2048 * 1024;
public $maxFileSize = 2097152;

// 调试日志
public function debug($message)
Expand Down
28 changes: 26 additions & 2 deletions mixphp/mix1/base/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function match($name)
* @param boolean $ucfirst
* @return string
*/
public function snakeToCamel($name, $ucfirst = false)
public static function snakeToCamel($name, $ucfirst = false)
{
$name = ucwords(str_replace(['_', '-'], ' ', $name));
$name = str_replace(' ', '', lcfirst($name));
Expand All @@ -121,7 +121,7 @@ public function snakeToCamel($name, $ucfirst = false)
* @param string $name
* @return string
*/
public function camelToSnake($name)
public static function camelToSnake($name)
{
$name = preg_replace_callback('/([A-Z]{1})/', function ($matches) {
return '_' . strtolower($matches[0]);
Expand All @@ -132,4 +132,28 @@ public function camelToSnake($name)
return $name;
}

/**
* 返回路径中的目录部分
* 正反斜杠linux兼容处理
*/
public static function dirname($path)
{
if (strpos($path, '\\') === false) {
return dirname($path);
}
return str_replace('/', '\\', dirname(str_replace('\\', '/', $path)));
}

/**
* 返回路径中的文件名部分
* 正反斜杠linux兼容处理
*/
public static function basename($path)
{
if (strpos($path, '\\') === false) {
return basename($path);
}
return str_replace('/', '\\', basename(str_replace('\\', '/', $path)));
}

}
4 changes: 2 additions & 2 deletions mixphp/mix1/swoole/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public function runAction($method, $action, $request, $response)
$action = "{$this->controllerNamespace}\\{$action}";
$classFull = dirname($action);
$classPath = dirname($classFull);
$className = \Mix::$app->route->snakeToCamel(basename($classFull));
$method = \Mix::$app->route->snakeToCamel(basename($action), true);
$className = \mix\base\Route::snakeToCamel(basename($classFull));
$method = \mix\base\Route::snakeToCamel(basename($action), true);
$class = "{$classPath}\\{$className}Controller";
$method = "action{$method}";
try {
Expand Down
2 changes: 1 addition & 1 deletion mixphp/mix1/web/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function renderPartial($name, $data = [])
// 视图前缀
private function viewPrefix()
{
return \Mix::$app->route->camelToSnake(str_replace([\Mix::$app->controllerNamespace . '\\', '\\', 'Controller'], ['', '.', ''], get_class($this)));
return \mix\base\Route::camelToSnake(str_replace([\Mix::$app->controllerNamespace . '\\', '\\', 'Controller'], ['', '.', ''], get_class($this)));
}

}
4 changes: 4 additions & 0 deletions mixphp/mix1/web/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ class Cookie extends Object

// 过期时间
public $expire = 31536000;

// 有效的服务器路径
public $path = '/';

// 有效域名/子域名
public $domain = '';

// 仅通过安全的 HTTPS 连接传给客户端
public $secure = false;

// 仅可通过 HTTP 协议访问
public $httponly = false;

Expand Down
10 changes: 5 additions & 5 deletions mixphp/mix1/web/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ class Session extends Object
{

// 处理者值
const HANDLER_FILES = 'files';
const HANDLER_FILES = 'files';
const HANDLER_MEMCACHE = 'memcache';
const HANDLER_REDIS = 'redis';
const HANDLER_REDIS = 'redis';
// 处理者
public $saveHandler = self::HANDLER_FILES;
// 保存路径
public $savePath;
public $savePath = '';
// 生存时间
public $gcMaxLifetime;
public $gcMaxLifetime = 7200;
// session名
public $name;
public $name = 'MIX_SSID';

// 初始化
public function init()
Expand Down

0 comments on commit 2bbf204

Please sign in to comment.