Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F92731761
DivinerAtomizer.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
Sat, Nov 23, 05:51
Size
1 KB
Mime Type
text/x-php
Expires
Mon, Nov 25, 05:51 (1 d, 20 h)
Engine
blob
Format
Raw Data
Handle
22488555
Attached To
rPH Phabricator
DivinerAtomizer.php
View Options
<?php
/**
* Generate @{class:DivinerAtom}s from source code.
*/
abstract
class
DivinerAtomizer
extends
Phobject
{
private
$book
;
private
$fileName
;
private
$atomContext
;
/**
* If you make a significant change to an atomizer, you can bump this version
* to drop all the old atom caches.
*/
public
static
function
getAtomizerVersion
()
{
return
1
;
}
final
public
function
atomize
(
$file_name
,
$file_data
,
array
$context
)
{
$this
->
fileName
=
$file_name
;
$this
->
atomContext
=
$context
;
$atoms
=
$this
->
executeAtomize
(
$file_name
,
$file_data
);
// Promote the `@group` special to a property. If there's no `@group` on
// an atom but the file it's in matches a group pattern, associate it with
// the right group.
foreach
(
$atoms
as
$atom
)
{
$group
=
null
;
try
{
$group
=
$atom
->
getDocblockMetaValue
(
'group'
);
}
catch
(
Exception
$ex
)
{
// There's no docblock metadata.
}
// If there's no group, but the file matches a group, use that group.
if
(
$group
===
null
&&
isset
(
$context
[
'group'
]))
{
$group
=
$context
[
'group'
];
}
if
(
$group
!==
null
)
{
$atom
->
setProperty
(
'group'
,
$group
);
}
}
return
$atoms
;
}
abstract
protected
function
executeAtomize
(
$file_name
,
$file_data
);
final
public
function
setBook
(
$book
)
{
$this
->
book
=
$book
;
return
$this
;
}
final
public
function
getBook
()
{
return
$this
->
book
;
}
protected
function
newAtom
(
$type
)
{
return
id
(
new
DivinerAtom
())
->
setBook
(
$this
->
getBook
())
->
setFile
(
$this
->
fileName
)
->
setType
(
$type
);
}
protected
function
newRef
(
$type
,
$name
,
$book
=
null
,
$context
=
null
)
{
$book
=
coalesce
(
$book
,
$this
->
getBook
());
return
id
(
new
DivinerAtomRef
())
->
setBook
(
$book
)
->
setContext
(
$context
)
->
setType
(
$type
)
->
setName
(
$name
);
}
}
Event Timeline
Log In to Comment