Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F1063506
AlmanacBinding.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
AlmanacBinding.php
View Options
<?php
final
class
AlmanacBinding
extends
AlmanacDAO
implements
PhabricatorPolicyInterface
,
PhabricatorCustomFieldInterface
,
PhabricatorApplicationTransactionInterface
,
AlmanacPropertyInterface
{
protected
$servicePHID
;
protected
$devicePHID
;
protected
$interfacePHID
;
protected
$mailKey
;
private
$service
=
self
::
ATTACHABLE
;
private
$device
=
self
::
ATTACHABLE
;
private
$interface
=
self
::
ATTACHABLE
;
private
$customFields
=
self
::
ATTACHABLE
;
private
$almanacProperties
=
self
::
ATTACHABLE
;
public
static
function
initializeNewBinding
(
AlmanacService
$service
)
{
return
id
(
new
AlmanacBinding
())
->
setServicePHID
(
$service
->
getPHID
())
->
attachAlmanacProperties
(
array
());
}
public
function
getConfiguration
()
{
return
array
(
self
::
CONFIG_AUX_PHID
=>
true
,
self
::
CONFIG_COLUMN_SCHEMA
=>
array
(
'mailKey'
=>
'bytes20'
,
),
self
::
CONFIG_KEY_SCHEMA
=>
array
(
'key_service'
=>
array
(
'columns'
=>
array
(
'servicePHID'
,
'interfacePHID'
),
'unique'
=>
true
,
),
'key_device'
=>
array
(
'columns'
=>
array
(
'devicePHID'
),
),
'key_interface'
=>
array
(
'columns'
=>
array
(
'interfacePHID'
),
),
),
)
+
parent
::
getConfiguration
();
}
public
function
generatePHID
()
{
return
PhabricatorPHID
::
generateNewPHID
(
AlmanacBindingPHIDType
::
TYPECONST
);
}
public
function
save
()
{
if
(!
$this
->
mailKey
)
{
$this
->
mailKey
=
Filesystem
::
readRandomCharacters
(
20
);
}
return
parent
::
save
();
}
public
function
getURI
()
{
return
'/almanac/binding/'
.
$this
->
getID
().
'/'
;
}
public
function
getService
()
{
return
$this
->
assertAttached
(
$this
->
service
);
}
public
function
attachService
(
AlmanacService
$service
)
{
$this
->
service
=
$service
;
return
$this
;
}
public
function
getDevice
()
{
return
$this
->
assertAttached
(
$this
->
device
);
}
public
function
attachDevice
(
AlmanacDevice
$device
)
{
$this
->
device
=
$device
;
return
$this
;
}
public
function
getInterface
()
{
return
$this
->
assertAttached
(
$this
->
interface
);
}
public
function
attachInterface
(
AlmanacInterface
$interface
)
{
$this
->
interface
=
$interface
;
return
$this
;
}
/* -( AlmanacPropertyInterface )------------------------------------------- */
public
function
attachAlmanacProperties
(
array
$properties
)
{
assert_instances_of
(
$properties
,
'AlmanacProperty'
);
$this
->
almanacProperties
=
mpull
(
$properties
,
null
,
'getFieldName'
);
return
$this
;
}
public
function
getAlmanacProperties
()
{
return
$this
->
assertAttached
(
$this
->
almanacProperties
);
}
public
function
hasAlmanacProperty
(
$key
)
{
$this
->
assertAttached
(
$this
->
almanacProperties
);
return
isset
(
$this
->
almanacProperties
[
$key
]);
}
public
function
getAlmanacProperty
(
$key
)
{
return
$this
->
assertAttachedKey
(
$this
->
almanacProperties
,
$key
);
}
public
function
getAlmanacPropertyValue
(
$key
,
$default
=
null
)
{
if
(
$this
->
hasAlmanacProperty
(
$key
))
{
return
$this
->
getAlmanacProperty
(
$key
)->
getFieldValue
();
}
else
{
return
$default
;
}
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */
public
function
getCapabilities
()
{
return
array
(
PhabricatorPolicyCapability
::
CAN_VIEW
,
PhabricatorPolicyCapability
::
CAN_EDIT
,
);
}
public
function
getPolicy
(
$capability
)
{
return
$this
->
getService
()->
getPolicy
(
$capability
);
}
public
function
hasAutomaticCapability
(
$capability
,
PhabricatorUser
$viewer
)
{
return
$this
->
getService
()->
hasAutomaticCapability
(
$capability
,
$viewer
);
}
public
function
describeAutomaticCapability
(
$capability
)
{
return
array
(
pht
(
'A binding inherits the policies of its service.'
),
pht
(
'To view a binding, you must also be able to view its device and '
.
'interface.'
),
);
}
/* -( PhabricatorCustomFieldInterface )------------------------------------ */
public
function
getCustomFieldSpecificationForRole
(
$role
)
{
return
array
();
}
public
function
getCustomFieldBaseClass
()
{
return
'AlmanacCustomField'
;
}
public
function
getCustomFields
()
{
return
$this
->
assertAttached
(
$this
->
customFields
);
}
public
function
attachCustomFields
(
PhabricatorCustomFieldAttachment
$fields
)
{
$this
->
customFields
=
$fields
;
return
$this
;
}
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
public
function
getApplicationTransactionEditor
()
{
return
new
AlmanacBindingEditor
();
}
public
function
getApplicationTransactionObject
()
{
return
$this
;
}
public
function
getApplicationTransactionTemplate
()
{
return
new
AlmanacBindingTransaction
();
}
public
function
willRenderTimeline
(
PhabricatorApplicationTransactionView
$timeline
,
AphrontRequest
$request
)
{
return
$timeline
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Jun 29, 10:40 AM (1 d, 23 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
258455
Default Alt Text
AlmanacBinding.php (4 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment