Skip to content

Commit

Permalink
Merge pull request #20 from TYPO3/task/v2-backports
Browse files Browse the repository at this point in the history
[TASK] Backport Phar alias changes
  • Loading branch information
ohader committed Mar 1, 2019
2 parents eaf0a73 + c7db495 commit b7a21f0
Show file tree
Hide file tree
Showing 12 changed files with 480 additions and 133 deletions.
31 changes: 31 additions & 0 deletions src/Collectable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
namespace TYPO3\PharStreamWrapper;

/*
* This file is part of the TYPO3 project.
*
* It is free software; you can redistribute it and/or modify it under the terms
* of the MIT License (MIT). For the full copyright and license information,
* please read the LICENSE file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/

use TYPO3\PharStreamWrapper\Resolver\PharInvocation;

interface Collectable
{
/**
* @param PharInvocation $invocation
* @param null $flags
* @return bool
*/
public function collect(PharInvocation $invocation, $flags = null);

/**
* @param callable $callback
* @param bool $reverse
* @return null|PharInvocation
*/
public function findByCallback($callback, $reverse = false);
}
2 changes: 1 addition & 1 deletion src/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* (and should not) maintain any runtime state information. In order to resolve
* Phar archive paths according resolvers have to be used.
*
* @see \TYPO3\PharStreamWrapper\Resolvable::resolveBaseName()
* @see \TYPO3\PharStreamWrapper\Resolvable::resolve()
*/
class Helper
{
Expand Down
6 changes: 3 additions & 3 deletions src/Interceptor/PharExtensionInterceptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ public function assert($path, $command)
*/
private function baseFileContainsPharExtension($path)
{
$baseFile = Manager::instance()->resolveBaseName($path);
if ($baseFile === null) {
$invocation = Manager::instance()->resolve($path);
if ($invocation === null) {
return false;
}
$fileExtension = pathinfo($baseFile, PATHINFO_EXTENSION);
$fileExtension = pathinfo($invocation->getBaseName(), PATHINFO_EXTENSION);
return strtolower($fileExtension) === 'phar';
}
}
6 changes: 3 additions & 3 deletions src/Interceptor/PharMetaDataInterceptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ public function assert($path, $command)
*/
private function baseFileDoesNotHaveMetaDataIssues($path)
{
$baseFile = Manager::instance()->resolveBaseName($path);
if ($baseFile === null) {
$invocation = Manager::instance()->resolve($path);
if ($invocation === null) {
return false;
}

try {
$reader = new Reader($baseFile);
$reader = new Reader($invocation->getBaseName());
$reader->resolveContainer()->getManifest()->deserializeMetaData();
} catch (DeserializationException $exception) {
return false;
Expand Down
51 changes: 39 additions & 12 deletions src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
* The TYPO3 project - inspiring people to share!
*/

use TYPO3\PharStreamWrapper\Resolver\BaseNameResolver;
use TYPO3\PharStreamWrapper\Resolver\PharInvocation;
use TYPO3\PharStreamWrapper\Resolver\PharInvocationCollection;
use TYPO3\PharStreamWrapper\Resolver\PharInvocationResolver;

class Manager implements Assertable, Resolvable
class Manager
{
/**
* @var self
Expand All @@ -30,15 +32,24 @@ class Manager implements Assertable, Resolvable
*/
private $resolver;

/**
* @var Collectable
*/
private $collection;

/**
* @param Behavior $behaviour
* @param Resolvable $resolver
* @param Collectable $collection
* @return self
*/
public static function initialize(Behavior $behaviour, Resolvable $resolver = null)
{
public static function initialize(
Behavior $behaviour,
Resolvable $resolver = null,
Collectable $collection = null
) {
if (self::$instance === null) {
self::$instance = new self($behaviour, $resolver);
self::$instance = new self($behaviour, $resolver, $collection);
return self::$instance;
}
throw new \LogicException(
Expand Down Expand Up @@ -76,14 +87,22 @@ public static function destroy()
/**
* @param Behavior $behaviour
* @param Resolvable $resolver
* @param Collectable $collection
*/
private function __construct(Behavior $behaviour, Resolvable $resolver = null)
{
private function __construct(
Behavior $behaviour,
Resolvable $resolver = null,
Collectable $collection = null
) {
if ($collection === null) {
$collection = new PharInvocationCollection();
}
if ($resolver === null) {
$resolver = new BaseNameResolver();
$resolver = new PharInvocationResolver();
}
$this->behavior = $behaviour;
$this->collection = $collection;
$this->resolver = $resolver;
$this->behavior = $behaviour;
}

/**
Expand All @@ -99,10 +118,18 @@ public function assert($path, $command)
/**
* @param string $path
* @param null|int $flags
* @return string|null
* @return null|PharInvocation
*/
public function resolve($path, $flags = null)
{
return $this->resolver->resolve($path, $flags);
}

/**
* @return Collectable
*/
public function resolveBaseName($path, $flags = null)
public function getCollection()
{
return $this->resolver->resolveBaseName($path, $flags);
return $this->collection;
}
}
27 changes: 25 additions & 2 deletions src/PharStreamWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
* The TYPO3 project - inspiring people to share!
*/

use TYPO3\PharStreamWrapper\Resolver\PharInvocation;

class PharStreamWrapper
{
/**
Expand All @@ -29,6 +31,11 @@ class PharStreamWrapper
*/
protected $internalResource;

/**
* @var PharInvocation
*/
protected $invocation;

/**
* @return bool
*/
Expand Down Expand Up @@ -409,7 +416,8 @@ public function url_stat($path, $flags)
*/
protected function assert($path, $command)
{
if ($this->resolveAssertable()->assert($path, $command) === true) {
if (Manager::instance()->assert($path, $command) === true) {
$this->collectInvocation($path);
return;
}

Expand All @@ -424,7 +432,22 @@ protected function assert($path, $command)
}

/**
* @return Assertable
* @param string $path
*/
protected function collectInvocation($path)
{
if (isset($this->invocation)) {
return;
}

$manager = Manager::instance();
$this->invocation = $manager->resolve($path);
$manager->getCollection()->collect($this->invocation);
}

/**
* @return Manager|Assertable
* @deprecated Use Manager::instance() directly
*/
protected function resolveAssertable()
{
Expand Down
6 changes: 4 additions & 2 deletions src/Resolvable.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
* The TYPO3 project - inspiring people to share!
*/

use TYPO3\PharStreamWrapper\Resolver\PharInvocation;

interface Resolvable
{
/**
* @param string $path
* @param null|int $flags
* @return null|string
* @return null|PharInvocation
*/
public function resolveBaseName($path, $flags = null);
public function resolve($path, $flags = null);
}
109 changes: 0 additions & 109 deletions src/Resolver/BaseNameResolver.php

This file was deleted.

Loading

0 comments on commit b7a21f0

Please sign in to comment.