/** * Test adding a new prefix. */ function test_prefixes_add_and_delete() { // Create a random prefix and an example namespace. $prefix = uniqid('prefix'); $namespace = 'http://example.org/ns/'; // Check that the prefix doesn't exist yet. $this->assertFalse(wl_prefixes_get($prefix)); // Add the prefix. wl_prefixes_add($prefix, $namespace); $path = uniqid('this/is/a/test/'); // Compact a URL. $url_to_compact = $namespace . $path; $url_compacted = wl_prefixes_compact($url_to_compact); $this->assertEquals($prefix . ':' . $path, $url_compacted); // Expand a URL. $url_to_expand = $url_compacted; $url_expanded = wl_prefixes_expand($url_to_expand); $this->assertEquals($namespace . $path, $url_expanded); // Check the namespace. $this->assertEquals($namespace, wl_prefixes_get($prefix)); // Now delete the prefix. wl_prefixes_delete($prefix); // Check that the prefix doesn't exist. $this->assertFalse(wl_prefixes_get($prefix)); }
/** * Get a property value using the specified name, language and graph. The property name can be a concatenated tree of * keys, e.g. schema:location>schema:latitude. * * @param object $graph The graph. * @param string $name The property tree. * @param null|string $language If provided, a two-characters language code. * @param string $suffix The suffix for remote requests (empty if not provided). * @return null|string The value or null if not found. */ function wl_jsonld_get_property($graph, $name, $language = null, $suffix = '', $index = 0) { $keys = explode('>', html_entity_decode($name)); $value = null; foreach ($keys as $key) { if (null !== $value) { $graph = wl_jsonld_load_remote($value . $suffix); } $key_exp = wl_prefixes_expand($key); $value = wl_jsonld_get_property_value($graph, $key_exp, $language, $index); } return $value; }