diff options
author | Remi Collet <fedora@famillecollet.com> | 2016-04-15 11:24:50 +0200 |
---|---|---|
committer | Remi Collet <fedora@famillecollet.com> | 2016-04-15 11:24:50 +0200 |
commit | 429ccf38f02f8aed5a3407d863ab5b3ec5f7ccd7 (patch) | |
tree | 6a8cee335716589d34ee72898481a72cf9eaec21 |
php-justinrainbow-json-schema: 2.0.0 (new package)
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | php-justinrainbow-json-schema-autoload.php | 19 | ||||
-rwxr-xr-x | php-justinrainbow-json-schema-makesrc.sh | 27 | ||||
-rw-r--r-- | php-justinrainbow-json-schema-rpm.patch | 45 | ||||
-rw-r--r-- | php-justinrainbow-json-schema.spec | 189 |
5 files changed, 284 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..91b0fd5 --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +SRCDIR := $(shell pwd) +NAME := $(shell basename $(SRCDIR)) +include ../../common/Makefile + diff --git a/php-justinrainbow-json-schema-autoload.php b/php-justinrainbow-json-schema-autoload.php new file mode 100644 index 0000000..24540d8 --- /dev/null +++ b/php-justinrainbow-json-schema-autoload.php @@ -0,0 +1,19 @@ +<?php +/** + * Autoloader for justinrainbow/json-schema and its dependencies + */ + +$vendorDir = '/usr/share/php'; + +// Use Symfony PSR4 autoloader +if (!isset($fedoraPsr4ClassLoader) || !($fedoraPsr4ClassLoader instanceof \Symfony\Component\ClassLoader\Psr4ClassLoader)) { + if (!class_exists('Symfony\\Component\\ClassLoader\\Psr4ClassLoader', false)) { + require_once '/usr/share/php/Symfony/Component/ClassLoader/Psr4ClassLoader.php'; + } + + $fedoraPsr4ClassLoader = new \Symfony\Component\ClassLoader\Psr4ClassLoader(); + $fedoraPsr4ClassLoader->register(true); +} + +$fedoraPsr4ClassLoader->addPrefix('JsonSchema\\', __DIR__); + diff --git a/php-justinrainbow-json-schema-makesrc.sh b/php-justinrainbow-json-schema-makesrc.sh new file mode 100755 index 0000000..0270766 --- /dev/null +++ b/php-justinrainbow-json-schema-makesrc.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +NAME=$(basename $PWD) +OWNER=$(sed -n '/^%global gh_owner/{s/.* //;p}' $NAME.spec) +PROJECT=$(sed -n '/^%global gh_project/{s/.* //;p}' $NAME.spec) +VERSION=$(sed -n '/^Version:/{s/.* //;p}' $NAME.spec) +COMMIT=$(sed -n '/^%global gh_commit/{s/.* //;p}' $NAME.spec) +SHORT=${COMMIT:0:7} + +echo -e "\nCreate git snapshot\nName=$NAME, Owner=$OWNER, Project=$PROJECT, Version=$VERSION\n" + +echo "Cloning..." +git clone https://github.com/$OWNER/$PROJECT.git $PROJECT-$COMMIT + +echo "Getting commit..." +pushd $PROJECT-$COMMIT +git checkout $COMMIT +cp composer.json ../composer-$VERSION.json +popd + +echo "Archiving..." +tar czf $NAME-$VERSION-$SHORT.tgz --exclude .git $PROJECT-$COMMIT + +echo "Cleaning..." +rm -rf $PROJECT-$COMMIT + +echo "Done." diff --git a/php-justinrainbow-json-schema-rpm.patch b/php-justinrainbow-json-schema-rpm.patch new file mode 100644 index 0000000..9d3962d --- /dev/null +++ b/php-justinrainbow-json-schema-rpm.patch @@ -0,0 +1,45 @@ +diff -up bin/validate-json.rpm bin/validate-json +--- bin/validate-json.rpm 2016-04-15 11:02:32.629960716 +0200 ++++ bin/validate-json 2016-04-15 11:07:01.583136406 +0200 +@@ -6,28 +6,7 @@ + * @author Christian Weiske <christian.weiske@netresearch.de> + */ + +-/** +- * Dead simple autoloader +- * +- * @param string $className Name of class to load +- * +- * @return void +- */ +-function __autoload($className) +-{ +- $className = ltrim($className, '\\'); +- $fileName = ''; +- $namespace = ''; +- if ($lastNsPos = strrpos($className, '\\')) { +- $namespace = substr($className, 0, $lastNsPos); +- $className = substr($className, $lastNsPos + 1); +- $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; +- } +- $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; +- if (stream_resolve_include_path($fileName)) { +- require_once $fileName; +- } +-} ++require_once '/usr/share/php/JsonSchema2/autoload.php'; + + /** + * Show the json parse error that happened last +@@ -84,11 +63,6 @@ function parseHeaderValue($headerValue) + } + + +-// support running this tool from git checkout +-if (is_dir(__DIR__ . '/../src/JsonSchema')) { +- set_include_path(__DIR__ . '/../src' . PATH_SEPARATOR . get_include_path()); +-} +- + $arOptions = array(); + $arArgs = array(); + array_shift($argv);//script itself diff --git a/php-justinrainbow-json-schema.spec b/php-justinrainbow-json-schema.spec new file mode 100644 index 0000000..ca6ebce --- /dev/null +++ b/php-justinrainbow-json-schema.spec @@ -0,0 +1,189 @@ +# remirepo/fedora spec file for php-justinrainbow-json-schema +# +# Copyright (c) 2016 Remi Collet +# License: CC-BY-SA +# http://creativecommons.org/licenses/by-sa/4.0/ +# +# Please, preserve the changelog entries +# +%global gh_commit f1f874d2c0eb546553290f56655c755f69cbaaa7 +%global gh_short %(c=%{gh_commit}; echo ${c:0:7}) +%global gh_owner justinrainbow +%global gh_project json-schema +%global php_home %{_datadir}/php +%global with_tests 0%{!?_without_tests:1} + +# Some sample files, only used for tests +# "json-schema/JSON-Schema-Test-Suite": "1.1.0", +%global ts_commit 4eaaea8711d49656089643baeac4d32a01c1fce2 +%global ts_short %(c=%{gh_commit}; echo ${c:0:7}) +%global ts_owner json-schema +%global ts_project JSON-Schema-Test-Suite +%global ts_version 1.1.0 + +%global eolv1 0 + +Name: php-%{gh_owner}-%{gh_project} +Version: 2.0.0 +Release: 1%{?dist} +Summary: A library to validate a json schema + +Group: Development/Libraries +License: MIT +URL: https://github.com/%{gh_owner}/%{gh_project} +# git snapshot to get upstream test suite +Source0: %{name}-%{version}-%{gh_short}.tgz +Source1: https://github.com/%{ts_owner}/%{ts_project}/archive/%{ts_commit}/%{ts_project}-%{ts_version}-%{gh_short}.tar.gz +Source2: %{name}-autoload.php +Source3: %{name}-makesrc.sh + +# Autoloader +Patch0: %{name}-rpm.patch + +BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) +BuildArch: noarch +%if %{with_tests} +# For tests +BuildRequires: php(language) >= 5.3.3 +BuildRequires: php-curl +BuildRequires: php-date +BuildRequires: php-filter +BuildRequires: php-json +BuildRequires: php-mbstring +BuildRequires: php-pcre +BuildRequires: php-spl +# From composer.json, "require-dev": { +# "json-schema/JSON-Schema-Test-Suite": "1.1.0", +# "phpunit/phpunit": "^4.8.22", +# "phpdocumentor/phpdocumentor": "~2" +BuildRequires: php-composer(phpunit/phpunit) >= 4.8.22 +# Autoloader +BuildRequires: php-composer(symfony/class-loader) >= 2.5 +# For composer schema +BuildRequires: composer +%endif + +# From composer.json, "require": { +# "php": ">=5.3.3" +Requires: php(language) >= 5.3.3 +# From phpcompatinfo report for version 2.0.0 +Requires: php-curl +Requires: php-date +Requires: php-filter +Requires: php-json +Requires: php-mbstring +Requires: php-pcre +Requires: php-spl +# Autoloader (2.5 for PSR-4) +Requires: php-composer(symfony/class-loader) >= 2.5 +%if %{eolv1} +Obsoletes: php-JsonSchema < 2 +Requires: php-cli +%endif + +Provides: php-composer(%{gh_owner}/%{gh_project}) = %{version} + + +%description +A PHP Implementation for validating JSON Structures against a given Schema. +%if %{eolv1} +This package provides the validate-json command. +%else +The validate-json command is provided by the php-JsonSchema package +with the JsonSchema library version 1.x. +%endif +See http://json-schema.org/ + +Autoloader: %{php_home}/JsonSchema2/autoload.php + + +%prep +%setup -q -n %{gh_project}-%{gh_commit} -a 1 + +%patch0 -p0 -b .rpm + +cp %{SOURCE2} src/JsonSchema/autoload.php + +: Needed for the test suite - use composer default path, as easier +mkdir -p vendor/json-schema/JSON-Schema-Test-Suite +mv %{ts_project}-%{ts_commit}/tests \ + vendor/json-schema/JSON-Schema-Test-Suite/tests + +: But without online tests +find vendor/json-schema/JSON-Schema-Test-Suite/tests \ + -name \*.json \ + -exec grep -q 'http://' {} \; \ + -exec rm {} \; \ + -print + +%if ! %{eolv1} +chmod -x bin/validate-json +%endif + + +%build +# Empty build section, most likely nothing required. + + +%install +rm -rf %{buildroot} + +: Library +mkdir -p %{buildroot}%{php_home} +cp -pr src/JsonSchema %{buildroot}%{php_home}/JsonSchema2 + +%if %{eolv1} +: Command +install -Dpm 0755 bin/validate-json %{buildroot}%{_bindir}/validate-json +%endif + + +%check +%if %{with_tests} +: Test suite autoloader +cat << 'EOF' | tee vendor/autoload.php +<?php +require '%{buildroot}%{php_home}/JsonSchema2/autoload.php'; +$fedoraPsr4ClassLoader->addPrefix('JsonSchema\\Tests\\', 'tests/JsonSchema/Tests/'); +EOF + +: Test the command +sed -e 's:%{php_home}:%{buildroot}%{php_home}:' \ + bin/validate-json > bin/validate-json-test +php bin/validate-json-test \ + composer.json \ + /usr/share/composer/res/composer-schema.json + +: Upstream test suite +%{_bindir}/phpunit --verbose + +if which php70; then + php70 %{_bindir}/phpunit --verbose +fi +%else +: Test suite disabled +%endif + + +%clean +rm -rf %{buildroot} + + +%files +%defattr(-,root,root,-) +%{!?_licensedir:%global license %%doc} +%license LICENSE +%doc composer.json +%doc *.md +%if %{eolv1} +%{_bindir}/validate-json +%else +%doc bin/validate-json +%endif +%{php_home}/JsonSchema2 + + +%changelog +* Fri Apr 15 2016 Remi Collet <remi@fedoraproject.org> - 2.0.0-1 +- initial package, version 2.0.0 + |