├── .gitignore ├── README-short.md ├── README.md ├── app ├── commands │ └── .gitkeep ├── config │ ├── app.php │ ├── auth.php │ ├── cache.php │ ├── database.php │ ├── mail.php │ ├── packages │ │ └── .gitkeep │ ├── queue.php │ ├── session.php │ ├── testing │ │ ├── cache.php │ │ └── session.php │ └── view.php ├── controllers │ ├── .gitkeep │ ├── BaseController.php │ └── HomeController.php ├── database │ ├── migrations │ │ └── .gitkeep │ ├── production.sqlite │ └── seeds │ │ ├── .gitkeep │ │ └── DatabaseSeeder.php ├── filters.php ├── lang │ └── en │ │ ├── pagination.php │ │ ├── reminders.php │ │ └── validation.php ├── models │ └── .gitkeep ├── routes.php ├── start │ ├── artisan.php │ ├── global.php │ └── local.php ├── storage │ ├── .gitignore │ ├── cache │ │ └── .gitignore │ ├── logs │ │ └── .gitignore │ ├── meta │ │ └── .gitignore │ ├── sessions │ │ └── .gitignore │ └── views │ │ └── .gitignore ├── tests │ ├── ExampleTest.php │ └── TestCase.php └── views │ └── hello.php ├── bootstrap ├── autoload.php ├── paths.php └── start.php ├── composer.json └── public ├── .htaccess ├── favicon.ico ├── index.php └── packages └── .gitkeep /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | composer.phar 3 | composer.lock 4 | -------------------------------------------------------------------------------- /README-short.md: -------------------------------------------------------------------------------- 1 | # DSL platform Tutorial 2 | 3 | ## Introduction 4 | 5 | This tutorial will show you how to develop a small PHP blog application by using DSL platform. 6 | 7 | ## Setup 8 | 9 | 1. Clone the repository 10 | 11 | You can clone or fork&clone the basic application from [Github](https://github.com/nutrija/dsl-php-tutorial). 12 | 13 | $ git clone https://github.com/ngs-doo/dsl-php-tutorial.git dslblog 14 | 15 | 2. Install dependencies via composer 16 | 17 | Run composer to install dependencies: 18 | 19 | $ cd dslblog 20 | $ curl -sS https://getcomposer.org/installer | php 21 | $ php composer.phar install 22 | 23 | Setup permissions: 24 | 25 | $ chown www-data. app/storage/ -R 26 | 27 | 3. Server setup 28 | 29 | Setup your server so it's document root points to the dslblog/public folder. 30 | Open your browser and go to http://localhost/dslblog. You should see a 'Hello world' message. 31 | 32 | 4. Install DSL platform 33 | 34 | Register at [dsl-platform.com] (https://dsl-platform.com). Then create a project and download the zip from the 'Downloads' section. Extract the download to the '/app/dsl-platform' folder. 35 | 36 | To load the platform, add at the beginning of start/global.php file: 37 | 38 | ```php 39 | require_once(__DIR__.'/../dsl-platform/platform/Bootstrap.php'); 40 | ``` 41 | 42 | Platform will need write permissions for the /app/dsl-platform/platform/ folder to download generated source files. For server running as www-data, set permissions like this: 43 | 44 | ```bash 45 | $ chown www-data. app/dsl-platform/platform/ -R 46 | ``` 47 | 48 | 5. Check installation 49 | 50 | Open browser, and enter url or path to your installation. You should get a "Hello, world!" response. That means everything is up and running. 51 | 52 | ## DSL 101 53 | 54 | We'll describe our models in DSL files. DSL files must be placed in /dsl-platform/dsl folder. Let's describe a blog post in DSL: 55 | 56 | module Blog 57 | { 58 | root Post 59 | { 60 | string title; 61 | string content; 62 | } 63 | } 64 | 65 | This DSL defines an aggregate root object named 'Post' that contains two string properties. Aggregate root is one of core concepts used in [Domain driven design](http://en.wikipedia.org/wiki/Domain-driven_design) (DDD). We'll be using this concept as a basic building block. For now, you can just regard a root as a single table in the database. 66 | 67 | Each time a DSL file is modified, platform will use it to update the database and generate PHP source files which can be found in the platform/modules folder. Go there and take a look at the beginning of generated Post.php file: 68 | 69 | ```php 70 | class Post extends \NGS\Patterns\AggregateRoot implements \IteratorAggregate 71 | { 72 | protected $URI; 73 | protected $ID; 74 | protected $title; 75 | protected $content; 76 | } 77 | ``` 78 | 79 | Title and content properties were specified in the DSL. URI and ID are generated properties, they are used as object identifiers. 80 | We can use this class to perform various operations, e.g. create and persist a new Post object. 81 | 82 | ### Persisting data: 83 | 84 | We'll create a route that persists a 'Hello world' post. Copy the following code on the beginning of routes.php file: 85 | 86 | ```php 87 | Route::get('/test', function() 88 | { 89 | $post = new \Blog\Post(); 90 | $post->title = 'Hello'; 91 | $post->content = 'Hello world!'; 92 | $post->persist(); 93 | 94 | return 'Created a new post. Post URI is: '.$post->URI; 95 | }); 96 | ``` 97 | 98 | (*note: it's not best practice to use HTTP GET methods to persist data, this is just an example) 99 | 100 | Now go to http://localhost/test (or your server URL). You should get a response containing "Created post with URI 1001". That means a new Post has been persisted to database. It was assigned ID with value equal to 1001. (numeric keys start increment starting from 1000) 101 | 102 | Inside the 'persist' method, a HTTP request is sent to the server, which persist the data to database, and then returns a generated URI value. 103 | 104 | ### Reading persisted data: 105 | 106 | Let's create a route that searches for a post with specific URI and passes it to view: 107 | 108 | ```php 109 | Route::get('/(:num)', function($uri) 110 | { 111 | $post = \Blog\Post::find($uri); 112 | return View::make('home.post')->with('post', $post); 113 | }); 114 | ``` 115 | 116 | The 'find' method queries the database for a Blog\Post with specified URI value. If the object is not found, an exception will be thrown. 117 | Let's create a view for basic site layout: 118 | 119 | /application/views/home.php: 120 | 121 | ```php 122 | 123 | 124 | 125 | 126 | DSL blog 127 | 128 | 129 | 130 | 131 | 132 | ``` 133 | 134 | And another view for post... 135 | 136 | /application/views/post.php: 137 | 138 | ```php 139 |

title?>

140 |

content?>

141 | ``` 142 | 143 | Now you should see the post contents at http://localhost/1001. 144 | 145 | ### Specifying relationships 146 | 147 | One way to specify a relationship is to specify a property as a reference to another object. We'll add a Comment that points to a post: 148 | 149 | root Comment 150 | { 151 | Post* post; 152 | string email; 153 | string content; 154 | date createdAt; 155 | } 156 | 157 | Property named 'post' points to a specific Post instance. Now let's expand the post view with comments and a form to post new comments: 158 | 159 | /application/views/post.php: 160 | 161 | ```php 162 |

Title?>

163 |

Content?>

164 | 165 | 170 | 171 |
172 |

Leave a comment...

173 |
174 | 175 | 176 |
177 | 178 | 179 |
180 |
181 | ``` 182 | 183 | And here's a route which will persist the comment posted from the form: 184 | 185 | ```php 186 | Route::post('/comment', function() { 187 | $postURI = Input::get('PostURI'); 188 | $comment = new Comment(); 189 | $post = Post::find($postURI); 190 | $comment->post = $post; 191 | $comment->email = Input::get('Email'); 192 | $comment->content = Input::get('Content'); 193 | $comment->persist(); 194 | return Redirect::to('/post/'.$postURI); 195 | }); 196 | ``` 197 | 198 | ### Finding objects 199 | 200 | Each root class has a findAll method which retrieves all persisted objects: 201 | 202 | ```php 203 | $comments = Comment::findAll(); 204 | ``` 205 | 206 | ### Generic search 207 | 208 | Retrieve only those comments pointing to a certain post: 209 | 210 | ```php 211 | $postID = 1001; 212 | $search = new GenericSearch('Blog\Comment'); 213 | $comments = $search->equals('PostID', $postID)->search(); 214 | ``` 215 | 216 | GenericSearch equals method is just one of many filter methods that can be used to customize search. 217 | 218 | ### Specifications 219 | 220 | Specification states a certain condition. It has various uses, one of them is to filter retrieved items. Here's a specification that fetches all comments belonging to a certain post: 221 | 222 | root Comment 223 | { 224 | Post* post; 225 | string email; 226 | string content; 227 | date createdAt; 228 | 229 | specification findByPost 'item => item.PostID == postID' 230 | { 231 | int postID; 232 | } 233 | } 234 | 235 | Use this specification in PHP to find all comments for a certain post: 236 | 237 | ```php 238 | $postID = 1001; 239 | $results = \Blog\Comment::findByPost($postID); 240 | ``` 241 | 242 | We can now expand a route that displays post with this specification: 243 | 244 | ```php 245 | Route::get('/(:num)', function($postURI) 246 | { 247 | $post = \Blog\Post::find($postURI); 248 | $comments = \Blog\Comment::findByPost($postURI); 249 | $view = View::make('base'); 250 | return $view->nest('content', 'post', array( 251 | 'post' => $post, 252 | 'comments' => $comments, 253 | )); 254 | }); 255 | ``` 256 | 257 | ### Deleting data 258 | 259 | Here's a route that deletes a certain comment: 260 | 261 | ```php 262 | Route::delete('/comment/(:uri)', function($uri) 263 | { 264 | $comment = \Blog\Comment::find($uri); 265 | $comment->delete(); 266 | return Redirect::back(); // referer 267 | }); 268 | ``` 269 | 270 | The delete method can be used on every root class. If the specified object is not found, exception will be thrown which you can handle like so: 271 | 272 | ```php 273 | Route::get('/comment/delete/(:id)', function($id) 274 | { 275 | try { 276 | $comment = \Blog\Comment::find($uri); 277 | $comment->delete(); 278 | return Redirect::back(); // referer 279 | } 280 | catch (\NGS\Client\NotFoundException\Exception $ex) { 281 | return Response::make($ex->getMessage(), 404); 282 | } 283 | }); 284 | ``` 285 | 286 | ## DSL and beyond 287 | 288 | There are many more features of DSL platform, such as generating reports in various formats and analyzing data using built-in [OLAP](http://en.wikipedia.org/wiki/Online_analytical_processing) features. 289 | 290 | Besides the features built-in in the platform, the DSL platform brings certain features specifically to PHP. One of the more interesting is type safety, which is a way to improve PHP's type system. 291 | 292 | ### PHP type safety 293 | 294 | PHP classes generated from the DSL will provide some type safety. Let's assume the following DSL: 295 | 296 | module Blog 297 | { 298 | root Post { 299 | string title; 300 | } 301 | } 302 | 303 | Title is a string property, and only strings should be assigned to it. If an illegal operation is performed by assigning it an invalid type such as array property: 304 | 305 | ```php 306 | $post = new Blog\Post(); 307 | $post->title = array(); 308 | ``` 309 | 310 | ... an InvalidArgumentException is thrown. Under the hood, each property is assigned in a setter method called using magic __set function. Each setter will raise an exception if value being assigned to the property cannot be converted to the analogous type specified in DSL. 311 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DSL platform Tutorial 2 | 3 | ## Introduction 4 | 5 | DSL platform is a multi-language platform inspired by Domain driven design. 6 | 7 | 8 | 9 | In this tutorial we'll show how you can rapidly develop a small PHP blog application by using DSL platform. 10 | 11 | ## Setup 12 | 13 | ### What you'll need: 14 | 15 | - PHP 5.3.7 or greater 16 | - basic OOP, you should know how to write your own class, create a new object instance and call its methods, that should do it for the first part... 17 | - server with working PHP installation, you'll probably use Apache with mod-php or Nginx with php-fpm. or, with PHP 5.4+, you could use PHP's built-in server (type in your shell: "php -S localhost:8000") 18 | - basic MVC knowledge, but you can do without it 19 | - Git 20 | 21 | To start writing our blog, we first need to write some routes, views etc. We want to focus on the platform and put the wiring out of the way. We don't want to spend time reinvent features like routing and templating, so we'll just use [Laravel](http://laravel.com) to handle that. In case you haven't heard, Laravel is a lightweight PHP MVC framework. Why Laravel, why not Symfony, Zend , "insert-your-framework-here"? Well, Laravel is simple enough to get you quickly started and has decent documentation. If you don't like it, you are welcome to choose a framework of your choice, be it a full-stack solution like Symfony, or something less complex like Sylex or Slim. Framework is here just for wiring and plumbing, we could write tutorial using bare PHP, but nobody uses that nowadays, right? 22 | 23 | 39 | 40 | ### Installation 41 | 42 | 1. Install basic Laravel application 43 | You can fork the basic skeleton application from [Github](https://github.com/ngs-doo/dsl-php-tutorial) and then clone it, or go to your projects folder and clone the original repository directly: 44 | 45 | $ git clone https://github.com/ngs-doo/dsl-php-tutorial.git dslblog 46 | 47 | This will clone your repository into a new 'dslblog' folder. Repository contains this readme file, composer.json and basic Laravel file structure. We'll use composer to install Laravel core files. If you have composer installed, you can run 'composer install' inside dslblog folder. If you haven't used composer yet, composer is a PHP package manager that will download and register your dependencies. It's simple to install it, go to dslblog and run: 48 | 49 | $ cd dslblog 50 | $ curl -sS https://getcomposer.org/installer | php 51 | $ php composer.phar install 52 | 53 | This will download and execute composer.phar file which will download all the required Laravel dependencies. 54 | 55 | Next, you should make app/storage folder writable by the server user. If you are running apache as www-data user, you can run: 56 | 57 | $ chown www-data. app/storage/ -R 58 | 59 | 2. Setup server 60 | 61 | Now you should setup your server to point to public folder. If you are using Apache, you can place a symlink to dslblog/public folder in your server root or setup in some other way. 62 | Open your browser and go to http://localhost/dslblog. You should see 'Hello world' text. That means Laravel installation is working. Next, we'll setup DSL platform. 63 | 64 | 3. Install DSL platform 65 | 66 | To install DSL platform, you'll first need to register and create a project at [dsl-platform.com] (https://dsl-platform.com). Each application should have a separate project, similar to application having a separate database. To create your first project, you need to register. It's a simple one-step process, just go to [registration page](https://dsl-platform.com/register/php) and enter your email. You'll be automatically logged in. 67 | 68 | After registration, you should be logged in. Click on the 'New project' button. This will create an empty new project. Now you can change its name to 'Blog' (this will make model classes reside in default \Blog namespace). Go to 'Downloads' section and download the zipped project files. Create a folder named 'dsl-platform' in '/app' folder of your Laravel installation and extract the download there. Now you should have two folders inside: dsl and platform. Platform folder contains necessary source files and generated code. The 'dsl' folder will be used to store .dsl files in which we'll describe our application data domain (models). 69 | 70 | We need to make Laravel recognize the DSL bundle. Normally, we'd make a separate bundle which handles initialization, but we'll skip that here and just glue registration at the beginning of start/global.php file: 71 | 72 | ```php 73 | require_once(__DIR__.'/../dsl-platform/platform/Bootstrap.php'); 74 | ``` 75 | 76 | Including bootstrap is all you need to get the platform running. Bootstrap will handle: 77 | 78 | - downloading and updating platform core source files 79 | - downloading generated model files (these will be generated from description inputted in DSL files, we'll soon get to details) 80 | - class loading (no autoloading is required) 81 | - initializing connection to the server 82 | 83 | Bootstrap needs write permissions to platform folder to copy downloaded source files. To set up permissions with apache as www-data user, run in your terminal: 84 | 85 | ```bash 86 | $ chown www-data. app/dsl-platform/platform/ -R 87 | ``` 88 | 89 | ### Validate your installation 90 | 91 | Open browser, and enter url or path to your installation. You should get a "Hello, world!" response. That means everything is up and running. 92 | 93 | ## DSL 101 94 | 95 | We're creating a blog application, so let's get started with creating some posts. 96 | Usually, if starting from scratch, we would first create a database and a table named 'Blog' and then use some sort of ORM to define a Post class with fields mapped to 'Blog' table columns. Each post needs a title and a content, so we'll end with a Blog class that looks something like this: 97 | 98 | ```php 99 | namespace Blog; 100 | 101 | class Post extends MyOrm\Model { 102 | public $title; 103 | public $content; 104 | } 105 | ``` 106 | 107 | We could also use annotations or properties to specify constraints, validations, relationships with other entities etc. Depending on the tools we use, we could specify those settings in database and then build our model classes, or vice versa, write PHP and let ORM update the database. In worst case, we'll have to update both models and database ourselves. 108 | 109 | In DSL platform, we'll do things a little different. First, there is no need for us to know anything about the database and we'll never work directly with it. Database will be running somewhere on the cloud, and DSL platform will manage it in the background for us. So, without the database, we need some way to define our data models. We could do that in PHP, but, well, PHP really wasn't intended to describe domain models and relationships, so we'll use a more suitable tool for that, we'll just call it DSL. DSL stands for [Domain specific language](http://en.wikipedia.org/wiki/Domain-specific_language). In case you haven't heard or worked with some kind of DSL, think again, if you ever wrote a single line of database query in SQL, you've used DSL, as SQL is also one kind of DSL. 110 | 111 | ### Writing our first DSL 112 | 113 | Let's get started by translating our post to DSL. Some conventions: all the .dsl files should be placed in /dsl-platform/dsl folder. Let's see how our blog class looks like in DSL. Copy the following lines to /dsl/dsl/Blog.dsl file: 114 | 115 | module Blog 116 | { 117 | root Post 118 | { 119 | string title; 120 | string content; 121 | } 122 | } 123 | 124 | This DSL is pretty straightforward: it tells the platform to define a Post object with two string properties. Keyword 'root' standing before Post is a DSL concept used to define an aggregate root. Aggregate root is one of core concepts used in [Domain driven design](http://en.wikipedia.org/wiki/Domain-driven_design) (DDD). DSL platform is founded on DDD concepts. There are other types besides roots, but for now we can put that aside, we'll just be using 'root' as a basic building block. For now, you can just regard a root as a single table in the database. 125 | 126 | First line is used to define a module. Modules are used to encapsulate objects and avoid name collisions, pretty similar to PHP namespaces. So, the first line tells the platform that Post object will be placed inside a Blog module. 127 | 128 | That defined a Post object in our DSL, what now? Open your browser and go to the URL of your application (the same you pointed to Laravel public folder to verify your installation). As before, you should get a 'Hello world' response. Currently we cannot see any difference here because the default controller returns the same response, we'll change that soon. But first, let's check what happened in the background. Check the contents of platform/modules in the dsl-platform folder. There should be a newly created Blog folder (taken from module name) and a Post.php file inside it. Those files were created using the description we provided in blog.dsl. 129 | 130 | Each time any .dsl file is modified, platform will send the DSL contents to the platform server. Server will use definitions in DSL to update the database and generate PHP files representing concepts defined in DSL. The platform/modules is a folder that will contain all the generated PHP classes. It's similar to some tools generating PHP by using only database. In our case, we're using DSL to generate both PHP files and the database. To make things clearer, take a look at the beginning of generated Post.php file: 131 | 132 | ```php 133 | class Post extends \NGS\Patterns\AggregateRoot implements \IteratorAggregate 134 | { 135 | protected $URI; 136 | protected $ID; 137 | protected $title; 138 | protected $content; 139 | } 140 | ``` 141 | 142 | All right, we got our Blog\Post class, we can see it extends from AggregateRoot class (remember we defined a Post as 'aggregate root' concept in blog.dsl). At the top of the class there are two properties that were defined in DSL: title and content. There are also two additional properties: "ID" and "URI". ID is a surrogate key, similar to AUTO_INCREMENT or SERIAL types found in mysql and postgresql. Column ID was automatically generated, because there were no explicitly defined keys inside of root Post (you could do that, we'll get to that later). Each time a new Post is inserted, ID will get the value of last inserted ID increased by 1. 143 | 144 | Another property we didn't specify is URI. URI is a special property that serves as a unique identifier. It holds a unique string representation of primary keys. With only one key (ID), URI value will be the same to ID (if we ignore types, since ID is an integer, and URI is a string). 145 | 146 | The generated Blog\Post class can now be used to handle CRUD operations like inserting new posts or updating and deleting existing ones: 147 | 148 | ### Inserting posts: 149 | 150 | Let's write some PHP code. We can try out our new Post class by storing (persisting) a post named 'Hello world' to the database. To do that, first we'll create a route that creates a 'Hello world' post and persists it. Copy the following code on the beginning of routes.php file: (for convenience and simplicity, we'll just stuff all the PHP in that file for now, which is not a best idea for a real-world application) 151 | 152 | ```php 153 | Route::get('/test', function() 154 | { 155 | $post = new \Blog\Post(); 156 | $post->title = 'Hello'; 157 | $post->content = 'Hello world!'; 158 | $post->persist(); 159 | 160 | return 'Created post with URI: '.$post->URI; 161 | }); 162 | ``` 163 | 164 | Now fire up your browser and go to {your-url}/test. You should get a response containing "Created post with URI 1001". This means a new Post has been persisted to database. It was assigned ID with value equal to 1001. That's because numeric keys start at 1000 by default and increase by 1, similarly to auto-incrementing or sequence keys. 165 | 166 | The code is self-descriptive: there is a new instance created, and some values are assigned to both Title and Content properties. After that, the persist method will start the communication with the server and tell it to store the object. Persist method is used both for inserting and updating. Since we created a new post instance which doesn't exist in database yet, a new post will be inserted into database. 167 | 168 | Now we need to display an existing post. For that we'll create a route that searches for a specific post and displays it in a view (template) file. Add that route to routes.php: 169 | 170 | ```php 171 | Route::get('/(:num)', function($uri) 172 | { 173 | $post = \Blog\Post::find($uri); 174 | return View::make('home.post')->with('post', $post); 175 | }); 176 | ``` 177 | 178 | The ::find($uri) method will query the database for a Blog\Post with specified URI value. This method can be used on every aggregate root. If the object is not found, an exception will be thrown. 179 | Let's create a (very) basic view for site's html layout: 180 | 181 | /application/views/home.php: 182 | 183 | ```php 184 | 185 | 186 | 187 | 188 | DSL blog 189 | 190 | 191 | 192 | 193 | 194 | ``` 195 | 196 | And another view for post... 197 | 198 | /application/views/post.php: 199 | 200 | ```php 201 |

title?>

202 |

content?>

203 | ``` 204 | 205 | Now you should see the post contents at {your-url}/1001. 206 | 207 | ### Specifying relationships 208 | 209 | Each blog should have some comments functionality, so let's add that. To do that, first we must describe a comment in the DSL. Let's expand our DSL with a Comment: 210 | 211 | module Blog 212 | { 213 | root Post 214 | { 215 | string title; 216 | string content; 217 | } 218 | 219 | root Comment 220 | { 221 | string email; 222 | string content; 223 | date createdAt; 224 | } 225 | } 226 | 227 | We added Comment as another root (that's the only DDD type we'll use for now). A basic comment has an email and content, and it should be useful to know when the comment was entered, so we specified a property named createdAt of 'date' type. Besides simple (or primitive) types such as strings, you can specify properties as complex types. Date is just one of the complex types you can use in the platform. In generated PHP code, date will be an instance of NGS\LocalDate class. 228 | 229 | If we refresh our blog, we'll see that Comment.php and some more files were generated and copied into modules folder. That means we can persist and read comments as we did with posts. That won't make much sense if we can't somehow connect each comment to a specific post. One way to do that is to specify a reference in each comment which specifies a particular post to which the comment belongs to. We can do that by adding a single line inside Comment: 230 | 231 | root Comment 232 | { 233 | Post* post; 234 | string email; 235 | string content; 236 | date createdAt; 237 | } 238 | 239 | This will create a new property called Post inside the Comment class. It serves as a reference to an existing Post instance and we can use it to link comments and posts. 240 | Now let's expand the post view with comments and a form to post new comments: 241 | 242 | /application/views/post.php: 243 | 244 | ```php 245 |

Title?>

246 |

Content?>

247 | 248 | 253 | 254 |
255 |

Leave a comment...

256 |
257 | 258 | 259 |
260 | 261 | 262 |
263 |
264 | ``` 265 | 266 | And here's a route which will persist the comment posted from the form: 267 | 268 | ```php 269 | Route::post('/comment', function() { 270 | $postURI = Input::get('PostURI'); 271 | $comment = new Comment(); 272 | $post = Post::find($postURI); 273 | $comment->post = $post; 274 | $comment->email = Input::get('Email'); 275 | $comment->content = Input::get('Content'); 276 | $comment->persist(); 277 | return Redirect::to('/post/'.$postURI); 278 | }); 279 | ``` 280 | 281 | The function find in Post::find($postURI) will search for a post with specified URI and return an instance of Post object. That object can then be assigned as reference in $comment->post. That reference will be persisted to database. 282 | 283 | ## Fetching objects 284 | 285 | Each root class has a findAll method which can be used to load all stored items. Let's use it to display comments on each post: 286 | 287 | ```php 288 | $postID = 1001; 289 | $postComments = array(); 290 | foreach(Comment::findAll() as $comment) 291 | if($comment->PostID == $postID) 292 | $postComments[] = $comment; 293 | ``` 294 | 295 | That will work, but that's not very efficient because findAll method fetches all the comments in the database. We need a more efficient way to filter comments before they are fetched. There are two ways to do this: generic search and specifications. 296 | 297 | ### Generic search 298 | 299 | By using generic search helper we can construct a filter which will return only comments pointing to a certain post: 300 | 301 | ```php 302 | $postID = 1001; 303 | $search = new GenericSearch('Blog\Comment'); 304 | $comments = $search->equals('PostID', $postID)->search(); 305 | ``` 306 | 307 | GenericSearch constructor receives the name of aggregate root on which the search will be performed. 308 | Equals method is one of the possible filters. It specifies exact match where the first argument is property name and the second argument is matched value. 309 | 310 | ### Specifications 311 | 312 | Specification states a certain condition, it has various uses, one of them is to filter items. We write a specification in the DSL. Here's a specification that fetches all comments belonging to a certain post: 313 | 314 | root Comment 315 | { 316 | Post* post; 317 | string email; 318 | string content; 319 | date createdAt; 320 | 321 | specification findByPost 'item => item.PostID == postID' 322 | { 323 | int postID; 324 | } 325 | } 326 | 327 | This creates a specification called findByPost. Specification consists of expression and the optional list of arguments. Expression specified behind the name is called a lambda expression. 328 | Lambda expression is used to state a condition which evaluates as true or false for each Comment. The condition we specified defines that condition is true for all comments that have PostID property equal to the specified postID argument. The line 'int postID' specifies the argument which the specification receives. This is the argument which we pass to specification in PHP: 329 | 330 | ```php 331 | $postID = 1001; 332 | $results = Comment::findByPost($postID); 333 | ``` 334 | This will fetch all the comments for post with ID 1001. $results will hold an array of Blog\Comment objects. 335 | If you aren't familiar with lambdas, you can think of it in PHP terms as passing anonymous function to [array_filter](http://php.net/array_filter), like this: 336 | 337 | ```php 338 | $postID = 1001; 339 | $results = array_filter(Comment::findAll(), function($item) use ($postID) { 340 | return $item->PostID === $postID; 341 | }) 342 | ``` 343 | 344 | Array_filter will iterate through each comment that is returned from Comment::findAll() (every comment in the database!) and return each element for which the passed in closure (similar to lambda in specification) returns true. 345 | You'll get the same results, but this serves just an example - you should never run code like this in production, as it is very inefficient to fetch all the comments from the server and only then filter them, and that's the reason why we write a specification inside DSL. 346 | 347 | We can now expand a route that displays post with specification for finding comments. 348 | 349 | ```php 350 | Route::get('/(:num)', function($postURI) 351 | { 352 | $post = \Blog\Post::find($postURI); 353 | $comments = \Blog\Comment::findByPost($postURI); 354 | $view = View::make('base'); 355 | return $view->nest('content', 'post', array( 356 | 'post' => $post, 357 | 'comments' => $comments, 358 | )); 359 | }); 360 | ``` 361 | 362 | ### Deleting comments 363 | 364 | Here's an example route showing how to delete a comment: 365 | 366 | ```php 367 | Route::delete('/comment/(:uri)', function($uri) 368 | { 369 | $comment = \Blog\Comment::find($uri); 370 | $comment->delete(); 371 | return Redirect::back(); // referer 372 | }); 373 | ``` 374 | 375 | Similar code can be used to delete any kind of root. If a comment wasn't found, the find method will throw an exception which should be handled in a try-catch block inside the route, or alternatively, you could handle those types of exceptions somewhere outside in global handler. Here's how to do it in the route: 376 | 377 | ```php 378 | Route::get('/comment/delete/(:id)', function($id) 379 | { 380 | try { 381 | $comment = \Blog\Comment::find($uri); 382 | $comment->delete(); 383 | return Redirect::back(); // referer 384 | } 385 | catch (\NGS\Client\NotFoundException\Exception $ex) { 386 | return Response::make($ex->getMessage(), 404); 387 | } 388 | }); 389 | ``` 390 | 391 | ### Login, logout... 392 | 393 | DSL platform is not intended to provide authentication. This is a job for a PHP framework or a standalone component. DSL platform can be integrated with those components and store authentication data. 394 | We'll provide a simple snippet that gives an idea of how to store user data, which can be basis for further authentication. 395 | 396 | This is a simple DSL for handling user data: 397 | 398 | module Security 399 | { 400 | root User (Username) 401 | { 402 | string Username; 403 | string Password; 404 | } 405 | } 406 | 407 | (obviously, you should not store passwords as plaintext) 408 | 409 | Putting "Username" property in parenthesis after root name defines the property as a primary key. Users can now be uniquely identified by that username (it will equal URI property), and there is no more need for a ID property. 410 | 411 | A simple login route where we check if posted username and password match any user. 412 | 413 | ```php 414 | Route::post('/login', function() { 415 | $username = Input::post('username'); 416 | $password = Input::post('password'); 417 | try { 418 | $user = User::find($username); 419 | // in real life, you would use some sort of password hashing 420 | if ($user->Password === $password) { 421 | // credentials are ok 422 | // do authentication stuff, store login in session, etc. 423 | } 424 | else { 425 | // login has failed 426 | } 427 | } 428 | catch (\NGS\Client\Exception\NotFoundException $ex) { 429 | // user with specified username does not exist 430 | } 431 | $user = Security\User()::find() 432 | }); 433 | ``` 434 | 435 | ## DSL and beyond 436 | 437 | There are many more features of DSL platform, such as generating reports in various formats and analyzing data using built-in [OLAP](http://en.wikipedia.org/wiki/Online_analytical_processing) features. 438 | 439 | Besides the features built-in in the platform, the DSL platform brings certain features specifically to PHP. One of the more interesting is type safety, which is a way to improve PHP's type system. 440 | 441 | ### PHP type safety 442 | 443 | PHP classes generated from the DSL will provide some type safety. Let's assume the following DSL: 444 | 445 | module Blog 446 | { 447 | root Post { 448 | string title; 449 | } 450 | } 451 | 452 | What happens when an illegal operation is performed, such as assigning an array to title property: 453 | 454 | ```php 455 | $post = new Blog\Post(); 456 | $post->title = array(); 457 | ``` 458 | 459 | This snippet will throw an InvalidArgumentException explaining that an invalid type is being assigned to a string property. Under the hood, each property is set using PHP's magic setter function __set which calls an appropriate setter function, in this case the setTitle function. The setter checks type of value being assigned to the property and raises an exception if that type cannot be converted to the type specified in DSL. 460 | -------------------------------------------------------------------------------- /app/commands/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ngs-doo/dsl-php-tutorial/70a7b1dccc413ae487a9fc267f02612e7ada9f16/app/commands/.gitkeep -------------------------------------------------------------------------------- /app/config/app.php: -------------------------------------------------------------------------------- 1 | true, 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Application Timezone 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Here you may specify the default timezone for your application, which 24 | | will be used by the PHP date and date-time functions. We have gone 25 | | ahead and set this to a sensible default for you out of the box. 26 | | 27 | */ 28 | 29 | 'timezone' => 'UTC', 30 | 31 | /* 32 | |-------------------------------------------------------------------------- 33 | | Application Locale Configuration 34 | |-------------------------------------------------------------------------- 35 | | 36 | | The application locale determines the default locale that will be used 37 | | by the translation service provider. You are free to set this value 38 | | to any of the locales which will be supported by the application. 39 | | 40 | */ 41 | 42 | 'locale' => 'en', 43 | 44 | /* 45 | |-------------------------------------------------------------------------- 46 | | Application Fallback Locale 47 | |-------------------------------------------------------------------------- 48 | | 49 | | The fallback locale determines the locale to use when the current one 50 | | is not available. You may change the value to correspond to any of 51 | | the language folders that are provided through your application. 52 | | 53 | */ 54 | 55 | 'fallback_locale' => 'en', 56 | 57 | /* 58 | |-------------------------------------------------------------------------- 59 | | Encryption Key 60 | |-------------------------------------------------------------------------- 61 | | 62 | | This key is used by the Illuminate encrypter service and should be set 63 | | to a random, long string, otherwise these encrypted values will not 64 | | be safe. Make sure to change it before deploying any application! 65 | | 66 | */ 67 | 68 | 'key' => 'YourSecretKey!!!', 69 | 70 | /* 71 | |-------------------------------------------------------------------------- 72 | | Autoloaded Service Providers 73 | |-------------------------------------------------------------------------- 74 | | 75 | | The service providers listed here will be automatically loaded on the 76 | | request to your application. Feel free to add your own services to 77 | | this array to grant expanded functionality to your applications. 78 | | 79 | */ 80 | 81 | 'providers' => array( 82 | 83 | 'Illuminate\Foundation\Providers\ArtisanServiceProvider', 84 | 'Illuminate\Auth\AuthServiceProvider', 85 | 'Illuminate\Cache\CacheServiceProvider', 86 | 'Illuminate\Foundation\Providers\CommandCreatorServiceProvider', 87 | 'Illuminate\Session\CommandsServiceProvider', 88 | 'Illuminate\Foundation\Providers\ComposerServiceProvider', 89 | 'Illuminate\Routing\ControllerServiceProvider', 90 | 'Illuminate\Cookie\CookieServiceProvider', 91 | 'Illuminate\Database\DatabaseServiceProvider', 92 | 'Illuminate\Encryption\EncryptionServiceProvider', 93 | 'Illuminate\Filesystem\FilesystemServiceProvider', 94 | 'Illuminate\Hashing\HashServiceProvider', 95 | 'Illuminate\Html\HtmlServiceProvider', 96 | 'Illuminate\Foundation\Providers\KeyGeneratorServiceProvider', 97 | 'Illuminate\Log\LogServiceProvider', 98 | 'Illuminate\Mail\MailServiceProvider', 99 | 'Illuminate\Database\MigrationServiceProvider', 100 | 'Illuminate\Pagination\PaginationServiceProvider', 101 | 'Illuminate\Foundation\Providers\PublisherServiceProvider', 102 | 'Illuminate\Queue\QueueServiceProvider', 103 | 'Illuminate\Redis\RedisServiceProvider', 104 | 'Illuminate\Auth\Reminders\ReminderServiceProvider', 105 | 'Illuminate\Database\SeedServiceProvider', 106 | 'Illuminate\Foundation\Providers\ServerServiceProvider', 107 | 'Illuminate\Session\SessionServiceProvider', 108 | 'Illuminate\Foundation\Providers\TinkerServiceProvider', 109 | 'Illuminate\Translation\TranslationServiceProvider', 110 | 'Illuminate\Validation\ValidationServiceProvider', 111 | 'Illuminate\View\ViewServiceProvider', 112 | 'Illuminate\Workbench\WorkbenchServiceProvider', 113 | 114 | ), 115 | 116 | /* 117 | |-------------------------------------------------------------------------- 118 | | Service Provider Manifest 119 | |-------------------------------------------------------------------------- 120 | | 121 | | The service provider manifest is used by Laravel to lazy load service 122 | | providers which are not needed for each request, as well to keep a 123 | | list of all of the services. Here, you may set its storage spot. 124 | | 125 | */ 126 | 127 | 'manifest' => __DIR__.'/../storage/meta', 128 | 129 | /* 130 | |-------------------------------------------------------------------------- 131 | | Class Aliases 132 | |-------------------------------------------------------------------------- 133 | | 134 | | This array of class aliases will be registered when this application 135 | | is started. However, feel free to register as many as you wish as 136 | | the aliases are "lazy" loaded so they don't hinder performance. 137 | | 138 | */ 139 | 140 | 'aliases' => array( 141 | 142 | 'App' => 'Illuminate\Support\Facades\App', 143 | 'Artisan' => 'Illuminate\Support\Facades\Artisan', 144 | 'Auth' => 'Illuminate\Support\Facades\Auth', 145 | 'Blade' => 'Illuminate\Support\Facades\Blade', 146 | 'Cache' => 'Illuminate\Support\Facades\Cache', 147 | 'ClassLoader' => 'Illuminate\Support\ClassLoader', 148 | 'Config' => 'Illuminate\Support\Facades\Config', 149 | 'Controller' => 'Illuminate\Routing\Controllers\Controller', 150 | 'Cookie' => 'Illuminate\Support\Facades\Cookie', 151 | 'Crypt' => 'Illuminate\Support\Facades\Crypt', 152 | 'DB' => 'Illuminate\Support\Facades\DB', 153 | 'Eloquent' => 'Illuminate\Database\Eloquent\Model', 154 | 'Event' => 'Illuminate\Support\Facades\Event', 155 | 'File' => 'Illuminate\Support\Facades\File', 156 | 'Form' => 'Illuminate\Support\Facades\Form', 157 | 'Hash' => 'Illuminate\Support\Facades\Hash', 158 | 'Html' => 'Illuminate\Html\HtmlBuilder', 159 | 'Input' => 'Illuminate\Support\Facades\Input', 160 | 'Lang' => 'Illuminate\Support\Facades\Lang', 161 | 'Log' => 'Illuminate\Support\Facades\Log', 162 | 'Mail' => 'Illuminate\Support\Facades\Mail', 163 | 'Paginator' => 'Illuminate\Support\Facades\Paginator', 164 | 'Password' => 'Illuminate\Support\Facades\Password', 165 | 'Queue' => 'Illuminate\Support\Facades\Queue', 166 | 'Redirect' => 'Illuminate\Support\Facades\Redirect', 167 | 'Redis' => 'Illuminate\Support\Facades\Redis', 168 | 'Request' => 'Illuminate\Support\Facades\Request', 169 | 'Response' => 'Illuminate\Support\Facades\Response', 170 | 'Route' => 'Illuminate\Support\Facades\Route', 171 | 'Schema' => 'Illuminate\Support\Facades\Schema', 172 | 'Seeder' => 'Illuminate\Database\Seeder', 173 | 'Session' => 'Illuminate\Support\Facades\Session', 174 | 'Str' => 'Illuminate\Support\Str', 175 | 'URL' => 'Illuminate\Support\Facades\URL', 176 | 'Validator' => 'Illuminate\Support\Facades\Validator', 177 | 'View' => 'Illuminate\Support\Facades\View', 178 | 179 | ), 180 | 181 | ); 182 | -------------------------------------------------------------------------------- /app/config/auth.php: -------------------------------------------------------------------------------- 1 | 'eloquent', 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Authentication Model 23 | |-------------------------------------------------------------------------- 24 | | 25 | | When using the "Eloquent" authentication driver, we need to know which 26 | | Eloquent model should be used to retrieve your users. Of course, it 27 | | is often just the "User" model but you may use whatever you like. 28 | | 29 | */ 30 | 31 | 'model' => 'User', 32 | 33 | /* 34 | |-------------------------------------------------------------------------- 35 | | Authentication Table 36 | |-------------------------------------------------------------------------- 37 | | 38 | | When using the "Database" authentication driver, we need to know which 39 | | table should be used to retrieve your users. We have chosen a basic 40 | | default value but you may easily change it to any table you like. 41 | | 42 | */ 43 | 44 | 'table' => 'users', 45 | 46 | /* 47 | |-------------------------------------------------------------------------- 48 | | Password Reminder Settings 49 | |-------------------------------------------------------------------------- 50 | | 51 | | Here you may set the settings for password reminders, including a view 52 | | that should be used as your password reminder e-mail. You will also 53 | | be able to set the name of the table that holds the reset tokens. 54 | | 55 | */ 56 | 57 | 'reminder' => array( 58 | 59 | 'email' => 'emails.auth.reminder', 'table' => 'password_reminders', 60 | 61 | ), 62 | 63 | ); -------------------------------------------------------------------------------- /app/config/cache.php: -------------------------------------------------------------------------------- 1 | 'file', 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | File Cache Location 23 | |-------------------------------------------------------------------------- 24 | | 25 | | When using the "file" cache driver, we need a location where the cache 26 | | files may be stored. A sensible default has been specified, but you 27 | | are free to change it to any other place on disk that you desire. 28 | | 29 | */ 30 | 31 | 'path' => __DIR__.'/../storage/cache', 32 | 33 | /* 34 | |-------------------------------------------------------------------------- 35 | | Database Cache Connection 36 | |-------------------------------------------------------------------------- 37 | | 38 | | When using the "database" cache driver you may specify the connection 39 | | that should be used to store the cached items. When this option is 40 | | null the default database connection will be utilized for cache. 41 | | 42 | */ 43 | 44 | 'connection' => null, 45 | 46 | /* 47 | |-------------------------------------------------------------------------- 48 | | Database Cache Table 49 | |-------------------------------------------------------------------------- 50 | | 51 | | When using the "database" cache driver we need to know the table that 52 | | should be used to store the cached items. A default table name has 53 | | been provided but you're free to change it however you deem fit. 54 | | 55 | */ 56 | 57 | 'table' => 'cache', 58 | 59 | /* 60 | |-------------------------------------------------------------------------- 61 | | Memcached Servers 62 | |-------------------------------------------------------------------------- 63 | | 64 | | Now you may specify an array of your Memcached servers that should be 65 | | used when utilizing the Memcached cache driver. All of the servers 66 | | should contain a value for "host", "port", and "weight" options. 67 | | 68 | */ 69 | 70 | 'memcached' => array( 71 | 72 | array('host' => '127.0.0.1', 'port' => 11211, 'weight' => 100), 73 | 74 | ), 75 | 76 | /* 77 | |-------------------------------------------------------------------------- 78 | | Cache Key Prefix 79 | |-------------------------------------------------------------------------- 80 | | 81 | | When utilizing a RAM based store such as APC or Memcached, there might 82 | | be other applications utilizing the same cache. So, we'll specify a 83 | | value to get prefixed to all our keys so we can avoid collisions. 84 | | 85 | */ 86 | 87 | 'prefix' => 'laravel', 88 | 89 | ); 90 | -------------------------------------------------------------------------------- /app/config/database.php: -------------------------------------------------------------------------------- 1 | PDO::FETCH_CLASS, 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Default Database Connection Name 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Here you may specify which of the database connections below you wish 24 | | to use as your default connection for all database work. Of course 25 | | you may use many connections at once using the Database library. 26 | | 27 | */ 28 | 29 | 'default' => 'mysql', 30 | 31 | /* 32 | |-------------------------------------------------------------------------- 33 | | Database Connections 34 | |-------------------------------------------------------------------------- 35 | | 36 | | Here are each of the database connections setup for your application. 37 | | Of course, examples of configuring each database platform that is 38 | | supported by Laravel is shown below to make development simple. 39 | | 40 | | 41 | | All database work in Laravel is done through the PHP PDO facilities 42 | | so make sure you have the driver for your particular database of 43 | | choice installed on your machine before you begin development. 44 | | 45 | */ 46 | 47 | 'connections' => array( 48 | 49 | 'sqlite' => array( 50 | 'driver' => 'sqlite', 51 | 'database' => __DIR__.'/../database/production.sqlite', 52 | 'prefix' => '', 53 | ), 54 | 55 | 'mysql' => array( 56 | 'driver' => 'mysql', 57 | 'host' => 'localhost', 58 | 'database' => 'database', 59 | 'username' => 'root', 60 | 'password' => '', 61 | 'charset' => 'utf8', 62 | 'collation' => 'utf8_unicode_ci', 63 | 'prefix' => '', 64 | ), 65 | 66 | 'pgsql' => array( 67 | 'driver' => 'pgsql', 68 | 'host' => 'localhost', 69 | 'database' => 'database', 70 | 'username' => 'root', 71 | 'password' => '', 72 | 'charset' => 'utf8', 73 | 'prefix' => '', 74 | 'schema' => 'public', 75 | ), 76 | 77 | 'sqlsrv' => array( 78 | 'driver' => 'sqlsrv', 79 | 'host' => 'localhost', 80 | 'database' => 'database', 81 | 'username' => 'root', 82 | 'password' => '', 83 | 'prefix' => '', 84 | ), 85 | 86 | ), 87 | 88 | /* 89 | |-------------------------------------------------------------------------- 90 | | Migration Repository Table 91 | |-------------------------------------------------------------------------- 92 | | 93 | | This table keeps track of all the migrations that have already run for 94 | | your application. Using this information, we can determine which of 95 | | the migrations on disk have not actually be run in the databases. 96 | | 97 | */ 98 | 99 | 'migrations' => 'migrations', 100 | 101 | /* 102 | |-------------------------------------------------------------------------- 103 | | Redis Databases 104 | |-------------------------------------------------------------------------- 105 | | 106 | | Redis is an open source, fast, and advanced key-value store that also 107 | | provides a richer set of commands than a typical key-value systems 108 | | such as APC or Memcached. Laravel makes it easy to dig right in. 109 | | 110 | */ 111 | 112 | 'redis' => array( 113 | 114 | 'default' => array( 115 | 'host' => '127.0.0.1', 116 | 'port' => 6379, 117 | 'database' => 0, 118 | ), 119 | 120 | ), 121 | 122 | ); -------------------------------------------------------------------------------- /app/config/mail.php: -------------------------------------------------------------------------------- 1 | 'smtp.postmarkapp.com', 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | SMTP Host Port 21 | |-------------------------------------------------------------------------- 22 | | 23 | | This is the SMTP port used by your application to delivery e-mails to 24 | | users of your application. Like the host we have set this value to 25 | | stay compatible with the Postmark e-mail application by default. 26 | | 27 | */ 28 | 29 | 'port' => 2525, 30 | 31 | /* 32 | |-------------------------------------------------------------------------- 33 | | Global "From" Address 34 | |-------------------------------------------------------------------------- 35 | | 36 | | You may wish for all e-mails sent by your application to be sent from 37 | | the same address. Here, you may specify a name and address that is 38 | | used globally for all e-mails that are sent by your application. 39 | | 40 | */ 41 | 42 | 'from' => array('address' => null, 'name' => null), 43 | 44 | /* 45 | |-------------------------------------------------------------------------- 46 | | E-Mail Encryption Protocol 47 | |-------------------------------------------------------------------------- 48 | | 49 | | Here you may specify the encryption protocol that should be used when 50 | | the application send e-mail messages. A sensible default using the 51 | | transport layer security protocol should provide great security. 52 | | 53 | */ 54 | 55 | 'encryption' => 'tls', 56 | 57 | /* 58 | |-------------------------------------------------------------------------- 59 | | SMTP Server Username 60 | |-------------------------------------------------------------------------- 61 | | 62 | | If your SMTP server requires a username for authentication, you should 63 | | set it here. This will get used to authenticate with your server on 64 | | connection. You may also set the "password" value below this one. 65 | | 66 | */ 67 | 68 | 'username' => null, 69 | 70 | /* 71 | |-------------------------------------------------------------------------- 72 | | SMTP Server Password 73 | |-------------------------------------------------------------------------- 74 | | 75 | | Here you may set the password required by your SMTP server to send out 76 | | messages from your application. This will be given to the server on 77 | | connection so that the application will be able to send messages. 78 | | 79 | */ 80 | 81 | 'password' => null, 82 | 83 | ); 84 | -------------------------------------------------------------------------------- /app/config/packages/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ngs-doo/dsl-php-tutorial/70a7b1dccc413ae487a9fc267f02612e7ada9f16/app/config/packages/.gitkeep -------------------------------------------------------------------------------- /app/config/queue.php: -------------------------------------------------------------------------------- 1 | 'sync', 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Queue Connections 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may configure the connection information for each server that 26 | | is used by your application. A default configuration has been added 27 | | for each back-end shipped with Laravel. You are free to add more. 28 | | 29 | */ 30 | 31 | 'connections' => array( 32 | 33 | 'sync' => array( 34 | 'driver' => 'sync', 35 | ), 36 | 37 | 'beanstalkd' => array( 38 | 'driver' => 'beanstalkd', 39 | 'host' => 'localhost', 40 | 'queue' => 'default', 41 | ), 42 | 43 | 'sqs' => array( 44 | 'driver' => 'sqs', 45 | 'key' => 'your-public-key', 46 | 'secret' => 'your-secret-key', 47 | 'queue' => 'your-queue-url', 48 | 'region' => 'us-east-1', 49 | ), 50 | 51 | ), 52 | 53 | ); 54 | -------------------------------------------------------------------------------- /app/config/session.php: -------------------------------------------------------------------------------- 1 | 'cookie', 20 | 21 | /* 22 | |-------------------------------------------------------------------------- 23 | | Session Lifetime 24 | |-------------------------------------------------------------------------- 25 | | 26 | | Here you may specify the number of minutes that you wish the session 27 | | to be allowed to remain idle for it is expired. If you want them 28 | | to immediately expire when the browser closes, set it to zero. 29 | | 30 | */ 31 | 32 | 'lifetime' => 120, 33 | 34 | /* 35 | |-------------------------------------------------------------------------- 36 | | Session File Location 37 | |-------------------------------------------------------------------------- 38 | | 39 | | When using the "file" session driver, we need a location where session 40 | | files may be stored. A default has been set for you but a different 41 | | location may be specified. This is only needed for file sessions. 42 | | 43 | */ 44 | 45 | 'path' => __DIR__.'/../storage/sessions', 46 | 47 | /* 48 | |-------------------------------------------------------------------------- 49 | | Session Database Connection 50 | |-------------------------------------------------------------------------- 51 | | 52 | | When using the "database" session driver, you may specify the database 53 | | connection that should be used to manage your sessions. This should 54 | | correspond to a connection in your "database" configuration file. 55 | | 56 | */ 57 | 58 | 'connection' => null, 59 | 60 | /* 61 | |-------------------------------------------------------------------------- 62 | | Session Database Table 63 | |-------------------------------------------------------------------------- 64 | | 65 | | When using the "database" session driver, you may specify the table we 66 | | should use to manage the sessions. Of course, a sensible default is 67 | | provided for you; however, you are free to change this as needed. 68 | | 69 | */ 70 | 71 | 'table' => 'sessions', 72 | 73 | /* 74 | |-------------------------------------------------------------------------- 75 | | Session Sweeping Lottery 76 | |-------------------------------------------------------------------------- 77 | | 78 | | Some session drivers must manually sweep their storage location to get 79 | | rid of old sessions from storage. Here are the chances that it will 80 | | happen on a given request. By default, the odds are 2 out of 100. 81 | | 82 | */ 83 | 84 | 'lottery' => array(2, 100), 85 | 86 | /* 87 | |-------------------------------------------------------------------------- 88 | | Session Cookie Name 89 | |-------------------------------------------------------------------------- 90 | | 91 | | Here you may change the name of the cookie used to identify a session 92 | | instance by ID. The name specified here will get used every time a 93 | | new session cookie is created by the framework for every driver. 94 | | 95 | */ 96 | 97 | 'cookie' => 'laravel_session', 98 | 99 | ); 100 | -------------------------------------------------------------------------------- /app/config/testing/cache.php: -------------------------------------------------------------------------------- 1 | 'array', 19 | 20 | ); -------------------------------------------------------------------------------- /app/config/testing/session.php: -------------------------------------------------------------------------------- 1 | 'array', 20 | 21 | ); -------------------------------------------------------------------------------- /app/config/view.php: -------------------------------------------------------------------------------- 1 | array(__DIR__.'/../views'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Pagination View 21 | |-------------------------------------------------------------------------- 22 | | 23 | | This view will be used to render the pagination link output, and can 24 | | be easily customized here to show any view you like. A clean view 25 | | compatible with Twitter's Bootstrap is given to you by default. 26 | | 27 | */ 28 | 29 | 'pagination' => 'pagination::slider', 30 | 31 | ); 32 | -------------------------------------------------------------------------------- /app/controllers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ngs-doo/dsl-php-tutorial/70a7b1dccc413ae487a9fc267f02612e7ada9f16/app/controllers/.gitkeep -------------------------------------------------------------------------------- /app/controllers/BaseController.php: -------------------------------------------------------------------------------- 1 | layout)) 13 | { 14 | $this->layout = View::make($this->layout); 15 | } 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /app/controllers/HomeController.php: -------------------------------------------------------------------------------- 1 | call('UserTableSeeder'); 13 | } 14 | 15 | } -------------------------------------------------------------------------------- /app/filters.php: -------------------------------------------------------------------------------- 1 | '« Previous', 17 | 18 | 'next' => 'Next »', 19 | 20 | ); -------------------------------------------------------------------------------- /app/lang/en/reminders.php: -------------------------------------------------------------------------------- 1 | "Passwords must be six characters and match the confirmation.", 17 | 18 | "user" => "We can't find a user with that e-mail address.", 19 | 20 | "token" => "This password reset token is invalid.", 21 | 22 | ); -------------------------------------------------------------------------------- /app/lang/en/validation.php: -------------------------------------------------------------------------------- 1 | "The :attribute must be accepted.", 17 | "active_url" => "The :attribute is not a valid URL.", 18 | "after" => "The :attribute must be a date after :date.", 19 | "alpha" => "The :attribute may only contain letters.", 20 | "alpha_dash" => "The :attribute may only contain letters, numbers, and dashes.", 21 | "alpha_num" => "The :attribute may only contain letters and numbers.", 22 | "before" => "The :attribute must be a date before :date.", 23 | "between" => array( 24 | "numeric" => "The :attribute must be between :min - :max.", 25 | "file" => "The :attribute must be between :min - :max kilobytes.", 26 | "string" => "The :attribute must be between :min - :max characters.", 27 | ), 28 | "confirmed" => "The :attribute confirmation does not match.", 29 | "date" => "The :attribute is not a valid date.", 30 | "date_format" => "The :attribute does not match the format :format.", 31 | "different" => "The :attribute and :other must be different.", 32 | "digits" => "The :attribute must be :digits digits.", 33 | "digits_between" => "The :attribute must be between :min and :max digits.", 34 | "email" => "The :attribute format is invalid.", 35 | "exists" => "The selected :attribute is invalid.", 36 | "image" => "The :attribute must be an image.", 37 | "in" => "The selected :attribute is invalid.", 38 | "integer" => "The :attribute must be an integer.", 39 | "ip" => "The :attribute must be a valid IP address.", 40 | "max" => array( 41 | "numeric" => "The :attribute must be less than :max.", 42 | "file" => "The :attribute must be less than :max kilobytes.", 43 | "string" => "The :attribute must be less than :max characters.", 44 | ), 45 | "mimes" => "The :attribute must be a file of type: :values.", 46 | "min" => array( 47 | "numeric" => "The :attribute must be at least :min.", 48 | "file" => "The :attribute must be at least :min kilobytes.", 49 | "string" => "The :attribute must be at least :min characters.", 50 | ), 51 | "notin" => "The selected :attribute is invalid.", 52 | "numeric" => "The :attribute must be a number.", 53 | "regex" => "The :attribute format is invalid.", 54 | "required" => "The :attribute field is required.", 55 | "required_with" => "The :attribute field is required when :values is present.", 56 | "same" => "The :attribute and :other must match.", 57 | "size" => array( 58 | "numeric" => "The :attribute must be :size.", 59 | "file" => "The :attribute must be :size kilobytes.", 60 | "string" => "The :attribute must be :size characters.", 61 | ), 62 | "unique" => "The :attribute has already been taken.", 63 | "url" => "The :attribute format is invalid.", 64 | 65 | /* 66 | |-------------------------------------------------------------------------- 67 | | Custom Validation Language Lines 68 | |-------------------------------------------------------------------------- 69 | | 70 | | Here you may specify custom validation messages for attributes using the 71 | | convention "attribute.rule" to name the lines. This makes it quick to 72 | | specify a specific custom language line for a given attribute rule. 73 | | 74 | */ 75 | 76 | 'custom' => array(), 77 | 78 | /* 79 | |-------------------------------------------------------------------------- 80 | | Custom Validation Attributes 81 | |-------------------------------------------------------------------------- 82 | | 83 | | The following language lines are used to swap attribute place-holders 84 | | with something more reader friendly such as E-Mail Address instead 85 | | of "email". This simply helps us make messages a little cleaner. 86 | | 87 | */ 88 | 89 | 'attributes' => array(), 90 | 91 | ); -------------------------------------------------------------------------------- /app/models/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ngs-doo/dsl-php-tutorial/70a7b1dccc413ae487a9fc267f02612e7ada9f16/app/models/.gitkeep -------------------------------------------------------------------------------- /app/routes.php: -------------------------------------------------------------------------------- 1 | client->request('GET', '/'); 13 | 14 | $this->assertTrue($this->client->getResponse()->isOk()); 15 | 16 | $this->assertCount(1, $crawler->filter('h1:contains("Hello World!")')); 17 | } 18 | 19 | } -------------------------------------------------------------------------------- /app/tests/TestCase.php: -------------------------------------------------------------------------------- 1 | Hello World! -------------------------------------------------------------------------------- /bootstrap/autoload.php: -------------------------------------------------------------------------------- 1 | __DIR__.'/../app', 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Public Path 21 | |-------------------------------------------------------------------------- 22 | | 23 | | The public path contains the assets for your web application, such as 24 | | your JavaScript and CSS files, and also contains the primary entry 25 | | point for web requests into these applications from the outside. 26 | | 27 | */ 28 | 29 | 'public' => __DIR__.'/../public', 30 | 31 | /* 32 | |-------------------------------------------------------------------------- 33 | | Base Path 34 | |-------------------------------------------------------------------------- 35 | | 36 | | The base path is the root of the Laravel installation. Most likely you 37 | | will not need to change this value. But, if for some wild reason it 38 | | is necessary you will do so here, just proceed with some caution. 39 | | 40 | */ 41 | 42 | 'base' => __DIR__.'/..', 43 | 44 | ); 45 | -------------------------------------------------------------------------------- /bootstrap/start.php: -------------------------------------------------------------------------------- 1 | detectEnvironment(array( 28 | 29 | 'local' => array('your-machine-name'), 30 | 31 | )); 32 | 33 | /* 34 | |-------------------------------------------------------------------------- 35 | | Bind Paths 36 | |-------------------------------------------------------------------------- 37 | | 38 | | Here we are binding the paths configured in paths.php to the app. You 39 | | should not be changing these here. If you need to change these you 40 | | may do so within the paths.php file and they will be bound here. 41 | | 42 | */ 43 | 44 | $app->bindInstallPaths(require __DIR__.'/paths.php'); 45 | 46 | /* 47 | |-------------------------------------------------------------------------- 48 | | Load The Application 49 | |-------------------------------------------------------------------------- 50 | | 51 | | Here we will load the Illuminate application. We'll keep this is in a 52 | | separate location so we can isolate the creation of an application 53 | | from the actual running of the application with a given request. 54 | | 55 | */ 56 | 57 | require $app->getBootstrapFile(); 58 | 59 | /* 60 | |-------------------------------------------------------------------------- 61 | | Return The Application 62 | |-------------------------------------------------------------------------- 63 | | 64 | | This script returns the application instance. The instance is given to 65 | | the calling script so we can separate the building of the instances 66 | | from the actual running of the application and sending responses. 67 | | 68 | */ 69 | 70 | return $app; 71 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nutrija/dsl-php-tutorial", 3 | "description": "PHP DSL-platform tutorial", 4 | "require": { 5 | "laravel/framework": "4.0.*" 6 | }, 7 | "autoload": { 8 | "classmap": [ 9 | "app/commands", 10 | "app/controllers", 11 | "app/models", 12 | "app/database/migrations", 13 | "app/database/seeds", 14 | "app/tests/TestCase.php" 15 | ] 16 | }, 17 | "minimum-stability": "dev" 18 | } -------------------------------------------------------------------------------- /public/.htaccess: -------------------------------------------------------------------------------- 1 | 2 | Options -MultiViews 3 | RewriteEngine On 4 | RewriteCond %{REQUEST_FILENAME} !-f 5 | RewriteRule ^ index.php [L] 6 | php_value mbstring.http_input pass 7 | php_value mbstring.http_output pass 8 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ngs-doo/dsl-php-tutorial/70a7b1dccc413ae487a9fc267f02612e7ada9f16/public/favicon.ico -------------------------------------------------------------------------------- /public/index.php: -------------------------------------------------------------------------------- 1 | 7 | */ 8 | 9 | define('LARAVEL_START', microtime(true)); 10 | 11 | /* 12 | |-------------------------------------------------------------------------- 13 | | Register The Auto Loader 14 | |-------------------------------------------------------------------------- 15 | | 16 | | Composer provides a convenient, automatically generated class loader 17 | | for our application. We just need to utilize it! We'll require it 18 | | into the script here so that we do not have to worry about the 19 | | loading of any our classes "manually". Feels great to relax. 20 | | 21 | */ 22 | 23 | require __DIR__.'/../bootstrap/autoload.php'; 24 | 25 | /* 26 | |-------------------------------------------------------------------------- 27 | | Turn On The Lights 28 | |-------------------------------------------------------------------------- 29 | | 30 | | We need to illuminate PHP development, so let's turn on the lights. 31 | | This bootstrap the framework and gets it ready for use, then it 32 | | will load up this application so that we can run it and send 33 | | the responses back to the browser and delight these users. 34 | | 35 | */ 36 | 37 | $app = require_once __DIR__.'/../bootstrap/start.php'; 38 | 39 | /* 40 | |-------------------------------------------------------------------------- 41 | | Run The Application 42 | |-------------------------------------------------------------------------- 43 | | 44 | | Once we have the application, we can simply call the run method, 45 | | which will execute the request and send the response back to 46 | | the client's browser allowing them to enjoy the creative 47 | | and wonderful applications we have created for them. 48 | | 49 | */ 50 | 51 | $app->run(); 52 | 53 | /* 54 | |-------------------------------------------------------------------------- 55 | | Shutdown The Application 56 | |-------------------------------------------------------------------------- 57 | | 58 | | Once Artisan has finished running. We will fire off the shutdown events 59 | | so that any final work may be done by the application before we shut 60 | | down the process. This is the last thing to happen to the request. 61 | | 62 | */ 63 | 64 | $app->shutdown(); -------------------------------------------------------------------------------- /public/packages/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ngs-doo/dsl-php-tutorial/70a7b1dccc413ae487a9fc267f02612e7ada9f16/public/packages/.gitkeep --------------------------------------------------------------------------------