Skip to content

Commit df8e732

Browse files
authored
Merge pull request #1 from CakeDC/feature/list-fixes
check Auth component loaded & fix list
2 parents cf85e31 + 58b494c commit df8e732

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/Controller/ApiController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ class ApiController extends AppController
3131
public function initialize()
3232
{
3333
parent::initialize();
34-
$this->Auth->allow(['process', 'describe', 'listing']);
34+
if ($this->components()->has('Auth')) {
35+
$this->Auth->allow(['process', 'describe', 'listing']);
36+
}
3537
if ($this->components()->has('RememberMe')) {
3638
$this->components()->unload('RememberMe');
3739
}

src/Service/Action/ListAction.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,18 @@ public function execute()
4444
$path = APP . 'Model' . DS . 'Table';
4545
$folder = new Folder($path);
4646
$tables = $folder->find('.*\.php');
47-
$services = collection($tables)->map(function ($item) {
48-
return Inflector::underscore(str_replace('Table', '', str_replace('.php', '', $item)));
49-
})->toArray();
47+
$services = collection($tables)
48+
->map(function ($item) {
49+
preg_match('/^(.*)Table\.php/', $item, $replacedMatch);
50+
if (empty($replacedMatch[1])) {
51+
return null;
52+
}
53+
return Inflector::underscore($replacedMatch[1]);
54+
})
55+
->filter(function ($item) {
56+
return !empty($item);
57+
})
58+
->toArray();
5059

5160
return $services;
5261
}

0 commit comments

Comments
 (0)