forked from BKWLD/croppa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementing the "Flexible thumbnail formats" feature. See: BKWLD#212.…
… WIP
- Loading branch information
Showing
6 changed files
with
263 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
|
||
namespace Bkwld\Croppa; | ||
|
||
class ParameterBucket | ||
{ | ||
protected string $path; | ||
protected ?int $width; | ||
protected ?int $height; | ||
protected array $urlOptions; | ||
protected URL|null $urlHelper; | ||
|
||
public function __construct( | ||
string $path, | ||
?int $width, | ||
?int $height, | ||
array $urlOptions | ||
) | ||
{ | ||
$this->path = $path; | ||
$this->width = $width; | ||
$this->height = $height; | ||
$this->urlOptions = $urlOptions; | ||
} | ||
|
||
/** | ||
* @param string $requestPath | ||
* @return static|null | ||
* @throws Exception | ||
*/ | ||
public static function createFrom(string $requestPath): ?static | ||
{ | ||
$url = app(URL::class); | ||
$params = $url->parse($requestPath); | ||
|
||
if (!$params) { | ||
return null; | ||
} | ||
|
||
[$path, $width, $height, $options] = $params; | ||
|
||
return new self( | ||
$path, | ||
$width, | ||
$height, | ||
$options | ||
); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getPath(): string | ||
{ | ||
return $this->path; | ||
} | ||
|
||
/** | ||
* @return int|null | ||
*/ | ||
public function getWidth(): ?int | ||
{ | ||
return $this->width; | ||
} | ||
|
||
/** | ||
* @return int|null | ||
*/ | ||
public function getHeight(): ?int | ||
{ | ||
return $this->height; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getUrlOptions(): array | ||
{ | ||
return $this->urlOptions; | ||
} | ||
|
||
/** | ||
* Take options in the URL and options from the config file | ||
* and produce a config array. | ||
*/ | ||
public function config(): array | ||
{ | ||
return $this->getUrlHelper()->config($this->getUrlOptions()); | ||
} | ||
|
||
protected function getUrlHelper() { | ||
$this->urlHelper = $this->urlHelper ?? app(URL::class); | ||
return $this->urlHelper; | ||
} | ||
} |
Oops, something went wrong.