Skip to content

Instantly share code, notes, and snippets.

@ssmusoke
Created May 8, 2012 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ssmusoke/2638526 to your computer and use it in GitHub Desktop.
Save ssmusoke/2638526 to your computer and use it in GitHub Desktop.
Zend Framework - Doctrine 2 integration using Bisna with Symfony 2 Validator configuration
[production]
; --------------------------
; PHP Specific Configuration
; --------------------------
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
; ----------------------------------------
; Zend Framework Application Configuration
; ----------------------------------------
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
pluginPaths.Bisna\Application\Resource\ = "Bisna/Application/Resource"
autoloaderNamespaces[] = Bisna
; ------------------------------------------------------------------------------
; cache Manager
; ------------------------------------------------------------------------------
resources.cachemanager.cache.frontend.name = Core
resources.cachemanager.cache.frontend.customFrontendNaming = false
resources.cachemanager.cache.frontend.options.lifetime = 7200
resources.cachemanager.cache.frontend.options.automatic_serialization = true
resources.cachemanager.cache.backend.customBackendNaming = false
resources.cachemanager.cache.backend.name = File
resources.cachemanager.cache.backend.options.cache_dir = APPLICATION_PATH "/temp"
resources.cachemanager.cache.frontendBackendAutoload = false
; ------------------------------
; Front Controller Configuration
; ------------------------------
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
; ------------------------------------------------------------------------------
; Layout & Templates
; ------------------------------------------------------------------------------
resources.layout.layout = "layout"
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
; ------------------------------------------------------------------------------
; Locale & Translate Configuration
; ------------------------------------------------------------------------------
; translate
resources.translate.adapter = ini
resources.translate.content = APPLICATION_PATH "/configs/en.language.ini"
resources.translate.cache = "cache"
; ------------------------------------------------------------------------------
; Logger
; ------------------------------------------------------------------------------
resources.log.stream.writerName = "Stream"
resources.log.stream.writerParams.stream = APPLICATION_PATH "/logs/app.log"
resources.log.stream.writerParams.mode = "a"
resources.log.stream.filterName = "Priority"
; warning priority
resources.log.stream.filterParams.priority = 4
; ------------------------------------------------------------------------------
; Doctrine Class Loader Configuration
; ------------------------------------------------------------------------------
resources.doctrine.classLoader.loaderClass = "Doctrine\Common\ClassLoader"
resources.doctrine.classLoader.loaderFile = APPLICATION_PATH "/../library/Doctrine/Common/ClassLoader.php"
resources.doctrine.classLoader.loaders.doctrine_common.namespace = "Doctrine\Common"
resources.doctrine.classLoader.loaders.doctrine_common.includePath = APPLICATION_PATH "/../library"
resources.doctrine.classLoader.loaders.doctrine_dbal.namespace = "Doctrine\DBAL"
resources.doctrine.classLoader.loaders.doctrine_dbal.includePath = APPLICATION_PATH "/../library"
resources.doctrine.classLoader.loaders.doctrine_orm.namespace = "Doctrine\ORM"
resources.doctrine.classLoader.loaders.doctrine_orm.includePath = APPLICATION_PATH "/../library/"
; ------------------------------------------------------------------------------
; Doctrine Cache Configuration
; ------------------------------------------------------------------------------
; Points to default cache instance to be used. Optional is only one cache is defined
resources.doctrine.cache.defaultCacheInstance = default
; Cache Instance configuration for "default" cache
;resources.doctrine.cache.instances.default.id = default
resources.doctrine.cache.instances.default.adapterClass = "Doctrine\Common\Cache\MemcacheCache"
resources.doctrine.cache.instances.default.namespace = "Application_"
resources.doctrine.cache.instances.default.options.servers.0.host = localhost
resources.doctrine.cache.instances.default.options.servers.0.port = 11211
;resources.doctrine.cache.instances.default.options.servers.0.persistent = true
;resources.doctrine.cache.instances.default.options.servers.0.weight = 1
;resources.doctrine.cache.instances.default.options.servers.0.timeout = 1
;resources.doctrine.cache.instances.default.options.servers.0.retryInterval = 15
;resources.doctrine.cache.instances.default.options.servers.0.status = true
; ------------------------------------------------------------------------------
; Doctrine DBAL Configuration
; ------------------------------------------------------------------------------
; Points to default connection to be used. Optional if only one connection is defined
resources.doctrine.dbal.defaultConnection = default
; DBAL Connection configuration for "default" connection
;resources.doctrine.dbal.connections.default.id = default
;resources.doctrine.dbal.connections.default.eventManagerClass = "Doctrine\Common\EventManager"
;resources.doctrine.dbal.connections.default.eventSubscribers[] = "DoctrineExtensions\Sluggable\SluggableSubscriber"
;resources.doctrine.dbal.connections.default.configurationClass = "Doctrine\DBAL\Configuration"
;resources.doctrine.dbal.connections.default.sqlLoggerClass = "Doctrine\DBAL\Logging\EchoSQLLogger"
;resources.doctrine.dbal.connections.default.types.my_type = "Application\DBAL\Type\MyType"
; Database configuration
;resources.doctrine.dbal.connections.default.parameters.wrapperClass = ""
resources.doctrine.dbal.connections.default.parameters.driver = "pdo_mysql"
resources.doctrine.dbal.connections.default.parameters.dbname = "fmm"
resources.doctrine.dbal.connections.default.parameters.host = "localhost"
resources.doctrine.dbal.connections.default.parameters.port = 3306
resources.doctrine.dbal.connections.default.parameters.user = "root"
resources.doctrine.dbal.connections.default.parameters.password = "password"
;resources.doctrine.dbal.connections.default.parameters.driverOptions.ATTR_USE_BUFFERED_QUERIES = true
; ------------------------------------------------------------------------------
; Doctrine ORM Configuration
; ------------------------------------------------------------------------------
; Points to default EntityManager to be used. Optional if only one EntityManager is defined
resources.doctrine.orm.defaultEntityManager = default
; EntityManager configuration for "default" manager
;resources.doctrine.orm.entityManagers.default.id = default
;resources.doctrine.orm.entityManagers.default.entityManagerClass = "Doctrine\ORM\EntityManager"
;resources.doctrine.orm.entityManagers.default.configurationClass = "Doctrine\ORM\Configuration"
;resources.doctrine.orm.entityManagers.default.entityNamespaces.app = "Entity"
resources.doctrine.orm.entityManagers.default.connection = default
resources.doctrine.orm.entityManagers.default.proxy.autoGenerateClasses = false
resources.doctrine.orm.entityManagers.default.proxy.namespace = "Proxy"
resources.doctrine.orm.entityManagers.default.proxy.dir = APPLICATION_PATH "/proxies"
;resources.doctrine.orm.entityManagers.default.metadataCache = default
;resources.doctrine.orm.entityManagers.default.queryCache = default
;resources.doctrine.orm.entityManagers.default.resultCache = default
;resources.doctrine.orm.entityManagers.default.DQLFunctions.numeric.PI = "DoctrineExtensions\ORM\Query\Functions\Numeric\PiFunction"
resources.doctrine.orm.entityManagers.default.metadataDrivers.annotationRegistry.annotationFiles[] = APPLICATION_PATH "/../library/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php"
resources.doctrine.orm.entityManagers.default.metadataDrivers.annotationRegistry.annotationNamespaces.0.namespace = "Symfony\Component\Validator\Constraints"
resources.doctrine.orm.entityManagers.default.metadataDrivers.annotationRegistry.annotationNamespaces.0.includePath = APPLICATION_PATH "/../library"
resources.doctrine.orm.entityManagers.default.metadataDrivers.drivers.0.adapterClass = "Doctrine\ORM\Mapping\Driver\AnnotationDriver"
resources.doctrine.orm.entityManagers.default.metadataDrivers.drivers.0.mappingNamespace = ""
resources.doctrine.orm.entityManagers.default.metadataDrivers.drivers.0.mappingDirs[] = APPLICATION_PATH "/models"
resources.doctrine.orm.entityManagers.default.metadataDrivers.drivers.0.annotationReaderClass = "Doctrine\Common\Annotations\AnnotationReader"
resources.doctrine.orm.entityManagers.default.metadataDrivers.drivers.0.annotationReaderCache = default
[staging : production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
resources.frontController.params.displayExceptions = 0
; ------------------------------------------------------------------------------
; cache Manager
; ------------------------------------------------------------------------------
resources.cachemanager.cache.frontend.options.lifetime = 1
; Doctrine Cache
resources.doctrine.cache.instances.default.adapterClass = "Doctrine\Common\Cache\ArrayCache"
resources.doctrine.orm.entityManagers.default.proxy.autoGenerateClasses = true
; Database configuration
resources.doctrine.dbal.connections.default.parameters.dbname = "staging"
resources.doctrine.dbal.connections.default.parameters.host = "localhost"
resources.doctrine.dbal.connections.default.parameters.user = "staging"
resources.doctrine.dbal.connections.default.parameters.password = "staging"
; ------------------------------------------------------------------------------
; Session configuration
; ------------------------------------------------------------------------------
resources.session.use_only_cookies = true
; set the maximum session lifetime to 1 hour in seconds
resources.session.gc_maxlifetime = 3600
resources.session.remember_me_seconds = 3600
[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
; Doctrine Cache
resources.doctrine.cache.instances.default.adapterClass = "Doctrine\Common\Cache\ArrayCache"
resources.doctrine.orm.entityManagers.default.proxy.autoGenerateClasses = true
; Database configuration
resources.doctrine.dbal.connections.default.parameters.dbname = "test"
resources.doctrine.dbal.connections.default.parameters.host = "127.0.0.1"
resources.doctrine.dbal.connections.default.parameters.port = 3306
resources.doctrine.dbal.connections.default.parameters.user = "dev"
resources.doctrine.dbal.connections.default.parameters.password = "dev"
[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
; ------------------------------------------------------------------------------
; cache Manager
; ------------------------------------------------------------------------------
resources.cachemanager.cache.frontend.options.lifetime = 1
; Doctrine Cache
resources.doctrine.cache.instances.default.adapterClass = "Doctrine\Common\Cache\ArrayCache"
resources.doctrine.orm.entityManagers.default.proxy.autoGenerateClasses = true
; Database configuration
resources.doctrine.dbal.connections.default.parameters.dbname = "dev"
resources.doctrine.dbal.connections.default.parameters.host = "127.0.0.1"
resources.doctrine.dbal.connections.default.parameters.port = 3306
resources.doctrine.dbal.connections.default.parameters.user = "dev"
resources.doctrine.dbal.connections.default.parameters.password = "dev"
; ------------------------------------------------------------------------------
; Session configuration
; ------------------------------------------------------------------------------
; set the maximum session lifetime to 3 hour in seconds
resources.session.gc_maxlifetime = 10800
resources.session.remember_me_seconds = 10800
<?php
use Doctrine\Common\ClassLoader;
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
public function _initDoctrine() {
$options = $this->getPluginResource('doctrine')->getOptions();
$container = new \Bisna\Doctrine\Container($options);
Zend_Registry::set('em', $container->getEntityManager());
}
function _initZendDBAdapter(){
// initialize the Zend_DB_Adapter from the Doctrine configuration
$options = $this->getPluginResource('doctrine')->getOptions();
$dbparams = $options['dbal']['connections']['default']['parameters'];
// change dbal user to username required for the Zend_DB_Adapter
$dbparams['username'] = $dbparams['user'];
Zend_Registry::set('dbAdapter', new Zend_Db_Adapter_Mysqli($dbparams));
}
/**
* Initialize the logger, cache and translate instances
*
*/
public function _initEnv() {
Zend_Registry::set("log", $this->getPluginResource('log')->getLog());
// use Zend_Translate as the key so that it is auto discovered by the view helpers
Zend_Registry::set("Zend_Translate", $this->getPluginResource('translate')->getTranslate());
Zend_Registry::set("cache", $this->getPluginResource('cachemanager')->getCacheManager()->getCache('cache'));
}
}
<?php
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Entity
* @ORM\Table(name="document")
*/
class Document extends BaseEntity {
/**
* @ORM\ManyToOne(targetEntity="DocumentCategory")
* @ORM\JoinColumn(name="categoryid", referencedColumnName="id")
* @Assert\NotBlank(message="document_category_error")
*/
protected $category;
/**
* @ORM\ManyToOne(targetEntity="UserAccount")
* @ORM\JoinColumn(name="userid", referencedColumnName="id")
* @Assert\NotBlank(message="document_user_error")
*/
protected $user;
/**
* @ORM\Column(type="string", length=500)
* @Assert\NotBlank(message="document_title_error")
*/
protected $title;
/**
* @ORM\Column(type="string", length=500)
*/
protected $keywords;
/**
* @ORM\Column(type="string")
* @Assert\NotBlank(message="document_description_error")
*/
protected $description;
/**
* @ORM\Column(type="string")
* @Assert\NotBlank(message="document_file_error")
*/
protected $filename;
/**
* @ORM\Column(type="string")
* @Assert\NotBlank(message="document_extension_error")
*/
protected $extension;
/**
* @ORM\Column(type="string", length=75)
* @Assert\NotBlank(message="document_mimetype_error")
*/
protected $mimetype;
/**
* @ORM\Column(type="integer")
* @Assert\NotBlank(message="document_filesize_error")
*/
protected $filesize;
/**
* @ORM\Column(type="string")
* @Assert\NotBlank(message="document_filepath_error")
*/
protected $filepath;
/**
* @ORM\Column(type="string", length=500)
*
*/
protected $slug;
/**
* @ORM\ManyToMany(targetEntity="Tag", cascade={"persist"})
* @ORM\JoinTable(name="documenttag",
* joinColumns={@ORM\JoinColumn(name="documentid", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="tagid", referencedColumnName="id")}
* )
*
*/
protected $tags;
/**
* Set the category
* @param integer $category The ID of the category
*/
function setCategoryID($categoryid) {
if (!isEmptyString($categoryid)) {
$this->category = loadEntity('DocumentCategory', $categoryid);
}
}
/**
* Return the ID of the category or FALSE if there is no category
*
* @return integer|FALSE
*/
function getCategoryID() {
if (is_null($this->category)) {
return false;
}
return $this->category->getID();
}
/**
* Set the user
* @param integer $user The ID of the user
*/
function setUserID($userid) {
if (!isEmptyString($userid)) {
$this->user = loadEntity('UserAccount', $userid);
}
}
/**
* Return the ID of the user or FALSE if there is no user
*
* @return integer|FALSE
*/
function getUserID() {
if (is_null($this->user)) {
return false;
}
return $this->user->getID();
}
/**
* Add the document tags
*
* @param Array $documenttags An array of ids for the document tags
*/
function setTags($documenttags) {
foreach ($documenttags as $tagid) {
$this->tags[] = loadEntity('Tag', $tagid);
}
}
}
<?php
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'development'));
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
realpath(APPLICATION_PATH . '/models'),
realpath(APPLICATION_PATH . '/forms'),
realpath(APPLICATION_PATH . '/controllers'),
realpath(APPLICATION_PATH . '/plugins'), # controller plugins
realpath(APPLICATION_PATH . '/includes'), # classes and scripts used through the application
get_include_path(),
)));
// public folder directory
if(APPLICATION_ENV == 'production'){
define('PUBLICFOLDER', 'public_html');
} else {
define('PUBLICFOLDER', 'public');
}
require_once APPLICATION_PATH.'/includes/commonfunctions.php';
/** register an autoloader - it knows where the Zend Framework files are */
require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->setFallbackAutoloader(true);
$autoloader->suppressNotFoundWarnings(false);
/** Zend_Application */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
# run the default page
$application->bootstrap()->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment