Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F106473589
HeraldRuleSerializer.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Mar 26, 00:43
Size
2 KB
Mime Type
text/x-php
Expires
Fri, Mar 28, 00:43 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
25193225
Attached To
rPH Phabricator
HeraldRuleSerializer.php
View Options
<?php
/**
* Serialize for RuleTransactions / Editor.
*/
final
class
HeraldRuleSerializer
extends
Phobject
{
public
function
serializeRule
(
HeraldRule
$rule
)
{
return
$this
->
serializeRuleComponents
(
(
bool
)
$rule
->
getMustMatchAll
(),
$rule
->
getConditions
(),
$rule
->
getActions
(),
HeraldRepetitionPolicyConfig
::
toString
(
$rule
->
getRepetitionPolicy
()));
}
public
function
serializeRuleComponents
(
$match_all
,
array
$conditions
,
array
$actions
,
$repetition_policy
)
{
assert_instances_of
(
$conditions
,
'HeraldCondition'
);
assert_instances_of
(
$actions
,
'HeraldActionRecord'
);
$conditions_array
=
array
();
foreach
(
$conditions
as
$condition
)
{
$conditions_array
[]
=
array
(
'field'
=>
$condition
->
getFieldName
(),
'condition'
=>
$condition
->
getFieldCondition
(),
'value'
=>
$condition
->
getValue
(),
);
}
$actions_array
=
array
();
foreach
(
$actions
as
$action
)
{
$actions_array
[]
=
array
(
'action'
=>
$action
->
getAction
(),
'target'
=>
$action
->
getTarget
(),
);
}
return
array
(
'match_all'
=>
$match_all
,
'conditions'
=>
$conditions_array
,
'actions'
=>
$actions_array
,
'repetition_policy'
=>
$repetition_policy
,
);
}
public
function
deserializeRuleComponents
(
array
$serialized
)
{
$deser_conditions
=
array
();
foreach
(
$serialized
[
'conditions'
]
as
$condition
)
{
$deser_conditions
[]
=
id
(
new
HeraldCondition
())
->
setFieldName
(
$condition
[
'field'
])
->
setFieldCondition
(
$condition
[
'condition'
])
->
setValue
(
$condition
[
'value'
]);
}
$deser_actions
=
array
();
foreach
(
$serialized
[
'actions'
]
as
$action
)
{
$deser_actions
[]
=
id
(
new
HeraldActionRecord
())
->
setAction
(
$action
[
'action'
])
->
setTarget
(
$action
[
'target'
]);
}
return
array
(
'match_all'
=>
$serialized
[
'match_all'
],
'conditions'
=>
$deser_conditions
,
'actions'
=>
$deser_actions
,
'repetition_policy'
=>
$serialized
[
'repetition_policy'
],
);
}
}
Event Timeline
Log In to Comment