summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemi Collet <fedora@famillecollet.com>2015-10-14 15:43:45 +0200
committerRemi Collet <fedora@famillecollet.com>2015-10-14 15:43:45 +0200
commit58890f0efb46f634ad62547ae9cc5d35bbd95659 (patch)
tree90a4a6c5c523f6583c3b3339a3f19623827a14f1
parent7f815979280e0c5109351e66055e390b6666edd3 (diff)
php-jsonlint: add an autoloader
-rw-r--r--php-jsonlint-autoload.php15
-rw-r--r--php-jsonlint-bin-without-composer-autoloader.patch13
-rw-r--r--php-jsonlint.spec35
3 files changed, 39 insertions, 24 deletions
diff --git a/php-jsonlint-autoload.php b/php-jsonlint-autoload.php
new file mode 100644
index 0000000..53f50f4
--- /dev/null
+++ b/php-jsonlint-autoload.php
@@ -0,0 +1,15 @@
+<?php
+/* Autoloader for seld/jsonlint and its dependencies */
+
+$vendorDir = '/usr/share/php';
+// Use Symfony autoloader
+if (!isset($fedoraClassLoader) || !($fedoraClassLoader instanceof \Symfony\Component\ClassLoader\ClassLoader)) {
+ if (!class_exists('Symfony\\Component\\ClassLoader\\ClassLoader', false)) {
+ require_once $vendorDir . '/Symfony/Component/ClassLoader/ClassLoader.php';
+ }
+
+ $fedoraClassLoader = new \Symfony\Component\ClassLoader\ClassLoader();
+ $fedoraClassLoader->register();
+}
+
+$fedoraClassLoader->addPrefix('Seld\\JsonLint\\', dirname(dirname(__DIR__)));
diff --git a/php-jsonlint-bin-without-composer-autoloader.patch b/php-jsonlint-bin-without-composer-autoloader.patch
index fdad739..d17357d 100644
--- a/php-jsonlint-bin-without-composer-autoloader.patch
+++ b/php-jsonlint-bin-without-composer-autoloader.patch
@@ -2,13 +2,7 @@ diff --git a/bin/jsonlint b/bin/jsonlint
index 1b9272a..c15cfa6 100755
--- a/bin/jsonlint
+++ b/bin/jsonlint
-@@ -1,4 +1,4 @@
--#!/usr/bin/env php
-+#!/usr/bin/php
- <?php
-
- /*
-@@ -10,20 +10,10 @@
+@@ -10,20 +10,7 @@
* file that was distributed with this source code.
*/
@@ -26,10 +20,7 @@ index 1b9272a..c15cfa6 100755
- fwrite(STDERR, $msg);
- exit(1);
-}
-+spl_autoload_register(function ($class) {
-+ $src = str_replace('\\', '/', $class).'.php';
-+ @include_once $src;
-+});
++require_once '/usr/share/php/Seld/JsonLint/autoload.php';
use Seld\JsonLint\JsonParser;
diff --git a/php-jsonlint.spec b/php-jsonlint.spec
index 23c67e0..fb0f115 100644
--- a/php-jsonlint.spec
+++ b/php-jsonlint.spec
@@ -1,5 +1,6 @@
+# remirepo spec file for php-jsonlint, from:
#
-# RPM spec file for php-jsonlint
+# Fedora spec file for php-jsonlint
#
# Copyright (c) 2013-2015 Shawn Iwinski <shawn.iwinski@gmail.com>
# Remi Collet <remi@fedoraproject.org>
@@ -23,7 +24,7 @@
Name: php-%{github_name}
Version: %{github_version}
-Release: 1%{?dist}
+Release: 3%{?dist}
Summary: JSON Lint for PHP
Group: Development/Libraries
@@ -31,6 +32,9 @@ License: MIT
URL: https://github.com/%{github_owner}/%{github_name}
Source0: %{url}/archive/%{github_commit}/%{name}-%{github_version}-%{github_commit}.tar.gz
+# Autoloader
+Source1: %{name}-autoload.php
+
# Bin usage without Composer autoloader
Patch0: %{name}-bin-without-composer-autoloader.patch
@@ -39,14 +43,19 @@ BuildArch: noarch
%if %{with_tests}
# For tests: composer.json
BuildRequires: php(language) >= %{php_min_ver}
-BuildRequires: php-phpunit-PHPUnit
+BuildRequires: php-composer(phpunit/phpunit)
# For tests: phpcompatinfo (computed from version 1.3.1)
BuildRequires: php-pcre
+# For autoloader
+BuildRequires: php-composer(symfony/class-loader)
%endif
Requires: php(language) >= %{php_min_ver}
# phpcompatinfo (computed from version 1.3.1)
+Requires: php-cli
Requires: php-pcre
+# For autoloader
+Requires: php-composer(symfony/class-loader)
Provides: php-composer(seld/jsonlint) = %{version}
@@ -57,10 +66,14 @@ Provides: php-composer(seld/jsonlint) = %{version}
This library is a port of the JavaScript jsonlint
(https://github.com/zaach/jsonlint) library.
+To use this library, you just have to add, in your project:
+ require_once '%{_datadir}/php/Seld/JsonLint/autoload.php';
+
%prep
%setup -q -n %{github_name}-%{github_commit}
+cp %{SOURCE1} src/Seld/JsonLint/autoload.php
%patch0 -p1
@@ -80,16 +93,9 @@ install -pm 0755 bin/jsonlint %{buildroot}%{_bindir}/
%check
%if %{with_tests}
-# Create autoloader
-cat > autoload.php <<'AUTOLOAD'
-<?php
-spl_autoload_register(function ($class) {
- $src = str_replace('\\', '/', $class).'.php';
- @include_once $src;
-});
-AUTOLOAD
-
-%{_bindir}/phpunit --bootstrap ./autoload.php --include-path %{buildroot}%{_datadir}/php .
+%{_bindir}/phpunit \
+ --bootstrap %{buildroot}%{_datadir}/php/Seld/JsonLint/autoload.php \
+ --verbose
%else
: Tests skipped
%endif
@@ -106,6 +112,9 @@ AUTOLOAD
%changelog
+* Wed Oct 14 2015 Remi Collet <remi@fedoraproject.org> - 1.3.1-3
+- add autoloader
+
* Mon Jan 5 2015 Remi Collet <remi@fedoraproject.org> - 1.3.1-1
- Updated to 1.3.1