meenie/munee — pull request #23 by elkangaroo (2013-08-16 21:16:52+00:00)
Title: PHP Warning: Invalid argument supplied for foreach() in Image.php on line 155

Requesting an image, which has not been cached yet, leads to a PHP warning:
```
request: "GET image.jpg?resize=h[100] HTTP/1.0"
```

```
PHP message: PHP Warning: Invalid argument supplied for foreach() in ../vendor/meenie/Munee/src/Munee/Asset/Type/Image.php on line 155
PHP message: PHP Stack trace:
PHP message: PHP 1. {main}() ../www.static/assetic.php:0
PHP message: PHP 2. Munee\Dispatcher::run() ../www.static/assetic.php:16
PHP message: PHP 3. Munee\Asset\Type->init() ../vendor/meenie/Munee/src/Munee/Dispatcher.php:69
PHP message: PHP 4. Munee\Asset\Type\Image->setupFile() ../vendor/meenie/Munee/src/Munee/Asset/Type.php:131
PHP message: PHP 5. Munee\Asset\Type\Image->checkNumberOfAllowedFilters() ../vendor/meenie/Munee/src/Munee/Asset/Type/Image.php:95
```

This is because glob() may return false instead of an empty array which is then passed to foreach (leading to a warning):

> On some systems it is impossible to distinguish between empty match and an error.
... from the PHP documentation (http://php.net/glob#refsect1-function.glob-returnvalues)

---

Here's my pull request which fixes this warning:

- Fixed "PHP Warning: Invalid argument supplied for foreach()" in Image::checkNumberOfAllowedFilters() when glob() returns false
- Moved Image::checkNumberOfAllowedFilters() and Image::checkReferrer() calls into Image::setupFile() function
- Removed duplicate code in Image::checkCache()