Skip to content

Commit e5619f3

Browse files
committed
Fix bug on optional parameters in router
1 parent bab95fc commit e5619f3

File tree

2 files changed

+53
-10
lines changed

2 files changed

+53
-10
lines changed

Ubiquity/cache/parser/ControllerParser.php

+18
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public function parse($controllerClass) {
4444
if (UString::isNull($annot->path)) {
4545
$newAnnot=$this->generateRouteAnnotationFromMethod($method);
4646
$annot->path=$newAnnot[0]->path;
47+
}else{
48+
$annot->path=$this->parseMethodPath($method, $annot->path);
4749
}
4850
}
4951
$this->routesMethods[$method->name]=[ "annotations" => $annots,"method" => $method ];
@@ -86,8 +88,24 @@ private static function getPathFromMethod(\ReflectionMethod $method) {
8688
}
8789
return "/" . \implode("/", $pathParts);
8890
}
91+
92+
private static function parseMethodPath(\ReflectionMethod $method,$path){
93+
if($path==null || $path==='')
94+
return;
95+
$parameters=$method->getParameters();
96+
foreach ( $parameters as $parameter ) {
97+
$name=$parameter->getName();
98+
if ($parameter->isVariadic()) {
99+
$path=str_replace('{'.$name.'}', '{...' . $name . '}',$path);
100+
}elseif ($parameter->isOptional()) {
101+
$path=str_replace('{'.$name.'}', '{~' . $name . '}',$path);
102+
}
103+
}
104+
return $path;
105+
}
89106

90107
private static function cleanpath($prefix, $path="") {
108+
$path=str_replace("//", "/", $path);
91109
if (!UString::endswith($prefix, "/"))
92110
$prefix=$prefix . "/";
93111
if ($path !== "" && UString::startswith($path, "/"))

Ubiquity/controllers/admin/viewers/ModelViewer.php

+35-10
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public function setFormFieldsComponent(DataForm $form,$fieldTypes){
9696
$form->fieldAsInput ( $property, [ "inputType" => "email" ,"rules"=>[["email"]]] );
9797
break;
9898
}
99+
99100
switch ($type) {
100101
case "tinyint(1)" :
101102
$form->fieldAsCheckbox ( $property );
@@ -114,6 +115,14 @@ public function setFormFieldsComponent(DataForm $form,$fieldTypes){
114115
}
115116
}
116117

118+
/**
119+
* Returns a DataElement object for displaying the instance
120+
* Used in the display method of the CrudController
121+
* @param object $instance
122+
* @param string $model The model class name (long name)
123+
* @param boolean $modal
124+
* @return \Ajax\semantic\widgets\dataelement\DataElement
125+
*/
117126
public function getModelDataElement($instance,$model,$modal){
118127
$adminRoute = $this->controller->_getBaseRoute ();
119128
$semantic = $this->jquery->semantic ();
@@ -181,14 +190,19 @@ public function getModelDataTable($instances, $model,$totalCount,$page=1) {
181190
return $dataTable;
182191
}
183192

193+
/**
194+
* @param string $model The model class name (long name)
195+
* @param number $totalCount The total count of objects
196+
* @return void|number default : 6
197+
*/
184198
public function recordsPerPage($model,$totalCount=0){
185199
if($totalCount>6)
186200
return 6;
187201
return ;
188202
}
189203

190204
/**
191-
*
205+
* Returns the fields on which a grouping is performed
192206
*/
193207
public function getGroupByFields(){
194208
return;
@@ -203,22 +217,28 @@ public function onGenerateFormField($field){
203217
}
204218

205219

220+
/**
221+
* Returns the dataTable instance for dispaying a list of object
222+
* @param array $instances
223+
* @param string $model
224+
* @param number $totalCount
225+
* @param number $page
226+
* @return DataTable
227+
*/
206228
protected function getDataTableInstance($instances,$model,$totalCount,$page=1):DataTable{
207229
$semantic = $this->jquery->semantic ();
208230
$recordsPerPage=$this->recordsPerPage($model,$totalCount);
231+
$grpByFields=$this->getGroupByFields();
232+
if(is_array($grpByFields)){
233+
$dataTable = $semantic->dataTable( "lv", $model, $instances );
234+
$dataTable->setGroupByFields($grpByFields);
235+
}else{
236+
$dataTable = $semantic->jsonDataTable( "lv", $model, $instances );
237+
}
209238
if(is_numeric($recordsPerPage)){
210-
$grpByFields=$this->getGroupByFields();
211-
if(is_array($grpByFields)){
212-
$dataTable = $semantic->dataTable( "lv", $model, $instances );
213-
$dataTable->setGroupByFields($grpByFields);
214-
}else{
215-
$dataTable = $semantic->jsonDataTable( "lv", $model, $instances );
216-
}
217239
$dataTable->paginate($page,$totalCount,$recordsPerPage,5);
218240
$dataTable->onActiveRowChange('$("#table-details").html("");');
219241
$dataTable->onSearchTerminate('$("#search-query-content").html(data);$("#search-query").show();$("#table-details").html("");');
220-
}else{
221-
$dataTable = $semantic->dataTable( "lv", $model, $instances );
222242
}
223243
return $dataTable;
224244
}
@@ -256,6 +276,11 @@ public function dataTableRowButton(HtmlButton $bt){
256276

257277
}
258278

279+
/**
280+
* To override for modifying the showConfMessage dialog buttons
281+
* @param HtmlButton $confirmBtn The confirmation button
282+
* @param HtmlButton $cancelBtn The cancellation button
283+
*/
259284
public function confirmButtons(HtmlButton $confirmBtn,HtmlButton $cancelBtn){
260285

261286
}

0 commit comments

Comments
 (0)