Skip to content

Commit

Permalink
Improving package
Browse files Browse the repository at this point in the history
  • Loading branch information
hxtree committed Nov 11, 2021
1 parent f2f202b commit 1b8bdf9
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 70 deletions.
47 changes: 45 additions & 2 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Contributing to DynamoImage

First off, thanks for taking the time to contribute!

For local package development use [Docker](https://www.docker.com/products/docker-desktop):

Build Test container
```
git clone https://github.com/Ouxsoft/DynamoImage.git
cd DynamoImage
docker build --target test --tag dynamoimage:latest -f Dockerfile .
docker run -it --mount type=bind,source="$(pwd)"/,target=/application/ dynamoimage:latest composer install
```

Run Automated Unit Tests using local volume
```
docker run -it --mount type=bind,source="$(pwd)"/,target=/application/ dynamoimage:latest composer test
```

Run Automated Benchmark Tests using local volume
```
docker run -it --mount type=bind,source="$(pwd)"/,target=/application/ dynamoimage:latest ./vendor/bin/phpbench run tests/src/Benchmark --report=default
```

Run Bin using local volume
```
docker run -it --mount type=bind,source="$(pwd)"/,target=/application/ dynamoimage:latest bin/dynamoimage 1d10+4*2 0
```

Start test server available at [http://localhost/](http://localhost/test.html)
```
docker run -it -p 80:80 --mount type=bind,source="$(pwd)"/,target=/application dynamoimage:latest bash -c 'cd public && php -S 0.0.0.0:80'
```

Rebuild Docs
```
docker build --target docs --tag dynamoimage:docs-latest -f Dockerfile .
docker run -it --mount type=bind,source="$(pwd)"/docs,target=/app/docs dynamoimage:docs-latest bash -c "doxygen Doxyfile && doxyphp2sphinx Ouxsoft::dynamoimage"
```
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,6 @@ COPY src /app/src
WORKDIR "/app/docs"

RUN doxygen Doxyfile \
&& doxyphp2sphinx Ouxsoft::LuckByDice
&& doxyphp2sphinx Ouxsoft::DynamoImage

SHELL ["/bin/bash", "-c"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A PHP library for resizing images based on request.

Example showing Symfony intergration:
Example showing Symfony integration:
```
<?php
Expand Down
10 changes: 5 additions & 5 deletions src/DynamoImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
* file that was distributed with this source code.
*/

namespace App\Model;
namespace Ouxsoft\DynamoImage;

use App\Model\DynamoImagePath;
use Laminas\Validator\File\Exists;
use GdImage;
use Exception;
use Laminas\Validator\File\Exists;

/**
* Class DynamoImage
* checks if the requested image exists in cache using a hash
*
* checks if the requested image exists in cache named using hash
* if it is not cached, it checks to see if the image exists as an assets
* if the image exists, then it generates a resized image, stores it in cache.
* does not handle serving image.
Expand Down Expand Up @@ -125,7 +125,7 @@ public function setAssetDir(string $assets_dir) : void
*/
public function setURL(string $request)
{
$parameters = DynamoImagePath::decodeParams("/{$request}", ['height','width','dimension','offset'], 'filename');
$parameters = Path::decode("/{$request}", ['height','width','dimension','offset'], 'filename');

if(
isset($parameters['dimension'])
Expand Down
64 changes: 3 additions & 61 deletions src/DynamoImagePath.php → src/Path.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
* file that was distributed with this source code.
*/

namespace App\Model;
namespace Ouxsoft\DynamoImage;

class DynamoImagePath
class Path
{

/**
* Parses URL to array containing key values
* e.g.
Expand All @@ -24,7 +23,7 @@ class DynamoImagePath
* @param string $catchAll
* @return array
*/
public static function decodeParams(string $string, array $args = [], string $catchAll) : array
public static function decode(string $string, array $args = [], string $catchAll) : array
{
$parameters = [];
$unparsed = $string;
Expand All @@ -48,63 +47,6 @@ public static function decodeParams(string $string, array $args = [], string $ca
return $parameters;
}

/**
* Decodes string of parameters to array
*
* @param string $string
* @return array
*/
public static function decode(string $string): array
{
$filepath = '';
$parts = explode('/', $string);
$parameters = [];
$previous_key = '';
foreach ($parts as $value) {
if ($value == null) {
continue;
}

// start by building out filepath
if (is_dir(dirname(__DIR__, 2) . $filepath . '/' . $value)) {
$filepath .= '/' . $value;
continue;
}

switch ($previous_key) {
case 'height':
$parameters['height'] = $value;
break;
case 'width':
$parameters['width'] = $value;
break;
case 'dimension':
// if dimensions then is array
if (preg_match('/([0-9]+x[0-9]+)/', $value)) {
list($width, $height) = explode('x', $value);
$parameters['width'] = $width;
$parameters['height'] = $height;
}
break;
case 'offset':
// if comma then is array
if (strpos($value, ',') !== false) {
list($x, $y) = explode(',', $value);
$parameters['offset_x'] = $x;
$parameters['offset_y'] = $y;
}
break;
default:
break;
}

$previous_key = $value;
}

$parameters['filename'] = $filepath . '/' . end($parts);

return $parameters;
}

/**
* Encodes parameters provided
Expand Down

0 comments on commit 1b8bdf9

Please sign in to comment.