Skip to content

Commit

Permalink
Merge pull request #1496 from BeMySlaveDarlin/fix/issue-1467-fix-empt…
Browse files Browse the repository at this point in the history
…y-namespace-generation

ISSUE-1467: Fixed empty namespace generating
  • Loading branch information
Jeckerson authored Mar 22, 2021
2 parents 5799835 + 0ef84da commit fa9bfbe
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- Added trailing semicolon to scaffolding crud views getters [#1477](https://github.com/phalcon/phalcon-devtools/issues/1477)
- Fixed optional options (namespace, abstract) checks on model create [#1491](https://github.com/phalcon/phalcon-devtools/issues/1491)
- Fixed wrong request filtering [#1468](https://github.com/phalcon/phalcon-devtools/issues/1468)
- Fixed empty namespace generation [#1467](https://github.com/phalcon/phalcon-devtools/issues/1467)

# [4.0.5](https://github.com/phalcon/cphalcon/releases/tag/v4.0.5) (2021-03-14)
## Fixed
Expand Down
6 changes: 4 additions & 2 deletions src/Builder/Component/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,14 @@ public function build()
*/
protected function constructNamespace(): string
{
$namespace = $this->options->get('namespace');
$namespace = $this->options->has('namespace')
? (string) $this->options->get('namespace') : null;

if ($namespace === null) {
return '';
}

if ($this->checkNamespace((string)$namespace)) {
if ($this->checkNamespace($namespace) && !empty(trim($namespace))) {
return 'namespace ' . $this->options->get('namespace') . ';' . PHP_EOL . PHP_EOL;
}

Expand Down
7 changes: 4 additions & 3 deletions src/Builder/Component/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,10 @@ public function build(): void
require_once $config->devtools->loader;
}

$namespace = '';
if ($this->modelOptions->hasOption('namespace') &&
$this->checkNamespace((string)$this->modelOptions->getOption('namespace'))) {
$namespace = $this->modelOptions->hasOption('namespace')
? (string) $this->modelOptions->getOption('namespace') : '';

if ($this->checkNamespace($namespace) && !empty(trim($namespace))) {
$namespace = 'namespace ' . $this->modelOptions->getOption('namespace') . ';' . PHP_EOL . PHP_EOL;
}

Expand Down
11 changes: 5 additions & 6 deletions src/Builder/Component/Scaffold.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,14 +459,13 @@ private function makeController(): void
$code = file_get_contents($this->options->get('templatePath') . '/scaffold/no-forms/Controller.php');
$usesNamespaces = false;

$controllerNamespace = (string)$this->options->get('controllersNamespace');
if ($this->options->has('controllersNamespace') &&
$controllerNamespace &&
$this->checkNamespace($controllerNamespace)
) {
$controllerNamespace = $this->options->has('controllersNamespace')
? (string) $this->options->get('controllersNamespace') : '';

if (!empty(trim($controllerNamespace)) && $this->checkNamespace($controllerNamespace)) {
$code = str_replace(
'$namespace$',
'namespace ' . $this->options->get('controllersNamespace').';' . PHP_EOL,
'namespace ' . $controllerNamespace.';' . PHP_EOL,
$code
);
$usesNamespaces = true;
Expand Down

0 comments on commit fa9bfbe

Please sign in to comment.