Tuesday 12 August 2014

Zend Framework 2 Depencency Injection

I found myself having to reteach myself the Zend Framework 2 DI system this week.

This is a great quick start to get the development environment running.

http://ocramius.github.io/blog/zend-framework-2-controllers-and-dependency-injection-with-zend-di/

And for production it's better to use factories.

http://www.zfdaily.com/2012/07/getting-dependencies-into-zf2-controllers/

Monday 28 July 2014

Problems with pdepend and phpmd dependencies in composer

I added phpmd to my composer.json for project but got this error when I tried to run phpmd.

vendor/bin/phpmd . codesize,design,naming,unusedcode --reportfile build/reports/messdetector.html --exclude vendor,build PHP Warning: require_once(PHP/Depend/Autoload.php): failed to open stream: No such file or directory in /mnt/hgfs/workspace/programmes-service/vendor/phpmd/phpmd/src/main/php/PHP/PMD/ParserFactory.php on line 48

This seems to be an issue with pdepend 2.0.0, adding the line below to pdepend 1.1.1 to you composer.json should fix the problem.

pdepend/pdepend" : "1.1.1"

Tuesday 4 February 2014

PHP CLI config on Mac

Quick post following a bit of frustration this morning.  I had an issue with phpmd and phpcs not being able to find my pear libs.


Warning: include_once(PHP/CodeSniffer/CLI.php): failed to open stream: No such file or directory in /usr/bin/phpcs on line 31 Warning: include_once(): Failed opening 'PHP/CodeSniffer/CLI.php' for inclusion (include_path='.:') in /usr/bin/phpcs on line 31 Fatal error: Class 'PHP_CodeSniffer_CLI' not found in /usr/bin/phpcs on line 34 Warning: require_once(PHP/PMD/TextUI/Command.php): failed to open stream: No such file or directory in /usr/bin/phpmd on line 45 Fatal error: require_once(): Failed opening required 'PHP/PMD/TextUI/Command.php' (include_path='.:') in /usr/bin/phpmd on line 45

This was because there is no php cli config file by default (in mavericks at least). Linking the existing php.ini.default to php.ini resolves this issue.

sudo ln -s /etc/php.ini.default /etc/php.ini

Tuesday 7 January 2014

Installing composer from a local or private location

This looks useful for loading personal or work libraries that are not hosted on github via composer.

http://marekkalnik.tumblr.com/post/22929686367/composer-installing-package-from-local-git-repository

Monday 9 December 2013

Setting up Continuous Integration with Jenkins for PHP

Some useful links I found for setting up Continuous Integration using Jenkins.

Server installation


http://aaronbonner.io/post/4965561040/getting-started-with-jenkins-for-php
http://aaronbonner.io/post/8339092868/installing-jenkins-on-ubuntu

Plugins

http://erichogue.ca/2011/05/php/continuous-integration-in-php/

- Credentials Plugin
- SSH Credentials Plugin
- Git Client Plugin
- Git Plugin
- Coverage Complexity Scatter Plot PlugIn
- Clover PHP Plugin
- xUnit Plugin
- JDepend Plugin
- Static Code Analysis Plug-ins
- Checkstyle Plugin
- PMD Plugin
- Plot Plugin
- Violations
- HTML Publisher Plugin
- DRY Plugin
- PHP Plugin
- Violations
- DRY Plugin
- Restarting Jenkins

Wednesday 27 November 2013

Database Table Names and and URL Structure

URLs

I regularly have to work with a host of different naming conventions.  For example, when dealing with an entity eg. Opportunity I will often find the table containing these entities named 'Opportunities' and a set of URL's for CRUD defined as

  • /opportunities
  • /opportunity/
  • /opportunity/create
  • /opportunity/delete/
  • /opportunity/update/
With URLs I find it much easier to work with plurals for consistency so I don't have to mess around mapping plural spellings to singular:


  • /opportunities
  • /opportunities/
  • /opportunities/create
  • /opportunities/delete/
  • /opportunities/update/
All the above URL's would map to a OpportunitiesController which would use a OpportunityService for interacting with the database.

Databases

On the flip side, I much prefer singular in the case of database tables.  My main reason for this is when working with Doctrine I don't have to add annotations to all my entity classes mapping the Opportunity entity to the opportunities table.  It also reads better when you have related tables eg. OpportunityMetadata table reads better than OpportunitiesMetadata.

This is just the way I do it, personal conventions are not important as long as they're consistent.