4 * This file is part of Zippy.
6 * (c) Alchemy <info@alchemy.fr>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Alchemy\Zippy\Resource;
22 * @param string $original
23 * @param string $target
25 public function __construct($original, $target)
27 $this->original = $original;
28 $this->target = $target;
36 public function getTarget()
42 * Returns the original path
46 public function getOriginal()
48 return $this->original;
52 * Returns whether the resource can be processed in place given a context or not.
55 * - /path/to/file1 can be processed to file1 in /path/to context
56 * - /path/to/subdir/file2 can be processed to subdir/file2 in /path/to context
58 * @param string $context
62 public function canBeProcessedInPlace($context)
64 if (!is_string($this->original)) {
68 if (!$this->isLocal()) {
72 $data = parse_url($this->original);
74 return sprintf('%s/%s', rtrim($context, '/'), $this->target) === $data['path'];
78 * Returns a context for computing this resource in case it is possible.
80 * Useful to avoid teleporting.
84 public function getContextForProcessInSinglePlace()
86 if (!is_string($this->original)) {
90 if (!$this->isLocal()) {
94 if (PathUtil::basename($this->original) === $this->target) {
95 return dirname($this->original);
102 * Returns true if the resource is local.
106 private function isLocal()
108 if (!is_string($this->original)) {
112 $data = parse_url($this->original);
114 return isset($data['path']);