Basic Usage Using PHP and Brew
JamesAllgood opened this issue · comments
Hey!
This is going to be a really basic question, I downloaded the library last week using brew. But having some issues getting it working, never used composer before and when its trying to use the import file command its not working?
I've used the example but it falls over on trying to use the items::from file command.
The code looks like this but unsure how to fix it?
use JsonMachine\Items;
use JsonMachine\JsonDecoder\PassThruDecoder;
$users = Items::fromFile
Your snippet doesn't seem complete. Also, usage with PassThruDecoder is described in Readme. Did you check it out?
Here’s the code and the layout of the web repository, the index file is what hosts the code pasted below.
<?php
//https://github.com/halaxa/json-machine
require __DIR__ . '/vendor/autoload.php';
// $loader = require __DIR__ . '/vendor/autoload.php';
// print_r($loader);
$fruits = Items::fromFile('fruitsArray.json', ['pointer' => '/results/-/color']);
foreach ($fruits as $key => $value) {
// 1st iteration:
$key == 'color';
$value == 'red';
$fruits->getMatchedJsonPointer() == '/results/-/color';
$fruits->getCurrentJsonPointer() == '/results/0/color';
// 2nd iteration:
$key == 'color';
$value == 'yellow';
$fruits->getMatchedJsonPointer() == '/results/-/color';
$fruits->getCurrentJsonPointer() == '/results/1/color';
}
What error specifically do you get? Can you also provide the contents of fruitsArray.json?
Please provide the requested info in order to keep this issue open.
What error specifically do you get? Can you also provide the contents of fruitsArray.json?
This is the location of the code.
http://test.themeparkguide.co.uk
http://test.themeparkguide.co.uk/fruitsArray.json
index.php code is...
![Screenshot 2023-06-02 at 20 37 00](https://user-images.githubusercontent.com/10291664/242976447-ef0cb289-dc85-4958-bdcb-acbfb59235ea.png)