Browse Source

ZF-9045
- Added DocsDirectory context
- Added support to default project structure to make a README file

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@20898 44c647ce-9c0f-0410-b52a-842ac1e357ba

ralph 16 years ago
parent
commit
42df123500

+ 37 - 2
library/Zend/Tool/Project/Context/Filesystem/File.php

@@ -39,6 +39,12 @@ require_once 'Zend/Tool/Project/Context/Filesystem/Abstract.php';
 class Zend_Tool_Project_Context_Filesystem_File extends Zend_Tool_Project_Context_Filesystem_Abstract
 {
 
+    protected $_fileOnlyContext = null;
+    
+    protected $_filesystemName = 'file.txt';
+    
+    protected $_content = null;
+    
     /**
      * getName()
      * 
@@ -56,7 +62,16 @@ class Zend_Tool_Project_Context_Filesystem_File extends Zend_Tool_Project_Contex
      */
     public function init()
     {
-        // @todo check to ensure that this 'file' resource has no children
+        if ($this->_resource->hasAttribute('filesystemName')) {
+            $this->_filesystemName = $this->_resource->getAttribute('filesystemName');
+        }
+        
+        // check to see if this file is 
+        if ($this->getName() == 'file') {
+            $this->_initFileOnlyContext();
+        }
+        
+        // @potential-todo check to ensure that this 'file' resource has no children
         parent::init();
         return $this;
     }
@@ -72,6 +87,16 @@ class Zend_Tool_Project_Context_Filesystem_File extends Zend_Tool_Project_Contex
         $this->_resource->setAppendable(false);
         return $this;
     }
+    
+    /**
+     * getResource()
+     * 
+     * @return Zend_Tool_Project_Profile_Resource
+     */
+    public function getResource()
+    {
+        return $this->_resource;
+    }
 
     /**
      * create()
@@ -116,7 +141,17 @@ class Zend_Tool_Project_Context_Filesystem_File extends Zend_Tool_Project_Contex
      */
     public function getContents()
     {
-        return null;
+        return $this->_content;
     }
 
+    protected function _initFileOnlyContext()
+    {
+        if ($this->_resource->hasAttribute('defaultContentCallback')) {
+            $contentFunc = $this->_resource->getAttribute('defaultContentCallback');
+            if (is_callable($contentFunc)) {
+                $this->_content = call_user_func_array($contentFunc, array($this));
+            }
+        }
+    }
+    
 }

+ 61 - 0
library/Zend/Tool/Project/Context/Zf/DocsDirectory.php

@@ -0,0 +1,61 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Tool
+ * @subpackage Framework
+ * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id: DataDirectory.php 20096 2010-01-06 02:05:09Z bkarwin $
+ */
+
+/**
+ * @see Zend_Tool_Project_Context_Filesystem_Directory
+ */
+require_once 'Zend/Tool/Project/Context/Filesystem/Directory.php';
+
+/**
+ * This class is the front most class for utilizing Zend_Tool_Project
+ *
+ * A profile is a hierarchical set of resources that keep track of
+ * items within a specific project.
+ *
+ * @category   Zend
+ * @package    Zend_Tool
+ * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Tool_Project_Context_Zf_DocsDirectory extends Zend_Tool_Project_Context_Filesystem_Directory
+{
+
+    /**
+     * @var string
+     */
+    protected $_filesystemName = 'docs';
+
+    /**
+     * getName()
+     *
+     * @return string
+     */
+    public function getName()
+    {
+        return 'DocsDirectory';
+    }
+    
+    public function create(){
+        parent::create();
+    }
+
+}

+ 55 - 1
library/Zend/Tool/Project/Provider/Project.php

@@ -90,7 +90,13 @@ class Zend_Tool_Project_Provider_Project
 
         $newProfile->loadFromData();
 
-        $this->_registry->getResponse()->appendContent('Creating project at ' . $path);
+        $response = $this->_registry->getResponse();
+        
+        $response->appendContent('Creating project at ' . $path);
+        $response->appendContent('Note: ', array('separator' => false, 'color' => 'yellow'));
+        $response->appendContent(
+            'This command created a web project, '
+            . 'for more information setting up your VHOST, please see docs/README');
 
         foreach ($newProfile->getIterator() as $resource) {
             $resource->create();
@@ -156,6 +162,9 @@ class Zend_Tool_Project_Provider_Project
             <sessionsDirectory enabled="false" />
             <uploadsDirectory enabled="false" />
         </dataDirectory>
+        <docsDirectory>
+            <file filesystemName="README.txt" defaultContentCallback="Zend_Tool_Project_Provider_Project::getDefaultReadmeContents"/>
+        </docsDirectory>
         <libraryDirectory>
             <zfStandardLibraryDirectory enabled="false" />
         </libraryDirectory>
@@ -182,4 +191,49 @@ class Zend_Tool_Project_Provider_Project
 EOS;
         return $data;
     }
+    
+    public static function getDefaultReadmeContents($caller = null)
+    {
+        $projectDirResource = $caller->getResource()->getProfile()->search('projectDirectory');
+        if ($projectDirResource) {
+            $name = ltrim(strrchr($projectDirResource->getPath(), DIRECTORY_SEPARATOR), DIRECTORY_SEPARATOR);
+            $path = $projectDirResource->getPath() . '/public';
+        } else {
+            $path = '/path/to/public';
+        }
+        
+        return <<< EOS
+README
+======
+
+This directory should be used to place project specfic documentation including
+but not limited to project notes, generated API/phpdoc documentation, or 
+manual files generated or hand written.  Ideally, this directory would remain
+in your development environment only and should not be deployed with your
+application to it's final production location.
+
+
+Setting Up Your VHOST
+=====================
+
+The following is a sample VHOST you might want to consider for your project.
+
+<VirtualHost *:80>
+   DocumentRoot "$path"
+   ServerName $name.local
+
+   # This should be omitted in the production environment
+   SetEnv APPLICATION_ENV development
+    
+   <Directory "$path">
+       Options Indexes MultiViews FollowSymLinks
+       AllowOverride All
+       Order allow,deny
+       Allow from all
+   </Directory>
+    
+</VirtualHost>
+
+EOS;
+    }
 }