Skip to content

Commit

Permalink
initial code commit
Browse files Browse the repository at this point in the history
  • Loading branch information
shevron committed Oct 17, 2009
0 parents commit 7884d03
Show file tree
Hide file tree
Showing 38 changed files with 1,552 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.buildpath
.project
.settings
.zfproject.xml
136 changes: 136 additions & 0 deletions application/Bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initRequest(array $options = array())
{
// Ensure front controller instance is present, and fetch it
$this->bootstrap('FrontController');
$front = $this->getResource('FrontController'); /* @var $front Zend_Controller_Front */

// Set up routes
$front->setDefaultControllerName('post');
$front->getRouter()->addConfig(
new Zend_Config(include APPLICATION_PATH . '/configs/routes.php')
);

// Initialize the request object
$request = new Zend_Controller_Request_Http();

// Add it to the front controller
$front->setRequest($request);

// Bootstrap will store this value in the 'request' key of its container
return $request;
}

protected function _initView()
{
$this->bootstrap(array('request', 'session'));

// Initialize view
$view = new Zend_View();
$view->doctype('XHTML1_STRICT');
$view->headTitle()->setSeparator(' » ');

// Save the base URL
$view->baseUrl = $this->getResource('request')->getBaseUrl();

// Add it to the ViewRenderer
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper(
'ViewRenderer'
);
$viewRenderer->setView($view);

// Add some stylesheet
$view->headLink()->appendStylesheet($view->baseUrl . '/css/default.css');

// Set user info
$session = $this->getResource('session');
$view->userLoggedIn = $session->logged_in;
$view->userInfo = $session->user;

$view->addHelperPath(APPLICATION_PATH . '/views/helpers', 'Stoa_View_Helper_');

// Add the Zendx_Jquery helper path
//$view->addHelperPath("ZendX/JQuery/View/Helper", "ZendX_JQuery_View_Helper");
//$view->jQuery()->addStylesheet($view->baseUrl . '/css/ui-lightness/jquery-ui-1.7.2.custom.css');

// Return it, so that it can be stored by the bootstrap
return $view;
}

protected function _initDb()
{
$dbConfig = $this->_options['couchdb'];
Geves_Model_Object::setDbConfig($dbConfig);

if ($dbConfig['validate']) {
// Make sure the DB exists
try {
$db = Sopha_Db::createDb($dbConfig['dbname'], $dbConfig['hostname'], $dbConfig['port']);

} catch (Sopha_Db_Exception $ex) {
if ($ex->getCode() != 412) {
throw $ex;
}
$db = Geves_Model_Object::getDb();
}

// Load design documents and create them
$views = require APPLICATION_PATH . '/configs/couchdb-views.php';
if (! is_array($views)) {
throw new ErrorException("Unable to configure database views: \$views is not properly defined");
}

foreach ($views as $view => $viewData) {
try {
$db->create($viewData, array('_design', $view));

} catch (Sopha_Db_Exception $ex) {
if ($ex->getCode() == 409) { // document already exists
if ($dbConfig['replaceViews']) {
$view = $db->retrieve(array('_design', $view));
$view->fromArray($viewData);
$db->update($view);
}
} else {
throw $ex;
}
}
}
}
}

protected function _initAutoloader()
{
$autoloader = new Zend_Application_Module_Autoloader(array(
'namespace' => 'Stoa_',
'basePath' => APPLICATION_PATH
));
return $autoloader;
}

protected function _initConfig()
{
Zend_Registry::set('config', $this->_options);
}

/**
* Initialize the session
*
* @return Zend_Session_Namespace
*/
protected function _initSession()
{
$this->bootstrap(array('autoloader', 'request'));

Zend_Session::start(array(
'name' => 'STOASESSID',
'use_only_cookies' => true,
'cookie_path' => $this->getResource('request')->getBaseUrl()
));

return new Zend_Session_Namespace('stoa');
}
}
36 changes: 36 additions & 0 deletions application/configs/application.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0

includePaths.library = APPLICATION_PATH "/../library"

bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"

resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"

resources.layout.layout = "layout"

; Autoloader configuration
autoloaderNamespaces.0 = "Zend_"
autoloaderNamespaces.1 = "Geves_"
autoloaderNamespaces.2 = "Sopha_"

; CouchDB Configuration
couchdb.hostname = localhost
couchdb.port = 5984
couchdb.dbname = stoa
couchdb.validate = Off
couchdb.replaceViews = Off

[staging : production]

[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
couchdb.validate = On
couchdb.replaceViews = On
58 changes: 58 additions & 0 deletions application/configs/couchdb-views.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/**
* CouchDB Views
*/

return array(
'post' => array(
'language' => 'javascript',
'views' => array(
'recent-posts' => array(
'map' => <<<EOJS
function(doc) {
if (doc['@doctype'] == 'Post' && doc.published) {
emit([doc.created_at, doc._id], doc);
}
}
EOJS
),

'with-comments' => array(
'map' => <<<EOJS
function(doc) {
if (doc['@doctype'] == 'Post') {
emit([doc._id, "I"], doc);
} else if (doc['@doctype'] == 'Comment') {
emit([doc.post_id, doc.created_at], doc);
}
}
EOJS
),

'comment-count' => array(
'map' => <<<EOJS
function(doc) {
if (doc['@doctype'] == 'Post') {
emit(doc._id, 0);
} else if (doc['@doctype'] == 'Comment') {
emit(doc.post_id, 1);
}
}
EOJS
,
'reduce' => <<<EOJS
function(key, values, rereduce) {
total = 0;
for (i = 0; i < values.length; ++i) {
total += values[i];
}
return total;
}
EOJS
)
)
)
);
24 changes: 24 additions & 0 deletions application/configs/routes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/**
* Route Configuration
*
*/

return array(
'new-post' => array(
'route' => 'new-post',
'defaults' => array(
'controller' => 'post',
'action' => 'new'
)
),

'show-post' => array(
'route' => 'post/:id',
'defaults' => array(
'controller' => 'post',
'action' => 'show'
)
)
);
31 changes: 31 additions & 0 deletions application/controllers/ErrorController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

class ErrorController extends Zend_Controller_Action
{

public function errorAction()
{
$errors = $this->_getParam('error_handler');

switch ($errors->type) {
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:

// 404 error -- controller or action not found
$this->getResponse()->setHttpResponseCode(404);
$this->view->message = 'Page not found';
break;
default:
// application error
$this->getResponse()->setHttpResponseCode(500);
$this->view->message = 'Application error';
break;
}

$this->view->exception = $errors->exception;
$this->view->request = $errors->request;
}


}

Loading

0 comments on commit 7884d03

Please sign in to comment.