alex-w
(Pr0j3ct A1ex)
1
Will more 2.0 classes allow chaining?
I was making use of some new 5.4 features trying to set the attributes of a model after it’s creation.
e.g.
$model = (new MyModel)->setAttributes(array(...));
And had to extend CModel just to return the instance on setAttributes.
samdark
(Alexander Makarov)
2
Yes, Yii2 will use chaining more.
thefsb
(Fsb)
3
Speaking of… does anyone have established style rules for chaining in PHP? I haven’t been able to come up with anything other than fugliness.
samdark
(Alexander Makarov)
4
What do you mean by style rules for chaining?
jeroen84
(Jeroendenhaan)
5
fsb, do you mean newlines & tabs with "style" ?
Like:
$model->something()
->someOtherThing()
->anotherThing();
#instead of:
$model->something()->someOtherThing()->anotherThing();
thefsb
(Fsb)
6
yes
i mean, this is just terrible:
Yii::app()->clientScript->addPackage('sm2-muxtape', array(
'basePath' => 'ext.Sm2Muxtape',
'baseUrl' => bu($baseUrl),
'js' => array('script/soundmanager2-nodebug-jsmin.js', 'page-player.js'),
'css' => array('', 'page-player.css', 'flashblock.css'),
))->registerPackage('sm2-muxtape'
)->registerCss('sm2-debug', <<<CSS
#soundmanager-debug {
/* SM2 debug container (optional, makes debug more useable) */
position: absolute;
position: fixed;
*position: absolute;
bottom: 10px;
right: 10px;
width: 50em;
height: 18em;
overflow: auto;
background: #fff;
margin: 1em;
padding: 1em;
border: 1px solid #999;
font-family: "lucida console", verdana, tahoma, "sans serif";
font-size: x-small;
line-height: 1.5em;
opacity: 0.9;
filter: alpha(opacity = 90);
z-index: 99;
}
CSS
)->registerScript('sm2-init',
"soundManager.url = '$baseUrl/swf/'",
CClientScript::POS_HEAD
);
and the variants i’ve tried are no better.
if anyone has anything good, please supply PhpStorm/IDEA code style config too! that would be real swell.
jeroen84
(Jeroendenhaan)
7
I always write the ‘)’ on the same line as the method it’s part of. Like:
Yii::app()->clientScript->addPackage('sm2-muxtape', array(
'basePath' => 'ext.Sm2Muxtape',
'baseUrl' => bu($baseUrl),
'js' => array('script/soundmanager2-nodebug-jsmin.js', 'page-player.js'),
'css' => array('', 'page-player.css', 'flashblock.css'),
))
->registerPackage('sm2-muxtape')
->registerCss('sm2-debug', $css)
->registerScript('sm2-init',
"soundManager.url = '$baseUrl/swf/'",
CClientScript::POS_HEAD);
samdark
(Alexander Makarov)
8
I’m doing it almost the same way as yJeroen does:
Yii::app()->clientScript->addPackage('sm2-muxtape', array(
'basePath' => 'ext.Sm2Muxtape',
'baseUrl' => bu($baseUrl),
'js' => array('script/soundmanager2-nodebug-jsmin.js', 'page-player.js'),
'css' => array('', 'page-player.css', 'flashblock.css'),
))
->registerPackage('sm2-muxtape')
->registerCss('sm2-debug', $css)
->registerScript(
'sm2-init',
"soundManager.url = '$baseUrl/swf/'",
CClientScript::POS_HEAD
);
thefsb
(Fsb)
9
I see. Thanks.
I’ll see if I can get PhpStorm to do this for me.
Jaggi
(Jaggi 2005)
10
Yea I do it the yJeroen and samdark way too.