Skip to content

Commit

Permalink
Refactored application to follow current suggested directory structur…
Browse files Browse the repository at this point in the history
…e and best practices
  • Loading branch information
weierophinney authored and Matthew Weier O'Phinney committed Sep 26, 2008
1 parent 9ecd189 commit f26e5d4
Show file tree
Hide file tree
Showing 42 changed files with 171 additions and 197 deletions.
2 changes: 2 additions & 0 deletions application/bootstrap.php
Expand Up @@ -4,6 +4,8 @@
defined('APPLICATION_STATE')
or define('APPLICATION_STATE', 'development');

require_once APPLICATION_PATH . '/plugins/Initialize.php';

$front = Zend_Controller_Front::getInstance();
$front->registerPlugin(new Bugapp_Plugin_Initialize(APPLICATION_STATE, APPLICATION_PATH))
->addControllerDirectory(APPLICATION_PATH . '/controllers');
10 changes: 0 additions & 10 deletions application/config/development.php

This file was deleted.

4 changes: 0 additions & 4 deletions application/config/production.php

This file was deleted.

9 changes: 9 additions & 0 deletions application/config/site.ini
@@ -0,0 +1,9 @@
[production]
showExceptions = false
db.adapter = "pdo_sqlite"
db.params.dbname = APPLICATION_PATH "/../data/db/bugs.db"

[development : production]
showExceptions = true

[test : production]
13 changes: 0 additions & 13 deletions application/config/site.php

This file was deleted.

3 changes: 0 additions & 3 deletions application/config/test.php

This file was deleted.

@@ -1,8 +1,28 @@
<?php
class Bugapp_Helper_GetForm extends Zend_Controller_Action_Helper_Abstract
{
/**
* @var array Form instances
*/
protected $_forms = array();

/**
* @var Zend_Loader_PluginLoader
*/
protected $_loader;

/**
* Initialize plugin loader for forms
*
* @return void
*/
public function __construct()
{
$this->_loader = new Zend_Loader_PluginLoader(array(
'Bugapp_Form' => APPLICATION_PATH . '/forms',
));
}

/**
* Load and return a form object
*
Expand All @@ -12,12 +32,11 @@ class Bugapp_Helper_GetForm extends Zend_Controller_Action_Helper_Abstract
*/
public function getForm($form, $config = null)
{
$form = ucfirst($form);
$class = 'Bugapp_Form_' . $form;
if (!array_key_exists($class, $this->_forms)) {
$this->_forms[$class] = new $class($config);
if (!array_key_exists($form, $this->_forms)) {
$class = $this->_loader->load($form);
$this->_forms[$form] = new $class($config);
}
return $this->_forms[$class];
return $this->_forms[$form];
}

/**
Expand Down
43 changes: 43 additions & 0 deletions application/controllers/helpers/GetModel.php
@@ -0,0 +1,43 @@
<?php
class Bugapp_Helper_GetModel extends Zend_Controller_Action_Helper_Abstract
{
/**
* @var Zend_Loader_PluginLoader
*/
protected $_loader;

/**
* Initialize plugin loader for models
*
* @return void
*/
public function __construct()
{
$this->_loader = new Zend_Loader_PluginLoader(array(
'Bugapp' => APPLICATION_PATH . '/models',
));
}

/**
* Load a model class and return an object instance
*
* @param string $model
* @return object
*/
public function getModel($model)
{
$class = $this->_loader->load($model);
return new $class;
}

/**
* Proxy to getModel()
*
* @param string $model
* @return object
*/
public function direct($model)
{
return $this->getModel($model);
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -3,17 +3,16 @@ class Bugapp_Form_Register extends Zend_Form
{
public function init()
{
$root = Bugapp_Plugin_Initialize::getConfig()->root;
require_once $root . '/models/User.php';
require_once APPLICATION_PATH . '/models/User.php';

$this->addElementPrefixPath('Bugapp_Validate', 'Bugapp/Validate/', 'validate');
$this->addElementPrefixPath('Bugapp_Validate', APPLICATION_PATH . '/models/Validate/', 'validate');

$username = $this->addElement('text', 'username', array(
'filters' => array('StringTrim', 'StringToLower'),
'validators' => array(
'Alpha',
array('StringLength', true, array(3, 20)),
array('UniqueUsername', false, array(new Model_User())),
array('UniqueUsername', false, array(new Bugapp_User())),
),
'required' => true,
'label' => 'Desired username:',
Expand All @@ -32,7 +31,7 @@ public function init()
'filters' => array('StringTrim'),
'validators' => array(
array('EmailAddress', true),
array('UniqueUsername', true, array(new Model_User())),
array('UniqueUsername', true, array(new Bugapp_User())),
),
'required' => false,
'label' => 'Your email address:',
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions application/models/Bug.php
@@ -1,5 +1,5 @@
<?php
require_once dirname(__FILE__) . '/AModel.php';
require_once dirname(__FILE__) . '/Model.php';

/**
* Bug application model
Expand All @@ -10,7 +10,7 @@
* @license New BSD {@link http://framework.zend.com/license/new-bsd}
* @version $Id: $
*/
class Model_Bug extends Model_AModel
class Bugapp_Bug extends Bugapp_Model
{
/**
* Primary table for operations
Expand Down Expand Up @@ -38,7 +38,7 @@ class Model_Bug extends Model_AModel
*
* @param string $field
* @param string $direction
* @return Model_Bug
* @return Bugapp_Bug
*/
public function setSortOrder($field, $direction)
{
Expand All @@ -51,7 +51,7 @@ public function setSortOrder($field, $direction)
*
* @param string $field
* @param string $direction
* @return Model_Bug
* @return Bugapp_Bug
*/
public function addSortOrder($field, $direction)
{
Expand Down Expand Up @@ -391,7 +391,7 @@ protected function _getSelect()
* @param Zend_Db_Table_Select $select
* @param int|null $limit
* @param int|null $offset
* @return Model_Bug
* @return Bugapp_Bug
*/
protected function _setLimit(Zend_Db_Table_Select $select, $limit, $offset)
{
Expand All @@ -409,7 +409,7 @@ protected function _setLimit(Zend_Db_Table_Select $select, $limit, $offset)
* Set sort order on select object
*
* @param Zend_Db_Table_Select $select
* @return Model_Bug
* @return Bugapp_Bug
*/
protected function _setSort(Zend_Db_Table_Select $select)
{
Expand Down
4 changes: 2 additions & 2 deletions application/models/Comment.php
@@ -1,5 +1,5 @@
<?php
require_once dirname(__FILE__) . '/AModel.php';
require_once dirname(__FILE__) . '/Model.php';

/**
* Comment model
Expand All @@ -10,7 +10,7 @@
* @license New BSD {@link http://framework.zend.com/license/new-bsd}
* @version $Id: $
*/
class Model_Comment extends Model_AModel
class Bugapp_Comment extends Bugapp_Model
{
/**
* Primary table for operations
Expand Down
Expand Up @@ -5,30 +5,30 @@
require_once dirname(__FILE__) . '/ResolutionType.php';
require_once dirname(__FILE__) . '/PriorityType.php';

class Model_Table_Bug extends Zend_Db_Table
class Bugapp_DbTable_Bug extends Zend_Db_Table
{
protected $_name = 'bug';
protected $_primary = 'id';

protected $_dependentTables = array(
'Model_Table_BugRelation',
'Model_Table_Comment',
'Bugapp_DbTable_BugRelation',
'Bugapp_DbTable_Comment',
);

protected $_referenceMap = array(
'IssueType' => array(
'columns' => 'type_id',
'refTableClass' => 'Model_Table_IssueType',
'refTableClass' => 'Bugapp_DbTable_IssueType',
'refColumns' => 'id',
),
'ResolutionType' => array(
'columns' => 'resolution_id',
'refTableClass' => 'Model_Table_ResolutionType',
'refTableClass' => 'Bugapp_DbTable_ResolutionType',
'refColumns' => 'id',
),
'PriorityType' => array(
'columns' => 'priority_id',
'refTableClass' => 'Model_Table_PriorityType',
'refTableClass' => 'Bugapp_DbTable_PriorityType',
'refColumns' => 'id',
),
);
Expand Down
Expand Up @@ -2,25 +2,25 @@
require_once dirname(__FILE__) . '/Bug.php';
require_once dirname(__FILE__) . '/RelationType.php';

class Model_Table_BugRelation extends Zend_Db_Table
class Bugapp_DbTable_BugRelation extends Zend_Db_Table
{
protected $_name = 'bug_relation';
protected $_primary = 'id';

protected $_referenceMap = array(
'BugChildren' => array(
'columns' => 'related_id',
'refTableClass' => 'Model_Table_Bug',
'refTableClass' => 'Bugapp_DbTable_Bug',
'refColumns' => 'id',
),
'BugParent' => array(
'columns' => 'bug_id',
'refTableClass' => 'Model_Table_Bug',
'refTableClass' => 'Bugapp_DbTable_Bug',
'refColumns' => 'id',
),
'RelationType' => array(
'columns' => 'relation_type',
'refTableClass' => 'Model_Table_RelationType',
'refTableClass' => 'Bugapp_DbTable_RelationType',
'refColumns' => 'id',
),
);
Expand Down
Expand Up @@ -2,20 +2,20 @@
require_once dirname(__FILE__) . '/User.php';
require_once dirname(__FILE__) . '/Bug.php';

class Model_Table_Comment extends Zend_Db_Table
class Bugapp_DbTable_Comment extends Zend_Db_Table
{
protected $_name = 'comment';
protected $_primary = 'id';

protected $_referenceMap = array(
'User' => array(
'columns' => 'user_id',
'refTableClass' => 'Model_Table_User',
'refTableClass' => 'Bugapp_DbTable_User',
'refColumns' => 'id',
),
'Bug' => array(
'columns' => 'bug_id',
'refTableClass' => 'Model_Table_Bug',
'refTableClass' => 'Bugapp_DbTable_Bug',
'refColumns' => 'id',
),
);
Expand Down
@@ -1,12 +1,12 @@
<?php
require_once dirname(__FILE__) . '/Bug.php';

class Model_Table_IssueType extends Zend_Db_Table
class Bugapp_DbTable_IssueType extends Zend_Db_Table
{
protected $_name = 'issue_type';
protected $_primary = 'id';

protected $_dependentTables = array(
'Model_Table_Bug',
'Bugapp_DbTable_Bug',
);
}
@@ -1,12 +1,12 @@
<?php
require_once dirname(__FILE__) . '/Bug.php';

class Model_Table_PriorityType extends Zend_Db_Table
class Bugapp_DbTable_PriorityType extends Zend_Db_Table
{
protected $_name = 'priority_type';
protected $_primary = 'id';

protected $_dependentTables = array(
'Model_Table_Bug',
'Bugapp_DbTable_Bug',
);
}
@@ -1,12 +1,12 @@
<?php
require_once dirname(__FILE__) . '/BugRelation.php';

class Model_Table_RelationType extends Zend_Db_Table
class Bugapp_DbTable_RelationType extends Zend_Db_Table
{
protected $_name = 'relation_type';
protected $_primary = 'id';

protected $_dependentTables = array(
'Model_Table_BugRelation',
'Bugapp_DbTable_BugRelation',
);
}
@@ -1,12 +1,12 @@
<?php
require_once dirname(__FILE__) . '/Bug.php';

class Model_Table_ResolutionType extends Zend_Db_Table
class Bugapp_DbTable_ResolutionType extends Zend_Db_Table
{
protected $_name = 'resolution_type';
protected $_primary = 'id';

protected $_dependentTables = array(
'Model_Table_Bug',
'Bugapp_DbTable_Bug',
);
}

0 comments on commit f26e5d4

Please sign in to comment.