Using @property to autocomplete components and helpers in some IDEs. Also added @property to bake of controller and model. Fixes #103.

This commit is contained in:
Juan Basso 2011-07-31 20:28:35 -04:00
parent 7604763888
commit d84531d29c
11 changed files with 54 additions and 1 deletions

View file

@ -24,6 +24,17 @@ echo "<?php\n";
/** /**
* <?php echo $controllerName; ?> Controller * <?php echo $controllerName; ?> Controller
* *
<?php
if (!$isScaffold) {
$defaultModel = Inflector::singularize($controllerName);
echo " * @property {$defaultModel} \${$defaultModel}\n";
if (!empty($components)) {
foreach ($components as $component) {
echo " * @property {$component}Component \${$component}\n";
}
}
}
?>
*/ */
class <?php echo $controllerName; ?>Controller extends <?php echo $plugin; ?>AppController { class <?php echo $controllerName; ?>Controller extends <?php echo $plugin; ?>AppController {

View file

@ -23,6 +23,15 @@ echo "<?php\n"; ?>
/** /**
* <?php echo $name ?> Model * <?php echo $name ?> Model
* *
<?php
foreach (array('hasOne', 'belongsTo', 'hasMany', 'hasAndBelongsToMany') as $assocType) {
if (!empty($associations[$assocType])) {
foreach ($associations[$assocType] as $relation) {
echo " * @property {$relation['className']} \${$relation['alias']}\n";
}
}
}
?>
*/ */
class <?php echo $name ?> extends <?php echo $plugin; ?>AppModel { class <?php echo $name ?> extends <?php echo $plugin; ?>AppModel {
<?php if ($useDbConfig != 'default'): ?> <?php if ($useDbConfig != 'default'): ?>

View file

@ -47,6 +47,14 @@ App::uses('View', 'View');
* using Router::connect(). * using Router::connect().
* *
* @package Cake.Controller * @package Cake.Controller
* @property AclComponent $Acl
* @property AuthComponent $Auth
* @property CookieComponent $Cookie
* @property EmailComponent $Email
* @property PaginatorComponent $Paginator
* @property RequestHandlerComponent $RequestHandler
* @property SecurityComponent $Security
* @property SessionComponent $Session
* @link http://book.cakephp.org/view/956/Introduction * @link http://book.cakephp.org/view/956/Introduction
*/ */
class Controller extends Object { class Controller extends Object {

View file

@ -270,6 +270,9 @@ class ControllerTaskTest extends CakeTestCase {
$this->Task->expects($this->any())->method('createFile')->will($this->returnValue(true)); $this->Task->expects($this->any())->method('createFile')->will($this->returnValue(true));
$result = $this->Task->bake('Articles', '--actions--', $helpers, $components); $result = $this->Task->bake('Articles', '--actions--', $helpers, $components);
$this->assertContains(' * @property Article $Article', $result);
$this->assertContains(' * @property AclComponent $Acl', $result);
$this->assertContains(' * @property AuthComponent $Auth', $result);
$this->assertContains('class ArticlesController extends AppController', $result); $this->assertContains('class ArticlesController extends AppController', $result);
$this->assertContains("\$components = array('Acl', 'Auth')", $result); $this->assertContains("\$components = array('Acl', 'Auth')", $result);
$this->assertContains("\$helpers = array('Ajax', 'Time')", $result); $this->assertContains("\$helpers = array('Ajax', 'Time')", $result);
@ -278,11 +281,13 @@ class ControllerTaskTest extends CakeTestCase {
$result = $this->Task->bake('Articles', 'scaffold', $helpers, $components); $result = $this->Task->bake('Articles', 'scaffold', $helpers, $components);
$this->assertContains("class ArticlesController extends AppController", $result); $this->assertContains("class ArticlesController extends AppController", $result);
$this->assertContains("public \$scaffold", $result); $this->assertContains("public \$scaffold", $result);
$this->assertNotContains('@property', $result);
$this->assertNotContains('helpers', $result); $this->assertNotContains('helpers', $result);
$this->assertNotContains('components', $result); $this->assertNotContains('components', $result);
$result = $this->Task->bake('Articles', '--actions--', array(), array()); $result = $this->Task->bake('Articles', '--actions--', array(), array());
$this->assertContains('class ArticlesController extends AppController', $result); $this->assertContains('class ArticlesController extends AppController', $result);
$this->assertIdentical(substr_count($result, '@property'), 1);
$this->assertNotContains('components', $result); $this->assertNotContains('components', $result);
$this->assertNotContains('helpers', $result); $this->assertNotContains('helpers', $result);
$this->assertContains('--actions--', $result); $this->assertContains('--actions--', $result);

View file

@ -726,6 +726,10 @@ STRINGEND;
) )
); );
$result = $this->Task->bake('BakeArticle', compact('associations')); $result = $this->Task->bake('BakeArticle', compact('associations'));
$this->assertContains(' * @property BakeUser $BakeUser', $result);
$this->assertContains(' * @property OtherModel $OtherModel', $result);
$this->assertContains(' * @property BakeComment $BakeComment', $result);
$this->assertContains(' * @property BakeTag $BakeTag', $result);
$this->assertPattern('/\$hasAndBelongsToMany \= array\(/', $result); $this->assertPattern('/\$hasAndBelongsToMany \= array\(/', $result);
$this->assertPattern('/\$hasMany \= array\(/', $result); $this->assertPattern('/\$hasMany \= array\(/', $result);
$this->assertPattern('/\$belongsTo \= array\(/', $result); $this->assertPattern('/\$belongsTo \= array\(/', $result);

View file

@ -27,6 +27,7 @@ App::uses('AppHelper', 'View/Helper');
* Automatic generation of HTML FORMs from given data. * Automatic generation of HTML FORMs from given data.
* *
* @package Cake.View.Helper * @package Cake.View.Helper
* @property HtmlHelper $Html
* @link http://book.cakephp.org/view/1383/Form * @link http://book.cakephp.org/view/1383/Form
*/ */
class FormHelper extends AppHelper { class FormHelper extends AppHelper {

View file

@ -28,6 +28,8 @@ App::uses('Multibyte', 'I18n');
* given client-side library. * given client-side library.
* *
* @package Cake.View.Helper * @package Cake.View.Helper
* @property HtmlHelper $Html
* @property FormHelper $Form
*/ */
class JsHelper extends AppHelper { class JsHelper extends AppHelper {
/** /**

View file

@ -25,6 +25,7 @@ App::uses('AppHelper', 'View/Helper');
* PaginationHelper encloses all methods needed when working with pagination. * PaginationHelper encloses all methods needed when working with pagination.
* *
* @package Cake.View.Helper * @package Cake.View.Helper
* @property HtmlHelper $Html
* @link http://book.cakephp.org/view/1458/Paginator * @link http://book.cakephp.org/view/1458/Paginator
*/ */
class PaginatorHelper extends AppHelper { class PaginatorHelper extends AppHelper {

View file

@ -24,6 +24,7 @@ App::uses('Xml', 'Utility');
* RSS Helper class for easy output RSS structures. * RSS Helper class for easy output RSS structures.
* *
* @package Cake.View.Helper * @package Cake.View.Helper
* @property TimeHelper $Time
* @link http://book.cakephp.org/view/1460/RSS * @link http://book.cakephp.org/view/1460/RSS
*/ */
class RssHelper extends AppHelper { class RssHelper extends AppHelper {

View file

@ -33,6 +33,7 @@ App::uses('Multibyte', 'I18n');
* Text manipulations: Highlight, excerpt, truncate, strip of links, convert email addresses to mailto: links... * Text manipulations: Highlight, excerpt, truncate, strip of links, convert email addresses to mailto: links...
* *
* @package Cake.View.Helper * @package Cake.View.Helper
* @property HtmlHelper $Html
* @link http://book.cakephp.org/view/1469/Text * @link http://book.cakephp.org/view/1469/Text
*/ */
class TextHelper extends AppHelper { class TextHelper extends AppHelper {

View file

@ -34,6 +34,16 @@ App::uses('Router', 'Routing');
* layout using `$this->set()` * layout using `$this->set()`
* *
* @package Cake.View * @package Cake.View
* @property CacheHelper $Cache
* @property FormHelper $Form
* @property HtmlHelper $Html
* @property JsHelper $Js
* @property NumberHelper $Number
* @property PaginatorHelper $Paginator
* @property RssHelper $Rss
* @property SessionHelper $Session
* @property TextHelper $Text
* @property TimeHelper $Time
*/ */
class View extends Object { class View extends Object {