Skip to content

Instantly share code, notes, and snippets.

View pronskiy's full-sized avatar
🐘
🇺🇦

Roman Pronskiy pronskiy

🐘
🇺🇦
View GitHub Profile
@pronskiy
pronskiy / PHP Enums.md
Last active February 10, 2019 23:22
PHP Enums - Available implementations of Enum type in PHP
@pronskiy
pronskiy / DynamicRelationBehavior.php
Created September 5, 2012 12:17
Yii DynamicRelationBehavior
class DynamicRelationBehavior extends CActiveRecordBehavior
{
/**
* @var string name of the relation which will be added to the owner dynamically
*/
public $relationName = 'posts';
public function afterFind($event)
{
$this->addRelation();
@pronskiy
pronskiy / gist:3635771
Created September 5, 2012 12:16
Yii CActiveRecord dynamic relation adding
$class = CActiveRecord::HAS_MANY; // Или любой другой вид отношений (HAS_ONE, BELONGS_TO, MANY_MANY)
$model->getMetaData()->relations[$relationName] =
new $class(
$relationName,
$className,
$foreignKey,
$options
);
@pronskiy
pronskiy / gist:3635739
Created September 5, 2012 12:12
CActiveRecord classic relation adding
class User extends CActiveRecord
{
public function relations()
{
return array(
'posts'=>array(self::HAS_MANY, 'Post', 'author_id'),
'profile'=>array(self::HAS_ONE, 'Profile', 'owner_id'),
);
}
@pronskiy
pronskiy / gist:3635704
Created September 5, 2012 12:09
XSS protection on Yii
...
public function rules()
{
return array(
array('attributes, that, are, edited, by, user','filter',
'filter'=>array($obj=new CHtmlPurifier(),'purify')),
...
);
}
...
@pronskiy
pronskiy / gist:3635611
Created September 5, 2012 11:58
Eclipse hotkeys for Sublime Text 2
[
{ "keys": ["shift+enter"], "command": "run_macro_file", "args": {"file": "Packages/Default/Add Line.sublime-macro"} },
{ "keys": ["alt+up"], "command": "swap_line_up" },
{ "keys": ["alt+down"], "command": "swap_line_down" },
{ "keys": ["ctrl+alt+j"], "command": "join_lines" },
{ "keys": ["ctrl+alt+down"], "command": "duplicate_line" },
{ "keys": ["shift+ctrl+r"], "command": "show_overlay", "args": {"overlay": "goto", "show_files": true} },
{ "keys": ["ctrl+shift+s"], "command": "save_all" },
{ "keys": ["ctrl+l"], "command": "show_overlay", "args": {"overlay": "goto", "text": ":"} },
{ "keys": ["shift+ctrl+f4"], "command": "close_all" },