Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F114385252
DivinerAtom.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
Sun, May 25, 13:36
Size
6 KB
Mime Type
text/x-php
Expires
Tue, May 27, 13:36 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
26393207
Attached To
rPH Phabricator
DivinerAtom.php
View Options
<?php
final
class
DivinerAtom
{
const
TYPE_FILE
=
'file'
;
const
TYPE_ARTICLE
=
'article'
;
private
$type
;
private
$name
;
private
$file
;
private
$line
;
private
$hash
;
private
$contentRaw
;
private
$length
;
private
$language
;
private
$docblockRaw
;
private
$docblockText
;
private
$docblockMeta
;
private
$warnings
=
array
();
private
$parentHash
;
private
$childHashes
=
array
();
private
$context
;
private
$extends
=
array
();
private
$links
=
array
();
private
$project
;
public
function
setProject
(
$project
)
{
$this
->
project
=
$project
;
return
$this
;
}
public
function
getProject
()
{
return
$this
->
project
;
}
public
function
setContext
(
$context
)
{
$this
->
context
=
$context
;
return
$this
;
}
public
function
getContext
()
{
return
$this
->
context
;
}
public
static
function
getAtomSerializationVersion
()
{
return
1
;
}
public
function
addWarning
(
$warning
)
{
$this
->
warnings
[]
=
$warning
;
return
$this
;
}
public
function
getWarnings
()
{
return
$this
->
warnings
;
}
public
function
setDocblockRaw
(
$docblock_raw
)
{
$this
->
docblockRaw
=
$docblock_raw
;
$parser
=
new
PhutilDocblockParser
();
list
(
$text
,
$meta
)
=
$parser
->
parse
(
$docblock_raw
);
$this
->
docblockText
=
$text
;
$this
->
docblockMeta
=
$meta
;
return
$this
;
}
public
function
getDocblockRaw
()
{
return
$this
->
docblockRaw
;
}
public
function
getDocblockText
()
{
if
(
$this
->
docblockText
===
null
)
{
throw
new
Exception
(
"Call setDocblockRaw() before getDocblockText()!"
);
}
return
$this
->
docblockText
;
}
public
function
getDocblockMeta
()
{
if
(
$this
->
docblockMeta
===
null
)
{
throw
new
Exception
(
"Call setDocblockRaw() before getDocblockMeta()!"
);
}
return
$this
->
docblockMeta
;
}
public
function
setType
(
$type
)
{
$this
->
type
=
$type
;
return
$this
;
}
public
function
getType
()
{
return
$this
->
type
;
}
public
function
setName
(
$name
)
{
$this
->
name
=
$name
;
return
$this
;
}
public
function
getName
()
{
return
$this
->
name
;
}
public
function
setFile
(
$file
)
{
$this
->
file
=
$file
;
return
$this
;
}
public
function
getFile
()
{
return
$this
->
file
;
}
public
function
setLine
(
$line
)
{
$this
->
line
=
$line
;
return
$this
;
}
public
function
getLine
()
{
return
$this
->
line
;
}
public
function
setContentRaw
(
$content_raw
)
{
$this
->
contentRaw
=
$content_raw
;
return
$this
;
}
public
function
getContentRaw
()
{
return
$this
->
contentRaw
;
}
public
function
setHash
(
$hash
)
{
$this
->
hash
=
$hash
;
return
$this
;
}
public
function
addLink
(
DivinerAtomRef
$ref
)
{
$this
->
links
[]
=
$ref
;
return
$this
;
}
public
function
addExtends
(
DivinerAtomRef
$ref
)
{
$this
->
extends
[]
=
$ref
;
return
$this
;
}
public
function
getLinkDictionaries
()
{
return
mpull
(
$this
->
links
,
'toDictionary'
);
}
public
function
getExtendsDictionaries
()
{
return
mpull
(
$this
->
extends
,
'toDictionary'
);
}
public
function
getHash
()
{
if
(
$this
->
hash
)
{
return
$this
->
hash
;
}
$parts
=
array
(
$this
->
getType
(),
$this
->
getName
(),
$this
->
getFile
(),
$this
->
getLine
(),
$this
->
getLength
(),
$this
->
getLanguage
(),
$this
->
getContentRaw
(),
$this
->
getDocblockRaw
(),
mpull
(
$this
->
extends
,
'toHash'
),
mpull
(
$this
->
links
,
'toHash'
),
);
return
md5
(
serialize
(
$parts
)).
'N'
;
}
public
function
setLength
(
$length
)
{
$this
->
length
=
$length
;
return
$this
;
}
public
function
getLength
()
{
return
$this
->
length
;
}
public
function
setLanguage
(
$language
)
{
$this
->
language
=
$language
;
return
$this
;
}
public
function
getLanguage
()
{
return
$this
->
language
;
}
public
function
addChildHash
(
$child_hash
)
{
$this
->
childHashes
[]
=
$child_hash
;
return
$this
;
}
public
function
getChildHashes
()
{
return
$this
->
childHashes
;
}
public
function
setParentHash
(
$parent_hash
)
{
if
(
$this
->
parentHash
)
{
throw
new
Exception
(
"Atom already has a parent!"
);
}
$this
->
parentHash
=
$parent_hash
;
return
$this
;
}
public
function
getParentHash
()
{
return
$this
->
parentHash
;
}
public
function
addChild
(
DivinerAtom
$atom
)
{
$atom
->
setParentHash
(
$this
->
getHash
());
$this
->
addChildHash
(
$atom
->
getHash
());
return
$this
;
}
public
function
getURI
()
{
$parts
=
array
();
$parts
[]
=
phutil_escape_uri_path_component
(
$this
->
getType
());
if
(
$this
->
getContext
())
{
$parts
[]
=
phutil_escape_uri_path_component
(
$this
->
getContext
());
}
$parts
[]
=
phutil_escape_uri_path_component
(
$this
->
getName
());
$parts
[]
=
null
;
return
implode
(
'/'
,
$parts
);
}
public
function
toDictionary
()
{
// NOTE: If you change this format, bump the format version in
// getAtomSerializationVersion().
return
array
(
'type'
=>
$this
->
getType
(),
'name'
=>
$this
->
getName
(),
'file'
=>
$this
->
getFile
(),
'line'
=>
$this
->
getLine
(),
'hash'
=>
$this
->
getHash
(),
'uri'
=>
$this
->
getURI
(),
'length'
=>
$this
->
getLength
(),
'context'
=>
$this
->
getContext
(),
'language'
=>
$this
->
getLanguage
(),
'docblockRaw'
=>
$this
->
getDocblockRaw
(),
'warnings'
=>
$this
->
getWarnings
(),
'parentHash'
=>
$this
->
getParentHash
(),
'childHashes'
=>
$this
->
getChildHashes
(),
'extends'
=>
$this
->
getExtendsDictionaries
(),
'links'
=>
$this
->
getLinkDictionaries
(),
'ref'
=>
$this
->
getRef
()->
toDictionary
(),
);
}
public
function
getRef
()
{
return
id
(
new
DivinerAtomRef
())
->
setProject
(
$this
->
getProject
())
->
setContext
(
$this
->
getContext
())
->
setType
(
$this
->
getType
())
->
setName
(
$this
->
getName
());
}
public
static
function
newFromDictionary
(
array
$dictionary
)
{
$atom
=
id
(
new
DivinerAtom
())
->
setType
(
idx
(
$dictionary
,
'type'
))
->
setName
(
idx
(
$dictionary
,
'name'
))
->
setFile
(
idx
(
$dictionary
,
'file'
))
->
setLine
(
idx
(
$dictionary
,
'line'
))
->
setHash
(
idx
(
$dictionary
,
'hash'
))
->
setLength
(
idx
(
$dictionary
,
'length'
))
->
setContext
(
idx
(
$dictionary
,
'context'
))
->
setLanguage
(
idx
(
$dictionary
,
'language'
))
->
setParentHash
(
idx
(
$dictionary
,
'parentHash'
))
->
setDocblockRaw
(
idx
(
$dictionary
,
'docblockRaw'
));
foreach
(
idx
(
$dictionary
,
'warnings'
,
array
())
as
$warning
)
{
$atom
->
addWarning
(
$warning
);
}
foreach
(
idx
(
$dictionary
,
'childHashes'
,
array
())
as
$child
)
{
$atom
->
addChildHash
(
$child
);
}
return
$atom
;
}
}
Event Timeline
Log In to Comment