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.

Wednesday, 5 June 2013

Set up remote PHP debugging on Ubuntu in Netbeans

This is the configuration I found works (after installing everything that's needed) to get remote debugging in Netbeans for a site running on an Ubuntu server with Apache2.

(/etc/php5/apache2/conf.d/20-xdebug.ini

zend_extension=/usr/lib/php5/20100525/xdebug.so
xdebug.max_nesting_level=2000

xdebug.remote_enable=On
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.remote_connect_back = 1
xdebug.profiler_enable = 1
xdebug.profiler_enable_trigger = 1
xdebug.profiler_output_name = cachegrind.out.%t.%p

You also need to set up a path mapping in Netbeans like this:  https://blogs.oracle.com/netbeansphp/entry/path_mapping_in_php_debugger

Restart apache...

Thursday, 26 May 2011

FTSE Friday 27th May 2011

Falling trend on the daily.  Market has rallied since Wednesday and is heading towards the upper trend line around 5960.  If it meets the upper line today short, stop at 6020, T1@5900,  T2@5860, T3@5790

Note.  At the beginning of Feb there was an identical down trend.  The market rallied all the way up to 6100. so might be smart to get out early if the trade breaks the upper trend.

Wednesday, 2 February 2011

Encrypt tar files during the tar - Ubuntu Forums

[ubuntu] Encrypt tar files during the tar - Ubuntu Forums: "encrypt:

tar -c directory | openssl des3 -salt > encrypted.tarfile

decrypt:

cat encrypted.tarfile | openssl des3 -d -salt |tar -xv"

Java stack tutorial

http://www.mkyong.com/spring/maven-spring-hibernate-mysql-example/

Useful getting started guide to Java, Maven, Spring and Hibernate

Tuesday, 11 January 2011

Good Hibernate Tutorial

Good Hibernate Tutorial.

Starts with the basics and builds.

Chapter 1. Tutorial

Tuesday, 2 November 2010