Skip to content

PHP API

Generated by parsing PHP's connector source, so this page cannot list a method that does not exist. Package: siol-data/dfc-connector.

Exports: PSR-4 DataFoodConsortium\Connector\ → src.

Surface

Every public method on the connector, as declared in the source.

Method Operation
registerTypes() —
getContextUrl() The @context URL in use
loadBundledTaxonomies() Load the bundled taxonomies
loadFacets() Replace the Facet vocabulary
loadMeasures() Replace the Measure vocabulary
loadProductTypes() Replace the ProductType vocabulary
loadVocabulary() Replace an arbitrary vocabulary
validate() —
export() Export objects to JSON-LD
import() Import JSON-LD into objects
getFacets() —
getMeasures() —
getProductTypes() —
getFacet() —
getMeasure() —
getProductType() —
getScope() —
getVocabularyTerm() —
getContext() The resolved @context
loadBundledContext() The bundled context, or null

Read-only method accessors: getContext(), getContextUrl(), getFacet(), getFacets(), getMeasure(), getMeasures(), getProductType(), getProductTypes(), getScope(), getVocabularyTerm().

Plus 89 createX factories, one per DFC class, listed in the model reference.

The same operation, three names

Every row below is one capability, present in all three connectors unless marked otherwise. The names differ; the behaviour does not.

Operation TypeScript Ruby PHP
Export objects to JSON-LD export(...objects) export export
Import JSON-LD into objects import(data) import import
The @context URL in use contextUrl context_url getContextUrl()
The resolved @context getContext() context getContext()
The bundled context, or null loadBundledContext() bundled_context loadBundledContext()
Load the bundled taxonomies loadBundledTaxonomies() load_bundled_taxonomies loadBundledTaxonomies()
Replace the Facet vocabulary loadFacets(data) load_facets loadFacets(data)
Replace the Measure vocabulary loadMeasures(data) load_measures loadMeasures(data)
Replace the ProductType vocabulary loadProductTypes(data) load_product_types loadProductTypes(data)
Replace an arbitrary vocabulary loadVocabulary(name, data) load_vocabulary loadVocabulary(name, data)
Fetch the Facet vocabulary loadFacetsFromUrl() load_facets_from_url — not present —
Fetch the Measure vocabulary loadMeasuresFromUrl() load_measures_from_url — not present —
Fetch the ProductType vocabulary loadProductTypesFromUrl() load_product_types_from_url — not present —

Constructing objects

The three connectors do not agree on this, and it is the single most common source of confusion when moving code between them.

Every class has a factory on the connector, taking either form:

c.createOrganization("https://example.org/org/1", { name: "Acme" });
c.createOrganization({ semanticId: "https://example.org/org/1", name: "Acme" });

There are no factories. Construct the model directly:

DfcLinkmlConnector::Models::Organization.new(
  "https://example.org/org/1", name: "Acme"
)

Factories, positional identity first:

$c->createOrganization("https://example.org/org/1", ['name' => 'Acme']);

All three take the identity as the first argument. TypeScript additionally accepts a single object whose semanticId key carries it, which is a migration aid for code written against the original connectors.

There are 89 classes. The generated model reference lists them all, and every one has a factory except in Ruby.

See also