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
F14476706: D11115.diff
Sat, Dec 28, 7:28 AM
Unknown Object (File)
Sun, Dec 22, 5:42 PM
Unknown Object (File)
Tue, Dec 17, 5:17 PM
Unknown Object (File)
Tue, Dec 17, 2:11 AM
Unknown Object (File)
Thu, Dec 12, 7:38 PM
Unknown Object (File)
Wed, Dec 11, 5:41 PM
Unknown Object (File)
Wed, Dec 11, 2:30 AM
Unknown Object (File)
Sun, Dec 8, 3:05 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
Branch
bootloader-register
Lint
Lint Passed
Unit
Tests Passed
Build Status
Buildable 3439
Build 3446: [Placeholder Plan] Wait for 30 Seconds

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.