Skip to content

Commit

Permalink
Merge pull request #18 from laryn/1.x-1.x-issue-17
Browse files Browse the repository at this point in the history
Issue #17: Allow library via XAutoload+bundled OR Composer OR bundled.
  • Loading branch information
jenlampton authored Sep 18, 2024
2 parents 7e0847b + 60782ef commit fcbba98
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 22 deletions.
2 changes: 1 addition & 1 deletion FeedsJSONPathParser.inc
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class FeedsJSONPathParser extends FeedsParser {
* In case the parsed json is not an array.
*/
protected function jsonPath($array, $expression) {
$result = (new JSONPath($array))->find($expression)->data();
$result = (new JSONPath($array))->find($expression)->getData();

// If the returned result is empty, just return an empty array.
if (empty($result)) {
Expand Down
11 changes: 11 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "backdrop/feeds_jsonpath_parser",
"require": {
"softcreatr/jsonpath": "^0.9"
},
"description": "Parse a JSON document using JSONPath.",
"homepage": "https://www.backdropcms.org/project/feeds_jsonpath_parser",
"support": {
"source": "https://github.com/backdrop-contrib/feeds_jsonpath_parser/issues"
}
}
3 changes: 2 additions & 1 deletion feeds_jsonpath_parser.info
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name = Feeds JSONPath Parser
description = Parse a JSON document using JSONPath.
backdrop = 1.x
type = module

dependencies[] = feeds
dependencies[] = xautoload

package = Feeds
2 changes: 1 addition & 1 deletion feeds_jsonpath_parser.install
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function feeds_jsonpath_parser_requirements($phase) {
return $requirements;
}

drupal_load('module', 'feeds_jsonpath_parser');
backdrop_load('module', 'feeds_jsonpath_parser');

$t = get_t();
$requirements['feeds_jsonpath_parser']['title'] = $t('JSONPath library');
Expand Down
42 changes: 23 additions & 19 deletions feeds_jsonpath_parser.module
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,27 @@ define('FEEDS_JSONPATH_PARSER_LIBRARY_VERSION', '0.8.0');
* Implements hook_autoload_info().
*/
function feeds_jsonpath_parser_autoload_info() {
return array(
// Instead of xautoload?
/*
'JSONPath' => 'libraries/JSONPath/src/Flow/JSONPath/JSONPath.php',
'JSONPathException' => 'libraries/JSONPath/src/Flow/JSONPath/JSONPathException.php',
'JSONPathLexer' => 'libraries/JSONPath/src/Flow/JSONPath/JSONPathLexer.php',
'JSONPathToken' => 'libraries/JSONPath/src/Flow/JSONPath/JSONPathToken.php',
'AccessHelper' => 'libraries/JSONPath/src/Flow/JSONPath/AccessHelper.php',
'AbstractFilter' => 'libraries/JSONPath/src/Flow/JSONPath/Filters/AbstractFilter.php',
'IndexesFilter' => 'libraries/JSONPath/src/Flow/JSONPath/Filters/IndexesFilter.php',
'IndexFilter' => 'libraries/JSONPath/src/Flow/JSONPath/Filters/IndexFilter.php',
'QueryMatchFilter' => 'libraries/JSONPath/src/Flow/JSONPath/Filters/QueryMatchFilter.php',
'QueryResultFilter' => 'libraries/JSONPath/src/Flow/JSONPath/Filters/QueryResultFilter.php',
'RecursiveFilter' => 'libraries/JSONPath/src/Flow/JSONPath/Filters/RecursiveFilter.php',
'SliceFilter' => 'libraries/JSONPath/src/Flow/JSONPath/Filters/SliceFilter.php',
*/
$autoloads = array(
'FeedsJSONPathParser' => 'FeedsJSONPathParser.inc',
);
if (!class_exists('Flow\JSONPath\JSONPath')) {
// If it hasn't been loaded with XAutoload or Composer, try to load library.
$autoloads += array(
'JSONPath' => 'libraries/JSONPath/src/JSONPath.php',
'JSONPathException' => 'libraries/JSONPath/src/JSONPathException.php',
'JSONPathLexer' => 'libraries/JSONPath/src/JSONPathLexer.php',
'JSONPathToken' => 'libraries/JSONPath/src/JSONPathToken.php',
'AccessHelper' => 'libraries/JSONPath/src/AccessHelper.php',
'AbstractFilter' => 'libraries/JSONPath/src/Filters/AbstractFilter.php',
'IndexesFilter' => 'libraries/JSONPath/src/Filters/IndexesFilter.php',
'IndexFilter' => 'libraries/JSONPath/src/Filters/IndexFilter.php',
'QueryMatchFilter' => 'libraries/JSONPath/src/Filters/QueryMatchFilter.php',
'QueryResultFilter' => 'libraries/JSONPath/src/Filters/QueryResultFilter.php',
'RecursiveFilter' => 'libraries/JSONPath/src/Filters/RecursiveFilter.php',
'SliceFilter' => 'libraries/JSONPath/src/Filters/SliceFilter.php',
);
}
return $autoloads;
}

/**
Expand Down Expand Up @@ -88,9 +91,10 @@ function feeds_jsonpath_parser_feeds_plugins() {
* Loads the jsonpath library.
*/
function feeds_jsonpath_parser_load_library() {
// Check first to see if the class is loaded some other way like composer.
if (!class_exists('\Flow\JSONPath\JSONPath', TRUE)) {
// If not, then we should have libraries installed.
// Check first to see if the class is loaded some other way like
// XAutoload (bundled version), Composer, or with Backdrop's autoload.
if (!class_exists('\Flow\JSONPath\JSONPath', TRUE) && !class_exists('JSONPath', TRUE)) {
// If not, then we can check if libraries is installed as a last resort.
if (!module_exists('libraries')) {
return FALSE;
}
Expand Down

0 comments on commit fcbba98

Please sign in to comment.