Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F1060602
AlmanacDevice.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
AlmanacDevice.php
View Options
<?php
final
class
AlmanacDevice
extends
AlmanacDAO
implements
PhabricatorPolicyInterface
,
PhabricatorCustomFieldInterface
,
PhabricatorApplicationTransactionInterface
,
PhabricatorProjectInterface
,
PhabricatorSSHPublicKeyInterface
,
AlmanacPropertyInterface
{
protected
$name
;
protected
$nameIndex
;
protected
$mailKey
;
protected
$viewPolicy
;
protected
$editPolicy
;
private
$customFields
=
self
::
ATTACHABLE
;
private
$almanacProperties
=
self
::
ATTACHABLE
;
public
static
function
initializeNewDevice
()
{
return
id
(
new
AlmanacDevice
())
->
setViewPolicy
(
PhabricatorPolicies
::
POLICY_USER
)
->
setEditPolicy
(
PhabricatorPolicies
::
POLICY_ADMIN
)
->
attachAlmanacProperties
(
array
());
}
public
function
getConfiguration
()
{
return
array
(
self
::
CONFIG_AUX_PHID
=>
true
,
self
::
CONFIG_COLUMN_SCHEMA
=>
array
(
'name'
=>
'text128'
,
'nameIndex'
=>
'bytes12'
,
'mailKey'
=>
'bytes20'
,
),
self
::
CONFIG_KEY_SCHEMA
=>
array
(
'key_name'
=>
array
(
'columns'
=>
array
(
'nameIndex'
),
'unique'
=>
true
,
),
'key_nametext'
=>
array
(
'columns'
=>
array
(
'name'
),
),
),
)
+
parent
::
getConfiguration
();
}
public
function
generatePHID
()
{
return
PhabricatorPHID
::
generateNewPHID
(
AlmanacDevicePHIDType
::
TYPECONST
);
}
public
function
save
()
{
AlmanacNames
::
validateServiceOrDeviceName
(
$this
->
getName
());
$this
->
nameIndex
=
PhabricatorHash
::
digestForIndex
(
$this
->
getName
());
if
(!
$this
->
mailKey
)
{
$this
->
mailKey
=
Filesystem
::
readRandomCharacters
(
20
);
}
return
parent
::
save
();
}
public
function
getURI
()
{
return
'/almanac/device/view/'
.
$this
->
getName
().
'/'
;
}
/* -( 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
)
{
switch
(
$capability
)
{
case
PhabricatorPolicyCapability
::
CAN_VIEW
:
return
$this
->
getViewPolicy
();
case
PhabricatorPolicyCapability
::
CAN_EDIT
:
return
$this
->
getEditPolicy
();
}
}
public
function
hasAutomaticCapability
(
$capability
,
PhabricatorUser
$viewer
)
{
return
false
;
}
public
function
describeAutomaticCapability
(
$capability
)
{
return
null
;
}
/* -( 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
AlmanacDeviceEditor
();
}
public
function
getApplicationTransactionObject
()
{
return
$this
;
}
public
function
getApplicationTransactionTemplate
()
{
return
new
AlmanacDeviceTransaction
();
}
public
function
willRenderTimeline
(
PhabricatorApplicationTransactionView
$timeline
,
AphrontRequest
$request
)
{
return
$timeline
;
}
/* -( PhabricatorSSHPublicKeyInterface )----------------------------------- */
public
function
getSSHPublicKeyManagementURI
(
PhabricatorUser
$viewer
)
{
return
$this
->
getURI
();
}
public
function
getSSHKeyDefaultName
()
{
return
$this
->
getName
();
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Jun 29, 8:34 AM (1 d, 18 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
258415
Default Alt Text
AlmanacDevice.php (4 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment