Practical GIT (2) : Update remote file after push with configure post-receive hooks
GIT version control got one feature that I really like, named hooks. With hooks, we can configure what GIT do after metadata pushed to the remote server. It can ease our development because we don’t need to upload file manually, just say : git push remoteserver, so the file in our online web will be replaced.
Zend Framework 2 : Setting Default Db Adapter via Service initializers
I just read very useful tutorial from akrabat site. He explain about Zend\ServiceManager configuration keys. And, the most I like is about service initializer. It can inject to all instance of something, for example, if Model is extends AbstractTableGateway.
For example, you have SampleTable class like the following :
class SampleTable extends AbstractTableGateway implements \Zend\Db\Adapter\AdapterAwareInterface { protected $table = 'sampletable'; public function setDbAdapter(Adapter $adapter) { $this->adapter = $adapter; $this->resultSetPrototype = new HydratingResultSet(); $this->resultSetPrototype->setObjectPrototype(new Sample()); $this->initialize(); } }
So, you can initialize of instantiation of all class that implement AdapterAwareInterface like SampleTable.
class Module { public function getServiceConfig() { return array( 'initializers' => array( function ($instance, $sm) { if ($instance instanceof \Zend\Db\Adapter\AdapterAwareInterface) { $instance->setDbAdapter($sm->get('Zend\Db\Adapter\Adapter')); } } ), 'factories' => array( 'SampleModule\Model\SampleTable' => function($sm){ $table = new Model\SampleTable(); return $table; }, ), ); } }
Easy setup, thanks Akrabat.
Reference :
http://akrabat.com/zend-framework-2/zendservicemanager-configuration-keys/
10 comments