|
@@ -2,18 +2,12 @@
|
|
|
use Dever;
|
|
|
class Import
|
|
|
{
|
|
|
- protected $param;
|
|
|
protected $class;
|
|
|
- protected $method;
|
|
|
protected $path;
|
|
|
public function __construct($class, $app, $path)
|
|
|
{
|
|
|
$this->class = false;
|
|
|
- $this->method = '';
|
|
|
$this->path = $path;
|
|
|
- if (strpos($class, '.')) {
|
|
|
- list($class, $this->method) = explode('.', $class);
|
|
|
- }
|
|
|
$project = Project::load($app);
|
|
|
if (strpos($project['path'], 'http') === 0) {
|
|
|
$this->class = $project;
|
|
@@ -23,81 +17,70 @@ class Import
|
|
|
}
|
|
|
public function __call($method, $param)
|
|
|
{
|
|
|
- $this->method = $method;
|
|
|
- $this->param = $param;
|
|
|
- return $this->loadDevelop();
|
|
|
+ return $this->loadDevelop($method, $param);
|
|
|
}
|
|
|
- public function loadDevelop()
|
|
|
+ public function loadDevelop($method, $param)
|
|
|
{
|
|
|
- if ($this->method) {
|
|
|
- if (is_array($this->class)) {
|
|
|
- return $this->loadDevelopServer();
|
|
|
+ if (is_array($this->class)) {
|
|
|
+ return $this->loadServer();
|
|
|
+ }
|
|
|
+ if ($this->path == 'api') {
|
|
|
+ if (method_exists($this->class, $method . '_secure')) {
|
|
|
+ $key = false;
|
|
|
+ $token = $method . '_token';
|
|
|
+ if (method_exists($this->class, $token)) {
|
|
|
+ $key = $this->class->{$token}();
|
|
|
+ }
|
|
|
+ \Dever\Helper\Secure::check($param, 300, $key);
|
|
|
}
|
|
|
- if ($this->path == 'api') {
|
|
|
- if (!$this->param) $this->param = Route::input();
|
|
|
- if (method_exists($this->class, $this->method . '_secure')) {
|
|
|
- $key = false;
|
|
|
- $token = $this->method . '_token';
|
|
|
- if (method_exists($this->class, $token)) {
|
|
|
- $key = $this->class->{$token}();
|
|
|
+ if ($param && is_array($param) && !isset($param[0])) {
|
|
|
+ $reflectionMethod = new \ReflectionMethod($this->class, $method);
|
|
|
+ $data = $reflectionMethod->getParameters();
|
|
|
+ $result = array();
|
|
|
+ foreach ($data as $k => $v) {
|
|
|
+ $name = $v->name;
|
|
|
+ if (isset($param[$name])) {
|
|
|
+ $result[] = $param[$name];
|
|
|
}
|
|
|
- \Dever\Helper\Secure::check($this->param, 300, $key);
|
|
|
+ }
|
|
|
+ $param = $result;
|
|
|
+ } else {
|
|
|
+ if (!is_array($param)) {
|
|
|
+ $param = array($param);
|
|
|
}
|
|
|
}
|
|
|
- return $this->loadDevelopCommit();
|
|
|
}
|
|
|
- return $this;
|
|
|
+ return $this->loadDevelopCommit($method, $param);
|
|
|
}
|
|
|
- private function loadDevelopServer()
|
|
|
+ private function loadDevelopCommit($method, $param)
|
|
|
{
|
|
|
- return 'error';
|
|
|
- }
|
|
|
- private function loadDevelopCommit()
|
|
|
- {
|
|
|
- if (method_exists($this->class, $this->method . '_commit')) {
|
|
|
+ if (method_exists($this->class, $method . '_commit') && Dever::$commit) {
|
|
|
$db = Dever::store();
|
|
|
try {
|
|
|
+ Dever::$commit = false;
|
|
|
$db->begin();
|
|
|
- $data = $this->loadDevelopCall();
|
|
|
+ $data = $this->loadDevelopMethod($method, $param);
|
|
|
$db->commit();
|
|
|
return $data;
|
|
|
} catch (\Exception $e) {
|
|
|
$db->rollBack();
|
|
|
$data = $e->getTrace();
|
|
|
Debug::trace($data);
|
|
|
- throw new Exceptions(json_encode($data));
|
|
|
+ throw new \Exception(json_encode($data));
|
|
|
}
|
|
|
} else {
|
|
|
- return $this->loadDevelopCall();
|
|
|
+ return $this->loadDevelopMethod($method, $param);
|
|
|
}
|
|
|
}
|
|
|
- private function loadDevelopCall()
|
|
|
+ private function loadServer()
|
|
|
{
|
|
|
- $param = $this->loadDevelopParam();
|
|
|
- $data = $this->class->{$this->method}(...$param);
|
|
|
- Debug::lib($this->class, $this->method);
|
|
|
- Dever::reset();
|
|
|
- $this->method = '';
|
|
|
- return $data;
|
|
|
+ return 'error';
|
|
|
}
|
|
|
- private function loadDevelopParam()
|
|
|
+ private function loadDevelopMethod($method, $param)
|
|
|
{
|
|
|
- if ($this->param && is_array($this->param) && !isset($this->param[0])) {
|
|
|
- $reflectionMethod = new \ReflectionMethod($this->class, $this->method);
|
|
|
- $param = $reflectionMethod->getParameters();
|
|
|
- $result = array();
|
|
|
- foreach ($param as $k => $v) {
|
|
|
- $name = $v->name;
|
|
|
- if (isset($this->param[$name])) {
|
|
|
- $result[] = $this->param[$name];
|
|
|
- }
|
|
|
- }
|
|
|
- return $result;
|
|
|
- } else {
|
|
|
- if (!is_array($this->param)) {
|
|
|
- $this->param = array($this->param);
|
|
|
- }
|
|
|
- return $this->param;
|
|
|
- }
|
|
|
+ $data = $this->class->$method(...$param);
|
|
|
+ Debug::lib($this->class, $method);
|
|
|
+ Dever::reset();
|
|
|
+ return $data;
|
|
|
}
|
|
|
}
|