public function doInsert() { global $baseDir; $movies_array = JSONParser::parseJSON($baseDir . '\\mysite\\inTheatre.json'); //9 items for ($i = 0; $i < count($movies_array); $i++) { $movie = Movie::create(); $movie = $movies_array[$i]; $movie->MovieListPageID = $this->ID; $movie->write(); } return $this->redirectBack(); }
/** * Constructor * * @param $context Context The current context */ public function __construct(Context $context) { $this->context = $context; if (file_exists($context->rootPath . '/config/admin.php')) { $this->config = (include $context->rootPath . '/config/admin.php'); } else { if (file_exists($context->rootPath . '/config/admin.json')) { $this->config = JSONParser::parse(file_get_contents($context->rootPath . '/config/admin.json')); } else { return; } } $this->setup(); }
/** * Gets the default and possible locales of the shop. */ private static function load() { // if request method is blocked if (!RESTClient::setRequestMethod("GET")) { return; } $content = JSONParser::parseJSON(RESTClient::send(self::RESTPATH)); // if respond is empty if (InputValidator::isEmpty($content)) { return; } // if there is no default AND items element if (!array_key_exists("default", $content) || !array_key_exists("items", $content)) { Logger::error("Respond for " . self::RESTPATH . " can not be interpreted."); return; } // reset values self::resetValues(); // save the default localization self::$DEFAULT = $content["default"]; // parse the possible localizations self::$ITEMS = $content["items"]; }
/** * Change writer type to convert to another format * * @param string $filetype Set the filetype of the file which will be written (XML/CSV/TSV/HTML/JSON) */ public function convertTo($filetype) { $this->constructWriter($filetype); $this->writer->setData($this->parser->getField()); }
/** * Faz o parsing de um array JSON para um objeto tipado do sistema */ private static function parseObjectArray($arr, $dest, $propName, $comment) { $arrayOf = JSONParser::GetAttribute($comment, JSONParser::arrayOf); if ($arrayOf === false) { $dest->{$propName} = $arr; } else { $dest->{$propName} = array(); foreach ($arr as $item) { $newObj = JSONParser::parseObject($item, new $arrayOf()); if (isset($newObj)) { array_push($dest->{$propName}, $newObj); } } } return $dest; }
* Command line testing */ if (isset($argv[1]) && $argv[1]) { $jsonString = $argv[1]; $_SERVER['REMOTE_ADDR'] = "127.0.0.1"; Config::$debug = true; } elseif ($_SERVER['REQUEST_METHOD'] == 'POST') { $jsonString = trim(file_get_contents('php://input')); /** * JSON Logger */ $jsonLogger = new JSONLogger(); $jsonLogger->setJson($jsonString); $jsonLogger->setIpAddress($_SERVER['REMOTE_ADDR']); $jsonLogger->insert(); $jsonParser = new JSONParser(); try { $jsonParser->parse($jsonString); } catch (Exception $e) { die("Exception: " . $e->getMessage()); } } else { function send401() { $realm = "Frogmod Database"; header('WWW-Authenticate: Basic realm="' . $realm . '"'); header('HTTP/1.1 401 Unauthorized'); die; } function verify_credentials($user, $password) {
} function arrayEnd($value, $property) { printf("]\n"); } function property($value, $property) { printf("Property: %s\n", $value); } function scalar($value, $property) { printf("Value: %s\n", $value); } // initialise the parser object $parser = new JSONParser(); // sets the callbacks $parser->setArrayHandlers('arrayStart', 'arrayEnd'); $parser->setObjectHandlers('objStart', 'objEnd'); $parser->setPropertyHandler('property'); $parser->setScalarHandler('scalar'); echo "Parsing top level object document...\n"; // parse the document $parser->parseDocument(__DIR__ . '/data.json'); $parser->initialise(); echo "Parsing top level array document...\n"; // parse the top level array