/** * Free a Statement's resources. * * @return void * @access public */ public function __destruct() { if ($this->statement) { librdf_free_statement($this->statement); } }
/** * Find a statement in the model. * * A NULL argument for any of source, predicate or target is treated as * a wildcard. If a context is given, only statements from that context * will be returned. The result is an object that be used in foreach * iteration. The returned iterator cannot be rewound. * * The search arguments can be either a (source, predicate target) triple * of LibRDF_Node objects or a LibRDF_Statement object. Valid argument * lists are (source, predicate, target, [context]) or * (statement, [context]). * * For more complex queries, see {@link LibRDF_Query}. * * @param mixed $statement The statement to match or a source node * @param LibRDF_Node $predicate The predicate to match * @param LibRDF_Node $target The target to match * @param LibRDF_URINode $context The context in which to search * @return LibRDF_StreamIterator An iterator over the matched statements * @access public */ public function findStatements() { $num_args = func_num_args(); if ($num_args == 1 or $num_args == 2) { $statement = func_get_arg(0); if (!$statement instanceof LibRDF_Statement) { throw new LibRDF_Error("First argument must be a LibRDF_Statement"); } if ($num_args == 2) { $context = func_get_arg(1); if (!$context instanceof LibRDF_URINode) { throw new LibRDF_Error("Context must be LibRDF_URINode"); } } else { $context = NULL; } $statement = $statement->getStatement(); } elseif ($num_args == 3 or $num_args == 4) { $source = func_get_arg(0); $predicate = func_get_arg(1); $target = func_get_arg(2); if ($source !== NULL) { if (!$source instanceof LibRDF_Node) { throw new LibRDF_Error("Argument 1 must be of type LibRDF_Node"); } else { $source = librdf_new_node_from_node($source->getNode()); } } if ($predicate !== NULL) { if (!$predicate instanceof LibRDF_Node) { throw new LibRDF_Error("Argument 2 must be of type LibRDF_Node"); } else { $predicate = librdf_new_node_from_node($predicate->getNode()); } } if ($target !== NULL) { if (!$target instanceof LibRDF_Node) { throw new LibRDF_Error("Argument 3 must be of type LibRDF_Node"); } else { $target = librdf_new_node_from_node($target->getNode()); } } if ($num_args == 4) { $context = func_get_arg(3); if (!$context instanceof LibRDF_URINode) { throw new LibRDF_Error("Context must be LibRDF_URINode"); } } else { $context = NULL; } $statement = librdf_new_statement_from_nodes(librdf_php_get_world(), $source, $predicate, $target); } else { throw new LibRDF_Error("findStatements takes 2-4 arguments"); } if ($context !== NULL) { $stream_resource = librdf_model_find_statements_in_context($this->model, $statement, $context->getNode()); } else { $stream_resource = librdf_model_find_statements($this->model, $statement); } if ($num_args > 2) { librdf_free_statement($statement); } if (!$stream_resource) { throw new LibRDF_Error("Unable to create new statement iterator"); } return new LibRDF_StreamIterator($stream_resource, $this); }