Jim Cheung

Tuesday, June 11, 2013

on Composer

add directory to autoloader search path

$loader = require '../vendor/autoload.php';
$loader->add('Vendor\Package', __DIR__);

use custom svn repository

as example, vendor=jchk, package=webservice

repo layout:

trunk
  +- JChk
      +- WebService
          +- composer.json

server composer.json:

{
  "name": "jchk/webservice",
  "description": "webservice class",
  "license": "proprietary",
  "authors": [
    {
      "name": "",
      "email": ""
    }
  ],
  "require": {
    "php": ">=5.3.3"
  },
  "autoload": {
    "psr-0": {
      "JChk\\WebService\\": ""
    }
  },
  "target-dir": "JChk/WebService"
}

note: use target-dir to set installation path on client side

client composer.json:

{
  "repositories": [
    {
      "type": "vcs",
      "url": "http://my.svn.repo/Composer/",
      "package-path": "JChk/WebService"
    }
  ],
  "require": {
    "jchk/webservice": "dev-trunk",
  }
}

note: use package-path to force composer to check trunk/JChk/WebService/composer.json instead of trunk/composer.json

Wednesday, June 19, 2013

tried redhat's openshift paas, deploy by rhc (ruby), just like heroku and appfog, very easy. and it seems a bit faster than appfog. the best thing of openshift is, it supports dance, a sinatra-like perl framework, i couldn't find any hosting supports it until openshift.

Tuesday, June 25, 2013

PHP 5.5 is released. sad that it doesn't support Windows XP anymore. I managed having it installed under cygwin, and here's a quick tests of new features

$pass = "meee";
$hash = password_hash($pass, PASSWORD_DEFAULT);

if (password_verify($pass, $hash)) {
  print "pass\n";
}

$pass2 = "chiii";
$hash = password_hash($pass2, PASSWORD_BCRYPT, array('cost' => 5, 'salt' => '1982734k2j3kljflk23f89723fj23klfj23klf32az'));
if (password_verify($pass2, $hash)) {
  print "pass2\n";
}

$lines = [
  'one' => ['123', 'ott'],
  'two' => ['456', 'ffs']
];
foreach($lines as $key => list($subkey, $subvalue)) {
  print $key. ":" . $subkey . "-" . $subvalue . "\n";
  
}

var_dump("string"[1]);
var_dump([1,2,3][1]);
var_dump([['foo','bar'], [1, 2]][0][1]);

Wednesday, June 26, 2013

reading Practical Object-Oriented Design in Ruby, quite good. on setting default values to arguments, it goes from

def initialize(args)
  @foo = args[:foo] || "foo"
end

to

def initialize(args)
  @foo = args.fetch(:foo, "foo")
end

to

def initialize(args)
  args = defaults.merge(args)
  @foo = args[:foo]
end

def defaults
  { :foo => "foo }
end

using merge is a very good suggestion.

Blog Archive