codeigniter4 / CodeIgniter4

Open Source PHP Framework (originally from EllisLab)
https://codeigniter.com/
MIT License
5.35k stars 1.9k forks source link

Bug: Wrong destination folder in generators if name is contained in APP_NAMESPACE #4959

Closed nynsen closed 3 years ago

nynsen commented 3 years ago

When using CLI Generators (aka spark) the file is generated in the wrong folder if the provided name is contained in the APP_NAMESPACE config var.

CodeIgniter 4 version 4.1.3

Example scenario N.B.: The default namespace is App

$ php spark make:controller attachment
CodeIgniter v4.1.3 Command Line Tool - Server Time: 2021-07-23 17:31:22 UTC+02:00

File created: APPPATH/Controllers/Attachment.php

$ php spark make:controller appointment
CodeIgniter v4.1.3 Command Line Tool - Server Time: 2021-07-23 17:32:28 UTC+02:00

File created: APPPATH/Appointment.php

The file Appointment.php should be generated in APPPATH/Controllers/Appointment.php. The same happens for the other generators and also in scaffolding.

Affected module(s) I traced down the problem to Line 346 in APPPATH/../framework/system/CLI/GeneratorTrait/GeneratorTrait.php

$file = $base . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, trim(str_replace($namespace . '\\', '', $class), '\\')) . '.php';

Context Ubuntu 20.04 LTS / bash / PHP 7.4 (ondrey)

paulbalandan commented 3 years ago

Hi, can you check if your issue is the same with #4857 ? If yes, there's already a fix for that: #4867

paulbalandan commented 3 years ago

Just tested this with the latest 4.2 branch and the issue is definitely fixed by that PR. Closing as duplicate.