class BlockProxy extends AbstractPartProxy implements IBlock (View source)

Class for lazy-proxy creation to ensure, that BEM elements are really accessed only at moment, when user needs them.

Properties

protected string $elementClass Element class, that is allowed in the collection. from AbstractElementCollection
protected string $className Class name to proxy. from AbstractProxy
protected mixed $object Object to proxy. from AbstractProxy
protected IElementLocator $locator Locator, that can be used to find associated elements on a page. from AbstractProxy
protected boolean $locatorUsed Determines if a locator was used to locate the elements. from AbstractProxy
protected IPageFactory $pageFactory Page Factory, that allows to create more elements on demand. from AbstractProxy
private string $_name Name. from AbstractPartProxy

Methods

__construct(string $name, IElementLocator $locator, IPageFactory $page_factory)

Initializes BEM block proxy.

boolean
acceptElement(mixed $element)

Determines if an element can be added to a collection.

void
offsetSet(mixed $index, mixed $newval)

Offset to set.

fromNodeElements(array $node_elements, string $element_class = null, IPageFactory $page_factory)

Creates new collection by wrapping given array of Node elements.

boolean
isNodeElementAware(string $class_name)

Determines if class is NodeElement aware.

boolean
assertElement(mixed $element)

Checks that element's class is allowed in collection.

Expectation
shouldReceive(string $name)

No description

setClassName(string $class_name)

Sets class name, used inside the proxy.

mixed
__get(string $property)

Proxies read access for properties to the sub-object.

void
__set(string $property, mixed $value)

Proxies write access for properties to the sub-object.

mixed
__call(string $method, array $arguments)

Proxies all methods to sub-object.

NodeElement
locateElement()

Locates element using the locator.

NodeElement[]
locateElements()

Locates elements using the locator.

boolean
offsetExists(mixed $index)

Whether a offset exists.

void
offsetUnset(mixed $index)

Offset to unset.

mixed|null
offsetGet(mixed $index)

Offset to retrieve.

integer
count()

Count elements of an object.

getIterator()

Returns the array iterator.

mixed
locateObject()

Locates object inside proxy.

mixed
getObject()

Returns block instance.

string
getName()

Returns name of the entity.

NodeElement[]
getNodes()

Returns block nodes.

NodeElement[]|null
getElement(string $element_name, string $modificator_name = null, string $modificator_value = null)

Returns first block element.

NodeElement[]
getElements(string $element_name, string $modificator_name = null, string $modificator_value = null)

Returns all block elements.

NodeElement[]
findAll(string $selector, string|array $locator)

Finds all elements with specified selector.

NodeElement|null
find(string $selector, string|array $locator)

Finds first element with specified selector.

mixed
waitFor(integer $timeout, callable $callback)

Waits for an element(-s) to appear and returns it.

Details

__construct(string $name, IElementLocator $locator, IPageFactory $page_factory)

Initializes BEM block proxy.

Parameters

string $name Name.
IElementLocator $locator Element selector.
IPageFactory $page_factory Page factory.

protected boolean acceptElement(mixed $element)

Determines if an element can be added to a collection.

Parameters

mixed $element Element.

Return Value

boolean

void offsetSet(mixed $index, mixed $newval)

Offset to set.

Parameters

mixed $index The offset to assign the value to.
mixed $newval The value to set.

Return Value

void

static AbstractElementCollection fromNodeElements(array $node_elements, string $element_class = null, IPageFactory $page_factory)

Creates new collection by wrapping given array of Node elements.

Parameters

array $node_elements Node elements to wrap.
string $element_class Class name to wrap Node elements with.
IPageFactory $page_factory Page factory (optional) to use during wrapping.

Return Value

AbstractElementCollection

Exceptions

ElementCollectionException When element class used doesn't allow adding NodeElements inside.

protected boolean isNodeElementAware(string $class_name)

Determines if class is NodeElement aware.

Parameters

string $class_name Class name.

Return Value

boolean

protected boolean assertElement(mixed $element)

Checks that element's class is allowed in collection.

Parameters

mixed $element Element.

Return Value

boolean

Exceptions

ElementCollectionException When class of given element doesn't match one, that collection accepts.

Expectation shouldReceive(string $name)

Parameters

string $name

Return Value

Expectation

IProxy setClassName(string $class_name)

Sets class name, used inside the proxy.

Parameters

string $class_name Class name to proxy.

Return Value

IProxy

mixed __get(string $property)

Proxies read access for properties to the sub-object.

Parameters

string $property Property to proxy.

Return Value

mixed

Exceptions

ElementException When sub-object doesn't have a specific property.

void __set(string $property, mixed $value)

Proxies write access for properties to the sub-object.

Parameters

string $property Property to proxy.
mixed $value Property value.

Return Value

void

Exceptions

ElementException When sub-object doesn't have a specific property.

mixed __call(string $method, array $arguments)

Proxies all methods to sub-object.

Parameters

string $method Method to proxy.
array $arguments Method arguments.

Return Value

mixed

Exceptions

ElementException When sub-object doesn't have a specified method.

protected NodeElement locateElement()

Locates element using the locator.

Return Value

NodeElement

protected NodeElement[] locateElements()

Locates elements using the locator.

Return Value

NodeElement[]

Exceptions

ElementNotFoundException When element wasn't found on the page.

boolean offsetExists(mixed $index)

Whether a offset exists.

Parameters

mixed $index An offset to check for.

Return Value

boolean

void offsetUnset(mixed $index)

Offset to unset.

Parameters

mixed $index The offset to unset.

Return Value

void

mixed|null offsetGet(mixed $index)

Offset to retrieve.

Parameters

mixed $index The offset to retrieve.

Return Value

mixed|null

integer count()

Count elements of an object.

Return Value

integer

ArrayIterator getIterator()

Returns the array iterator.

Return Value

ArrayIterator

protected mixed locateObject()

Locates object inside proxy.

Return Value

mixed

Exceptions

ElementNotFoundException When block not found.

mixed getObject()

Returns block instance.

Return Value

mixed

string getName()

Returns name of the entity.

Return Value

string

NodeElement[] getNodes()

Returns block nodes.

Return Value

NodeElement[]

NodeElement[]|null getElement(string $element_name, string $modificator_name = null, string $modificator_value = null)

Returns first block element.

Parameters

string $element_name Element name.
string $modificator_name Modificator name.
string $modificator_value Modificator value.

Return Value

NodeElement[]|null

NodeElement[] getElements(string $element_name, string $modificator_name = null, string $modificator_value = null)

Returns all block elements.

Parameters

string $element_name Element name.
string $modificator_name Modificator name.
string $modificator_value Modificator value.

Return Value

NodeElement[]

NodeElement[] findAll(string $selector, string|array $locator)

Finds all elements with specified selector.

Parameters

string $selector Selector engine name.
string|array $locator Selector locator.

Return Value

NodeElement[]

NodeElement|null find(string $selector, string|array $locator)

Finds first element with specified selector.

Parameters

string $selector Selector engine name.
string|array $locator Selector locator.

Return Value

NodeElement|null

mixed waitFor(integer $timeout, callable $callback)

Waits for an element(-s) to appear and returns it.

Parameters

integer $timeout Maximal allowed waiting time in seconds.
callable $callback Callback, which result is both used as waiting condition and returned. Will receive reference to this element as first argument.

Return Value

mixed