Skip to content
This repository has been archived by the owner on Aug 14, 2023. It is now read-only.

Commit

Permalink
refactor: replaces use of deprecated each function to improve PHP7 co…
Browse files Browse the repository at this point in the history
…mpatibility (#14)
  • Loading branch information
Phillip Hartin authored and sherwinski committed Sep 20, 2019
1 parent e4ebc6f commit 75183bc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
dist: trusty
language: php
php:
- '7.0'
- '5.6'
- '5.5'
install:
- 'cd site/addons/Imgix && composer install'
script: 'echo "Tests pending a harness from Statamic. imgix-php is well-tested though, and that''s there most of imgix-statamic''s logic lives."'
script: 'echo "Tests pending a harness from Statamic. imgix-php is well-tested though, and that''s where most of imgix-statamic''s logic lives."'
25 changes: 14 additions & 11 deletions site/addons/Imgix/ImgixTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ protected function categorizedAttributes() {

unset($attrs['path']);

while (list($key, $val) = each($attrs)) {
$is_html_attr = in_array($key, self::$html_attributes);
$is_data_attr = strpos($key, 'data-') === 0;
$is_aria_attr = strpos($key, 'aria-') === 0;

if ($is_html_attr || $is_data_attr || $is_aria_attr) {
$categorized_attrs['img_attributes'][$key] = $val;
} else {
$categorized_attrs['imgix_attributes'][$key] = $val;
if (is_array($attrs)) {
foreach ($attrs as $key => $val) {
$is_html_attr = in_array($key, self::$html_attributes);
$is_data_attr = strpos($key, 'data-') === 0;
$is_aria_attr = strpos($key, 'aria-') === 0;
if ($is_html_attr || $is_data_attr || $is_aria_attr) {
$categorized_attrs['img_attributes'][$key] = $val;
} else {
$categorized_attrs['imgix_attributes'][$key] = $val;
}
}
}

Expand All @@ -48,8 +49,10 @@ protected function buildHtmlAttributes($categorized_attrs) {

$html = '';

while (list($key, $val) = each($img_attributes)) {
$html .= " $key=\"$val\"";
if (is_array($img_attributes)) {
foreach ($img_attributes as $key => $val) {
$html .= " $key=\"$val\"";
}
}

return $html;
Expand Down

0 comments on commit 75183bc

Please sign in to comment.