├── .editorconfig
├── .gitattributes
├── .gitignore
├── .jshintrc
├── .travis.yml
├── LICENSE
├── README.md
├── app
├── index.js
└── templates
│ ├── _bower.json
│ ├── _build.xml
│ ├── _composer.json
│ ├── _package.json
│ ├── build
│ ├── phpcs.xml
│ ├── phpdox.xml
│ └── phpmd.xml
│ ├── editorconfig
│ ├── jshintrc
│ ├── phalcon
│ ├── _htaccess
│ ├── private
│ │ ├── common
│ │ │ └── lib
│ │ │ │ └── application
│ │ │ │ ├── Application.php
│ │ │ │ ├── ApplicationModule.php
│ │ │ │ ├── RoutedModule.php
│ │ │ │ ├── controllers
│ │ │ │ ├── ApplicationApiController.php
│ │ │ │ ├── ApplicationController.php
│ │ │ │ └── ApplicationViewController.php
│ │ │ │ ├── models
│ │ │ │ ├── ApplicationCollection.php
│ │ │ │ └── ApplicationModel.php
│ │ │ │ └── router
│ │ │ │ └── ApplicationRouter.php
│ │ └── config
│ │ │ ├── config.php
│ │ │ └── modules.php
│ ├── public
│ │ ├── .htaccess
│ │ ├── index.php
│ │ └── src
│ │ │ └── app
│ │ │ ├── layouts
│ │ │ └── main.html
│ │ │ └── partials
│ │ │ └── index.html
│ └── test
│ │ ├── application
│ │ ├── ApplicationTest.php
│ │ └── phpunit.xml
│ │ ├── helpers
│ │ ├── TestHelper.php
│ │ └── UnitTestCase.php
│ │ └── phalcon
│ │ ├── FunctionalTestCase.php
│ │ ├── ModelTestCase.php
│ │ └── UnitTestCase.php
│ └── travis.yml
├── controller-api
├── index.js
└── templates
│ ├── controllers
│ └── api
│ │ └── IndexController.php
│ └── test
│ └── ControllerTest.php
├── controller-view
├── index.js
└── templates
│ ├── controllers
│ └── view
│ │ └── IndexController.php
│ └── views
│ └── index
│ └── index.html
├── module
├── index.js
└── templates
│ ├── module
│ ├── Module.php
│ ├── ModuleRoutes.php
│ ├── config
│ │ └── config.php
│ ├── controllers
│ │ └── .gitignore
│ ├── lib
│ │ ├── controllers
│ │ │ ├── ModuleApiController.php
│ │ │ ├── ModuleController.php
│ │ │ └── ModuleViewController.php
│ │ └── models
│ │ │ ├── ModuleCollection.php
│ │ │ └── ModuleModel.php
│ └── models
│ │ └── .gitignore
│ └── test
│ ├── ModuleTest.php
│ ├── helpers
│ ├── ModuleTestHelper.php
│ └── ModuleUnitTestCase.php
│ └── phpunit.xml
├── package.json
└── test
├── test-creation.js
└── test-load.js
/.editorconfig:
--------------------------------------------------------------------------------
1 | # http://editorconfig.org
2 | root = true
3 |
4 | [*]
5 | indent_style = space
6 | indent_size = 4
7 | end_of_line = lf
8 | charset = utf-8
9 | trim_trailing_whitespace = true
10 | insert_final_newline = true
11 |
12 | [*.md]
13 | trim_trailing_whitespace = false
14 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | temp/
3 |
--------------------------------------------------------------------------------
/.jshintrc:
--------------------------------------------------------------------------------
1 | {
2 | "node": true,
3 | "esnext": true,
4 | "bitwise": true,
5 | "camelcase": true,
6 | "curly": true,
7 | "eqeqeq": true,
8 | "immed": true,
9 | "indent": 4,
10 | "latedef": true,
11 | "newcap": true,
12 | "noarg": true,
13 | "quotmark": "single",
14 | "regexp": true,
15 | "undef": true,
16 | "unused": true,
17 | "strict": true,
18 | "trailing": true,
19 | "smarttabs": true,
20 | "white": true
21 | }
22 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - '0.8'
4 | - '0.10'
5 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright 2013
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining
4 | a copy of this software and associated documentation files (the
5 | "Software"), to deal in the Software without restriction, including
6 | without limitation the rights to use, copy, modify, merge, publish,
7 | distribute, sublicense, and/or sell copies of the Software, and to
8 | permit persons to whom the Software is furnished to do so, subject to
9 | the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be
12 | included in all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # generator-phalcon
2 |
3 | A generator for [Yeoman](http://yeoman.io). Let Yeoman generate a multi module [Phalcon PHP Framework](http://phalconphp.com) application.
4 |
5 |
6 | ## Getting Started
7 |
8 | Since this is a Yeoman generator you have to install him first:
9 |
10 | ```
11 | $ npm install -g yo
12 | ```
13 |
14 | ### Phalcon Generator
15 |
16 | To install generator-phalcon from npm, run:
17 |
18 | ```
19 | $ npm install -g generator-phalcon
20 | ```
21 |
22 | Finally, initiate the generator:
23 |
24 | ```
25 | $ yo phalcon
26 | ```
27 |
28 | You will be asked some questions about your application. You can specify the main namespace where all generated classes will live in. This will also be used to generate the project name. You can specify the folder name this project lives in (if it differs from the project name). Finally you have a working multi-module application set up:
29 |
30 | ```
31 | I welcome you to the Phalcon project generator.
32 |
33 | I will create a new Phalcon multi module application
34 | Please answer some questions first:
35 |
36 | [?] How would you like to call the new Project? (Enter the global namespace of the project, eg. MyApplication)
37 | [?] How would you like to name the main module? (Enter the namespace of the default module, eg. MyMainModule)
38 | [?] Please enter the name of the folder this project lives in (defaults to the slugified project name).
39 |
40 | ```
41 |
42 | ### Module Subgenerator
43 |
44 | If you would like to add another module to your project, just issue the module subgenerator like this:
45 |
46 | ```
47 | $ yo phalcon:module
48 | ```
49 |
50 | This will kickstart the module generator which will include a new module in your project. This works for every project created by the generator-phalcon generator.
51 |
52 | The subgenerator will ask you about the project namespace and the namespace of the new module:
53 |
54 | ```
55 | I will create a new Phalcon module for your application.
56 |
57 | Please answer these simple questions:
58 |
59 | [?] What is the namespace of the project this module should belong to? (Enter the global namespace of the project, eg. MyApplication)
60 | [?] How would you like to name your module? (Enter the namespace of your new module, eg. MyNewModule)
61 | ```
62 |
63 | ### Controller Subgenerator
64 |
65 | If you would like to add another controller to your project, just issue the module subgenerator like this:
66 |
67 | ```
68 | $ yo phalcon:controller
69 | ```
70 |
71 | This will kickstart the controller generator which will include a new controller in one of your projects modules.
72 |
73 | The subgenerator will ask you about the project namespace, the namespace of the new module and the controller name:
74 |
75 | ```
76 | I will create a new Phalcon controller for your application.
77 |
78 | Please answer these simple questions:
79 |
80 | [?] What is the namespace of the project this controller should belong to? (Enter the global namespace of the project, eg. MyApplication)
81 | [?] How is the namespace of the module your controller should belong to? (Enter the namespace of your new module, eg. MyNewModule)
82 | [?] What is the name of your controller (Without "Controller" suffix)? (Enter the simple controller name, eg. Auth)
83 |
84 | ```
85 |
86 | ### Build the project
87 |
88 | By now the project can be build with Ant. The build directory contains some PHP specific configurations for PHP MessDetector, PHPDox and CodeSniffer.
89 |
90 | ### About the generated project
91 |
92 | As every Yeoman generator, this generator is opinionated about how you should manage your application, be it directory structure, class inheritance or every other detail of your application.
93 | As Phalcon is a very flexible framework feel free to adjust the project to your needs.
94 | The project generated with the generator-phalcon generator will have the following structure:
95 |
96 | ```
97 | .
98 | ├── bower.json
99 | ├── build
100 | │ ├── phpcs.xml
101 | │ ├── phpdox.xml
102 | │ └── phpmd.xml
103 | ├── build.xml
104 | ├── composer.json
105 | ├── package.json
106 | ├── private
107 | │ ├── common
108 | │ │ └── lib
109 | │ │ └── application
110 | │ │ ├── ApplicationModule.php
111 | │ │ ├── Application.php
112 | │ │ ├── controllers
113 | │ │ │ ├── ApplicationApiController.php
114 | │ │ │ └── ApplicationController.php
115 | │ │ ├── models
116 | │ │ │ └── ApplicationModel.php
117 | │ │ ├── RoutedModule.php
118 | │ │ └── router
119 | │ │ └── ApplicationRouter.php
120 | │ ├── config
121 | │ │ ├── config.php
122 | │ │ └── modules.php
123 | │ └── modules
124 | │ └── mainmodule
125 | │ ├── config
126 | │ │ └── config.php
127 | │ ├── controllers
128 | │ │ ├── api
129 | │ │ │ └── IndexController.php
130 | │ │ ├── ModuleApiController.php
131 | │ │ └── ModuleController.php
132 | │ ├── lib
133 | │ ├── models
134 | │ │ └── ModuleModel.php
135 | │ ├── Module.php
136 | │ └── ModuleRoutes.php
137 | ├── public
138 | │ ├── assets
139 | │ ├── common
140 | │ ├── index.php
141 | │ ├── src
142 | │ │ └── app
143 | │ │ ├── layouts
144 | │ │ │ └── main.html
145 | │ │ ├── modules
146 | │ │ │ └── mainmodule
147 | │ │ │ └── views
148 | │ │ │ └── index
149 | │ │ │ └── index.html
150 | │ │ └── partials
151 | │ │ └── index.html
152 | │ └── styles
153 | └── test
154 | ├── application
155 | │ ├── ApplicationTest.php
156 | │ └── phpunit.xml
157 | ├── helpers
158 | │ ├── TestHelper.php
159 | │ └── UnitTestCase.php
160 | ├── modules
161 | │ └── mainmodule
162 | │ ├── helpers
163 | │ │ ├── ModuleTestHelper.php
164 | │ │ └── ModuleUnitTestCase.php
165 | │ ├── IndexControllerTest.php
166 | │ ├── ModuleTest.php
167 | │ └── phpunit.xml
168 | └── phalcon
169 | ├── FunctionalTestCase.php
170 | ├── ModelTestCase.php
171 | └── UnitTestCase.php
172 |
173 | ```
174 |
175 | ### Todo
176 |
177 | * Documentation
178 | * Subgenerators for models, routes
179 | * Generators for client side scripts
180 |
181 | ### Getting To Know Yeoman
182 |
183 | Yeoman has a heart of gold. He's a person with feelings and opinions, but he's very easy to work with. If you think he's too opinionated, he can be easily convinced.
184 |
185 | If you'd like to get to know Yeoman better and meet some of his friends, [Grunt](http://gruntjs.com) and [Bower](http://bower.io), check out the complete [Getting Started Guide](https://github.com/yeoman/yeoman/wiki/Getting-Started).
186 |
187 |
188 | ## License
189 |
190 | [MIT License](http://en.wikipedia.org/wiki/MIT_License)
191 |
--------------------------------------------------------------------------------
/app/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var util = require('util');
4 | var path = require('path');
5 | var colors = require('colors');
6 | var yeoman = require('yeoman-generator');
7 |
8 | var PhalconGenerator = module.exports = function PhalconGenerator(args, options, config) {
9 | yeoman.generators.Base.apply(this, arguments);
10 |
11 | this.on('end', function () {
12 | this.installDependencies({ skipInstall: options['skip-install'] });
13 |
14 | // we assume project slug as root folder, inform the user about this fact
15 | console.log(
16 | 'Please make sure this project is located in the ' +
17 | (this.project.rewritePath).yellow.bold +
18 | ' directory under your webserver root!'
19 | );
20 |
21 | // call module generator
22 | this.invoke('phalcon:module', {
23 | options: {
24 | 'skip-install': true,
25 | 'moduleName': this.module.name,
26 | 'projectName': this.project.name
27 | }
28 | });
29 | });
30 |
31 | this.pkg = JSON.parse(this.readFileAsString(path.join(__dirname, '../package.json')));
32 | };
33 |
34 | util.inherits(PhalconGenerator, yeoman.generators.Base);
35 |
36 | PhalconGenerator.prototype.askFor = function askFor()
37 | {
38 | var cb = this.async();
39 |
40 | console.log('\nI welcome you to the ' + 'Phalcon project generator'.bold + '.\n\n' +
41 | 'I will create a new ' + 'Phalcon multi module application'.yellow + '\n' +
42 | 'Please answer some questions first:\n'
43 | );
44 |
45 | var prompts = [
46 | {
47 | type: 'input',
48 | name: 'projectName',
49 | message: 'How would you like to call the new Project?',
50 | validate: function (input) {
51 | if (!input) {
52 | return 'I think your ' + 'project'.red + ' deserves an awesome ' + 'name'.red + '!';
53 | }
54 | return true;
55 | }
56 | },
57 |
58 | {
59 | type: 'input',
60 | name: 'moduleName',
61 | message: 'How would you like to name the main module?',
62 | validate: function (input) {
63 | if (!input) {
64 | return 'Please specify a valid ' + 'module name'.red + ' - this is not too difficult since it may be any string ...';
65 | }
66 | return true;
67 | }
68 | },
69 |
70 | {
71 | type: 'input',
72 | name: 'rewritePath',
73 | message: 'Please enter the name of the folder this project lives in (defaults to the slugified project name).'
74 | }
75 | ];
76 |
77 | this.prompt(prompts, function (props) {
78 | this.project = this.getProjectObject(props.projectName, props.rewritePath);
79 | this.module = this.getModuleObject(props.moduleName);
80 | cb();
81 | }.bind(this));
82 | };
83 |
84 | PhalconGenerator.prototype.app = function app()
85 | {
86 | this.publicDirs();
87 | this.privateDirs();
88 | this.testDirs();
89 | this.buildDirs();
90 |
91 | /* copy .htaccess file as template */
92 | this.template('phalcon/_htaccess', '.htaccess');
93 |
94 | /* build related files */
95 | this.copy('_package.json', 'package.json');
96 | this.copy('_bower.json', 'bower.json');
97 | this.copy('_composer.json', 'composer.json');
98 | this.copy('_build.xml', 'build.xml');
99 | };
100 |
101 | /*
102 | * Create public directory structure
103 | */
104 | PhalconGenerator.prototype.publicDirs = function publicDirs()
105 | {
106 | var dir = 'public';
107 | this.mkdir(dir);
108 | this.mkdir(dir + '/assets');
109 | this.mkdir(dir + '/common');
110 | this.mkdir(dir + '/styles');
111 | this.directory('phalcon/public', dir);
112 | };
113 |
114 | /*
115 | * Create private directory structure
116 | */
117 | PhalconGenerator.prototype.privateDirs = function privateDirs()
118 | {
119 | var dir = 'private';
120 | this.mkdir(dir);
121 | this.directory('phalcon/private', dir);
122 | };
123 |
124 | /*
125 | * Create private directory structure
126 | */
127 | PhalconGenerator.prototype.testDirs = function testDirs()
128 | {
129 | var dir = 'test';
130 | this.mkdir(dir);
131 | this.directory('phalcon/test', dir);
132 | };
133 |
134 | /*
135 | * Create private directory structure
136 | */
137 | PhalconGenerator.prototype.buildDirs = function buildDirs()
138 | {
139 | var dir = 'build';
140 | this.mkdir(dir);
141 | this.directory('build', dir);
142 | };
143 |
144 | PhalconGenerator.prototype.projectfiles = function projectfiles()
145 | {
146 | this.copy('editorconfig', '.editorconfig');
147 | this.copy('jshintrc', '.jshintrc');
148 | };
149 |
150 | PhalconGenerator.prototype.getModuleObject = function getModuleObject(moduleName)
151 | {
152 | return {
153 | name: moduleName,
154 | namespace: this._.camelize(this._.capitalize(moduleName)),
155 | slug: this._.slugify(moduleName),
156 | camelCase: this._.camelize(moduleName),
157 | viewsDir: "__DIR__ . '/../../../public/src/app/modules/" + this._.slugify(moduleName) + "/views/'"
158 | };
159 | };
160 |
161 | PhalconGenerator.prototype.getProjectObject = function getProjectObject(projectName, rewritePath)
162 | {
163 | return {
164 | name: projectName,
165 | namespace: this._.camelize(this._.capitalize(projectName)),
166 | slug: this._.slugify(projectName),
167 | camelCase: this._.camelize(projectName),
168 | rewritePath: '/' + this._.slugify(rewritePath || projectName) + '/',
169 | layoutsDir: "__DIR__ . '/../../../public/src/app/layouts/'"
170 | };
171 | };
--------------------------------------------------------------------------------
/app/templates/_bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "package",
3 | "version": "0.0.0",
4 | "dependencies": {}
5 | }
6 |
7 |
--------------------------------------------------------------------------------
/app/templates/_build.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
162 | * $this->app->request([ 'controller' => 'do', 'action' => 'something' ], 'param');
163 | *
164 | *
165 | * @param array $location Array with the route information: 'namespace', 'module', 'controller', 'action', 'params'
166 | * @return mixed
167 | */
168 | public function request(array $location)
169 | {
170 | /** @var \Phalcon\Mvc\Dispatcher $dispatcher */
171 | $dispatcher = clone $this->di->get('dispatcher');
172 | $defaults = [
173 | 'controller' => 'index',
174 | 'action' => 'index',
175 | 'params' => []
176 | ] + $location;
177 |
178 | if (isset($location['module'])) {
179 | $dispatcher->setModuleName($location['module']);
180 | }
181 |
182 | if (isset($location['namespace'])) {
183 | $dispatcher->setNamespaceName($location['namespace']);
184 | }
185 |
186 | $dispatcher->setControllerName($defaults['controller']);
187 | $dispatcher->setActionName($defaults['action']);
188 | $dispatcher->setParams((array)$defaults['params']);
189 | $dispatcher->dispatch();
190 |
191 | $response = $dispatcher->getReturnedValue();
192 |
193 | if ($response instanceof ResponseInterface) {
194 | return $response->getContent();
195 | }
196 |
197 | return $response;
198 | }
199 | }
200 |
--------------------------------------------------------------------------------
/app/templates/phalcon/private/common/lib/application/ApplicationModule.php:
--------------------------------------------------------------------------------
1 | \Application;
4 |
5 | use \Phalcon\Mvc\ModuleDefinitionInterface,
6 | \Phalcon\Mvc\User\Module as UserModule,
7 | \<%= project.namespace %>\Application\RoutedModule;
8 |
9 | /**
10 | * Abstract application module base class
11 | */
12 | abstract class ApplicationModule
13 | extends UserModule
14 | implements ModuleDefinitionInterface, RoutedModule
15 | {
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/app/templates/phalcon/private/common/lib/application/RoutedModule.php:
--------------------------------------------------------------------------------
1 | \Application;
4 |
5 | use \Phalcon\DiInterface;
6 |
7 | /**
8 | * Abstract application module base class
9 | */
10 | interface RoutedModule
11 | {
12 | /**
13 | * Load the module specific routes and mount them to the router
14 | * before the whole module gets loaded and add routing annotated
15 | * controllers
16 | *
17 | * @param \Phalcon\DiInterface $di
18 | */
19 | static function initRoutes(DiInterface $di);
20 | }
21 |
--------------------------------------------------------------------------------
/app/templates/phalcon/private/common/lib/application/controllers/ApplicationApiController.php:
--------------------------------------------------------------------------------
1 | \Application\Controllers;
4 |
5 |
6 | /**
7 | * Controller base class for all application API controllers
8 | */
9 | class ApplicationApiController extends ApplicationController
10 | {
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/app/templates/phalcon/private/common/lib/application/controllers/ApplicationController.php:
--------------------------------------------------------------------------------
1 | \Application\Controllers;
4 |
5 | use Phalcon\Mvc\Controller;
6 |
7 | /**
8 | * Controller base class for all application controllers
9 | */
10 | class ApplicationController extends Controller
11 | {
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/app/templates/phalcon/private/common/lib/application/controllers/ApplicationViewController.php:
--------------------------------------------------------------------------------
1 | \Application\Controllers;
4 |
5 | use Phalcon\Mvc\Controller;
6 |
7 | /**
8 | * Controller base class for all application controllers
9 | */
10 | class ApplicationViewController extends ApplicationController
11 | {
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/app/templates/phalcon/private/common/lib/application/models/ApplicationCollection.php:
--------------------------------------------------------------------------------
1 | \Application\Models;
4 |
5 | use \Phalcon\Mvc\Collection;
6 |
7 | class ApplicationCollection extends Collection
8 | {
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/app/templates/phalcon/private/common/lib/application/models/ApplicationModel.php:
--------------------------------------------------------------------------------
1 | \Application\Models;
4 |
5 | use \Phalcon\Mvc\Model;
6 |
7 | /**
8 | * Application model base class
9 | */
10 | class ApplicationModel extends Model
11 | {
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/app/templates/phalcon/private/common/lib/application/router/ApplicationRouter.php:
--------------------------------------------------------------------------------
1 | \Application\Router;
4 |
5 | use \Phalcon\Mvc\Router\Annotations as Router;
6 |
7 | /**
8 | * This class acts as the application router and defines global application routes.
9 | * Module specific routes are defined inside the ModuleRoutes classes. Since this
10 | * class extends the \Phalcon\Mvc\Router\Annotations class annotations are also allowed
11 | * for routing. Therefore add the Controllers as resources in the ModuleRoutes by invoking
12 | * addModuleResource on an instance of this class. Remember to register the controllers to the
13 | * autoloader.
14 | */
15 | class ApplicationRouter extends Router
16 | {
17 | /**
18 | * Creates a new instance of ApplicationRouter class and defines standard application routes
19 | * @param boolean $defaultRoutes
20 | */
21 | public function __construct($defaultRoutes = false)
22 | {
23 | parent::__construct($defaultRoutes);
24 |
25 | $this->removeExtraSlashes(true);
26 |
27 | /**
28 | * Controller and action always default to 'index'
29 | */
30 | $this->setDefaults([
31 | 'controller' => 'index',
32 | 'action' => 'index'
33 | ]);
34 |
35 | /**
36 | * Add global matching route for the default module '<%= module.namespace %>': 'default-route'
37 | */
38 | $this->add('/', [
39 | 'module' => '<%= module.slug %>',
40 | 'namespace' => '<%= project.namespace %>\<%= module.namespace %>\Controllers\API\\'
41 | ])->setName('default-route');
42 |
43 | /**
44 | * Add default not found route
45 | */
46 | $this->notFound([
47 | 'controller' => 'index',
48 | 'action' => 'route404'
49 | ]);
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/app/templates/phalcon/private/config/config.php:
--------------------------------------------------------------------------------
1 | [
8 | 'baseUri' => '<%= project.rewritePath %>',
9 | 'annotations' => ['adapter' => 'Apc'],
10 | 'models' => [
11 | 'metadata' => ['adapter' => 'Apc']
12 | ]
13 | ]
14 | ]);
15 |
--------------------------------------------------------------------------------
/app/templates/phalcon/private/config/modules.php:
--------------------------------------------------------------------------------
1 | project
6 | */
7 | return [];
8 |
--------------------------------------------------------------------------------
/app/templates/phalcon/public/.htaccess:
--------------------------------------------------------------------------------
1 | AddDefaultCharset UTF-8
2 |
3 |
141 | * $expected = array('Content-Type' => 'application/json')
142 | *
143 | *
144 | * @param string $expected The expected headers
145 | *
146 | * @return void
147 | */
148 | public function assertHeader(array $expected)
149 | {
150 | foreach ($expected as $expectedField => $expectedValue) {
151 | $actualValue = $this->di->getShared('response')->getHeaders()->get($expectedField);
152 | if ($actualValue != $expectedValue) {
153 | throw new \PHPUnit_Framework_ExpectationFailedException(
154 | sprintf(
155 | 'Failed asserting "%s" has a value of "%s", actual "%s" header value is "%s"',
156 | $expectedField,
157 | $expectedValue,
158 | $expectedField,
159 | $actualValue
160 | )
161 | );
162 | }
163 | $this->assertEquals($expectedValue, $actualValue);
164 | }
165 | }
166 |
167 | /**
168 | * Asserts that the response code matches the given one
169 | *
170 | * @param string $expected the expected response code
171 | *
172 | * @return void
173 | */
174 | public function assertResponseCode($expected)
175 | {
176 | $actualValue = $this->di->getShared('response')->getHeaders()->get('Status');
177 | if (empty($actualValue) || stristr($actualValue, $expected)) {
178 | throw new \PHPUnit_Framework_ExpectationFailedException(
179 | sprintf(
180 | 'Failed asserting response code "%s", actual response code is "%s"',
181 | $expected,
182 | $actualValue
183 | )
184 | );
185 | }
186 | $this->assertContains($expected, $actualValue);
187 | }
188 |
189 | /**
190 | * Asserts that the dispatched url resulted in a redirection
191 | *
192 | * @return void
193 | */
194 | public function assertRedirection()
195 | {
196 | $actual = $this->di->getShared('dispatcher')->wasForwarded();
197 | if (!$actual) {
198 | throw new \PHPUnit_Framework_ExpectationFailedException(
199 | 'Failed asserting response caused a redirect'
200 | );
201 | }
202 | $this->assertTrue($actual);
203 | }
204 | }
--------------------------------------------------------------------------------
/app/templates/phalcon/test/phalcon/ModelTestCase.php:
--------------------------------------------------------------------------------
1 |
13 | * @author Nikolaos Dimopoulos You're now flying with Phalcon. Great things are about to happen!
-------------------------------------------------------------------------------- /module/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var util = require('util'); 4 | var path = require('path'); 5 | var yeoman = require('yeoman-generator'); 6 | var colors = require('colors'); 7 | var fs = require('fs') 8 | 9 | var ModuleGenerator = module.exports = function ModuleGenerator(args, options, config) { 10 | yeoman.generators.Base.apply(this, arguments); 11 | 12 | this.on('end', function () { 13 | this.installDependencies({ skipInstall: options['skip-install'] }); 14 | console.log('The module ' + (this.module.slug).yellow.bold + ' has been created.'); 15 | 16 | // call controller generator 17 | this.invoke('phalcon:controller-view', { 18 | options: { 19 | 'skip-install': true, 20 | 'moduleName': this.module.name, 21 | 'projectName': this.project.name, 22 | 'controllerName': 'Index' 23 | } 24 | }); 25 | 26 | // call controller generator 27 | this.invoke('phalcon:controller-api', { 28 | options: { 29 | 'skip-install': true, 30 | 'moduleName': this.module.name, 31 | 'projectName': this.project.name, 32 | 'controllerName': 'Index' 33 | } 34 | }); 35 | }); 36 | 37 | console.log( 38 | '\nWelcome to the ' + 'Phalcon module generator'.bold + '.\n\n' + 39 | 'I will create a new ' + 'Phalcon module'.yellow + ' for your application.\n' 40 | ); 41 | 42 | this.module = false; 43 | this.project = false; 44 | 45 | if (options.moduleName) { 46 | this.module = this.getModuleObject(options.moduleName); 47 | } 48 | 49 | if (options.projectName) { 50 | this.project = this.getProjectObject(options.projectName); 51 | } 52 | }; 53 | 54 | util.inherits(ModuleGenerator, yeoman.generators.Base); 55 | 56 | ModuleGenerator.prototype.askFor = function askFor() 57 | { 58 | var prompts, 59 | cb = this.async(); 60 | 61 | if (!this.module || !this.project) { 62 | console.log('Please answer these simple questions:\n'); 63 | prompts = [ 64 | { 65 | type: 'input', 66 | name: 'projectName', 67 | message: 'What is the namespace of the project this module should belong to?', 68 | validate: function (input) { 69 | if (!input) { 70 | return 'I think your ' + 71 | 'project'.red + 72 | ' deserves an awesome ' + 73 | 'namespace'.red + '!'; 74 | } 75 | return true; 76 | } 77 | }, 78 | { 79 | type: 'input', 80 | name: 'moduleName', 81 | message: 'How would you like to name your module?', 82 | validate: function (input) { 83 | if (!input) { 84 | return 'Please specify a valid ' + 85 | 'module name'.red + 86 | ' - this is not too difficult since it may be any string ...'; 87 | } 88 | return true; 89 | } 90 | } 91 | ]; 92 | 93 | this.prompt(prompts, function (props) { 94 | this.project = this.getProjectObject(props.projectName); 95 | this.module = this.getModuleObject(props.moduleName); 96 | this.files(); 97 | cb(); 98 | }.bind(this)); 99 | } else { 100 | this.files(); 101 | cb(); 102 | } 103 | }; 104 | 105 | /* 106 | * Create module directory structure and module specific files, 107 | * copy the view files to the public resources 108 | */ 109 | ModuleGenerator.prototype.files = function files() 110 | { 111 | this.moduleFiles(); 112 | this.addModuleConfig(); 113 | }; 114 | 115 | /* 116 | * Add a module config entry to the application wide modules configuration. 117 | */ 118 | ModuleGenerator.prototype.addModuleConfig = function addModuleConfig() 119 | { 120 | var file = 'private/config/modules.php', 121 | moduleString = "\n\t'" + this.module.slug + "' => [\n\t\t" + 122 | "'className' => '\\" + this.project.namespace + "\\" + this.module.namespace + "\\Module',\n\t\t" + 123 | "'path' => __DIR__ . '/../modules/" + this.module.slug + "/Module.php',\n\t" + 124 | "],\n" + 125 | "];\n"; 126 | 127 | fs.readFile(file, 'utf8', function (err, data) { 128 | if (err) { 129 | return console.log(err); 130 | } else { 131 | var result = data.replace(/\];/g, moduleString); 132 | fs.writeFile(file, result, 'utf8', function (err) { 133 | if (err) { 134 | return console.log(err); 135 | } 136 | }); 137 | } 138 | }); 139 | }; 140 | 141 | /* 142 | * Create module directory structure and module specific files 143 | */ 144 | ModuleGenerator.prototype.moduleFiles = function moduleFiles() 145 | { 146 | var dir = 'private/modules/' + this.module.slug; 147 | this.mkdir(dir); 148 | this.directory('module', dir); 149 | this.directory('test', 'test/modules/' + this.module.slug); 150 | }; 151 | 152 | ModuleGenerator.prototype.getProjectObject = function getProjectObject(projectName) 153 | { 154 | return { 155 | name: projectName, 156 | namespace: this._.camelize(this._.capitalize(projectName)), 157 | slug: this._.slugify(projectName), 158 | camelCase: this._.camelize(projectName), 159 | rewritePath: '/' + this._.slugify(projectName) + '/', 160 | layoutsDir: "__DIR__ . '/../../../public/src/app/layouts/'" 161 | }; 162 | }; 163 | 164 | ModuleGenerator.prototype.getModuleObject = function getModuleObject(moduleName) 165 | { 166 | return { 167 | name: moduleName, 168 | namespace: this._.camelize(this._.capitalize(moduleName)), 169 | slug: this._.slugify(moduleName), 170 | camelCase: this._.camelize(moduleName), 171 | viewsDir: "__DIR__ . '/../../../public/src/app/modules/" + this._.slugify(moduleName) + "/views/'" 172 | }; 173 | }; -------------------------------------------------------------------------------- /module/templates/module/Module.php: -------------------------------------------------------------------------------- 1 | \<%= module.namespace %>; 4 | 5 | use \Phalcon\Loader, 6 | \Phalcon\DI, 7 | \Phalcon\Mvc\View, 8 | \Phalcon\Mvc\Dispatcher, 9 | \Phalcon\Config, 10 | \Phalcon\DiInterface, 11 | \Phalcon\Mvc\Url as UrlResolver, 12 | \Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter, 13 | \<%= project.namespace %>\Application\ApplicationModule; 14 | 15 | /** 16 | * Application module definition for multi module application 17 | * Defining the <%= module.namespace %> module 18 | */ 19 | class Module extends ApplicationModule 20 | { 21 | /** 22 | * Mount the module specific routes before the module is loaded. 23 | * Add ModuleRoutes Group and annotated controllers for parsing their routing information. 24 | * 25 | * @param \Phalcon\DiInterface $di 26 | */ 27 | public static function initRoutes(DiInterface $di) 28 | { 29 | $loader = new Loader(); 30 | $loader->registerNamespaces( 31 | [ 32 | '<%= project.namespace %>\<%= module.namespace %>' => __DIR__, 33 | '<%= project.namespace %>\<%= module.namespace %>\Controllers' => __DIR__ . '/controllers/', 34 | '<%= project.namespace %>\<%= module.namespace %>\Controllers\API' => __DIR__ . '/controllers/api/', 35 | '<%= project.namespace %>\<%= module.namespace %>\Controllers\View' => __DIR__ . '/controllers/view/', 36 | '<%= project.namespace %>\<%= module.namespace %>\Library\Controllers' => __DIR__ . '/lib/controllers' 37 | ], 38 | true 39 | )->register(); 40 | 41 | /** 42 | * Add ModuleRoutes Group and annotated controllers for parsing their routing information. 43 | * Be aware that the parsing will only be triggered if the request URI matches the third 44 | * parameter of addModuleResource. 45 | */ 46 | $router = $di->getRouter(); 47 | $router->mount(new ModuleRoutes()); 48 | 49 | /** 50 | * Read names of annotated controllers from the module config and add them to the router 51 | */ 52 | $moduleConfig = include __DIR__ . '/config/config.php'; 53 | if ( isset($moduleConfig['controllers']['annotationRouted']) ) { 54 | foreach ($moduleConfig['controllers']['annotationRouted'] as $ctrl) { 55 | $router->addModuleResource('<%= module.slug %>', $ctrl, '/<%= module.slug %>'); 56 | } 57 | } 58 | } 59 | 60 | /** 61 | * Registers the module auto-loader 62 | */ 63 | public function registerAutoloaders() 64 | { 65 | $loader = new Loader(); 66 | $loader->registerNamespaces( 67 | [ 68 | '<%= project.namespace %>\<%= module.namespace %>' => __DIR__, 69 | '<%= project.namespace %>\<%= module.namespace %>\Controllers' => __DIR__ . '/controllers/', 70 | '<%= project.namespace %>\<%= module.namespace %>\Controllers\API' => __DIR__ . '/controllers/api/', 71 | '<%= project.namespace %>\<%= module.namespace %>\Controllers\View' => __DIR__ . '/controllers/view/', 72 | '<%= project.namespace %>\<%= module.namespace %>\Models' => __DIR__ . '/models/', 73 | '<%= project.namespace %>\<%= module.namespace %>\Library' => __DIR__ . '/lib/', 74 | '<%= project.namespace %>\<%= module.namespace %>\Library\Models' => __DIR__ . '/lib/models', 75 | '<%= project.namespace %>\<%= module.namespace %>\Library\Controllers' => __DIR__ . '/lib/controllers' 76 | ], 77 | true 78 | )->register(); 79 | } 80 | 81 | /** 82 | * Registers the module-only services 83 | * 84 | * @param \Phalcon\DiInterface $di 85 | */ 86 | public function registerServices($di) 87 | { 88 | /** 89 | * Read application wide and module only configurations 90 | */ 91 | $appConfig = $di->get('config'); 92 | $moduleConfig = include __DIR__ . '/config/config.php'; 93 | 94 | $di->set('moduleConfig', $moduleConfig); 95 | 96 | /** 97 | * Setting up the view component 98 | */ 99 | $di->set( 100 | 'view', 101 | function() { 102 | $view = new View(); 103 | $view->setViewsDir(<%= module.viewsDir %>) 104 | ->setLayoutsDir('../../../layouts/') 105 | ->setPartialsDir('../../../partials/') 106 | ->setTemplateAfter('main') 107 | ->registerEngines(['.html' => 'Phalcon\Mvc\View\Engine\Php']); 108 | return $view; 109 | } 110 | ); 111 | 112 | /** 113 | * The URL component is used to generate all kind of urls in the application 114 | */ 115 | $di->set( 116 | 'url', 117 | function () use ($appConfig) { 118 | $url = new UrlResolver(); 119 | $url->setBaseUri($appConfig->application->baseUri); 120 | return $url; 121 | } 122 | ); 123 | 124 | /** 125 | * Module specific dispatcher 126 | */ 127 | $di->set( 128 | 'dispatcher', 129 | function () use ($di) { 130 | $dispatcher = new Dispatcher(); 131 | $dispatcher->setEventsManager($di->getShared('eventsManager')); 132 | $dispatcher->setDefaultNamespace('<%= project.namespace %>\<%= module.namespace %>\\'); 133 | return $dispatcher; 134 | } 135 | ); 136 | 137 | /** 138 | * Module specific database connection 139 | */ 140 | $di->set( 141 | 'db', 142 | function() use ($moduleConfig) { 143 | return new DbAdapter( 144 | [ 145 | 'host' => $moduleConfig->database->host, 146 | 'username' => $moduleConfig->database->username, 147 | 'password' => $moduleConfig->database->password, 148 | 'dbname' => $moduleConfig->database->dbname 149 | ] 150 | ); 151 | } 152 | ); 153 | 154 | /** 155 | * Module specific database connection 156 | */ 157 | $di->set( 158 | 'mongo', 159 | function () use ($moduleConfig) { 160 | $mongo = new Mongo($moduleConfig->mongoDB->connectionUrl); 161 | return $mongo->selectDb($moduleConfig->mongoDB->dbname); 162 | }, 163 | true 164 | ); 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /module/templates/module/ModuleRoutes.php: -------------------------------------------------------------------------------- 1 | \<%= module.namespace %>; 4 | 5 | use \Phalcon\Mvc\Router\Group; 6 | 7 | /** 8 | * This class defines routes for the <%= project.namespace %>\<%= module.namespace %> module 9 | * which will be prefixed with '/<%= module.slug %>' 10 | */ 11 | class ModuleRoutes extends Group 12 | { 13 | /** 14 | * Initialize the router group for the <%= module.namespace %> module 15 | */ 16 | public function initialize() 17 | { 18 | /** 19 | * In the URI this module is prefixed by '/<%= module.slug %>' 20 | */ 21 | $this->setPrefix('/<%= module.slug %>'); 22 | 23 | /** 24 | * Configure the instance 25 | */ 26 | $this->setPaths( 27 | [ 28 | 'module' => '<%= module.slug %>', 29 | 'namespace' => '<%= project.namespace %>\<%= module.namespace %>\Controllers\View\\', 30 | 'controller' => 'index', 31 | 'action' => 'index' 32 | ] 33 | ); 34 | 35 | /** 36 | * Default route: '<%= module.slug %>-api-root' 37 | */ 38 | $this->addGet( 39 | '/api', 40 | [ 41 | 'namespace' => '<%= project.namespace %>\<%= module.namespace %>\Controllers\API\\' 42 | ] 43 | )->setName('<%= module.slug %>-api-root'); 44 | 45 | /** 46 | * API Controller route: '<%= module.slug %>-api-controller' 47 | */ 48 | $this->addGet( 49 | '/api/:controller', 50 | [ 51 | 'namespace' => '<%= project.namespace %>\<%= module.namespace %>\Controllers\API\\', 52 | 'controller' => 1 53 | ] 54 | )->setName('<%= module.slug %>-api-controller'); 55 | 56 | /** 57 | * API Action route: '<%= module.slug %>-api-action' 58 | */ 59 | $this->addGet( 60 | '/api/:controller/:action/:params', 61 | [ 62 | 'namespace' => '<%= project.namespace %>\<%= module.namespace %>\Controllers\API\\', 63 | 'controller' => 1, 64 | 'action' => 2, 65 | 'params' => 3 66 | ] 67 | )->setName('<%= module.slug %>-api-action'); 68 | 69 | /** 70 | * Default route: '<%= module.slug %>-view-root' 71 | */ 72 | $this->addGet( 73 | '/view', 74 | [ 75 | 'namespace' => '<%= project.namespace %>\<%= module.namespace %>\Controllers\View\\' 76 | ] 77 | )->setName('<%= module.slug %>-view-root'); 78 | 79 | /** 80 | * View Controller route: '<%= module.slug %>-view-controller' 81 | */ 82 | $this->addGet( 83 | '/view/:controller', 84 | [ 85 | 'namespace' => '<%= project.namespace %>\<%= module.namespace %>\Controllers\View\\', 86 | 'controller' => 1 87 | ] 88 | )->setName('<%= module.slug %>-view-controller'); 89 | 90 | /** 91 | * View Action route: '<%= module.slug %>-view-action' 92 | */ 93 | $this->addGet( 94 | '/api/:controller/:action/:params', 95 | [ 96 | 'namespace' => '<%= project.namespace %>\<%= module.namespace %>\Controllers\View\\', 97 | 'controller' => 1, 98 | 'action' => 2, 99 | 'params' => 3 100 | ] 101 | )->setName('<%= module.slug %>-view-action'); 102 | 103 | /** 104 | * Add all <%= project.namespace %>\<%= module.namespace %> specific routes here 105 | */ 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /module/templates/module/config/config.php: -------------------------------------------------------------------------------- 1 | [ 5 | 'adapter' => 'Mysql', 6 | 'host' => 'localhost', 7 | 'username' => 'root', 8 | 'password' => '', 9 | 'dbname' => 'test', 10 | 'persistent' => true, 11 | 'charset' => 'utf8' 12 | ], 13 | 'mongoDB' => [ 14 | 'dbname' => 'test', 15 | 'connectionUrl' => 'localhost' 16 | ], 17 | 'controllers' => [ 18 | 'annotationRouted' => [ 19 | ] 20 | ] 21 | ]); 22 | -------------------------------------------------------------------------------- /module/templates/module/controllers/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelkrone/generator-phalcon/58daac265e575e7a4e9eb5eeefaa2e3547194281/module/templates/module/controllers/.gitignore -------------------------------------------------------------------------------- /module/templates/module/lib/controllers/ModuleApiController.php: -------------------------------------------------------------------------------- 1 | \<%= module.namespace %>\Library\Controllers; 4 | 5 | use <%= project.namespace %>\Application\Controllers\ApplicationApiController; 6 | 7 | /** 8 | * Base class of <%= module.namespace %> module API controller 9 | */ 10 | class ModuleApiController extends ApplicationApiController 11 | { 12 | public function beforeExecuteRoute($dispatcher) 13 | { 14 | $this->response->setContentType('application/json'); 15 | } 16 | } -------------------------------------------------------------------------------- /module/templates/module/lib/controllers/ModuleController.php: -------------------------------------------------------------------------------- 1 | \<%= module.namespace %>\Library\Controllers; 4 | 5 | use <%= project.namespace %>\Application\Controllers\ApplicationController; 6 | 7 | /** 8 | * Base class of <%= module.namespace %> module controller 9 | */ 10 | class ModuleController extends ApplicationController 11 | { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /module/templates/module/lib/controllers/ModuleViewController.php: -------------------------------------------------------------------------------- 1 | \<%= module.namespace %>\Library\Controllers; 4 | 5 | use <%= project.namespace %>\Application\Controllers\ApplicationController; 6 | 7 | /** 8 | * Base class of <%= module.namespace %> module View controller 9 | */ 10 | class ModuleViewController extends ApplicationController 11 | { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /module/templates/module/lib/models/ModuleCollection.php: -------------------------------------------------------------------------------- 1 | \<%= module.namespace %>\Library\Models; 4 | 5 | use <%= project.namespace %>\Application\Models\ApplicationCollection; 6 | 7 | class ModuleCollection extends ApplicationCollection 8 | { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /module/templates/module/lib/models/ModuleModel.php: -------------------------------------------------------------------------------- 1 | \<%= module.namespace %>\Library\Models; 4 | 5 | use <%= project.namespace %>\Application\Models\ApplicationModel; 6 | 7 | /** 8 | * Base class of <%= module.namespace %> model 9 | */ 10 | class ModuleModel extends ApplicationModel 11 | { 12 | 13 | } -------------------------------------------------------------------------------- /module/templates/module/models/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelkrone/generator-phalcon/58daac265e575e7a4e9eb5eeefaa2e3547194281/module/templates/module/models/.gitignore -------------------------------------------------------------------------------- /module/templates/test/ModuleTest.php: -------------------------------------------------------------------------------- 1 | \<%= module.namespace %>\Test; 4 | 5 | use Phalcon\DI, 6 | <%= project.namespace %>\<%= module.namespace %>\Test\Helper\ModuleUnitTestCase; 7 | 8 | /** 9 | * Test class for <%= module.namespace %> Module class 10 | */ 11 | class ModuleTest extends ModuleUnitTestCase 12 | { 13 | /** 14 | * Test class for module routes 15 | * @covers \<%= project.namespace %>\<%= module.namespace %>\Module::initRoutes 16 | */ 17 | public function testSimpleModuleRoute() 18 | { 19 | $di = $this->application->di; 20 | $router = $di->get('router'); 21 | $router->handle('/'); 22 | $this->assertEquals('<%= module.slug %>', $router->getModuleName()); 23 | $this->assertEquals('index', $router->getControllerName()); 24 | $this->assertEquals('index', $router->getActionName()); 25 | } 26 | 27 | /** 28 | * Test url generation 29 | * 30 | * @covers \<%= project.namespace %>\<%= module.namespace %>\Module::registerServices 31 | */ 32 | public function testServiceRegistration() 33 | { 34 | $this->assertInstanceOf('\Phalcon\Config', $this->application->di->get('moduleConfig')); 35 | $this->assertInstanceOf('\Phalcon\Mvc\View', $this->application->di->get('view')); 36 | $this->assertInstanceOf('\Phalcon\Mvc\Url', $this->application->di->get('url')); 37 | $this->assertInstanceOf('\Phalcon\Mvc\Dispatcher', $this->application->di->get('dispatcher')); 38 | $this->assertInstanceOf('\Phalcon\Db\AdapterInterface', $this->application->di->get('db')); 39 | $this->assertInstanceOf('\Phalcon\Db\AdapterInterface', $this->application->di->get('mongoDB')); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /module/templates/test/helpers/ModuleTestHelper.php: -------------------------------------------------------------------------------- 1 | registerNamespaces([ 21 | 'Phalcon\Test' => ROOT_PATH . 'test/phalcon/', 22 | '<%= project.namespace %>\Test\Helper' => ROOT_PATH . 'test/helpers/', 23 | '<%= project.namespace %>\Application' => ROOT_PATH . 'private/common/lib/application/', 24 | '<%= project.namespace %>\Application\Controllers' => ROOT_PATH . 'private/common/lib/application/controllers/', 25 | '<%= project.namespace %>\<%= module.namespace %>' => ROOT_PATH . 'private/modules/<%= module.slug %>/', 26 | '<%= project.namespace %>\<%= module.namespace %>\Controllers' => ROOT_PATH . 'private/modules/<%= module.slug %>/controllers/', 27 | '<%= project.namespace %>\<%= module.namespace %>\Controllers\API' => ROOT_PATH . 'private/modules/<%= module.slug %>/controllers/api/', 28 | '<%= project.namespace %>\<%= module.namespace %>\Controllers\View' => ROOT_PATH . 'private/modules/<%= module.slug %>/controllers/view/', 29 | '<%= project.namespace %>\<%= module.namespace %>\Models' => ROOT_PATH . 'private/modules/<%= module.slug %>/models/', 30 | '<%= project.namespace %>\<%= module.namespace %>\Library' => ROOT_PATH . 'private/modules/<%= module.slug %>/lib/', 31 | '<%= project.namespace %>\<%= module.namespace %>\Library\Models' => ROOT_PATH . 'private/modules/<%= module.slug %>/lib/models/', 32 | '<%= project.namespace %>\<%= module.namespace %>\Library\Controllers' => ROOT_PATH . 'private/modules/<%= module.slug %>/lib/Controllers/', 33 | '<%= project.namespace %>\<%= module.namespace %>\Test\Helper' => ROOT_PATH . 'test/modules/<%= module.slug %>/helpers/', 34 | 35 | ])->register(); 36 | 37 | $di = new FactoryDefault(); 38 | DI::reset(); 39 | 40 | // add any needed services to the DI here 41 | 42 | DI::setDefault($di); 43 | -------------------------------------------------------------------------------- /module/templates/test/helpers/ModuleUnitTestCase.php: -------------------------------------------------------------------------------- 1 | \<%= module.namespace %>\Test\Helper; 3 | 4 | use Phalcon\DI, 5 | \Phalcon\Test\UnitTestCase as PhalconTestCase, 6 | \<%= project.namespace %>\Application\Application, 7 | \<%= project.namespace %>\<%= module.namespace %>\Module; 8 | 9 | abstract class ModuleUnitTestCase extends PhalconTestCase 10 | { 11 | /** 12 | * @var \Voice\Cache 13 | */ 14 | protected $_cache; 15 | 16 | /** 17 | * @var \Phalcon\Config 18 | */ 19 | protected $_config; 20 | 21 | protected $application; 22 | 23 | /** 24 | * @var bool 25 | */ 26 | private $_loaded = false; 27 | 28 | public function setUp(\Phalcon\DiInterface $di = null, \Phalcon\Config $config = null) 29 | { 30 | // Load any additional services that might be required during testing 31 | $di = DI::getDefault(); 32 | $this->application = new Application($di); 33 | 34 | // init module 35 | $module = new Module(); 36 | $module->registerServices($di); 37 | 38 | // get any DI components here. If you have a config, be sure to pass it to the parent 39 | parent::setUp($this->application->di, $this->application->config); 40 | 41 | $this->_loaded = true; 42 | } 43 | 44 | public function tearDown() { 45 | $this->application = null; 46 | } 47 | 48 | /** 49 | * Check if the test case is setup properly 50 | * @throws \PHPUnit_Framework_IncompleteTestError; 51 | */ 52 | public function __destruct() { 53 | if(!$this->_loaded) { 54 | throw new \PHPUnit_Framework_IncompleteTestError('Please run parent::setUp().'); 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /module/templates/test/phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 |