Class Socialveo\Core\library\FormatPhrase

InheritanceSocialveo\Core\library\FormatPhrase
Uses TraitsSocialveo\Core\Translatable

Class FormatPhrase

Protected Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$builtMethods array Socialveo\Core\library\FormatPhrase

Public Methods

Hide inherited methods

MethodDescriptionDefined By
_t() Gets translations Socialveo\Core\Translatable
create() Create phrase for saving in db, it saves only const data such as uuid, so all dynamic data such username or link, can be changed without broke the saved phrases in db. Socialveo\Core\library\FormatPhrase
escape() Create format for escape Socialveo\Core\library\FormatPhrase
link() Create format for link Socialveo\Core\library\FormatPhrase
parse() Parse previously saved phrase and returns translated string Socialveo\Core\library\FormatPhrase
t() Gets translations Socialveo\Core\Translatable
url() Create format for url Socialveo\Core\library\FormatPhrase

Property Details

$builtMethods protected static property
protected static array $builtMethods = ['@url' => 'url''@escape' => 'escape''@link' => 'link']

Method Details

compactData() protected static method

Compact data

protected static mixed compactData ( $arg )
$arg mixed
throws Exception
compactEscape() protected static method

Compact escape

protected static array compactEscape ( $args )
$args array
compactLink() protected static method

Compact link

protected static array compactLink ( $args )
$args array
compactModel() protected static method

Compact model

protected static array compactModel ( $object, $property, $arg )
$object Socialveo\Core\models\SocialveoModel
$property string
$arg array
throws Exception
compactUrl() protected static method

Compact url

protected static array compactUrl ( $args )
$args array
create() public static method

Create phrase for saving in db, it saves only const data such as uuid, so all dynamic data such username or link, can be changed without broke the saved phrases in db.

It uses even i18n!

Example: Phrase::create('User %userName1% say something to user %userName2%, got to %link% with textlink %url%', [

'userName1' => [$user1, 'getFullName()'],
'userName2' => [$user2, 'getFullName()'],
'url' => ['@url', 'for' => 'postView', 'uuid' => [$post, 'uuid']]),
'link' => ['@link', ['@url', 'for' => 'network', 'uuid' => [$user2->network, 'uuid']], ['@escape', [$user2, 'getFullName()']]]

]);

Example 2: $phrase = FormatPhrase::create('User %userLink% connected to dialog', [

  'userLink' => ['@link', ['@url', 'for' => 'network', 'uuid' => [$user->network, 'uuid']], ['@escape', [$user, 'getFullName()']]],

]);

print_r($phrase); // encoded phrase for saving in db, will output: // ["User {userLink} connected to dialog",{"userLink":["@link",{"0":"@url","for":"network","uuid":["network:1","uuid"]},["user:1","getFullName()"]]}]

print_r(FormatPhrase::parse($phrase)); // parsed phrase with actual data, will output: // User Izman Andrey connected to dialog

public static string create ( $format, $arguments = [] )
$format string
$arguments array

[optional]

escape() public static method

Create format for escape

public static array escape ( $data )
$data array
extractData() protected static method

Parse data

protected static mixed|null extractData ( $arg )
$arg mixed
extractEscape() protected static method

Escape html

protected static array|string extractEscape ( $args )
$args mixed
extractLink() protected static method

Get saved tag link

protected static string extractLink ( $args )
$args array
extractUrl() protected static method

Get saved url

protected static string extractUrl ( $args )
$args array
getModel() protected static method

protected static Socialveo\Core\models\SocialveoModel|null getModel ( $option )
$option array
link() public static method

Create format for link

public static array link ( $url, $name )
$url array
$name array
throws Exception
modelCall() protected static method

Call model property or method

protected static mixed|null modelCall ( $model, $property, $args = [] )
$model Phalcon\Mvc\Model
$property string
$args array

[optional]

parse() public static method

Parse previously saved phrase and returns translated string

public static mixed|null|string parse ( $data, &$params = [] )
$data string
$params array
url() public static method

Create format for url

public static array url ( $uri )
$uri array
throws Exception