Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Work on tutorial2 not successful

  • Loading branch information...
commit c8beb6dd902f4a4e6a9e6e405370aa3c179e93f4 1 parent 1217549
@abtris authored
View
2  README.markdown
@@ -13,5 +13,7 @@ doctrine.
Branch: tutorial2
+http://subversion.zucchi.co.uk/listing.php?repname=titan
+
Make db yaml scheme and generate database and ZF models with correct names.
View
34 application/configs/application.ini
@@ -1,10 +1,37 @@
[production]
+phpSettings.display_startup_errors = 0
+phpSettings.display_errors = 0
+includePaths.application = APPLICATION_PATH
+includePaths.library = APPLICATION_PATH "/../library"
+bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
+bootstrap.class = "Bootstrap"
+; additional namespaces
+autoloaderNamespaces.namespace[] = "Models_"
+autoloaderNamespaces.namespace[] = "Zucchi_"
+autoloaderNamespaces.namespace[] = "Doctrine_"
+autoloaderNamespaces.namespace[] = "Doctrine"
+; doctrine
resources.doctrine.connection_string = "mysql://doctrine:doctrine@127.0.0.1/doctrine"
-resources.doctrine.compiled = true ; use compiled version of Doctrine
-resources.doctrine.cache = true ; use query cache
+resources.doctrine.charset = "utf8"
+resources.doctrine.cache = "false"
+resources.doctrine.compiled = "false"
resources.doctrine.models_path = APPLICATION_PATH "/models"
+resources.doctrine.data_fixtures_path = APPLICATION_PATH "/doctrine/data/fixtures"
+resources.doctrine.sql_path = APPLICATION_PATH "/doctrine/data/sql"
+resources.doctrine.migrations_path = APPLICATION_PATH "/doctrine/migrations"
+resources.doctrine.yaml_schema_path = APPLICATION_PATH "/doctrine/schema"
+
+resources.doctrine.generate_models_options.pearStyle = true
+resources.doctrine.generate_models_options.generateTableClasses = false
+resources.doctrine.generate_models_options.generateBaseClasses = false
+resources.doctrine.generate_models_options.classPrefix = "Model_"
+resources.doctrine.generate_models_options.baseClassPrefix = "Base_"
+resources.doctrine.generate_models_options.baseClassesDirectory = "Base"
+resources.doctrine.generate_models_options.classPrefixFiles = false
+resources.doctrine.generate_models_options.generateAccessors = false
+
resources.doctrine.phpDocPackage = Project
resources.doctrine.phpDocSubpackage = Sub project
resources.doctrine.phpDocName = Company
@@ -17,6 +44,3 @@ pluginPaths.App_Application_Resource = "App/Application/Resource"
[testing : production]
[development : production]
-
-resources.doctrine.compiled = false ; use compiled version of Doctrine
-resources.doctrine.cache = false ; use query cache
View
0  application/doctrine/data/fixtures/.placeholder
No changes.
View
0  application/doctrine/data/sql/.placeholder
No changes.
View
0  application/doctrine/migrations/.placeholder
No changes.
View
0  application/doctrine/schema/.placeholder
No changes.
View
46 application/doctrine/schema/schema.yml
@@ -0,0 +1,46 @@
+aclRole:
+ columns:
+ id:
+ type: integer(11)
+ autoincrement: true
+ primary: true
+ name: string(255)
+ protected: boolean
+
+aclRoleParents:
+ columns:
+ id:
+ type : integer(11)
+ autoincrement: true
+ primary: true
+ role:
+ type: string(255)
+ parent:
+ type: string(255)
+ relations:
+
+
+aclRule:
+ columns:
+ id:
+ type: integer(11)
+ autoincrement: true
+ primary: true
+ aclKey: string(50)
+ role: string(255)
+ resource: string(255)
+ rule:
+ type: enum
+ length: 5
+ values: ['allow', 'deny']
+
+aclRuleRights:
+ columns:
+ id:
+ type: integer(11)
+ autoincrement: true
+ primary: true
+ rule_id:
+ type: integer(11)
+ rightName:
+ type: string(50)
View
40 bin/Doctrine/Task/GenerateModels.php
@@ -0,0 +1,40 @@
+<?php
+
+/**
+ * Doctrine Models generator
+ *
+ * @author Juozas Kaziukenas (juozas@juokaz.com)
+ */
+class Doctrine_Task_GenerateModels extends Doctrine_Task_GenerateModelsDb
+{
+ public $description = 'Generates models compatible with zend framework',
+ $optionalArguments = array(
+ 'connection' => 'Optionally specify a single connection to generate the models for.',
+ 'phpDocPackage' => 'Optionaly specify package name',
+ 'phpDocSubpackage' => 'Optionali specify sub package name',
+ 'phpDocName' => 'Optionaly specify author name',
+ 'phpDocEmail' => 'Optionaly specify author email',
+ );
+
+ public function execute()
+ {
+ $models = $this->getArgument('models_path');
+
+ $options = array(
+ 'pearStyle' => true,
+ 'generateTableClasses' => true,
+ 'classPrefix' => 'Model_',
+ 'baseClassPrefix' => 'Base_',
+ 'baseClassesDirectory' => null,
+ 'classPrefixFiles' => false,
+ 'generateAccessors' => false,
+ );
+
+ $options += $this->getArguments();
+
+ $import = new Doctrine_Import(Doctrine_Manager::connection());
+ $import->importSchema($models, (array) $this->getArgument('connection'), $options);
+
+ $this->notify('Generated models successfully from databases');
+ }
+}
View
32 bin/Doctrine/Task/ZucchiGenerateModelsYaml.php
@@ -0,0 +1,32 @@
+<?php
+/**
+ * Doctrine_Task_GenerateModelsYaml
+ *
+ * @package Doctrine
+ * @subpackage Task
+ */
+class Doctrine_Task_ZucchiGenerateModelsYaml extends Doctrine_Task
+{
+ public $description = 'Generates your Doctrine_Record definitions from a Yaml schema file',
+ $requiredArguments = array('yaml_schema_path' => 'Specify the complete directory path to your yaml schema files.',
+ 'models_path' => 'Specify complete path to your Doctrine_Record definitions.'),
+ $optionalArguments = array('generate_models_options' => 'Array of options for generating models');
+
+ public function execute()
+ {
+
+ $options = array(
+ 'pearStyle' => true,
+ 'generateTableClasses' => true,
+ 'classPrefix' => 'Model_',
+ 'baseClassPrefix' => 'Base_',
+ 'baseClassesDirectory' => null,
+ 'classPrefixFiles' => false,
+ 'generateAccessors' => false,
+ );
+
+ Doctrine_Core::generateModelsFromYaml($this->getArgument('yaml_schema_path'), $this->getArgument('models_path'), $this->getArgument('generate_models_options', $options));
+
+ $this->notify('Generated models successfully from YAML schema');
+ }
+}
View
38 bin/doctrine-cli
@@ -0,0 +1,38 @@
+#!/usr/bin/env php
+<?php
+error_reporting(E_ALL | E_STRICT);
+ini_set('display_startup_errors', 1);
+ini_set('display_errors', 1);
+date_default_timezone_set('Europe/London');
+/*
+ * Setup libraries & autoloaders
+ */
+set_include_path(dirname(__FILE__).'/../library'
+ . PATH_SEPARATOR . dirname(__FILE__).'/../application/models'
+ . PATH_SEPARATOR . dirname(__FILE__).'/../application/models/generated'
+ . PATH_SEPARATOR . get_include_path());
+require 'Zend/Loader/Autoloader.php';
+$autoloader = Zend_Loader_Autoloader::getInstance();
+$autoloader->registerNamespace('Zucchi_');
+$autoloader->registerNamespace('Doctrine_');
+$autoloader->registerNamespace('Doctrine');
+$autoloader->registerNamespace('Base');
+
+/*
+ * Set super-global data
+ */
+Doctrine_Manager::connection("mysql://doctrine:doctrine@127.0.0.1/doctrine");
+
+/*
+ * Configure Doctrine
+ */
+$doctrine_config = array(
+ 'data_fixtures_path' => dirname(__FILE__).'/../application/doctrine/data/fixtures',
+ 'models_path' => dirname(__FILE__).'/../application/models',
+ 'migrations_path' => dirname(__FILE__).'/../application/doctrine/migrations',
+ 'sql_path' => dirname(__FILE__).'/../application/doctrine/data/sql',
+ 'yaml_schema_path' => dirname(__FILE__).'/../application/doctrine/schema'
+ );
+
+$cli = new Doctrine_Cli($doctrine_config);
+$cli->run($_SERVER['argv']);
View
38 bin/doctrine-cli.php
@@ -0,0 +1,38 @@
+<?php
+/**
+ * Doctrine CLI script
+ *
+ * @author Juozas Kaziukenas (juozas@juokaz.com)
+ */
+
+define('APPLICATION_ENV', 'development');
+define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
+
+set_include_path(implode(PATH_SEPARATOR, array(
+ realpath(APPLICATION_PATH . '/../library'),
+ get_include_path(),
+)));
+
+require_once 'Zend/Application.php';
+
+// Create application, bootstrap, and run
+$application = new Zend_Application(
+ APPLICATION_ENV,
+ APPLICATION_PATH . '/configs/application.ini'
+);
+
+$application->getBootstrap()->bootstrap('doctrine');
+$options = $application->getBootstrap()->getOptions();
+
+// Zend_Debug::dump($options['resources']['doctrine']);exit();
+$cli = new Doctrine_Cli($options['resources']['doctrine']);
+
+
+// Load tasks from custom location
+$tasks = './Doctrine/Task';
+if (file_exists($tasks))
+{
+ $cli->loadTasks($tasks);
+}
+
+$cli->run($_SERVER['argv']);
View
87 library/Zucchi/Application/Resource/Doctrine.php
@@ -0,0 +1,87 @@
+<?php
+/**
+ * Resource for initializing doctrine
+ *
+ * @category Zucchi
+ * @package Zucchi_Application
+ * @subpackage Resource
+ * @copyright Copyright (c) 2009 Zucchi.co.uk
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+class Zucchi_Application_Resource_Doctrine extends Zend_Application_Resource_ResourceAbstract {
+
+ private $_doctrine;
+
+ public function init()
+ {
+ return $this->build();
+ }
+
+ public function build()
+ {
+ if (null === $this->_doctrine) {
+ $options = $this->getOptions();
+ if (isset($options['compiled']) && $options['compiled'] == true &&
+ file_exists(APPLICATION_PATH . '/../library/Doctrine.compiled.php')){
+ require_once 'Doctrine.compiled.php';
+ } else {
+ require_once 'Doctrine.php';
+ }
+
+ $this->getBootstrap()
+ ->getApplication()
+ ->getAutoloader()
+ ->pushAutoloader(array('Doctrine', 'autoload'), 'Doctrine')
+ ->pushAutoLoader(new Zucchi_Doctrine_Application_Autoloader(array(
+ 'namespace' => '',
+ 'basePath' => APPLICATION_PATH,
+ )), 'ZucchiDoctrine');
+
+ $this->_doctrine = Doctrine_Manager::getInstance();
+
+ $this->_doctrine->setAttribute(Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
+
+ // set models to be autoloaded and not included (Doctrine::MODEL_LOADING_AGGRESSIVE)
+ $this->_doctrine->setAttribute(
+ Doctrine::ATTR_MODEL_LOADING,
+ Doctrine::MODEL_LOADING_CONSERVATIVE
+ );
+
+ // enable ModelTable classes to be loaded automatically
+ $this->_doctrine->setAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES, true);
+
+ // enable validation on save()
+ $this->_doctrine->setAttribute(
+ Doctrine::ATTR_VALIDATE,
+ Doctrine::VALIDATE_ALL
+ );
+
+ // enable automatic queries resource freeing
+ $this->_doctrine->setAttribute(
+ Doctrine_Core::ATTR_AUTO_FREE_QUERY_OBJECTS,
+ true
+ );
+
+ if (!isset($options['connection_string'])) {
+ throw new Exception('You must define a connection for doctrine to connect with');
+ }
+ // connect to database
+ $this->_doctrine->openConnection($options['connection_string'], 'doctrine');
+
+ if (isset($options['charset'])) {
+ // set charset
+ $this->_doctrine->connection()->setCharset($options['charset']);
+ }
+ if (isset($options['cache']) && $options['cache']) {
+ // set cache
+ // implement cacheing here
+ }
+
+ $this->_doctrine->connection()->setAttribute(Doctrine::ATTR_USE_NATIVE_ENUM, true);
+ }
+
+ return $this->_doctrine;
+ }
+
+
+}
View
49 library/Zucchi/Doctrine/Application/Autoloader.php
@@ -0,0 +1,49 @@
+<?php
+/**
+ * Resource loader for application module classes
+ *
+ * @uses Zucchi_Doctrine_Application_Autoloader
+ * @package Zucchi_Doctrine
+ * @subpackage Application
+ * @copyright Copyright (c) 2009 Zucchi.co.uk
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+class Zucchi_Doctrine_Application_Autoloader extends Zend_Loader_Autoloader_Resource
+{
+ /**
+ * Constructor
+ *
+ * @param array|Zend_Config $options
+ * @return void
+ */
+ public function __construct($options)
+ {
+ parent::__construct($options);
+ $this->initDefaultResourceTypes();
+ }
+
+ /**
+ * Initialize default resource types for module resource classes
+ *
+ * @return void
+ */
+ public function initDefaultResourceTypes()
+ {
+ $basePath = $this->getBasePath();
+ $this->addResourceTypes(array(
+ 'dbtable' => array(
+ 'namespace' => 'Model_DbTable',
+ 'path' => 'models/DbTable',
+ ),
+ 'model' => array(
+ 'namespace' => 'Model',
+ 'path' => 'models',
+ ),
+ 'modelbase' => array(
+ 'namespace' => 'Model_Base',
+ 'path' => 'models/Base',
+ )
+ ));
+ $this->setDefaultResourceType('model');
+ }
+}
View
6 scripts/Doctrine/Task/GenerateModels.php
@@ -26,8 +26,8 @@ public function execute()
'classPrefix' => 'Model_',
'baseClassPrefix' => 'Base_',
'baseClassesDirectory' => null,
- 'classPrefixFiles' => false,
- 'generateAccessors' => false,
+ 'classPrefixFiles' => true,
+ 'generateAccessors' => true,
);
$options += $this->getArguments();
@@ -37,4 +37,4 @@ public function execute()
$this->notify('Generated models successfully from databases');
}
-}
+}
Please sign in to comment.
Something went wrong with that request. Please try again.