Code snippets

Data types for Latitude/Longitude on Doctrine 2 with YAML
 

NameI'm a devote Doctrine 1.2 user but times are changing and now I'm faced with the challenge of learning and updating all of my applications to use the brand new Doctrine 2.2 framework.

Doctrine 2.2 has been completely renewed and a lot of cool stuff from Doctrine 1.2 has dissapeared, one that will be missed the most I'm sure is the auto-magic the behaviours provided, this said some new challeneges arise, for example, what type of data to use to store basic data like latitud and longitud since the Geographical behaviour is now gone.

A solution I've find is to use decimal type of data with a size of 18,12, so if you are defining your models with YAML like I do you can do the following:

 

EntitiesCity:
  type: entity
  fields:

    id:
      type: integer
      id: true
      generator:
        strategy: AUTO      
    name:
      type: string(255)
    latitude:
      type: decimal(18)
      scale: 12
      precision: 18
      nullable: true

    longitude:
      type: decimal(18)
      scale: 12
      precision: 18
      nullable: true

With this type of data I fixed my need of storing latitude and longitud data.

 
 
Using split on PHP 5.3.0
 

It's been a while since it started coding again in PHP specially in PHP 5.3.0 and I've come across some interesting finding, for example some functions such as ereg, eregi and split are deprecated now in favor of a new library call Perl-Compatible Regular Expressions. For old coders (like me) we need to start updating our code to keep with the up to date standards.

A function I use a lot (for good or for bad) is split but as a matter of fact is one of the new deprecated functions on php so instead of calling it as usual (delimiter, string) now we have to call it using a perl-compatible regular expression (regex,string) as follows...