PHP Class Mercator\Mapping

显示文件 Open project: humanmade/mercator Class Usage Examples

Protected Properties

Property Type Description
$data array Mapping data
$site integer Site ID

Public Methods

Method Description
__clone ( ) Clone magic method when clone( self ) is called.
create ( string $site, string $domain, boolean $active = false ) : Mapping | WP_Error Create a new domain mapping
delete ( ) : boolean | WP_Erro\WP_Error Delete the mapping
get ( integer | Mapping $mapping ) : Mapping | WP_Erro\WP_Error | null Get mapping by mapping ID
get_by_domain ( string | array $domains ) : Mapping | WP_Erro\WP_Error | null Get mapping by domain(s)
get_by_site ( integer | stdClass $site ) : Mapping | WP_Erro\WP_Error | null Get mapping by site ID
get_domain ( ) : string Get the domain from the mapping
get_id ( ) : integer Get mapping ID
get_site ( ) : stdClass | boolean Get site object
get_site_id ( ) : integer Get site ID
is_active ( ) : boolean Is the mapping active?
make_primary ( ) : boolean | WP_Error Make this mapping the primary domain, eg. set the homeurl for the site
set_active ( boolean $active ) : boolean | WP_Erro\WP_Error Set whether the mapping is active
set_domain ( string $domain ) : boolean | WP_Erro\WP_Error Set the domain for the mapping
update ( array | stdClass $data ) : boolean | WP_Erro\WP_Error Update the mapping

Protected Methods

Method Description
__construct ( array $data ) Constructor
to_instance ( stdClass $data ) : Mapping Convert data to Mapping instance
to_instances ( stdClass[] $data ) : Mapping[] Convert list of data to Mapping instances

Method Details

__clone() public method

As the internal data is stored in an object, we have to make a copy when this object is cloned.
public __clone ( )

__construct() protected method

Constructor
protected __construct ( array $data )
$data array Mapping data

create() public static method

Create a new domain mapping
public static create ( string $site, string $domain, boolean $active = false ) : Mapping | WP_Error
$site string Site ID, or site object from {@see \get_blog_details}
$domain string
$active boolean
return Mapping | WP_Error

delete() public method

Delete the mapping
public delete ( ) : boolean | WP_Erro\WP_Error
return boolean | WP_Erro\WP_Error True if we updated, false if we didn't need to, or WP_Error if an error occurred

get() public static method

Get mapping by mapping ID
public static get ( integer | Mapping $mapping ) : Mapping | WP_Erro\WP_Error | null
$mapping integer | Mapping Mapping ID or instance
return Mapping | WP_Erro\WP_Error | null Mapping on success, WP_Error if error occurred, or null if no mapping found

get_by_domain() public static method

Get mapping by domain(s)
public static get_by_domain ( string | array $domains ) : Mapping | WP_Erro\WP_Error | null
$domains string | array Domain(s) to match against
return Mapping | WP_Erro\WP_Error | null Mapping on success, WP_Error if error occurred, or null if no mapping found

get_by_site() public static method

Get mapping by site ID
public static get_by_site ( integer | stdClass $site ) : Mapping | WP_Erro\WP_Error | null
$site integer | stdClass Site ID, or site object from {@see \get_blog_details}
return Mapping | WP_Erro\WP_Error | null Mapping on success, WP_Error if error occurred, or null if no mapping found

get_domain() public method

Get the domain from the mapping
public get_domain ( ) : string
return string

get_id() public method

Get mapping ID
public get_id ( ) : integer
return integer Mapping ID

get_site() public method

Get site object
public get_site ( ) : stdClass | boolean
return stdClass | boolean {@see \get_blog_details}

get_site_id() public method

Get site ID
public get_site_id ( ) : integer
return integer Site ID

is_active() public method

Is the mapping active?
public is_active ( ) : boolean
return boolean

make_primary() public method

Make this mapping the primary domain, eg. set the homeurl for the site
public make_primary ( ) : boolean | WP_Error
return boolean | WP_Error True if we created the old mapping or WP_Error if an error occurred

set_active() public method

Set whether the mapping is active
public set_active ( boolean $active ) : boolean | WP_Erro\WP_Error
$active boolean Should the mapping be active? (True for active, false for inactive)
return boolean | WP_Erro\WP_Error True if we updated, false if we didn't need to, or WP_Error if an error occurred

set_domain() public method

Set the domain for the mapping
public set_domain ( string $domain ) : boolean | WP_Erro\WP_Error
$domain string Domain name
return boolean | WP_Erro\WP_Error True if we updated, false if we didn't need to, or WP_Error if an error occurred

to_instance() protected static method

Allows use as a callback, such as in array_map
protected static to_instance ( stdClass $data ) : Mapping
$data stdClass Raw mapping data
return Mapping

to_instances() protected static method

Convert list of data to Mapping instances
protected static to_instances ( stdClass[] $data ) : Mapping[]
$data stdClass[] Raw mapping rows
return Mapping[]

update() public method

See also, {@see \set_domain} and {@see \set_active} as convenience methods.
public update ( array | stdClass $data ) : boolean | WP_Erro\WP_Error
$data array | stdClass Mapping fields (associative array or object properties)
return boolean | WP_Erro\WP_Error True if we updated, false if we didn't need to, or WP_Error if an error occurred

Property Details

$data protected_oe property

Mapping data
protected array $data
return array

$site protected_oe property

Site ID
protected int $site
return integer