@ 2014-03-18T06:13:57Z <?php
define("UV_VERSION", "1.2.0");
define("UV_LIB_VERSION", "1.0.1");
class UVArray extends UVObject {
public function add($object) {
$count = count(get_object_vars($this));
$this->$count = new UVObject($object);
}
public function set($key, $value) {
if (is_numeric($key)) {
$this->$key = $value;
}
}
}
class UVObject {
public function __construct($attributes=array()) {
if (!empty($attributes)) {
foreach ($attributes as $key => $value) {
$this->set($key, $value);
}
}
$this->convertNestedObjects();
}
public function set($key, $value) {
$this->$key = $value;
}
public function get($index) {
return $this->$index;
}
public function toArray() {
$obj = array();
$vars = get_object_vars($this);
foreach ($vars as $key => $value) {
if (is_object($value) && method_exists($value, "toArray")) {
$obj[$key] = $value->toArray();
} else {
$obj[$key] = $value;
}
}
if (count($obj) == 0 && !($this instanceof UVArray)) {
return new stdClass();
}
return $obj;
}
public function isEmpty() {
$vars = get_object_vars($this);
if (empty($vars)) {
return true;
} else if (count($vars) === 1 && isset($vars["line_items"]) && count(get_object_vars($vars["line_items"])) == 0) {
return true;
} else if (count($vars) === 1 && isset($vars["items"]) && count(get_object_vars($vars["items"])) == 0) {
return true;
} else if (count($vars) === 2 && isset($vars["linked_products"]) && count(get_object_vars($vars["linked_products"])) == 0 && isset($vars["reviews"]) && count(get_object_vars($vars["reviews"])) == 0) {
return true;
} else {
return false;
}
}
private function convertNestedObjects() {
$vars = get_object_vars($this);
foreach($vars as $key => $value) {
if (is_array($value) && $this->isAssociative($value)) {
$this->$key = new UVObject($value);
} else if (is_array($value)) {
$this->$key = new UVArray($value);
}
}
}
private function isAssociative($arr) {
return array_keys($arr) !== range(0, count($arr) - 1);
}
}
class BuildUV extends UVObject {
public function __construct() {
$this->set("page", new UVObject());
$this->set("user", new UVObject());
$this->set("product", new UVObject());
$this->get("product")->set("linked_products", new UVArray());
$this->get("product")->set("reviews", new UVArray());
$this->set("listing", new UVObject());
$this->get("listing")->set("items", new UVArray());
$this->set("transaction", new UVObject());
$this->get("transaction")->set("line_items", new UVArray());
$this->set("basket", new UVObject());
$this->get("basket")->set("line_items", new UVArray());
$this->set("events", new UVArray());
$this->set("recommendation", new UVArray());
}
public function toJSON() {
$uvOutput = array();
$uvOutput["page"] = $this->page->toArray();
$uvOutput["user"] = $this->user->toArray();
$uvOutput["events"] = $this->events->toArray();
$uvOutput["version"] = UV_VERSION;
$uvOutput["php_lib_version"] = UV_LIB_VERSION;
$vars = get_object_vars($this);
foreach ($vars as $key => $value) {
if (isset($uvOutput[$key])) {
continue;
}
if (method_exists($value, "isEmpty") && !$value->isEmpty()) {
if (method_exists($value, "toArray")) {
$uvOutput[$key] = $value->toArray();
} else {
$uvOutput[$key] = $value;
}
}
}
return json_encode($uvOutput);
}
public function toHTML() {
return "\n
<!-- Qubit Universal Variable data layer v" + UV_VERSION + " - PHP Lib v" + UV_LIB_VERSION + " -->
<script>
window.universal_variable = " . $this->toJSON() . ";
</script>
<!-- End UV -->
\n";
}
}
?>
<?php
$uv = new BuildUV();
$uv->get("page")->set("category", "Home");
$uv->get("page")->set("subcategory", "Mens - Shoes");
print $uv->toJSON();
=> {"page":{"category":"Home","subcategory":"Mens - Shoes"},"user":{},"events":[]}
?>
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 5.4.26 0.013 0.062 12.43 5.4.25 0.006 0.044 12.43 5.4.24 0.009 0.045 12.43 5.4.23 0.008 0.042 12.42 5.4.22 0.008 0.043 12.42 5.4.21 0.007 0.040 12.42 5.4.20 0.007 0.043 12.42 5.4.19 0.008 0.038 12.42 5.4.18 0.007 0.035 12.42 5.4.17 0.008 0.040 12.43 5.4.16 0.006 0.038 12.42 5.4.15 0.005 0.039 12.42 5.4.14 0.008 0.038 12.11 5.4.13 0.008 0.037 12.09 5.4.12 0.008 0.034 12.05 5.4.11 0.006 0.036 12.05 5.4.10 0.007 0.037 12.05 5.4.9 0.007 0.037 12.05 5.4.8 0.007 0.038 12.05 5.4.7 0.007 0.038 12.04 5.4.6 0.007 0.039 12.05 5.4.5 0.006 0.039 12.05 5.4.4 0.005 0.041 12.04 5.4.3 0.004 0.039 12.03 5.4.2 0.006 0.037 12.03 5.4.1 0.008 0.036 12.03 5.4.0 0.005 0.038 11.52 5.3.28 0.005 0.039 12.72 5.3.27 0.007 0.041 12.74 5.3.26 0.008 0.041 12.74 5.3.25 0.006 0.043 12.74 5.3.24 0.008 0.040 12.74 5.3.23 0.009 0.041 12.73 5.3.22 0.008 0.046 12.69 5.3.21 0.009 0.047 12.69 5.3.20 0.009 0.050 12.69 5.3.19 0.007 0.050 12.70 5.3.18 0.008 0.046 12.69 5.3.17 0.009 0.049 12.69 5.3.16 0.011 0.052 12.69 5.3.15 0.010 0.048 12.69 5.3.14 0.011 0.048 12.68 5.3.13 0.011 0.055 12.68 5.3.12 0.007 0.046 12.68 5.3.11 0.007 0.043 12.68 5.3.10 0.006 0.040 12.16 5.3.9 0.006 0.038 12.14 5.3.8 0.005 0.038 12.13 5.3.7 0.007 0.042 12.13 5.3.6 0.007 0.051 12.11 5.3.5 0.007 0.043 12.06 5.3.4 0.009 0.041 12.06 5.3.3 0.007 0.047 12.03 5.3.2 0.006 0.044 11.81 5.3.1 0.007 0.048 11.77 5.3.0 0.006 0.039 11.76 5.2.17 0.006 0.030 9.27 5.2.16 0.005 0.035 9.27 5.2.15 0.004 0.038 9.26 5.2.14 0.003 0.039 9.26 5.2.13 0.004 0.031 9.22 5.2.12 0.003 0.030 9.22 5.2.11 0.007 0.038 9.23 5.2.10 0.005 0.031 9.23 5.2.9 0.005 0.030 9.22 5.2.8 0.005 0.035 9.22 5.2.7 0.006 0.031 9.21 5.2.6 0.007 0.034 9.17 5.2.5 0.006 0.037 9.15 5.2.4 0.005 0.033 9.12 5.2.3 0.006 0.032 9.09 5.2.2 0.007 0.037 9.09 5.2.1 0.005 0.032 8.99 5.2.0 0.006 0.033 8.85 5.1.6 0.004 0.027 8.15 5.1.5 0.006 0.026 8.15 5.1.4 0.003 0.027 8.13 5.1.3 0.004 0.029 8.48 5.1.2 0.005 0.032 8.50 5.1.1 0.005 0.030 8.22 5.1.0 0.004 0.028 8.22 5.0.5 0.004 0.021 6.71 5.0.4 0.003 0.022 6.57 5.0.3 0.004 0.031 6.39 5.0.2 0.004 0.022 6.36 5.0.1 0.003 0.021 6.33 5.0.0 0.004 0.034 6.32 4.4.9 0.003 0.016 4.78 4.4.8 0.004 0.015 4.75 4.4.7 0.003 0.016 4.76 4.4.6 0.003 0.016 4.76 4.4.5 0.005 0.016 4.77 4.4.4 0.004 0.027 4.71 4.4.3 0.004 0.016 4.76 4.4.2 0.004 0.016 4.84 4.4.1 0.003 0.018 4.85 4.4.0 0.004 0.025 4.76 4.3.11 0.005 0.019 4.67 4.3.10 0.002 0.017 4.67 4.3.9 0.002 0.018 4.63 4.3.8 0.005 0.025 4.58 4.3.7 0.003 0.015 4.63 4.3.6 0.002 0.017 4.63 4.3.5 0.002 0.017 4.63 4.3.4 0.002 0.030 4.53 4.3.3 0.002 0.018 3.37 4.3.2 0.002 0.018 3.36 4.3.1 0.001 0.018 3.33 4.3.0 0.000 0.023 7.27
preferences:dark mode live preview
142.78 ms | 1394 KiB | 7 Q