PHP Class Essence\Replacer

Datei anzeigen Open project: benjamminf/craft-embedded-assets Class Usage Examples

Protected Properties

Property Type Description
$_Extractor Extractor Extractor.
$_urlPattern string A pattern to match URLs.

Public Methods

Method Description
__construct ( Extractor $Extractor ) Constructor.
replace ( string $text, callable $template = null, array $options = [] ) : string Replaces URLs in the given text by media informations if they point on an extractable resource.
setUrlPattern ( string $pattern ) Sets the URL pattern for replacements.

Protected Methods

Method Description
_defaultTemplate ( ) : Closure Returns a default templating callback for replace().
_replaceFunction ( callable $template, array $options ) : Closure Returns a function used to replace URLs by informations.

Method Details

__construct() public method

Constructor.
public __construct ( Extractor $Extractor )
$Extractor Extractor Extractor.

_defaultTemplate() protected method

Returns a default templating callback for replace().
See also: replace()
protected _defaultTemplate ( ) : Closure
return Closure Templating function.

_replaceFunction() protected method

Returns a function used to replace URLs by informations.
See also: replace()
protected _replaceFunction ( callable $template, array $options ) : Closure
$template callable Templating callback.
$options array Custom options to be interpreted by a provider.
return Closure Function.

replace() public method

By default, links will be replaced by the html property of Media. If $template is a callable function, it will be used to generate replacement strings, given a Media object.
public replace ( string $text, callable $template = null, array $options = [] ) : string
$text string Text in which to replace URLs.
$template callable Templating callback.
$options array Custom options to be interpreted by a provider.
return string Text with replaced URLs.

setUrlPattern() public method

Sets the URL pattern for replacements.
See also: replace()
public setUrlPattern ( string $pattern )
$pattern string URL pattern.

Property Details

$_Extractor protected_oe property

Extractor.
protected Extractor,Essence $_Extractor
return Extractor

$_urlPattern protected_oe property

A pattern to match URLs.
See also: http://daringfireball.net/2010/07/improved_regex_for_matching_urls
protected string $_urlPattern
return string