Namespaces Naming Convention
#21
Posted 03 April 2013 - 02:59 PM
For example, for models directory, you would need to name it as "Models" so that your model classes could be namespaced as "\My\Models\Post".
However, for other directories not storing PHP classes, you don't want to do so in general.
#22
Posted 03 April 2013 - 03:30 PM
Usually namespaces follow the same naming conventions as the folder structure. I don't know what you've have planned for the folder naming conventions in yii2 but I think that it would be great if it followed the same naming conventions as it's predecessor. In other words it would be something like:
echo \Yii::t(); $obj = new \yii\base\Object();
#23
Posted 03 April 2013 - 03:52 PM
I think your example applies for the application directory (currently "protected"), "public" files are separated anyway and don't have to follow these conventions.
At the moment I can think i.e. example of uploaded data and non-PHP scripts which go also into "protected", but maybe it's time to refactor the protected structure.
I know that the existing one is a very slim implementation and very useful for running your app out-of-the-box from your default webserver root, but I won't sacrifice so much for it.
Fork on github
Follow phundament on Twitter
DevSystem: Mac OS X 10.7 - PHP 5.3 - Apache2 - Yii 1.1 / trunk - Firefox or Safari
#24
Posted 03 April 2013 - 04:01 PM
How would you name your view files and view directories? And what about data directories, etc.?
@Chris83: The current implementation of Yii 2 uses the namespace format like you wrote (same as Yii 1.1). Here we are debating whether we should adopt CamelCase in namespace in Yii 2. So far, I'm most concerned with the mixed use of cases in directory names: class directories use CamelCase, while non-class directories use lower-case, which doesn't look good to me.
#25
Posted 03 April 2013 - 04:13 PM
\_Yii
But may work according to PSR-0
Fork on github
Follow phundament on Twitter
DevSystem: Mac OS X 10.7 - PHP 5.3 - Apache2 - Yii 1.1 / trunk - Firefox or Safari
#26
Posted 03 April 2013 - 04:18 PM
Personally I don't see the mixture as a very crucial point, because it would also indicate a different usage of the contained files.
Fork on github
Follow phundament on Twitter
DevSystem: Mac OS X 10.7 - PHP 5.3 - Apache2 - Yii 1.1 / trunk - Firefox or Safari
#27
Posted 03 April 2013 - 05:04 PM
root app config application.php theme bootstrap views site home.php ... src Component Form.php ... Controller Site.php AnotherController.php ... Model Site.php AnotherModel.php ... Module Shop Controller Product.php ShoppingCart.php ... Model Product.php ShoppingCart.php ... Resource views product index.php ... shopping-cart summary.twig ... Resource assets css site.css js site.js views site home.php another-page.tpl another-controller index.twig ... vendor yii src Application Console.php Rest.php Web.php ... Base ... Component ... ... www assets ... index.php
#28
Posted 03 April 2013 - 10:17 PM
I actually start liking the idea of Uppercase names for folders which (only) contain PHP classes in a namespace.
I think it even helps understanding how a application works.
. ├── app │ ├── config │ ├── data │ │ └── upload │ ├── messages │ │ └── de │ ├── runtime │ ├── tests │ └── themes (views) │ ├── backend │ └── frontend ├── src │ ├── Commands │ │ └── views │ ├── Components │ ├── Controllers │ ├── Extensions │ ├── Models │ ├── Modules │ └── Phundament ├── vendor │ └── yiisoft │ └── yii └── www ├── assets ├── images ├── runtime └── themes ├── backend └── frontend
app and src could also be combined.
. ├── app-src │ ├── Commands │ │ └── views │ ├── Components │ ├── config │ ├── Controllers │ ├── data │ │ └── p3media │ ├── messages │ │ └── de │ ├── Models │ ├── runtime │ ├── tests │ └── themes (views) │ ├── backend │ └── frontend ├── vendor │ └── yiisoft │ └── yii └── www ├── assets ├── images ├── runtime └── themes ├── backend └── frontend
Here's how Symfony does it: https://github.com/s...ymfony-standard ... somehow similar to the solutions above.
Fork on github
Follow phundament on Twitter
DevSystem: Mac OS X 10.7 - PHP 5.3 - Apache2 - Yii 1.1 / trunk - Firefox or Safari
#29
Posted 04 April 2013 - 07:33 PM
https://github.com/a...ucture-proposal
It could be better documented, but I will try to do it shortly, depending on the feedback from others.
Since this is also related to the skeleton application, I posted a comment where I judge is a proper place:
https://github.com/y...omment-15932432
#30
Posted 05 April 2013 - 05:28 AM
@Qiang: I don't think Yii 2 should use CamelCase for namespaces unless it's absolutely necessary. I share your concerns in this matter.
#31
Posted 05 April 2013 - 05:55 AM
IMHO it would be really annoying, when working with namespaces in Yii2, that the namespace syntax would be mixed all the time.
$obj = new \yii\base\Object(); $foo = new \Another\Base\Object(); use Composer\Script\Event; use yii\console\script\Event; use \Monolog use \yii\log\Logger;

Btw: PSR-0 uses only CamelCase in it's examples.
Fork on github
Follow phundament on Twitter
DevSystem: Mac OS X 10.7 - PHP 5.3 - Apache2 - Yii 1.1 / trunk - Firefox or Safari
#32
Posted 05 April 2013 - 06:05 AM
schmunk, on 05 April 2013 - 05:55 AM, said:
IMHO it would be really annoying, when working with namespaces in Yii2, that the namespace syntax would be mixed all the time.
$obj = new \yii\base\Object(); $foo = new \Another\Base\Object(); use Composer\Script\Event; use yii\console\script\Event; use \Monolog use \yii\log\Logger;

Btw: PSR-0 uses only CamelCase in it's examples.
I share your pain

I would like to also point out that this is the time for this kind of changes.
Leave as it is, so it looks familiar with the current implementation should not be a big concern.
Yii2 is jumping to the next generation and I have high hopes that it is going to set the new top standard.
#33
Posted 05 April 2013 - 06:11 AM
schmunk, on 05 April 2013 - 05:55 AM, said:
IMHO it would be really annoying, when working with namespaces in Yii2, that the namespace syntax would be mixed all the time.
$obj = new \yii\base\Object(); $foo = new \Another\Base\Object(); use Composer\Script\Event; use yii\console\script\Event; use \Monolog use \yii\log\Logger;

Btw: PSR-0 uses only CamelCase in it's examples.
Agree. +1
#34
Posted 05 April 2013 - 06:49 AM
#35
Posted 05 April 2013 - 06:57 AM
I'm not totally against using CamelCase in namespace because it has its pros as you explained.
But I'm very bothered by the inconsistent naming in directories, and also as Mike wrote, it's uncommon to use upper case in directory names.
@schmunk: even if the directories are organized as you proposed, there are still cases that directories are named differently under the same directory, which is confusing. And another minor issue is: should the names be plural or not.
#36
Posted 05 April 2013 - 07:08 AM
Quote
I think that has been changed for many PHP projects, eg. Composer.
Quote
You mean eg. "views"?
Quote
Haven't thought about it, but I'd tend to singular, eg. Monolog.
Fork on github
Follow phundament on Twitter
DevSystem: Mac OS X 10.7 - PHP 5.3 - Apache2 - Yii 1.1 / trunk - Firefox or Safari
#37
Posted 05 April 2013 - 07:28 AM
- lowercase directory names
- CamelCase class names
- plural base folder names (components, models, extensions etc)
imho it doesnt violate psr-0
compare
https://github.com/g.../ItemStore.java
https://github.com/s...rnel/Client.php
#38
Posted 05 April 2013 - 02:12 PM
Besides I like the current folder naming conventions in Yii, both the casing and plural form. I kind of dislike the CamelCase singular directory names, it feels a bit less natural.
#39
Posted 05 April 2013 - 02:37 PM
On file systems that are case sensitive it may cause more problems than before. I've seen many people deploying code from a windows machine to a linux server and wondering why it did not work there.
I haven't heard really good arguments except "All the other do it like this." for CamelCase namespaces...
I think we can agree that namespaces should reflect the directory structure and so lowerCase directory names will result in lowerCase name spaces. As Mike pointed out it is very uncommon to name directories in CamelCase on a linux system. On a terminal to create a directory or to go into you always have to remember to type the right case when you want to enter a directory. This is a bit annoying when you have CamelCase but even more when you have a mixed structure.
Unless there is a really good reason we should not use a possibly confusing convention.
Btw, Müller: Why is "Resource"-directory UpperCase in your example? it does not contain any classes...
#40
Posted 05 April 2013 - 03:40 PM
Mike, Chris83 and CeBe have outlined the best arguments. Plus, the less we have to press [shift], the better.
For singular x plural names for the directories, I'm slightly in favor of singular, but either one is good.