예제 #1
0
 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();
 }
예제 #2
0
파일: Admin.php 프로젝트: jawngee/Stem
 /**
  * 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();
 }
예제 #3
0
 /**
  * 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"];
 }
예제 #4
0
 /**
  * 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());
 }
예제 #5
0
 /**
  * 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;
 }
예제 #6
0
 * 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)
    {
예제 #7
0
파일: test.php 프로젝트: ksneo/JSONParser
}

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