Example #1
0
 public function __construct($consumerKey = NULL, $consumerSecret = NULL, $serializer = NULL, $applicationName = NULL, $use_compression = FALSE, $username = NULL, $password = NULL, $session_file = '/tmp/session.dat')
 {
     $this->use_compression = $use_compression;
     if (empty($applicationName)) {
         $this->applicationName = $this->wrapperName . '/' . WRAPPER_VERSION;
     } else {
         $this->applicationName = $applicationName . '/' . $this->wrapperName . '/' . WRAPPER_VERSION;
     }
     if (empty($serializer)) {
         $serializer = new JsonSerializer();
     }
     $this->serializer = $serializer;
     $this->format = $serializer->getType();
     $this->applicationName = $this->applicationName . '/' . strtoupper($this->format);
     if (empty($consumerKey) && empty($consumerSecret)) {
         list($consumerKey, $consumerSecret) = $this->obtainKeys($username, $password, $session_file);
         if (empty($consumerKey) || empty($consumerSecret)) {
             throw new \Exception('Cannot obtain Semantria keys. Wrong username or password.');
         }
     }
     if (empty($consumerKey)) {
         throw new \Exception('Consumer KEY can\'t be empty.');
     }
     if (empty($consumerSecret)) {
         throw new \Exception('Consumer SECRET can\'t be empty.');
     }
     $this->consumerKey = $consumerKey;
     $this->consumerSecret = $consumerSecret;
     $this->request = new AuthRequest($this->consumerKey, $this->consumerSecret, $this->applicationName, $this->use_compression);
 }
 function testSerialize()
 {
     $ser = new JsonSerializer();
     $jsonString = $ser->serialize($this->model);
     $memModel = new MemModel();
     $memModel->loadFromString($jsonString, 'json');
     $this->assertTrue($this->model->equals($memModel));
 }
 public function __construct($consumerKey, $consumerSecret, $serializer = NULL, $applicationName = NULL, $use_compression = FALSE)
 {
     if (empty($consumerKey)) {
         throw new \Exception('Consumer KEY can\'t be empty.');
     }
     if (empty($consumerSecret)) {
         throw new \Exception('Consumer SECRET can\'t be empty.');
     }
     $this->consumerKey = $consumerKey;
     $this->consumerSecret = $consumerSecret;
     $this->use_compression = $use_compression;
     if (empty($applicationName)) {
         $this->applicationName = $this->wrapperName . '/' . WRAPPER_VERSION;
     } else {
         $this->applicationName = $applicationName . '/' . $this->wrapperName . '/' . WRAPPER_VERSION;
     }
     if (empty($serializer)) {
         $serializer = new JsonSerializer();
     }
     $this->serializer = $serializer;
     $this->format = $serializer->getType();
     $this->applicationName = $this->applicationName . '/' . strtoupper($this->format);
     $this->request = new AuthRequest($this->consumerKey, $this->consumerSecret, $this->applicationName, $this->use_compression);
 }
Example #4
0
require_once 'lib/generator/' . $kwargs['store'] . '/Serializer.php';
require_once 'lib/generator/JsonSerializer.php';
require_once 'lib/generator/XmlSerializer.php';
if ($clean) {
    Freezer::clean('cache', 'nodes');
    Freezer::clean('cache', 'resources');
    if ($kwargs['outfile']) {
        if (isset($kwargs['serialize']['json'])) {
            JsonSerializer::clean('cache', 'json', $kwargs['outfile']);
        }
        if (isset($kwargs['serialize']['xml'])) {
            XmlSerializer::clean('cache', 'xml', $kwargs['outfile']);
        }
    } else {
        if (isset($kwargs['serialize']['json'])) {
            JsonSerializer::clean('cache', 'json');
        }
        if (isset($kwargs['serialize']['xml'])) {
            XmlSerializer::clean('cache', 'xml');
        }
    }
}
$files = dojo_get_files($args);
$nodes = new Freezer('cache', 'nodes');
$resources = new Freezer('cache', 'resources');
print "=== PARSING FILES ===\n";
flush();
foreach ($files as $set) {
    list($namespace, $file) = $set;
    if (!$namespaces[$namespace]) {
        $namespaces[$namespace] = true;
Example #5
0
 /**
  * @test
  * @dataProvider deserializeProvider
  * @param mixed $serialized
  * @param string $type
  * @param mixed $expected
  */
 public function deserializeReconstructsValue($serialized, string $type, $expected)
 {
     $serializer = new JsonSerializer();
     $actual = $serializer->deserialize($serialized, $type);
     self::assertEquals($expected, $actual);
 }
 /**
  * @test
  */
 public function serializationTest()
 {
     $input = NULL;
     $this->assertSame($input, $this->fixture->unserialize($this->fixture->serialize($input)));
     $input = 'A string';
     $this->assertSame($input, $this->fixture->unserialize($this->fixture->serialize($input)));
     $input = 'This is some unicode äü ♞ <= do you see the horse?';
     $this->assertSame($input, $this->fixture->unserialize($this->fixture->serialize($input)));
     $input = 0.999009;
     $this->assertSame($input, $this->fixture->unserialize($this->fixture->serialize($input)));
     $input = -0.999009;
     $this->assertSame($input, $this->fixture->unserialize($this->fixture->serialize($input)));
     $input = 5;
     $this->assertSame($input, $this->fixture->unserialize($this->fixture->serialize($input)));
     $input = PHP_INT_MAX;
     $this->assertSame($input, $this->fixture->unserialize($this->fixture->serialize($input)));
     $input = 0;
     $this->assertSame($input, $this->fixture->unserialize($this->fixture->serialize($input)));
     $input = -100;
     $this->assertSame($input, $this->fixture->unserialize($this->fixture->serialize($input)));
     $input = TRUE;
     $this->assertSame($input, $this->fixture->unserialize($this->fixture->serialize($input)));
     $input = FALSE;
     $this->assertSame($input, $this->fixture->unserialize($this->fixture->serialize($input)));
     $input = array();
     $this->assertSame($input, $this->fixture->unserialize($this->fixture->serialize($input)));
     $input = new \stdClass();
     $input->firstName = 'Daniel';
     $input->lastName = 'Corn';
     $this->assertEquals(get_object_vars($input), $this->fixture->unserialize($this->fixture->serialize($input)));
     $input = array(1 => 'A', 2 => 'B', 3 => 'C');
     $this->assertEquals($input, $this->fixture->unserialize($this->fixture->serialize($input)));
     $input = range('A', 9);
     $input = array_rand($input, count($input));
     $this->assertEquals($input, $this->fixture->unserialize($this->fixture->serialize($input)));
 }
Example #7
0
                    break;
                }
            }
            if (!$has_children) {
                unset($roots[$id]);
            }
        }
    }
}
print "=== SERIALIZING OBJECTS ===\n";
// Aggregate and save
if ($outfile) {
    $json = new JsonSerializer('cache', 'json', $outfile);
    $xml = new XmlSerializer('cache', 'xml', $outfile);
} else {
    $json = new JsonSerializer('cache', 'json');
    $xml = new XmlSerializer('cache', 'xml');
}
foreach ($roots as $id => $root) {
    if (!$id) {
        // Minor bug
        continue;
    }
    $node = $nodes->open($id, null);
    $parts = explode('.', $id);
    foreach ($ids as $child_id) {
        $child_parts = explode('.', $child_id);
        if (count($child_parts) == count($parts) + 1 && strpos($child_id, "{$id}.") === 0 && !array_key_exists($child_id, $roots)) {
            $node['#children'][array_pop($child_parts)] = $nodes->open($child_id, null);
        }
    }
$endTime = $endDate . ' 23:59:59';
$lastEvenYear = date('Y') % 2 === 0 ? date('Y') : date('Y') - 1;
$lastEvenYearTimestamp = mktime(0, 0, 0, 1, 1, $lastEvenYear);
$startHoursElapsedSinceLastEvenYear = floor((strtotime($startTime) - $lastEvenYearTimestamp) / 3600);
$endHoursElapsedSinceLastEvenYear = floor((strtotime($endTime) - $lastEvenYearTimestamp) / 3600);
$dbNames = DbUtil::getDbNames($appId);
$response = array();
try {
    $sql = 'SELECT country.country_id as id, country.code as country_code, country.name AS country_label, city.name AS city_label, SUM(city_summary.page_views) AS pageViews, ROUND(SUM(city_summary.avg_load_time*city_summary.page_views)/SUM(city_summary.page_views), 2) AS loadTime
        FROM ' . $dbNames['summary'] . '.city_summary, newmonk_common.country, newmonk_common.city
        WHERE hours_elapsed_since_last_even_year >= :start_hours_elapsed_since_last_even_year
        AND hours_elapsed_since_last_even_year <= :end_hours_elapsed_since_last_even_year
        AND page_id = :page_id
        AND country.country_id = :country_id
        AND city_summary.city_id = city.city_id
        AND city.country_id = country.country_id
        GROUP BY city.city_id';
    $st = $db->prepare($sql);
    $st->bindValue(':start_hours_elapsed_since_last_even_year', $startHoursElapsedSinceLastEvenYear, PDO::PARAM_INT);
    $st->bindValue(':end_hours_elapsed_since_last_even_year', $endHoursElapsedSinceLastEvenYear, PDO::PARAM_INT);
    $st->bindValue(':page_id', $urlId, PDO::PARAM_INT);
    $st->bindValue(':country_id', $countryId, PDO::PARAM_INT);
    $st->execute();
    $response = $st->fetchAll(PDO::FETCH_ASSOC);
    $st->closeCursor();
} catch (Exception $e) {
    die('Error: ' . $e->getMessage() . "<br />\n");
}
$jsonSerializer = new JsonSerializer();
header("Content-Type: text/javascript");
echo 'var ' . $_REQUEST['responseVarName'] . ' = ' . $jsonSerializer->serialize($response);