开发者

Zend Framework class filenames in windows vs. linux

Background: We often work on web applications which are developed in PHP (Zend Framework) and hosted on a linux server. The programming team may consist of individuals that may use either Linux or Windows for their local development platform.

Because Zend model names are mapped into filenames, case matters. A programmer may write $this->something, where "something" is a model that has a filename on the linux server of "Something.php".

His code will work fine on his Windows development PC, because "something" will correctly map to "Something.php" on windows. But when uploaded to the linux server, the code will break because the filename is case-sensitive on Linux. He should have written the code as "$this->Something".

So finally my question, is there a Zend Framework conf开发者_开发问答iguration that will generate an error even in Windows, if the system detects that the case of the model name in code doesn't match the case of the actual filename in the filesystem?


So finally my question, is there a Zend Framework configuration that will generate an error even in Windows, if the system detects that the case of the model name in code doesn't match the case of the actual filename in the filesystem?

Not that I'm aware of, but it would be pretty easy to add some checks in to a copy of ZF on a development server / workstation. ZF uses spl_autoload_register to load classes, and all the logic to convert class names to filesystem locations lives in the Loader namespace.

HTH.


ZF Naming Conventions

Zend Framework coding convention state that you should use uppercase names. Some of the conventions are as important to follow as the API docs themself.

http://framework.zend.com/manual/en/coding-standard.naming-conventions.html

If a class name is comprised of more than one word, the first letter of each new word must be capitalized. Successive capitalized letters are not allowed, e.g. a class "Zend_PDF" is not allowed while "Zend_Pdf" is acceptable.

and

Class names may only contain alphanumeric characters. Numbers are permitted in class names but are discouraged in most cases. Underscores are only permitted in place of the path separator; the filename "Zend/Db/Table.php" must map to the class name "Zend_Db_Table".

As a note, your example provided was wrong. But in any event, keep your model names all uppercase, and the path to the models also uppercase inline with the ZF naming conventions.


Maybe something like PHP_CodeSniffer might help you.

Never tried it, but from what I understand, you can define rules to validate your code, thus define rules based on the filename case for your problem.

There is a already defined Zend ruleset from what I read, maybe it already has this kind of rule enclosed (or maybe the PEAR ruleset also).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜