Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F100841009
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
Mon, Feb 3, 04:43
Size
3 KB
Mime Type
text/x-php
Expires
Wed, Feb 5, 04:43 (1 d, 21 h)
Engine
blob
Format
Raw Data
Handle
24005892
Attached To
rPH Phabricator
CelerityResourceMap.php
View Options
<?php
/*
* Copyright 2012 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.
*/
/**
* Interface to the static resource map, which is a graph of available
* resources, resource dependencies, and packaging information. You generally do
* not need to invoke it directly; instead, you call higher-level Celerity APIs
* and it uses the resource map to satisfy your requests.
*
* @group celerity
*/
final
class
CelerityResourceMap
{
private
static
$instance
;
private
$resourceMap
;
private
$packageMap
;
private
$reverseMap
;
public
static
function
getInstance
()
{
if
(
empty
(
self
::
$instance
))
{
self
::
$instance
=
new
CelerityResourceMap
();
$root
=
phutil_get_library_root
(
'phabricator'
);
$path
=
PhabricatorEnv
::
getEnvConfig
(
'celerity.resource-map'
,
'__celerity_resource_map__.php'
);
$ok
=
include_once
Filesystem
::
resolvePath
(
$path
,
$root
);
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 Celerity resource, '{$symbol}'."
);
}
$info
=
$this
->
resourceMap
[
$symbol
];
foreach
(
$info
[
'requires'
]
as
$requires
)
{
if
(!
empty
(
$map
[
$requires
]))
{
continue
;
}
$this
->
resolveResource
(
$map
,
$requires
);
}
$map
[
$symbol
]
=
$info
;
}
public
function
setPackageMap
(
$package_map
)
{
$this
->
packageMap
=
$package_map
;
return
$this
;
}
public
function
packageResources
(
array
$resolved_map
)
{
$packaged
=
array
();
$handled
=
array
();
foreach
(
$resolved_map
as
$symbol
=>
$info
)
{
if
(
isset
(
$handled
[
$symbol
]))
{
continue
;
}
if
(
empty
(
$this
->
packageMap
[
'reverse'
][
$symbol
]))
{
$packaged
[
$symbol
]
=
$info
;
}
else
{
$package
=
$this
->
packageMap
[
'reverse'
][
$symbol
];
$package_info
=
$this
->
packageMap
[
'packages'
][
$package
];
$packaged
[
$package_info
[
'name'
]]
=
$package_info
;
foreach
(
$package_info
[
'symbols'
]
as
$packaged_symbol
)
{
$handled
[
$packaged_symbol
]
=
true
;
}
}
}
return
$packaged
;
}
public
function
resolvePackage
(
$package_hash
)
{
$package
=
idx
(
$this
->
packageMap
[
'packages'
],
$package_hash
);
if
(!
$package
)
{
return
null
;
}
$paths
=
array
();
foreach
(
$package
[
'symbols'
]
as
$symbol
)
{
$paths
[]
=
$this
->
resourceMap
[
$symbol
][
'disk'
];
}
return
$paths
;
}
public
function
lookupSymbolInformation
(
$symbol
)
{
return
idx
(
$this
->
resourceMap
,
$symbol
);
}
public
function
lookupFileInformation
(
$path
)
{
if
(
empty
(
$this
->
reverseMap
))
{
$this
->
reverseMap
=
array
();
foreach
(
$this
->
resourceMap
as
$symbol
=>
$data
)
{
$data
[
'provides'
]
=
$symbol
;
$this
->
reverseMap
[
$data
[
'disk'
]]
=
$data
;
}
}
return
idx
(
$this
->
reverseMap
,
$path
);
}
}
Event Timeline
Log In to Comment