If I try to use a simple Phar call in my controller:

$tar = new \PharData('/path/to/myTar.tar');

I get the error:

"Unexpected file extension"

This is because Drupal Security checks to see if the file extension contains "phar", and rejects it if not. Unfortunately, the Phar library needs the extension to be ".tar" otherwise it won't work.

As a test, I disabled the security check, but it still didn't work:

TYPO3\PharStreamWrapper\Exception: Expected invocation could not be resolved

I've tested this on the same server outside of the Drupal environment and it worked fine. Has anybody had any success using Phar in Drupal 8?

  • 1
    I think you're out of luck - the phar manager (with the custom interceptor) is initialised in DrupalKernel::boot(), unconditionally, if there's a phar stream wrapper available. It's not possible to re-initialise the phar manager (see TYPO3\PharStreamWrapper\Manager::initialise()), so without patching either the Kernel or Drupal's interceptor, I don't think there's an option – Clive Sep 19 '19 at 18:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.