Page MenuHomePhabricator

Allow in-memory maps to be registered in libphutil
ClosedPublic

Authored by hach-que on Jan 1 2015, 5:04 AM.
Tags
None
Referenced Files
F13135184: D11115.diff
Thu, May 2, 7:25 AM
Unknown Object (File)
Sun, Apr 28, 1:40 PM
Unknown Object (File)
Fri, Apr 26, 9:23 AM
Unknown Object (File)
Wed, Apr 24, 11:49 PM
Unknown Object (File)
Thu, Apr 11, 6:41 PM
Unknown Object (File)
Thu, Apr 11, 6:41 PM
Unknown Object (File)
Thu, Apr 11, 3:03 PM
Unknown Object (File)
Thu, Apr 11, 8:02 AM
Subscribers

Details

Summary

This allows libphutil to have maps and libraries registered from an existing array. Currently when Phage runs (or any similar mechanism that bundles PHP into a single file or stream), all calls to PhutilSymbolLoader will return an empty set of classes when querying, because the appropriate maps haven't been loaded.

In my code, I'm using the following to load in the libphutil maps after concatenating all of the source files:

    // $library is the library name, $map is the map returned
    // from getLibraryMap.
    foreach ($maps as $library => $map) {
      $library_serialized = base64_encode(serialize($library));
      $map_serialized = base64_encode(serialize($map));
      $bootstrap->addText(<<<EOF

PhutilBootloader::getInstance()->registerInMemoryLibrary(
  unserialize(base64_decode("$library_serialized")),
  unserialize(base64_decode("$map_serialized")));

EOF
      );
    }
Test Plan

Tested inside Omni (the UNIX shell I'm working on) as part of it's bundling process (so that scripts can be run on systems without Omni).

Diff Detail

Repository
rPHU libphutil
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

hach-que retitled this revision from to Allow in-memory maps to be registered in libphutil.
hach-que updated this object.
hach-que edited the test plan for this revision. (Show Details)
hach-que added a reviewer: epriestley.
epriestley edited edge metadata.

Seems reasonable to me.

src/moduleutils/PhutilBootloader.php
30

For consistency, prefer to use the more explicit {$name} syntax when embedding strings.

This revision is now accepted and ready to land.Jan 1 2015, 4:18 PM

phutil_var_export() might also be an alternative to base64 + serialize().

This revision was automatically updated to reflect the committed changes.