diff --git a/demo.php b/demo.php index 65c95a3..ba9cafa 100644 --- a/demo.php +++ b/demo.php @@ -2,16 +2,16 @@ require 'vendor/autoload.php'; if ('save' == ($_GET['action'] ?? null)) { - echo 'OK'; exit; + echo 'OK'; exit; } else if ('marriage' == ($_GET['action'] ?? null)) { - $groups = array( - array('value' => 0, 'text' => 'Unmarried 未婚'), - array('value' => 1, 'text' => 'Marriaged 已婚'), - array('value' => 2, 'text' => 'Divorced 离异'), - array('value' => 3, 'text' => 'Widowed 丧偶'), - ); - echo json_encode($groups); - exit; + $groups = array( + array('value' => 0, 'text' => 'Unmarried 未婚'), + array('value' => 1, 'text' => 'Marriaged 已婚'), + array('value' => 2, 'text' => 'Divorced 离异'), + array('value' => 3, 'text' => 'Widowed 丧偶'), + ); + echo json_encode($groups); + exit; } ?> diff --git a/src/Editable.php b/src/Editable.php index 855fa89..2e4c98b 100644 --- a/src/Editable.php +++ b/src/Editable.php @@ -5,7 +5,7 @@ use Editable\Integrates\EditableException; use AvpLab\PhpHtmlBuilder; -class Editable implements Interfaces\EditableInterface{ +class Editable implements Interfaces\EditableInterface { /** * @var array 已声明使用的类型, 用于加载JS */ @@ -100,7 +100,7 @@ class Editable implements Interfaces\EditableInterface{ */ public function __construct($row = null, $pk = "id", $hidden = [], $ajax = '') { - if(!$row) { + if (!$row) { throw new EditableException(null, EditableException::NO_DATA); } @@ -109,13 +109,13 @@ public function __construct($row = null, $pk = "id", $hidden = [], $ajax = '') $this->hidden = array_flip($hidden); $this->ajax = $ajax; - $this->hidden[$pk] = 1; + $this->hidden[$pk] = 1; - if(class_exists('\Editable\Assets\LocalAssets')) { + if (class_exists('\Editable\Assets\LocalAssets')) { $this->vendor_assets = \Editable\Assets\LocalAssets::instance()->getVendorAssetsRoutingUrl(); } - foreach($this->row as $key => $value) { + foreach ($this->row as $key => $value) { $this->input($key, $value); } } @@ -143,8 +143,8 @@ public function registerComponent($type, $key, $value = null, $options = [], $in */ public function protect($key) { - if(is_array($key)) { - foreach($key as $each) { + if (is_array($key)) { + foreach ($key as $each) { $this->protect($each); } } else { @@ -287,45 +287,45 @@ protected function __every_element($each) $type = $each[0]; $key = $each[1]; - if($each[2] === null && isset($this->row[$key]) && $this->row[$key] != null) { + if ($each[2] === null && isset($this->row[$key]) && $this->row[$key] != null) { $each[2] = $this->row[$key]; } - $value = $each[2]; + $value = $each[2]; $show_name = ucfirst(preg_replace_callback('/(_([a-zA-Z0-9]))/', function($a) { - if(isset($a[2])) { + if (isset($a[2])) { return ' '.strtoupper($a[2]); } return $a; }, $key)); - $title = 'Type the '.$show_name; + $title = 'Type the '.$show_name; $show_type = $type; $show_value = $value; - if($type == 'select') { + if ($type == 'select') { $show_value = ''; - if(is_array($each[3])) { - foreach($each[3] as $option) { - $option_value = isset($option['value']) ? $option['value']: null; - if($value == $option_value) { + if (is_array($each[3])) { + foreach ($each[3] as $option) { + $option_value = isset($option['value']) ? $option['value'] : null; + if ($value == $option_value) { $show_value = $option['text']; break; } } - } else if(is_string($each[3])) { + } else if (is_string($each[3])) { } - } else if($type == 'typeaheadjs') { + } else if ($type == 'typeaheadjs') { $show_value = ''; - foreach($each[3] as $option) { - $option_value = isset($option['value']) ? $option['value']: null; - if($value == $option_value) { - $show_value = $option['text'] . ' (' . $value . ') '; + foreach ($each[3] as $option) { + $option_value = isset($option['value']) ? $option['value'] : null; + if ($value == $option_value) { + $show_value = $option['text'].' ('.$value.') '; break; } } - } else if($type == 'wysiwyg') { + } else if ($type == 'wysiwyg') { $show_type = 'wysihtml5'; - } else if($type == 'tag') { + } else if ($type == 'tag') { $show_type = 'select2'; } @@ -341,24 +341,24 @@ protected function __every_element($each) /**//**//**/->setDataType($show_type) /**//**//**/->setDataValue($value) /**//**//**/->setDataPlacement('bottom'); - /**//**//**/if(!isset($this->hidden[$key])) { + /**//**//**/if (!isset($this->hidden[$key])) { /**//**//**//**/$this->builder->setClass('editable-link'); /**//**//**/} - /**//**//**/if($type == 'select' || $type == 'tag' || $type == 'checklist') { - /**//**//**//**/$this->builder->setDataSource(is_string($each[3])?$each[3]:json_encode($each[3])); - /**//**//**/} else if($type == 'typeaheadjs') { + /**//**//**/if ($type == 'select' || $type == 'tag' || $type == 'checklist') { + /**//**//**//**/$this->builder->setDataSource(is_string($each[3]) ? $each[3] : json_encode($each[3])); + /**//**//**/} else if ($type == 'typeaheadjs') { /**//**//**//**/$this->builder->setDataTypeahead( # @todo: template /**//**//**//**//**/json_encode([ /**//**//**//**//**/'name' => $key, /**//**//**//**//**/'local' => $each[3], /**//**//**//**//**/]) /**//**//**//**/); - /**//**//**/} else if($type == 'date') { + /**//**//**/} else if ($type == 'date') { /**//**//**//**/$this->builder->setDataType('combodate') /**//**//**//**//**//**/->setDataTemplate('YYYY/MM/DD') /**//**//**//**//**//**/->setDataFormat('YYYY-MM-DD') /**//**//**//**//**//**/->setDataViewformat('YYYY-MM-DD'); - /**//**//**/} else if($type == 'datetime') { + /**//**//**/} else if ($type == 'datetime') { /**//**//**//**/$this->builder->setDataType('combodate') /**//**//**//**//**//**/->setDataTemplate('YYYY/MM/DD HH:mm:ss') /**//**//**//**//**//**/->setDataFormat('YYYY-MM-DD HH:mm:ss') @@ -479,8 +479,8 @@ public function render($and_destroy = true) $this->builder->div()->setClass('table-wrapper')->setId('table-wrapper-'.$this->uuid); /**/$this->builder->link()->setRel('stylesheet')->setHref($this->vendor_assets['xeditable']['css'][0])->end(); /**/$this->builder->link()->setRel('stylesheet')->setHref($this->vendor_assets['xeditable']['css'][1])->end(); - foreach($this->existed_dom_type as $dom_type => $one) { - foreach($this->vendor_assets[$dom_type]['css'] as $css) { + foreach ($this->existed_dom_type as $dom_type => $one) { + foreach ($this->vendor_assets[$dom_type]['css'] as $css) { /**/$this->builder->link()->setRel('stylesheet')->setHref($css)->end(); } } @@ -493,7 +493,7 @@ public function render($and_destroy = true) /**//**/$this->builder->end(); /**//**/$this->builder->tbody(); - foreach($this->data as $component) { + foreach ($this->data as $component) { $this->__every_element($component); } @@ -504,8 +504,8 @@ public function render($and_destroy = true) /**/$this->builder->script()->setType('application/javascript')->setSrc($this->vendor_assets['xeditable']['js'][1])->end(); /**/$this->builder->script()->setType('application/javascript')->setSrc($this->vendor_assets['xeditable']['js'][2])->end(); - foreach($this->existed_dom_type as $dom_type => $one) { - foreach($this->vendor_assets[$dom_type]['js'] as $js) { + foreach ($this->existed_dom_type as $dom_type => $one) { + foreach ($this->vendor_assets[$dom_type]['js'] as $js) { /**/$this->builder->script()->setType('application/javascript')->setSrc($js)->end(); } } @@ -516,7 +516,7 @@ public function render($and_destroy = true) $response = new EditableResponse(200, $html); - if($and_destroy){ + if ($and_destroy) { $this->existed_dom_type = []; $this->data = []; $this->builder = null; diff --git a/src/Integrates/EditableException.php b/src/Integrates/EditableException.php index 23ceb5e..ac4e536 100644 --- a/src/Integrates/EditableException.php +++ b/src/Integrates/EditableException.php @@ -1,7 +1,7 @@ status_code = $status_code; - if($body !== null) $this->body = $body; + if ($status_code !== null) $this->status_code = $status_code; + if ($body !== null) $this->body = $body; } @@ -51,16 +51,16 @@ public function getBody() return $this->body; } - public function getProtocolVersion(){} - public function withProtocolVersion($version){} - public function getHeaders(){} - public function hasHeader($name){} - public function getHeader($name){} - public function getHeaderLine($name){} - public function withHeader($name, $value){} - public function withAddedHeader($name, $value){} - public function withoutHeader($name){} - public function withBody(StreamInterface $body){} - public function withStatus($code, $reasonPhrase = ''){} - public function getReasonPhrase(){} + public function getProtocolVersion() {} + public function withProtocolVersion($version) {} + public function getHeaders() {} + public function hasHeader($name) {} + public function getHeader($name) {} + public function getHeaderLine($name) {} + public function withHeader($name, $value) {} + public function withAddedHeader($name, $value) {} + public function withoutHeader($name) {} + public function withBody(StreamInterface $body) {} + public function withStatus($code, $reasonPhrase = '') {} + public function getReasonPhrase() {} } \ No newline at end of file