First commit

This commit is contained in:
Theodotos Andreou 2018-01-14 13:10:16 +00:00
commit c6e2478c40
13918 changed files with 2303184 additions and 0 deletions

View file

@ -0,0 +1,25 @@
<?php
namespace Civi\Token\Event;
use Symfony\Component\EventDispatcher\Event;
/**
* Class TokenListEvent
* @package Civi\Token\Event
*/
class TokenEvent extends Event {
protected $tokenProcessor;
public function __construct($tokenProcessor) {
$this->tokenProcessor = $tokenProcessor;
}
/**
* @return \Civi\Token\TokenProcessor
*/
public function getTokenProcessor() {
return $this->tokenProcessor;
}
}

View file

@ -0,0 +1,70 @@
<?php
namespace Civi\Token\Event;
/**
* Class TokenRegisterEvent
* @package Civi\Token\Event
*
* The TokenRegisterEvent is fired when constructing a list of available
* tokens. Listeners may register by specifying the entity/field/label for the token.
*
* @code
* $ev->entity('profile')
* ->register('viewUrl', ts('Default Profile URL (View Mode)')
* ->register('editUrl', ts('Default Profile URL (Edit Mode)');
* $ev->register(array(
* 'entity' => 'profile',
* 'field' => 'viewUrl',
* 'label' => ts('Default Profile URL (View Mode)'),
* ));
* @endcode
*/
class TokenRegisterEvent extends TokenEvent {
/**
* Default values to put in new registrations.
*
* @var array
*/
protected $defaults;
public function __construct($tokenProcessor, $defaults) {
parent::__construct($tokenProcessor);
$this->defaults = $defaults;
}
/**
* Set the default entity name.
*
* @param string $entity
* @return TokenRegisterEvent
*/
public function entity($entity) {
$defaults = $this->defaults;
$defaults['entity'] = $entity;
return new TokenRegisterEvent($this->tokenProcessor, $defaults);
}
/**
* Register a new token.
*
* @param array|string $paramsOrField
* @param NULL|string $label
* @return TokenRegisterEvent
*/
public function register($paramsOrField, $label = NULL) {
if (is_array($paramsOrField)) {
$params = $paramsOrField;
}
else {
$params = array(
'field' => $paramsOrField,
'label' => $label,
);
}
$params = array_merge($this->defaults, $params);
$this->tokenProcessor->addToken($params);
return $this;
}
}

View file

@ -0,0 +1,44 @@
<?php
namespace Civi\Token\Event;
/**
* Class TokenRenderEvent
* @package Civi\Token\Event
*
* A TokenRenderEvent is fired after the TokenProcessor has rendered
* a message.
*
* The render event may be used for post-processing the text, but
* it's very difficult to do substantive work in a secure, robust
* way within this event. The event primarily exists to facilitate
* a transition of some legacy code.
*/
class TokenRenderEvent extends TokenEvent {
/**
* @var array|\ArrayAccess
*/
public $context;
/**
* @var array|\ArrayAccess
*
* The original message template.
*/
public $message;
/**
* @var \Civi\Token\TokenRow
*
* The record for which we're generating date
*/
public $row;
/**
* @var string
*
* The rendered string, with tokens replaced.
*/
public $string;
}

View file

@ -0,0 +1,45 @@
<?php
namespace Civi\Token\Event;
/**
* Class TokenValueEvent
* @package Civi\Token\Event
*
* A TokenValueEvent is fired to convert raw query data into mergeable
* tokens. For example:
*
* @code
* $event = new TokenValueEvent($myContext, 'text/html', array(
* array('contact_id' => 123),
* array('contact_id' => 456),
* ));
*
* // Compute tokens one row at a time.
* foreach ($event->getRows() as $row) {
* $row->setTokens('contact', array(
* 'profileUrl' => CRM_Utils_System::url('civicrm/profile/view', 'reset=1&gid=456&id=' . $row['contact_id']'),
* ));
* }
*
* // Compute tokens with a bulk lookup.
* $ids = implode(',', array_filter(CRM_Utils_Array::collect('contact_id', $event->getRows()), 'is_numeric'));
* $dao = CRM_Core_DAO::executeQuery("SELECT contact_id, foo, bar FROM foobar WHERE contact_id in ($ids)");
* while ($dao->fetch) {
* $row->setTokens('oddball', array(
* 'foo' => $dao->foo,
* 'bar' => $dao->bar,
* ));
* }
* @encode
*
*/
class TokenValueEvent extends TokenEvent {
/**
* @return \Traversable<TokenRow>
*/
public function getRows() {
return $this->tokenProcessor->getRows();
}
}