Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F96510456
CelerityResourceMap.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
Fri, Dec 27, 10:27
Size
1 KB
Mime Type
text/x-php
Expires
Sun, Dec 29, 10:27 (2 d)
Engine
blob
Format
Raw Data
Handle
23195874
Attached To
rPH Phabricator
CelerityResourceMap.php
View Options
<?php
/*
* Copyright 2011 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final
class
CelerityResourceMap
{
private
static
$instance
;
private
$resourceMap
;
public
static
function
getInstance
()
{
if
(
empty
(
self
::
$instance
))
{
self
::
$instance
=
new
CelerityResourceMap
();
$root
=
phutil_get_library_root
(
'phabricator'
);
$ok
=
@
include_once
$root
.
'/__celerity_resource_map__.php'
;
if
(!
$ok
)
{
throw
new
Exception
(
"Failed to load Celerity resource map!"
);
}
}
return
self
::
$instance
;
}
public
function
setResourceMap
(
$resource_map
)
{
$this
->
resourceMap
=
$resource_map
;
return
$this
;
}
public
function
resolveResources
(
array
$symbols
)
{
$map
=
array
();
foreach
(
$symbols
as
$symbol
)
{
if
(!
empty
(
$map
[
$symbol
]))
{
continue
;
}
$this
->
resolveResource
(
$map
,
$symbol
);
}
return
$map
;
}
private
function
resolveResource
(
array
&
$map
,
$symbol
)
{
if
(
empty
(
$this
->
resourceMap
[
$symbol
]))
{
throw
new
Exception
(
"Attempting to resolve unknown resource, '{$symbol}'."
);
}
$info
=
$this
->
resourceMap
[
$symbol
];
foreach
(
$info
[
'requires'
]
as
$requires
)
{
if
(!
empty
(
$map
[
$requires
]))
{
continue
;
}
$this
->
resolveResource
(
$map
,
$requires
);
}
$map
[
$symbol
]
=
$info
;
}
}
function
celerity_register_resource_map
(
array
$map
)
{
$instance
=
CelerityResourceMap
::
getInstance
();
$instance
->
setResourceMap
(
$map
);
}
Event Timeline
Log In to Comment