{"action":"created","issue":{"url":"https://api.github.com/repos/leancloud/php-sdk/issues/37","labels_url":"https://api.github.com/repos/leancloud/php-sdk/issues/37/labels{/name}","comments_url":"https://api.github.com/repos/leancloud/php-sdk/issues/37/comments","events_url":"https://api.github.com/repos/leancloud/php-sdk/issues/37/events","html_url":"https://github.com/leancloud/php-sdk/pull/37","id":119887996,"number":37,"title":"[WIP] LeanEngine runtime","user":{"login":"juvenn","id":6934,"avatar_url":"https://avatars.githubusercontent.com/u/6934?v=3","gravatar_id":"","url":"https://api.github.com/users/juvenn","html_url":"https://github.com/juvenn","followers_url":"https://api.github.com/users/juvenn/followers","following_url":"https://api.github.com/users/juvenn/following{/other_user}","gists_url":"https://api.github.com/users/juvenn/gists{/gist_id}","starred_url":"https://api.github.com/users/juvenn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juvenn/subscriptions","organizations_url":"https://api.github.com/users/juvenn/orgs","repos_url":"https://api.github.com/users/juvenn/repos","events_url":"https://api.github.com/users/juvenn/events{/privacy}","received_events_url":"https://api.github.com/users/juvenn/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2015-12-02T08:01:12Z","updated_at":"2015-12-15T08:06:47Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/leancloud/php-sdk/pulls/37","html_url":"https://github.com/leancloud/php-sdk/pull/37","diff_url":"https://github.com/leancloud/php-sdk/pull/37.diff","patch_url":"https://github.com/leancloud/php-sdk/pull/37.patch"},"body":"* 添加 Engine\\Cloud 支持云函数及回调函数的定义\n* 添加 Engine\\LeanEngine 作为 web 应用的中间件，对函数调用进行路由\n* 跨域 OPTIONS 请求握手的支持\n* POST text/plain 跨域请求的处理\n\nTODO:\n\n* class hook 请求中对象数据的encode/decode\n* class hook 中 _updatedKeys 的特殊处理\n* https redirect"},"comment":{"url":"https://api.github.com/repos/leancloud/php-sdk/issues/comments/164679541","html_url":"https://github.com/leancloud/php-sdk/pull/37#issuecomment-164679541","issue_url":"https://api.github.com/repos/leancloud/php-sdk/issues/37","id":164679541,"user":{"login":"juvenn","id":6934,"avatar_url":"https://avatars.githubusercontent.com/u/6934?v=3","gravatar_id":"","url":"https://api.github.com/users/juvenn","html_url":"https://github.com/juvenn","followers_url":"https://api.github.com/users/juvenn/followers","following_url":"https://api.github.com/users/juvenn/following{/other_user}","gists_url":"https://api.github.com/users/juvenn/gists{/gist_id}","starred_url":"https://api.github.com/users/juvenn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juvenn/subscriptions","organizations_url":"https://api.github.com/users/juvenn/orgs","repos_url":"https://api.github.com/users/juvenn/repos","events_url":"https://api.github.com/users/juvenn/events{/privacy}","received_events_url":"https://api.github.com/users/juvenn/received_events","type":"User","site_admin":false},"created_at":"2015-12-15T08:06:47Z","updated_at":"2015-12-15T08:06:47Z","body":"PHP 云引擎的开发已经基本完成，实现以下功能：\r\n\r\n* 运行云引擎：\r\n```php\r\n// 启用 cookie session\r\nuse LeanCloud\\LeanClient;\r\nuse LeanCloud\\Storage\\CookieStorage;\r\nLeanClient::setStorage(new CookieStorage());\r\n\r\n// 启用 https 转发\r\nuse LeanCloud\\Engine\\HttpsRedirect;\r\nHttpsRedirect::redirect();\r\n\r\n// 启用云引擎支持云函数及 hook 的调用\r\nuse LeanCloud\\Engine\\LeanEngine;\r\nLeanEngine::start();\r\n```\r\n\r\n* 云函数及 hook 的定义：\r\n```php\r\nuse LeanCloud\\Engine\\Cloud;\r\n// 用户函数可选择接收 $meta 参数\r\nCloud::define(\"hello\", function($params, $user, $meta) {\r\n  return \"hello {$params['name']}\";\r\n});\r\nCloud::beforeUpdate(\"TestObject\", function($obj, $user, $meta){});\r\n\r\n// 服务端可直接调用云函数及hook\r\nCloud::run(\"hello\", $params, LeanUser::getCurrentUser());\r\nCloud::runHook(\"TestObject\", \"beforeUpdate\", $obj, $user);\r\n```\r\n\r\n* 用户函数中可以通过抛出 FunctionError 的异常来自定义错误响应码:\r\n```php\r\nuse LeanCloud\\Engine\\FunctionError;\r\nCloud::onLogin(function($userObj) {\r\n  if ($userObj->get(\"isBlocked\")) {\r\n    throw new FunctionError(\"User is blocked.\", 123);\r\n  }\r\n});\r\n// 返回结果 {\"code\": \"123\", \"error\": \"User is blocked.\"}\r\n```\r\n\r\n测试用例位于 `tests/engine/`。希望大家审阅。\r\n\r\n @jysperm @aisk @sdjcw "}}