Not so long ago
, the first alpha Yii 2
came out , you can already get acquainted with it in more detail.
After numerous debates, the authors chose small letters for spaces. And they can not be condemned for it. After all, all the arguments in favor of one option or another boil down to personal preferences.
A similar case with the endless war "spaces vs. tabulation. We just say: "Get over it, do not worry."
')
OK. I try to accept it. Even the first time it turned out, who cares what is inside the framework. But nothing works.
namespace app\controllers; use yii\web\Controller; use Zend\Barcode\Barcode; class SiteController extends Controller { }
I'm not comfortable when in the application here is such a mess.
Spaces and tabs can be inter replaced. Git hooks or IDE will do this very quickly. It’s harder with spaces, but it won’t stop us :)
Remember that in PHP classes are not case sensitive, it only remains to import the desired file.
To do this, add the required class autoloader, you need to do this after registering the Yii loader.
spl_autoload_register(function ($class) { if (0 === strncmp($class, 'Yii\\', 4)) { $pos = strrpos($class, '\\'); $parts = explode('\\', substr($class, 0, $pos)); array_walk( $parts, function (&$item) { $item = lcfirst($item); } ); spl_autoload_call( implode('\\', $parts) . '\\' . substr($class, $pos + 1) ); return true; } return false; });
The code is in the
repository , if you use Composer, you can add the following dependency
"repositories": [ { "type": "package", "package": { "name": "slavcodev/ucfirst-namespace", "version": "dev-master", "source": { "type": "git", "url": "https://github.com/slavcodev/yii2-ucfirst-namespace.git", "reference": "master" }, "autoload": { "files": ["autoload.php"] } } } ], "require": { "php": ">=5.4.0", "ext-intl": "*", "yiisoft/yii2": "*", "slavcodev/ucfirst-namespace": "*" }
Everything is now in order.
namespace App\Controllers; use Yii\Web\Controller; use Zend\Barcode\Barcode; class SiteController extends Controller { }
PS I beg you not to arrange in the holivar comments and not to express your indignation towards the decision of the developers. Let's concentrate on the text of the post, maybe you have comments or ideas on how to improve the code. Thank.