- Created on Friday, 06 February 2015 14:58
Most of the PHP projects I work on have a very similar structure. That’s why I created this template so I can reuse it across most projects.
The initial Ansible package has originated from Phansible.com which is an awesome tool for easy generating vagrant provisioning using ansible.
In order for this to be a good learning exercise, I created a github repository for the generic vagrant template using ansible where I added branches for each configuration step with clear commits along the way.
As an overview, these are the steps I’ve taken.
- (1) Generate the initial template from Phansible.com
- (2) Added Ansible tasks to import files in order to create the database schema and also to populate the database.
- (3) Created composer.json and added a task to run composer.
- (4) Created a basic hello world application with a namespace that uses composer’s autoloading.
If you’re just interested for the final implementation, go straight to branch step4
- Created on Tuesday, 04 February 2014 19:45
Getting started with PSR-4 and composer in your projects
For comments, go to gist.github.com/pavlakis/8810829#file-gistfile1-php
For completeness, I've included one of my comments below:
For efficiency, we shouldn't be including the tests directory on the main namespace. Instead, we can add it to the autoloader but only in the phpunit's bootstrap. (thanks to @noginn for his suggestion)
We can adapt the above example by making three changes:
- In composer.json remove the reference to tests/, save and run composer update
- Create MyApp/tests/bootstrap.php
- $autoloader = require DIR . '/../vendor/autoload.php';
- Change the bootstrap reference in MyApp/tests/phpunit.xml.dist to: bootstrap.php
The above example is available through github: https://github.com/pavlakis/psr4-with-composer
- Created on Saturday, 30 March 2013 23:20
Composer is a great tool for managing the dependencies in your project.
I must admit, I’ve only just started using it and can already see how powerful and easy to use it is.
There are many good articles on how to set it up, so I’ll go over the basics on getting started in your own project with a basic Hello World example.
- Created on Thursday, 07 March 2013 23:42
Having managed to install PHPUnit in my mac at work with no problems, found it odd - to say the least - that I was having so many issues at my personal one.
So here is the issue I was having. I set the $PATH with the location of of PHPUnit but when run phpunit --version, I got a bad request error.
After trying different ways of installing/uninstalling, I fixed it by changing the first line of PHPUnit as it wasn’t pointing to the right location of php.