Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SS4/PHP compatibility tweaks #13

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 17 additions & 21 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,31 @@
language: php

php:
- 5.5
- 5.6
- 7.0
- 7.1

env:
- DB=MYSQL CORE_RELEASE=4
global:
- COMPOSER_ROOT_VERSION="4.x-dev"

matrix:
include:
- php: 7.1
env: DB=SQLITE CORE_RELEASE=4 COVERAGE=1
- php: 5.6
env: DB=PGSQL CORE_RELEASE=4
env: DB=MYSQL PHPCS_TEST=1 PHPUNIT_TEST=1
- php: 7.0
env: DB=PGSQL PHPUNIT_TEST=1
- php: 7.1
env: DB=MYSQL PHPUNIT_COVERAGE_TEST=1

before_script:
- composer self-update
- phpenv rehash
- git clone git://github.com/silverstripe/silverstripe-travis-support.git ~/travis-support
- php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss
- cd ~/builds/ss
- phpenv config-rm xdebug.ini

- composer validate
- composer require --no-update silverstripe/recipe-core:4.x-dev
- if [[ $DB == PGSQL ]]; then composer require --no-update silverstripe/postgresql:2.x-dev; fi
- composer install --prefer-source --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile

script:
- "if [ \"$COVERAGE\" != \"1\" ]; then vendor/bin/phpunit externalurlfield/tests; fi"
- "if [ \"$COVERAGE\" = \"1\" ]; then vendor/bin/phpunit --coverage-clover ~/coverage.xml externalurlfield/tests; fi"
- if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit; fi
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xml; fi
- if [[ $PHPCS_TEST ]]; then vendor/bin/phpcs src tests; fi

after_success:
- >
test "$COVERAGE" = "1"
&& cd externalurlfield
&& wget https://scrutinizer-ci.com/ocular.phar
&& php ocular.phar code-coverage:upload -v --format=php-clover ~/coverage.xml
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload -v --format=php-clover coverage.xml; fi
6 changes: 6 additions & 0 deletions _config/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
Name: externalurlfield
---
SilverStripe\Core\Injector\Injector:
ExternalURL:
class: BurnBright\ExternalURLField\ExternalURL
15 changes: 9 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
{
"name": "burnbright/silverstripe-externalurlfield",
"description": "Provides SilverStripe with a DBField and FormField for handling external URLs.",
"type": "silverstripe-module",
"type": "silverstripe-vendormodule",
"license": "MIT",
"keywords": ["silverstripe", "url", "link", "form", "field"],
"require": {
"silverstripe/framework": "^4.0@dev",
"silverstripe/framework": "^4.0",
"silverstripe/vendor-plugin": "^1.0",
"jakeasmith/http_build_url": "^1"
},
"extra": {
"installer-name": "externalurlfield"
},
"require-dev": {
"phpunit/phpunit": "^5.7",
"squizlabs/php_codesniffer": "^3.0"
},
"authors": [
{
"name": "Jeremy Shipman",
Expand All @@ -23,5 +25,6 @@
"BurnBright\\ExternalURLField\\": "src/",
"BurnBright\\ExternalURLField\\Tests\\": "tests/"
}
}
},
"minimum-stability": "dev"
}
11 changes: 11 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="SilverStripe">
<description>CodeSniffer ruleset for SilverStripe coding conventions.</description>

<!-- base rules are PSR-2 -->
<rule ref="PSR2" >
<!-- Current exclusions -->
<exclude name="PSR1.Methods.CamelCapsMethodName.NotCamelCaps" />
<exclude name="Squiz.Classes.ValidClassName.NotCamelCaps" />
</rule>
</ruleset>
10 changes: 4 additions & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
<phpunit bootstrap="framework/tests/bootstrap.php" colors="true">
<phpunit bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true">

<testsuite name="Default">
<directory>tests</directory>
<directory>tests/</directory>
</testsuite>

<listeners>
<listener class="SilverStripe\Dev\TestListener" />
</listeners>

<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src/</directory>
Expand All @@ -15,4 +12,5 @@
</exclude>
</whitelist>
</filter>

</phpunit>
11 changes: 8 additions & 3 deletions src/ExternalURLField.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ class ExternalURLField extends TextField
'fragment' => false
),
'html5validation' => true,
'validregex' => '%^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@|\d{1,3}(?:\.\d{1,3}){3}|(?:(?:[a-z\d\x{00a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)(?:\.(?:[a-z\d\x{00a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)*(?:\.[a-z\x{00a1}-\x{ffff}]{2,6}))(?::\d+)?(?:[^\s]*)?$%iu'
'validregex' => '%^(?:(?:https?|ftp)://)(?:\S+(?::\S*)'
. '?@|\d{1,3}(?:\.\d{1,3}){3}|(?:(?:[a-z\d\x{00a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)'
. '(?:\.(?:[a-z\d\x{00a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)*(?:\.[a-z\x{00a1}-\x{ffff}]{2,6}))'
. '(?::\d+)?(?:[^\s]*)?$%iu'
);

/**
Expand Down Expand Up @@ -116,13 +119,15 @@ public function getAttributes()
/**
* Rebuild url on save
* @param string $url
* @param array|DataObject $data {@see Form::loadDataFrom}
* @return $this
*/
public function setValue($url)
public function setValue($url, $data = null)
{
if ($url) {
$url = $this->rebuildURL($url);
}
parent::setValue($url);
parent::setValue($url, $data);
}

/**
Expand Down