summaryrefslogtreecommitdiffstats
path: root/php-flow-jsonpath.spec
blob: 160cee8bc3db577c318d1d28899a5e2f9eea8be7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# remirepo spec file for php-flow-jsonpath
#
# Fedora spec file for php-flow-jsonpath
#
# Copyright (c) 2017 Shawn Iwinski <shawn@iwin.ski>
#
# License: MIT
# http://opensource.org/licenses/MIT
#
# Please preserve changelog entries
#

%global github_owner     FlowCommunications
%global github_name      JSONPath
%global github_version   0.3.4
%global github_commit    00aa9c361e4d0a210dd95f3c917a1e0dde3a957f

%global composer_vendor  flow
%global composer_project jsonpath

# "php": ">=5.4.0"
%global php_min_ver 5.4.0

# Build using "--without tests" to disable tests
%global with_tests 0%{!?_without_tests:1}

%{!?phpdir:  %global phpdir  %{_datadir}/php}

Name:          php-%{composer_vendor}-%{composer_project}
Version:       %{github_version}
Release:       1%{?github_release}%{?dist}
Summary:       JSONPath implementation for parsing, searching and flattening arrays

Group:         Development/Libraries
License:       MIT
URL:           https://github.com/%{github_owner}/%{github_name}
Source0:       %{url}/archive/%{github_commit}/%{name}-%{github_version}-%{github_commit}.tar.gz

# Add LICENSE file
# https://github.com/FlowCommunications/JSONPath/pull/20
Patch0:        %{name}-add-license-file.patch

BuildArch:     noarch
# Tests
%if %{with_tests}
## composer.json
BuildRequires: php(language) >= %{php_min_ver}
BuildRequires: php-composer(phpunit/phpunit)
## phpcompatinfo (computed from version 0.3.4)
BuildRequires: php-json
BuildRequires: php-pcre
BuildRequires: php-spl
## Autoloader
BuildRequires: php-composer(fedora/autoloader)
%endif

# composer.json
Requires:      php(language) >= %{php_min_ver}
# phpcompatinfo (computed from version 0.3.4)
Requires:      php-json
Requires:      php-pcre
Requires:      php-spl
# Autoloader
Requires:      php-composer(fedora/autoloader)

# Composer
Provides:      php-composer(%{composer_vendor}/%{composer_project}) = %{version}

%description
This is a JSONPath [1] implementation for PHP based on Stefan Goessner's
JSONPath script.

JSONPath is an XPath-like expression language for filtering, flattening and
extracting data.

I believe that is improves on the original script (which was last updated in
2007) by doing a few things:
* Object-oriented code (should be easier to manage or extend in future)
* Expressions are parsed into tokens using some code cribbed from Doctrine
  Lexer and cached
* There is no eval() in use
* Performance is pretty much the same
* Any combination of objects/arrays/ArrayAccess-objects can be used as the data
  input which is great if you're de-serializing JSON in to objects or if you
  want to process your own data structures.

Autoloader: %{phpdir}/Flow/JSONPath/autoload.php

[1] http://goessner.net/articles/JsonPath/


%prep
%setup -qn %{github_name}-%{github_commit}

: Add LICENSE file
%patch0 -p1


%build
: Create autoloader
cat <<'AUTOLOAD' | tee src/Flow/JSONPath/autoload.php
<?php
/**
 * Autoloader for %{name} and its' dependencies
 * (created by %{name}-%{version}-%{release}).
 */
require_once '%{phpdir}/Fedora/Autoloader/autoload.php';

\Fedora\Autoloader\Autoload::addPsr4('Flow\\JSONPath\\', __DIR__);
AUTOLOAD


%install
mkdir -p %{buildroot}%{phpdir}/Flow
cp -rp src/Flow/JSONPath %{buildroot}%{phpdir}/Flow/


%check
%if %{with_tests}
: Create tests bootstrap
cat <<'BOOTSTRAP' | tee bootstrap.php
<?php
require '%{buildroot}%{phpdir}/Flow/JSONPath/autoload.php';
\Fedora\Autoloader\Autoload::addPsr4('Flow\\JSONPath\\Test\\', __DIR__.'/tests/Flow/JSONPath/Test');
BOOTSTRAP

: Mock Composer autoloader
mkdir vendor
ln -s %{buildroot}%{phpdir}/Flow/JSONPath/autoload.php vendor/autoload.php

: Upstream tests
RETURN_CODE=0
PHPUNIT=$(which phpunit)
for PHP_EXEC in php %{?rhel:php55} php56 php70 php71 php72; do
    if [ "php" == "$PHP_EXEC" ] || which $PHP_EXEC; then
        $PHP_EXEC $PHPUNIT --verbose --bootstrap bootstrap.php || RETURN_CODE=1
    fi
done
exit $RETURN_CODE
%else
: Tests skipped
%endif


%files
%{!?_licensedir:%global license %%doc}
%license LICENSE
%doc *.md
%doc composer.json
%dir %{phpdir}/Flow
     %{phpdir}/Flow/JSONPath


%changelog
* Sun Aug 20 2017 Shawn Iwinski <shawn@iwin.ski> - 0.3.4-1
- Initial package