Skip to content

Commit

Permalink
Make 7.2+
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Jan 18, 2021
1 parent cd91ebd commit ee8b2bb
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 25 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: ['5.6', '7.4']
php-version: ['7.2', '7.4', '8.0']
prefer-lowest: ['']
include:
- php-version: '5.6'
- php-version: '7.2'
prefer-lowest: 'prefer-lowest'

steps:
Expand Down Expand Up @@ -44,7 +44,7 @@ jobs:
- name: Composer install --no-progress --prefer-dist --optimize-autoloader
run: |
composer --version
composer require --dev phpunit/phpunit:"^5.7.27|^6.5.12|^7.0|^8.5|^9.5"
composer require --dev phpunit/phpunit:"^8.5|^9.5"
if ${{ matrix.prefer-lowest == 'prefer-lowest' }}
then
composer update --prefer-lowest --prefer-stable
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MediaEmbed
[![CI](https://github.com/dereuromark/media-embed/workflows/CI/badge.svg)](https://github.com/dereuromark/media-embed/actions?query=workflow%3ACI+branch%3Amaster)
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%205.6-8892BF.svg)](https://php.net/)
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.2-8892BF.svg)](https://php.net/)
[![License](https://poser.pugx.org/dereuromark/media-embed/license.svg)](https://packagist.org/packages/dereuromark/media-embed)
[![Total Downloads](https://poser.pugx.org/dereuromark/media-embed/d/total.svg)](https://packagist.org/packages/dereuromark/media-embed)
[![Coding Standards](https://img.shields.io/badge/cs-PSR--2--R-yellow.svg)](https://github.com/php-fig-rectified/fig-rectified-standards)
Expand All @@ -25,7 +25,7 @@ https://sandbox.dereuromark.de/sandbox/media-embed

## Requirements

- PHP 5.6+
- PHP 7.2+ since 0.6
- Composer
- [jbroadway/urlify](https://github.com/jbroadway/urlify) for slugging

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
}
],
"require": {
"php": ">=5.6",
"php": ">=7.2",
"jbroadway/urlify": "^1.0.0"
},
"require-dev":{
"sebastian/diff": "@stable",
"fig-r/psr2r-sniffer": "^0.6"
"fig-r/psr2r-sniffer": "dev-master"
},
"autoload": {
"psr-4": {
Expand Down
31 changes: 17 additions & 14 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="vendor/autoload.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">

<testsuites>
<testsuite name="media-embed">
<directory>tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<coverage>
<include>
<directory suffix=".php">src/</directory>
<exclude>
<directory suffix=".php">src/Docs/</directory>
</exclude>
</whitelist>
</filter>
</include>
<exclude>
<directory suffix=".php">src/Docs/</directory>
</exclude>
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
</report>
</coverage>

<logging>
<log type="tap" target="build/report.tap"/>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<junit outputFile="build/report.junit.xml"/>
</logging>

</phpunit>
4 changes: 2 additions & 2 deletions src/Docs/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class Generator {

use DiffTrait;

const CODE_SUCCESS = 0;
const CODE_ERROR = 1;
public const CODE_SUCCESS = 0;
public const CODE_ERROR = 1;

/**
* @var bool
Expand Down
9 changes: 9 additions & 0 deletions src/MediaEmbed.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ public function parseId($id, $host, $config = []) {
if (!$res) {
$stub = [];
$Object = $this->object($stub, $config);

return $Object;
}

//TODO
return null;
}
Expand Down Expand Up @@ -117,6 +119,7 @@ public function parseUrl($url, $config = []) {

$stub['match'] = $this->_match;
$Object = $this->object($stub, $config + $this->config);

return $Object;
}

Expand All @@ -137,6 +140,7 @@ protected function _matchUrl($url, array $regexRules) {
return $match;
}
}

return [];
}

Expand All @@ -162,6 +166,7 @@ protected function _parseLink($url, $regex) {

if (preg_match('~' . $regex . '~imu', $source, $match)) {
$this->_match = $match;

return true;
}

Expand All @@ -183,6 +188,7 @@ public function setHosts(array $stubs, $reset = false) {
$slug = $this->_slug($stub['name']);
$this->_hosts[$slug] = $stub;
}

return $this;
}

Expand All @@ -199,6 +205,7 @@ public function getHosts($whitelist = []) {
}
$res[$slug] = $host;
}

return $res;
}

Expand All @@ -216,6 +223,7 @@ public function getHost($alias) {
if (empty($this->_hosts[$alias])) {
return null;
}

return $this->_hosts[$alias];
}

Expand Down Expand Up @@ -246,6 +254,7 @@ public function object($stub, array $config = []) {
if (!isset($stub['slug']) && !empty($stub['name'])) {
$stub['slug'] = $this->_slug($stub['name']);
}

return new MediaObject($stub, $config);
}

Expand Down
22 changes: 20 additions & 2 deletions src/Object/MediaObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public function stub($property = null, $value = null) {
if (!empty($property) && !empty($value)) {
$this->_stub[$property] = $value;
}

return $this;
}

Expand All @@ -138,6 +139,7 @@ public function id() {
for ($i = 1; $i <= $count; $i++) {
$id = str_ireplace('$' . $i, $res[$i - 1], $id);
}

return $id;
}

Expand Down Expand Up @@ -167,6 +169,7 @@ public function name() {
for ($i = 1; $i <= $count; $i++) {
$name = str_ireplace('$' . $i, $res[$i - 1], $name);
}

return $name;
}

Expand Down Expand Up @@ -207,14 +210,15 @@ public function icon() {
if ($file === false) {
return null;
}

// TODO: transform into 16x16 png
return $file;
}

/**
* @param string $location Absolute path with trailing slash
* @param string|null $icon Icon data
* @return string|null $filename
* @return string|null Filename
*/
public function saveIcon($location, $icon = null) {
if ($icon === null) {
Expand All @@ -231,6 +235,7 @@ public function saveIcon($location, $icon = null) {
if (!file_put_contents($file, $icon)) {
return null;
}

return $filename;
}

Expand Down Expand Up @@ -264,13 +269,14 @@ public function setParam($param, $value = null) {
$this->_objectParams[$param] = $value;
}
}

return $this;
}

/**
* Override a default object attribute value
*
* @param mixed $param The name of the attribute to be set
* @param mixed $param The name of the attribute to be set
* or an array of multiple attribs to be set
* @param string|int|null $value (optional) the value to set the param to
* if only one param is being set
Expand All @@ -296,6 +302,7 @@ public function setAttribute($param, $value = null) {
$this->_objectAttributes[$param] = $value;
}
}

return $this;
}

Expand All @@ -310,6 +317,7 @@ public function setHeight($height, $adjustWidth = false) {
if ($adjustWidth && is_numeric($height)) {
$this->_adjustDimensions('width', 'height', $height);
}

return $this->setAttribute('height', $height);
}

Expand All @@ -324,6 +332,7 @@ public function setWidth($width, $adjustHeight = false) {
if ($adjustHeight && is_numeric($width)) {
$this->_adjustDimensions('height', 'width', $width);
}

return $this->setAttribute('width', $width);
}

Expand Down Expand Up @@ -359,6 +368,7 @@ public function getParams($key = null) {
if (!isset($this->_iframeParams[$key])) {
return null;
}

return $this->_iframeParams[$key];
}

Expand All @@ -368,6 +378,7 @@ public function getParams($key = null) {
if (!isset($this->_objectParams[$key])) {
return null;
}

return $this->_objectParams[$key];
}

Expand All @@ -385,6 +396,7 @@ public function getAttributes($key = null) {
if (!isset($this->_iframeAttributes[$key])) {
return null;
}

return $this->_iframeAttributes[$key];
}

Expand All @@ -394,6 +406,7 @@ public function getAttributes($key = null) {
if (!isset($this->_objectAttributes[$key])) {
return null;
}

return $this->_objectAttributes[$key];
}

Expand All @@ -406,6 +419,7 @@ public function getEmbedCode() {
if (!empty($this->_stub['iframe-player']) && $this->config['prefer'] === 'iframe') {
return $this->_buildIframe();
}

return $this->_buildObject();
}

Expand Down Expand Up @@ -446,9 +460,11 @@ protected function prefers($type = null) {
if (!empty($this->_stub['iframe-player']) && $this->config['prefer'] === 'iframe') {
$prefers = 'iframe';
}

return $prefers;
}
$this->config['prefer'] = $type;

return $this;
}

Expand All @@ -474,6 +490,7 @@ protected function _getObjectSrc($type = 'embed-src') {
$src = str_replace($placeholder, $replacement, $src);
}
}

return $src;
}

Expand Down Expand Up @@ -545,6 +562,7 @@ protected function _buildObject() {
if (!$objectAttributes && !$objectParams) {
return '';
}

return sprintf('<object %s> %s</object>', $objectAttributes, $objectParams);
}

Expand Down
1 change: 1 addition & 0 deletions tests/MediaEmbedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public function getUrls() {
foreach ($this->_stubs as $k => $v) {
$urls[] = [$k, $v];
}

return $urls;
}

Expand Down

0 comments on commit ee8b2bb

Please sign in to comment.