Prismic.io PHP kit  3.0.0
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Attributes | List of all members
Prismic\Api Class Reference

Public Member Functions

 refs ()
 
 getRef ($label)
 
 bookmarks ()
 
 bookmark ($name)
 
 master ()
 
 forms ()
 
 getExperiments ()
 
 previewSession ($token, $linkResolver, $defaultUrl)
 
 oauthInitiateEndpoint ()
 
 oauthTokenEndpoint ()
 
 getData ()
 
 getCache ()
 
 getHttpClient ()
 
 submit ()
 
 query ($q, $options=array())
 
 queryFirst ($q)
 
 getByID ($id)
 
 getByUID ($type, $uid)
 
 getByIDs ($ids)
 

Static Public Member Functions

static get ($action, $accessToken=null, $httpClient=null, CacheInterface $cache=null, $apiCacheTTL=5)
 
static defaultCache ()
 

Public Attributes

const VERSION = "3.0.0"
 
const PREVIEW_COOKIE = "io.prismic.preview"
 
const EXPERIMENTS_COOKIE = "io.prismic.experiment"
 

Protected Attributes

 $accessToken
 
 $data
 

Detailed Description

This class embodies a connection to your prismic.io repository's API. Initialize it with Prismic::Api::get(), and use your Prismic::Api::forms() to make API calls (read more in the kit's README file)

Member Function Documentation

§ bookmark()

Prismic\Api::bookmark (   $name)

From a bookmark name, returns the ID of the attached document. You can then use this ID for anything, for instance to query with a predicate that looks like this [:d = at(document.id, "abcdefghijkl")]. Most starter projects embed a helper to query a document from their ID string, which makes this even easier.

Parameters
string$namethe bookmark name to use
Returns
string|null the ID string for a given bookmark name

§ bookmarks()

Prismic\Api::bookmarks ( )

Returns the list of all bookmarks on the repository. If you're looking for a document from it's bookmark name, you should use the bookmark() function.

Returns
array the array of bookmarks

§ defaultCache()

static Prismic\Api::defaultCache ( )
static

Use the APC cache if APC is activated on the server, otherwise fallback to the noop cache (no cache)

Returns
ApcCache::NoCache

§ forms()

Prismic\Api::forms ( )

Returns all forms of type Prismic::SearchForm that are available for this repository's API. The intended syntax of a call is: api->forms()->everything->query(query)->ref(ref)->submit(). Learn more about those keywords in prismic.io's documentation on our developers' portal.

Returns
all forms

§ get()

static Prismic\Api::get (   $action,
  $accessToken = null,
  $httpClient = null,
CacheInterface  $cache = null,
  $apiCacheTTL = 5 
)
static

This is the endpoint to build your API, and is a static method. If your API is set to "public" or "open", you can instantiate your Api object just like this: Api::get('http://idofyourrepository.prismic.io/api')

Parameters
string$actionthe URL of your repository API's endpoint
string$accessTokena permanent access token to use to access your content, for instance if your repository API is set to private
Client$httpClientCustom Guzzle http client
CacheInterface$cacheCache implementation
int$apiCacheTTLmax time to keep the API object in cache (in seconds)
Exceptions
RuntimeException
Returns
Api the Api object, usable to perform queries

§ getByID()

Prismic\Api::getByID (   $id)

Search a document by its id

Parameters
string$idthe requested id
Returns
Prismic::Document the resulting document (null if no match)

§ getByIDs()

Prismic\Api::getByIDs (   $ids)

Return a set of document from their ids

Parameters
array$idsarray of strings, the requested ids
Returns
Prismic::Response the response, including documents and pagination information

§ getByUID()

Prismic\Api::getByUID (   $type,
  $uid 
)

Search a document by its uid

Parameters
string$typethe custom type of the requested document
string$uidthe requested uid
Returns
Prismic::Document the resulting document (null if no match)

§ getCache()

Prismic\Api::getCache ( )

Accessing the cache object specifying how to store the cache

Returns
CacheInterface the cache object itself

§ getData()

Prismic\Api::getData ( )

Accessing raw data returned by the /api endpoint

Returns
ApiData the raw data

§ getExperiments()

Prismic\Api::getExperiments ( )
Returns
Experiments

§ getHttpClient()

Prismic\Api::getHttpClient ( )

Accessing the underlying Guzzle HTTP client

Returns
HttpAdapterInterface

§ getRef()

Prismic\Api::getRef (   $label)
Parameters
string$labelthe label of the requested ref
Returns
Ref a reference or null

§ master()

Prismic\Api::master ( )

Returns the master ref repository: the ref which is to be used to query content that is live right now.

Returns
string the master ref

§ oauthInitiateEndpoint()

Prismic\Api::oauthInitiateEndpoint ( )

Returning the URL of the endpoint to initiate OAuth authentication.

Returns
string the URL of the endpoint

§ oauthTokenEndpoint()

Prismic\Api::oauthTokenEndpoint ( )

Returning the URL of the endpoint to use OAuth authentication.

Returns
string the URL of the endpoint

§ previewSession()

Prismic\Api::previewSession (   $token,
  $linkResolver,
  $defaultUrl 
)

Return the URL to display a given preview

Parameters
string$tokenas received from Prismic server to identify the content to preview
\Prismic\LinkResolver$linkResolverthe link resolver to build URL for your site
string$defaultUrlthe URL to default to return if the preview doesn't correspond to a document (usually the home page of your site)
Returns
string the URL you should redirect the user to preview the requested change

§ query()

Prismic\Api::query (   $q,
  $options = array() 
)

Shortcut to query on the default reference. Use the reference from previews or experiment cookie, fallback to the master reference otherwise.

Parameters
string | array | \Prismic\Predicate$qthe query, as a string, predicate or array of predicates
array$optionsquery options: pageSize, orderings, etc.
Returns
Prismic::Response the response, including documents and pagination information

§ queryFirst()

Prismic\Api::queryFirst (   $q)

Return the first document matching the query Use the reference from previews or experiment cookie, fallback to the master reference otherwise.

Parameters
string | array | \Prismic\Predicate$qthe query, as a string, predicate or array of predicates
Returns
Prismic::Document the resulting document, or null

§ refs()

Prismic\Api::refs ( )

Returns all of the repository's references (queryable points in time)

Returns
array the array of references, with their IDs, labels, ...

§ submit()

Prismic\Api::submit ( )

Submit several requests in parallel

Returns
array

Member Data Documentation

§ $accessToken

Prismic\Api::$accessToken
protected

string the API's access token to be used with each API call

§ $data

Prismic\Api::$data
protected

ApiData the raw data of the /api document (prefer to use this class's instance methods)

§ EXPERIMENTS_COOKIE

const Prismic\Api::EXPERIMENTS_COOKIE = "io.prismic.experiment"

Name of the cookie that will be used to remember the experiment reference

§ PREVIEW_COOKIE

const Prismic\Api::PREVIEW_COOKIE = "io.prismic.preview"

Name of the cookie that will be used to remember the preview reference

§ VERSION

const Prismic\Api::VERSION = "3.0.0"

Kit version number


The documentation for this class was generated from the following file: