views:

101

answers:

2

I am writing a piece of small software to go through the folders and files of all the php projects that are passed in and detect if any of them is actually also a Zend project. Is there any particular file that I can immediately read and tell that the current project is a Zend project? or is there any convenient way to tell?

+1  A: 

alt text

This is the default directory structure that ZF creates for you when you start a project. So if you're just looking at directory structure this should work.

Alternatively you could look to see if a directory has a hidden file called .zfproject.xml.

I hope that helps!

Thomas
Thanks Thomas. Can you tell me where .zfproject.xml locates exactly? Thanks again.
Winston Chen
Again, is ".zfproject.xml" a must in any zend framework?
Winston Chen
.zfproject.xml is located in the root directory of the project. So, in the above example it would be on the same level as the application, docs, and library directories. That file is automatically created whenever one uses ZF's tool to create a project. I guess it's possible to use ZF without using the tool, but I've never seen it done. Also, the library directory will usually contain a directory called 'Zend'. I would say that with these two criteria you will catch 99% of the Zend projects out there. There's always a chance, however, that somebody will be using a custom setup and... good luck
Thomas
Thanks again, Thomas. You have done such a great help ;)
Winston Chen
+3  A: 

I don't think the above answer heads in the right direction. To begin,

Zend Framework is often called a 'component library', because it has many loosely coupled components that you can use more or less independently.

Source: Zend Framework & MVC Introduction

Assuming that standard use will include both the suggested MVC structure and zftool for project creation is a bad assumption because many projects hand-pick a subset of Zend components to minimize the now 45MB class footprint.

Instead, lets look at a point Thomas hinted at in his answer above:

Also, the library directory will usually contain a directory called 'Zend'.

And now from Zend's Programmer's Reference Guide:

Zend Framework standardizes on a class naming convention whereby the names of the classes directly map to the directories in which they are stored. The root level directory ... is the "Zend/" directory ... All Zend Framework classes are stored hierarchically under these root directories..

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".

Important: Code that must be deployed alongside Zend Framework libraries but is not part of the standard or extras libraries (e.g. application code or libraries that are not distributed by Zend) must never start with "Zend_" or "ZendX_".

Source: Naming Conventions

A better suggestion would be to check for the root directory '/Zend', however this excludes any projects where the developer has decided to forgo the above suggestions and has thrown Zend class files into some global library directory.

The best guess would be to recursively glob all the files in a project's directory looking for class names that match the suggested pseudo namespace (Zend_ ...).

yenta
@Yenta thank you for your detailed explanation. It's really a very good answer.
Winston Chen