sentence1 stringlengths 52 3.87M | sentence2 stringlengths 1 47.2k | label stringclasses 1
value |
|---|---|---|
public function trigger($event, $target = null, $params = null)
{
if (!$event instanceof Event) {
$event = new Event($event, $target, $params);
}
if (false !== strpos($event->getName(), ':')) {
$namespace = substr($event->getName(), 0, strpos($event->getName(), ':'))... | Trigger event
@param string|Event $event
@param string|object $target
@param array|object $params
@return string|object
@throws EventException | entailment |
protected function fire($listeners, $event): void
{
ksort($listeners);
foreach ($listeners as $list) {
foreach ($list as $listener) {
$result = $listener($event);
if (null === $result) {
// continue;
} elseif (false === ... | Fire!
@param array $listeners
@param Event $event
@return void | entailment |
public function getOption($key, ...$keys)
{
$method = 'get' . Str::toCamelCase($key);
if (method_exists($this, $method)) {
return $this->$method($key, ...$keys);
}
return Collection::get($this->options, $key, ...$keys);
} | Get option by key
@param string $key
@param array $keys
@return mixed | entailment |
public function setOption($key, $value): void
{
$method = 'set' . Str::toCamelCase($key);
if (method_exists($this, $method)) {
$this->$method($value);
} else {
$this->options[$key] = $value;
}
} | Set option by key over setter
@param string $key
@param string $value
@return void | entailment |
public function setOptions(array $options = null): void
{
// store options by default
$this->options = (array)$options;
// apply options
foreach ($this->options as $key => $value) {
$this->setOption($key, $value);
}
} | Setup, check and init options
Requirements
- options must be a array
- options can be null
@param array $options
@return void | entailment |
public static function get(array $array, ...$keys)
{
$key = array_shift($keys);
if (!isset($array[$key])) {
return null;
}
if (empty($keys)) {
return $array[$key] ?? null;
}
if (!\is_array($array[$key])) {
return null;
}
... | Get an element to array by key and sub-keys
@param array $array
@param array ...$keys
@return mixed|null | entailment |
public static function has(array $array, ...$keys): bool
{
$key = array_shift($keys);
if (!isset($array[$key])) {
return false;
}
if (empty($keys)) {
return isset($array[$key]);
}
if (!\is_array($array[$key])) {
return false;
... | Check an element of array by key and sub-keys
@param array $array
@param array ...$keys
@return bool | entailment |
public static function set(array &$array, ...$keys): void
{
if (\count($keys) < 2) {
throw new \InvalidArgumentException('Method `Collection::set()` is required minimum one key and value');
}
$value = array_pop($keys);
while (\count($keys) > 1) {
$key = array... | Set an element of array by key and sub-keys
@param array $array
@param array ...$keys
@return void
@throws \InvalidArgumentException | entailment |
public function open($savePath, $sessionName): bool
{
$this->prefix = $sessionName . ':';
$this->ttl = (int)ini_get('session.gc_maxlifetime');
// No more action necessary because connection is injected
// in constructor and arguments are not applicable.
return true;
} | Initialize session
@param string $savePath
@param string $sessionName
@return bool | entailment |
public function validate($input): bool
{
if (!\is_array($input)) {
return false;
}
$filtered = array_filter($input, $this->callback);
return \count($input) === \count($filtered);
} | Check input data
@param mixed $input
@return bool | entailment |
public function linkTo($key, $model, $foreign): void
{
Relations::setRelation($this->model, $key, $model, $foreign);
} | Setup relation "one to one" or "one to many"
@param string $key
@param string $model
@param string $foreign
@return void | entailment |
public function linkToMany($model, $link): void
{
Relations::setRelations($this->model, $model, [$link]);
} | Setup relation "many to many"
[table1-key] [table1_key-table2-table3_key] [table3-key]
@param string $model
@param string $link
@return void | entailment |
protected function filterData($data): array
{
if (empty($this->getFields())) {
return $data;
}
return array_intersect_key($data, array_flip($this->getFields()));
} | Filter input Fields
@param array $data Request
@return array | entailment |
protected function filterRow(RowInterface $row): RowInterface
{
if (empty($this->getFields())) {
return $row;
}
$fields = array_keys($row->toArray());
$toDelete = array_diff($fields, $this->getFields());
foreach ($toDelete as $field) {
unset($row->$fi... | Filter output Row
@param RowInterface $row from database
@return RowInterface | entailment |
public static function fromGlobals(
array $server = null,
array $query = null,
array $body = null,
array $cookies = null,
array $files = null
) : ServerRequest {
$request = parent::fromGlobals($server, $query, $body, $cookies, $files);
$contentType = current... | {@inheritdoc} | entailment |
public static function exception($exception): void
{
self::getInstance()->error(
$exception->getMessage() . ' [' .
$exception->getFile() . ':' .
$exception->getLine() . ']'
);
} | exception
@param \Exception $exception
@return void | entailment |
public function create(): PHPMailer
{
// can initial, can't use
if (!class_exists(PHPMailer::class)) {
throw new ComponentException(
"PHPMailer library is required for `Bluz\\Mailer` package. <br/>\n" .
"Read more: <a href='https://github.com/bluzphp/frame... | Creates new instance of PHPMailer and set default options from config
@return PHPMailer
@throws ComponentException
@throws \PHPMailer\PHPMailer\Exception | entailment |
public function send(PHPMailer $mail)
{
if ($template = $this->getOption('subjectTemplate')) {
/** @var string $template */
$mail->Subject = Translator::translate($template, $mail->Subject);
}
if (!$mail->send()) {
// Why you don't use "Exception mode" of... | Send email
@todo Add mail to queue
@param PHPMailer $mail
@return bool
@throws MailerException
@throws \PHPMailer\PHPMailer\Exception | entailment |
public static function setRelation($modelOne, $keyOne, $modelTwo, $keyTwo): void
{
$relations = [$modelOne => $keyOne, $modelTwo => $keyTwo];
self::setRelations($modelOne, $modelTwo, $relations);
} | Setup relation between two models
@param string $modelOne
@param string $keyOne
@param string $modelTwo
@param string $keyTwo
@return void | entailment |
public static function setRelations($modelOne, $modelTwo, $relations): void
{
$name = [$modelOne, $modelTwo];
sort($name);
$name = implode(':', $name);
// create record in static variable
self::$relations[$name] = $relations;
} | Setup multi relations
@param string $modelOne
@param string $modelTwo
@param array $relations
@return void | entailment |
public static function getRelations($modelOne, $modelTwo)
{
$name = [$modelOne, $modelTwo];
sort($name);
$name = implode(':', $name);
return self::$relations[$name] ?? false;
} | Get relations
@param string $modelOne
@param string $modelTwo
@return array|false | entailment |
public static function findRelation($row, $relation): array
{
$model = $row->getTable()->getModel();
/** @var \Bluz\Db\Table $relationTable */
$relationTable = self::getModelClass($relation);
$relationTable::getInstance();
if (!$relations = self::getRelations($model, $relat... | findRelation
@param Row $row
@param string $relation
@return array
@throws Exception\TableNotFoundException
@throws Exception\RelationNotFoundException | entailment |
public static function findRelations($modelOne, $modelTwo, $keys): array
{
$keys = (array)$keys;
if (!$relations = self::getRelations($modelOne, $modelTwo)) {
throw new RelationNotFoundException("Relations between model `$modelOne` and `$modelTwo` is not defined");
}
/* ... | Find Relations between two tables
@param string $modelOne Table
@param string $modelTwo Target table
@param array $keys Keys from first table
@return array
@throws Exception\RelationNotFoundException | entailment |
public static function getModelClass($model): string
{
if (!isset(self::$modelClassMap[$model])) {
// try to detect
$className = '\\Application\\' . $model . '\\Table';
if (!class_exists($className)) {
throw new RelationNotFoundException("Related class fo... | Get information about Model classes
@param string $model
@return string
@throws Exception\RelationNotFoundException | entailment |
public static function createRow($modelName, $data): RowInterface
{
$tableClass = self::getModelClass($modelName);
/* @var Table $tableClass name */
return $tableClass::getInstance()::create($data);
} | Get information about Table classes
@param string $modelName
@param array $data
@return RowInterface
@throws Exception\RelationNotFoundException | entailment |
public static function fetch($input): array
{
$output = [];
$map = [];
foreach ($input as $i => $row) {
$model = '';
foreach ($row as $key => $value) {
if (strpos($key, '__') === 0) {
$model = substr($key, 2);
co... | Fetch by Divider
@param array $input
@return array
@throws Exception\RelationNotFoundException | entailment |
public function setContent($content): void
{
try {
$this->content = value($content);
} catch (\Exception $e) {
$this->content = $e->getMessage();
}
} | Set content
@param View|callable $content
@return void | entailment |
public function get(...$keys)
{
// configuration is missed
if (empty($this->container)) {
throw new ConfigException('System configuration is missing');
}
if (!\count($keys)) {
return $this->container;
}
return Collection::get($this->container... | Return configuration by key
@param array $keys
@return array|mixed
@throws ConfigException | entailment |
public function getClientId($clientId = null)
{
// Return given parameter
if ($clientId) {
return $clientId;
}
// If clientId is null and no clientId has previously been set
if (!$this->clientId) {
throw new RequestRequiresClientIdException();
... | Get clientId.
@param string clientId optional
@return string clientId | entailment |
public function sendRequest($type = 'GET', $path = '', $token = false, $options = [], $availableOptions = [])
{
/**
* TODO: $availableOptions is currently not being used, as it's
* just a limitation in case Twitch adds to, or makes changes to them.
* This variable can either be removed completed or used for som... | Send request to Twitch API.
@param string $type Request type
@param string $path Request URL path
@param bool $token Twitch token
@param array $options URL queries
@param array $availableOptions Available URL queries
@return JSON JSON object from Twitch | entailment |
public function generateUrl($url, $token, $options, $availableOptions)
{
// Append client id
$url .= (parse_url($url, PHP_URL_QUERY) ? '&' : '?').'client_id='.$this->getClientId();
// Append token if provided
if ($token) {
$url .= (parse_url($url, PHP_URL_QUERY) ? '&' :... | Generate URL with queries.
@param string $url Original URL
@param array $options Parameter values
@param array $availableOptions Parameters
@return string URL with queries | entailment |
public function channelsSubscriptions($channel, $options = [], $token = null)
{
$availableOptions = ['limit', 'offset', 'direction'];
return $this->sendRequest('GET', 'channels/'.$channel.'/subscriptions', $this->getToken($token), $options, $availableOptions);
} | List of channel subscribers.
@param string $channel Channel name
@param array $options Subscriber list options
@param string $token Twitch token
@return JSON List of subscribers | entailment |
public function channelSubscriptionUser($channel, $user, $token = null)
{
return $this->sendRequest('GET', 'channels/'.$channel.'/subscriptions/'.$user, $this->getToken($token));
} | Get subscription object of a single channel subscriber.
@param string $channel Channel name
@param string $user Username
@param string $token Twitch name
@return JSON A channel subscriber | entailment |
public function userSubscriptionChannel($channel, $user, $token = null)
{
return $this->sendRequest('GET', 'users/'.$user.'/subscriptions/'.$channel, $this->getToken($token));
} | Get user object of a single channel subscriber.
@param string $channel Channel name
@param string $user Username
@param string $token Twitch token
@return JSON User object | entailment |
public function getAuthenticationUrl($state = null, $forceVerify = false)
{
return 'https://api.twitch.tv/kraken/oauth2/authorize?response_type=code'
.'&client_id='.config('twitch-api.client_id')
.'&redirect_uri='.config('twitch-api.redirect_url')
.'&scope='.implode(config('twitch-ap... | Get the Twitch OAuth url where the user signs in through Twitch.
@param string $state Will be appended to the redirect_uri to help avoid cross-stire scripting
@param bool $forceVerify Prompt user to confirm authorization, allowing users to switch accounts
@return string Authentication url | entailment |
public function getAccessToken($code, $state = null)
{
$response = $this->getAccessObject($code, $state);
return $response['access_token'];
} | Get access_token from Twitch.
@deprecated Use getAccessObject() instead
@param string $code code from redirect_uri
@param string $state optional state OAuth2 parameter to prevent cross-site scripting attacks
@return JSON JSON response object containing the access token | entailment |
public function getAccessObject($code, $state = null)
{
$availableOptions = ['client_secret', 'grant_type', 'state', 'code', 'redirect_uri'];
$options = [
'client_secret' => config('twitch-api.client_secret'),
'grant_type' => 'authorization_code',
'code' => $code... | Returns access_token, refresh_token and scope from Twitch.
@param string $code code from redirect_uri
@param string $state optional state OAuth2 parameter to prevent cross-site scripting attacks
@return JSON JSON response object from Twitch | entailment |
public function putChannel($channel, $rawOptions, $token = null)
{
$options = [];
foreach ($rawOptions as $key => $value) {
$options['channel['.$key.']'] = $value;
}
return $this->sendRequest('PUT', 'channels/'.$channel, $this->getToken($token), $options);
} | Update channel.
@param string $channel Channel name
@param array $options Channel options
@param string $token Twitch token
@return JSON Request result | entailment |
public function deleteStreamKey($channel, $token = null)
{
return $this->sendRequest('DELETE', 'channels/'.$channel.'/stream_key', $this->getToken($token));
} | Reset stream key.
@param string $channel Channel name
@param string $token Twitch token
@return JSON Request result with new stream key | entailment |
public function postCommercial($channel, $length = 30, $token = null)
{
$availableOptions = ['length'];
$options = ['length' => $length];
return $this->sendRequest('POST', 'channels/'.$channel.'/commercial', $this->getToken($token), $options, $availableOptions);
} | Run commercial.
@param string $channel Channel name
@param number $length Commercial length
@param string $token Twitch token
@return JSON Request result | entailment |
public function channelFollows($channel, $options = [])
{
$availableOptions = ['limit', 'offset', 'direction'];
return $this->sendRequest('GET', 'channels/'.$channel.'/follows', false, $options, $availableOptions);
} | Get channel's list of following users.
@param string $channel Channel name
@param array $options List options
@return JSON List of followers | entailment |
public function userFollowsChannels($user, $options = [])
{
$availableOptions = ['limit', 'offset', 'direction', 'sortby'];
return $this->sendRequest('GET', 'users/'.$user.'/follows/channels', false, $options, $availableOptions);
} | Get list of who the user is following.
@param string $user Username
@param array $options List options
@return JSON List of who the user is following | entailment |
public function authenticatedUserFollowsChannel($user, $channel, $options = [], $token = null)
{
$availableOptions = ['notifications'];
return $this->sendRequest('PUT', 'users/'.$user.'/follows/channels/'.$channel, $this->getToken($token), $options, $availableOptions);
} | Follow a channel.
@param string $user Username
@param string $channel Target channel's name
@param array $options Follow options
@param string $token Twitch token
@return JSON Request result | entailment |
public function authenticatedUserUnfollowsChannel($user, $channel, $token = null)
{
return $this->sendRequest('DELETE', 'users/'.$user.'/follows/channels/'.$channel, $this->getToken($token));
} | Unfollow a channel.
@param string $user Username
@param string $channel Target channel's name
@param string $token Twitch token
@return JSON Response result | entailment |
public function blocks($user, $token = null)
{
return $this->sendRequest('GET', 'users/'.$user.'/blocks', $this->getToken($token));
} | Get user's block list.
@param string $user Username
@param string $token Twitch token
@return JSON List of ignored users | entailment |
public function putBlock($user, $target, $token = null)
{
return $this->sendRequest('PUT', 'users/'.$user.'/blocks/'.$target, $this->getToken($token));
} | Add target to user's block list.
@param string $user Username
@param string $target Target's username
@param string $token Twitch token
@return JSON Request result | entailment |
public function deleteBlock($user, $target, $token = null)
{
return $this->sendRequest('DELETE', 'users/'.$user.'/blocks/'.$target, $this->getToken($token));
} | Delete target from user's block list.
@param string $user Username
@param string $target Target's username
@param string $token Twitch token
@return JSON Request result | entailment |
public function channelVideos($channel, $options = [])
{
$availableOptions = ['limit', 'offset', 'broadcasts', 'hls'];
return $this->sendRequest('GET', 'channels/'.$channel.'/videos', false, $options, $availableOptions);
} | Get list of video objects belonging to channel.
@param string $channel Channel name
@param array $options Video list options
@return JSON List of videos | entailment |
public function getAuthenticationUrl($state = null, $forceVerify = false)
{
$authentication = new Authentication();
return $authentication->getAuthenticationUrl($state, $forceVerify);
} | Authentication. | entailment |
public function ignoreList($user, $token = null)
{
$blocks = new Blocks($this->getToken($token));
return $blocks->blocks($user);
} | Blocks. | entailment |
public function subscribers($channel, $options = [], $token = null)
{
$subscriptions = new Subscriptions();
return $subscriptions->channelsSubscriptions($channel, $options, $this->getToken($token));
} | Subscriptions. | entailment |
public function init()
{
parent::init();
if ($this->owner->swatch) {
$this->addComponents(array('swatch' => $this->owner->swatch));
}
} | / }}} | entailment |
public function addButton($label = null, $options = array())
{
/** @type Button $but */
$but = $this->add('Button', $options);
$but->set($label);
if ($this->vertical) {
$but->js(true)->css('margin-top', '-3px');
}
return $but;
} | Add button to buttonset.
@param string $label Label of button
@param array $options Options to pass to button
@return Button | entailment |
public function addButton($label, $class = 'Button')
{
if (!$this->buttonset) {
$this->buttonset = $this->add('ButtonSet', null, 'grid_buttons')->setClass('atk-actions');
}
return $this->buttonset
->add($class, 'gbtn'.count($this->elements))
->set($label)... | Adds button.
@param string|array $label label of button
@param string $class optional name of button class
@return Button | entailment |
public function addColumn($formatters, $name = null, $descr = null)
{
if ($name === null) {
$name = $formatters;
$formatters = 'text';
}
if ($formatters === null) {
$formatters = 'text';
}
if ($descr === null) {
$descr = ucword... | Add column to grid.
@param mixed $formatters
@param string $name
@param string|array $descr
@return $this|Controller_Grid_Format | entailment |
public function removeColumn($name)
{
unset($this->columns[$name]);
if ($this->last_column == $name) {
$this->last_column = null;
}
return $this;
} | Remove column from grid.
@param string $name
@return $this | entailment |
public function setFormatter($field, $formatter, $options = null)
{
// support for field names as array
if (is_array($field)) {
foreach ($field as $f) {
$this->setFormatter($f, $formatter, $options);
}
return $this;
}
if (!isset($... | Replace current formatter for field.
@param string|array $field
@param mixed $formatter
@return $this | entailment |
public function addFormatter($field, $formatter, $options = null)
{
// support for field names as array
if (is_array($field)) {
foreach ($field as $f) {
$this->setFormatter($f, $formatter, $options);
}
return $this;
}
if (!isset($... | Add extra formatter to existing field.
@param string|array $field
@param mixed $formatter
@param array $options
@return $this || Controller_Grid_Format | entailment |
public function renderRows()
{
// precache template chunks
$this->precacheTemplate();
// extend CompleteLister renderRows method
parent::renderRows();
// if we have at least one data row rendered, then remove not_found message
if ($this->total_rows) {
$t... | Render grid rows.
Extends renderRows method of CompleteLister | entailment |
public function precacheTemplate()
{
// Extract template chunks from grid template
// header
$header = $this->template->cloneRegion('header');
$header_col = $header->cloneRegion('col');
$header_sort = $header_col->cloneRegion('sort');
$header->del('cols');
/... | Precaches template chunks. | entailment |
public function formatRow()
{
// execute CompleteLister row formating
parent::formatRow();
if (empty($this->columns)) {
throw $this->exception('No columns defined for grid');
}
foreach ($this->columns as $field => $column) {
if ((is_array($this->curr... | Format grid row.
Extends formatRow method of CompleteLister | entailment |
public function executeFormatters($field, $column, $formatter_prefix = 'format_', $silent = false)
{
if (is_object($column['type']) && $column['type'] instanceof Closure) {
return $this->current_row[$field] = call_user_func($column['type'], $this->current);
}
$formatters = explod... | Format field value using appropriate formatters.
@param string $field field name
@param array $column column configuration
@param string $formatter_prefix prefix of formatter methods
@param bool $silent don't throw exception if formatter not found | entailment |
public function allow($user, $pass = null)
{
// creates fictional model to allow specified user and password
// TODO: test this
if ($this->model) {
$this->model->table[] = array($this->login_field => $user, $this->password_field => $pass);
return $this;
}
... | Configure this Auth controller with a generic Model based on static
collection of user/password combinations. Use this method if you
only want one or few accounts to access the system.
@param string|array $user Either string username or associative array with data
@param string $pass Password if username is string
@r... | entailment |
public function setModel($model, $login_field = null, $password_field = null)
{
parent::setModel($model);
// Set login field and password field or use default ones
if ($login_field !== null) {
$this->login_field = $login_field;
}
if ($password_field !== null) {
... | Associate model with authentication class. Username / password
check will be performed against the model in the following steps:
Model will attempt to load record where login_field matches
specified. Password is then loaded and verified using configured
encryption method.
@param string|object $model
@param string $log... | entailment |
public function addEncryptionHook($model)
{
// If model is saved, encrypt password
$t = $this;
if (isset($model->has_encryption_hook) && $model->has_encryption_hook) {
return;
}
$model->has_encryption_hook = true;
$model->addHook('beforeSave', function ($m... | Adds a hook to specified model which will encrypt password before save.
This method will be applied on $this->model, so you should not call
it manually. You can call it on a fresh model, however.
@param Model $model | entailment |
public function get($property = null, $default = null)
{
if (is_null($property)) {
return $this->info;
}
if (!isset($this->info[$property])) {
return $default;
}
return $this->info[$property];
} | Auth memorizes data about a logged-in user in session. You can either use this function to access
that data or $auth->model (preferred). $auth->get('username') will always point to the login field
value of the user regardless of how your field is named.
@param string $property
@param mixed $default
@return mixed | entailment |
public function allowPage($page)
{
if (is_array($page)) {
foreach ($page as $p) {
$this->allowPage($p);
}
return $this;
}
$this->allowed_pages[] = $page;
return $this;
} | Specify page or array of pages which will exclude authentication. Add your registration page here
or page containing terms and conditions.
@param string|array $page
@return $this | entailment |
public function isPageAllowed($page)
{
if ($this->hook('isPageAllowed', array($page)) === true) {
return true;
}
return in_array($page, $this->allowed_pages) || in_array(str_replace('_', '/', $page), $this->allowed_pages);
} | Verifies if the specified page is allowed to be accessed without
authentication.
@param string $page
@return bool | entailment |
public function encryptPassword($password, $salt = null)
{
if (!is_string($this->password_encryption) && is_callable($this->password_encryption)) {
$e = $this->password_encryption;
return $e($password, $salt);
}
if ($this->password_encryption) {
$this->de... | Manually encrypt password
@param string $password
@param string $salt
@return string|bool Returns false on failure, encrypted string otherwise | entailment |
public function check()
{
if ($this->isPageAllowed($this->app->page)) {
return;
} // no authentication is required
// Check if user's session contains authentication information
if (!$this->isLoggedIn()) {
$this->memorizeURL();
// Brings up ... | Call this function to perform a check for logged in user. This will also display a login-form
and will verify user's credential. If you want to handle log-in form on your own, use
auth->isLoggedIn() to check and redirect user to a login page.
check() returns true if user have just logged in and will return "null" for ... | entailment |
public function addInfo($key, $val = null)
{
if (is_array($key)) {
foreach ($key as $a => $b) {
$this->addInfo($a, $b);
}
return $this;
}
$this->debug("Gathered info: $key=$val");
$this->info[$key] = $val;
return $this;
... | Add additional info to be stored in user session.
@param string|array $key
@param mixed $val
@return $this | entailment |
public function verifyCredentials($user, $password)
{
$this->debug('verifying credentials for '.$user.' '.$password);
// First, perhaps model has a method for verifying credentials.
if ($this->model->hasMethod('verifyCredentials')) {
return $this->model->verifyCredentials($user,... | This function verifies credibility of supplied authentication data.
It will search based on user and verify the password. It's also
possible that the function will re-hash user password with
updated hash.
if default authentication method is used, the function will
automatically determine hash used for password generat... | entailment |
public function memorizeURL()
{
if ($this->app->page !== 'index' && !$this->recall('page', false)) {
$this->memorize('page', $this->app->page);
$g = $_GET;
unset($g['page']);
$this->memorize('args', $g);
}
} | Memorize current URL. Called when the first unsuccessful check is executed. | entailment |
public function getURL()
{
$p = $this->recall('page');
// If there is a login page, no need to return to it
if ($p == 'login') {
return $this->app->url('/');
}
$url = $this->app->url($p, $this->recall('args', null));
$this->forget('page');
$this-... | Return originally requested URL.
@return string | entailment |
public function loggedIn($user = null, $pass = null)
{
if ($this->hook('loggedIn', array($user, $pass)) !== false) {
$this->app->redirect($this->getURL());
}
} | This function is always executed after successful login through a normal means (login form or plugin).
It will create cache model data.
@param string $user
@param string $pass | entailment |
public function memorizeModel()
{
if (!$this->model->loaded()) {
throw $this->exception('Authentication failure', 'AccessDenied');
}
// Don't store password in model / memory / session
$this->model['password'] = null;
unset($this->model->dirty['password']);
... | Store model in session data so that it can be retrieved faster. | entailment |
public function loginBy($field, $value)
{
$this->model->tryLoadBy($field, $value);
$this->memorizeModel();
return $this;
} | Manually Log in with specified condition.
@param string $field
@param mixed $value
@return $this | entailment |
public function login($user)
{
if (is_object($user)) {
if (!$this->model) {
throw $this->exception('Auth Model should be set');
}
$c = get_class($this->model);
if (!$user instanceof $c) {
throw $this->exception('Specified model... | Manually Log in as specified users by using login name.
@param string $user
@return $this | entailment |
public function logout()
{
$this->hook('logout');
$this->model->unload();
// maybe can use $this->app->destroySession() here instead?
$this->forget('info');
$this->forget('id');
setcookie(session_name(), '', time() - 42000, '/');
if (session_status() === PH... | Manually log out user.
@return $this | entailment |
public function createForm($page)
{
/** @type Form $form */
$form = $page->add('Form', null, null, array('form/minimal'));
/** @type Field $email */
$email = $this->model->hasElement($this->login_field);
/** @type Field $password */
$password = $this->model->hasElem... | Creates log-in form.
Override if you want to use your own form. If you need to change template used by a log-in form,
add template/default/page/login.html.
@param Page $page
@return Form | entailment |
public function showLoginForm()
{
$this->app->template->trySet('page_title', 'Login');
if ($this->app->layout && $this->login_layout_class) {
$this->app->layout->destroy();
$this->app->add($this->login_layout_class);
/** @type Page $p */
$p = $this->ap... | Do not override this function.
@return Page | entailment |
public function processLogin()
{
$this->memorizeURL();
$this->app->template->tryDel('Menu');
$this->showLoginForm();
$this->app->hook('post-init');
$this->app->hook('pre-exec');
if (isset($_GET['submit']) && $_POST) {
$this->app->hook('submitted');
... | Do not override this function. | entailment |
public function setModel($model, $actual_fields = null)
{
parent::setModel($model);
if ($this->model instanceof \atk4\data\Model) {
// Switch to Agile Data implementation
if (isset($this->default_controller)) {
$this->default_controller = str_replace('MVC', '... | Associate view with a model. Additionally may initialize a controller
which would copy fields from the model into the View.
@param object|string $model Class without "Model_" prefix or object
@param array|string|null $actual_fields List of fields in order to populate
@return AbstractModel object | entailment |
public function getHTML($destroy = true, $execute_js = true)
{
$this->addHook('output', array($this, '_tsBuffer'));
$this->recursiveRender();
$this->removeHook('output', array($this, '_tsBuffer'));
$ret = $this->_tsBuffer;
$this->_tsBuffer = '';
if ($execute_js && iss... | Converting View into string will render recursively and produce HTML.
If argument is passed, JavaScript will be added into on_ready section
of your document like when rendered normally. Note that you might
require to destroy object if you don't want it's HTML to appear normally.
@param bool $destroy Destroy object ... | entailment |
public function initializeTemplate($template_spot = null, $template_branch = null)
{
if ($template_spot === null) {
$template_spot = $this->defaultSpot();
}
$this->spot = $template_spot;
if (@$this->owner->template
&& !$this->owner->template->is_set($this->spo... | Called automatically during init for template initalization.
@param string $template_spot Where object's output goes
@param string|array $template_branch Where objects gets it's template
@return AbstractView $this
@internal | entailment |
public function initTemplateTags()
{
if ($this->template
&& $this->app->hasMethod('setTags')
) {
/** @type App_Web $this->app */
$this->app->setTags($this->template);
}
} | This method is called to automatically fill in some of the tags in this
view. Normally the call is bassed to $app->setTags(), however you can
extend and add more tags to fill. | entailment |
public function recursiveRender()
{
if ($this->hook('pre-recursive-render')) {
return;
}
$cutting_here = false;
$cutting_output = '';
$this->initTemplateTags();
if (isset($_GET['cut_object'])
&& ($_GET['cut_object'] == $this->name
... | Recursively renders all views. Calls render() for all or for the one
being cut. In some cases you may want to redefine this function instead
of render(). The difference is that this function is called before
sub-views are rendered, but render() is called after.
function recursiveRender(){
$this->add('Text')->set('test... | entailment |
public function modelRender()
{
if ($this->model instanceof \atk4\data\Model) {
if ($this->controller instanceof Controller_ADView) {
return;
}
$data = $this->model->persistence->typecastSaveRow($this->model, $this->model->get());
} else {
... | When model is specified for a view, values of the model is
inserted inside the template if corresponding tags exist.
This is used as default values and filled out before
the actual render kicks in. | entailment |
public function moveJStoParent()
{
/** @type AbstractView $this->owner */
$this->owner->js = array_merge_recursive($this->owner->js, $this->js);
} | Append our chains to owner's chains. JS chains bubble up to
app, which plugs them into template. If the object is being
"cut" then only relevant chains will be outputed. | entailment |
public function render()
{
if (!($this->template)) {
throw $this->exception('You should specify template for this object')
->addMoreInfo('object', $this->name)
->addMoreInfo('spot', $this->spot);
}
$this->output(($render = $this->template->render()... | Default rendering method. Generates HTML presentation of $this view.
For most views, rendering the $this->template would be sufficient.
If your view requires to do some heavy-duty work, please be sure to do
it inside render() method. This way would save some performance in cases
when your object is not being rendered.... | entailment |
public function output($txt)
{
if (!is_null($this->hook('output', array($txt)))) {
if (isset($this->owner->template)
&& !empty($this->owner->template)
) {
$this->owner->template->append($this->spot, $txt, false);
} elseif ($this->owner inst... | Low level output function which append's to the parent object's
template. For normal objects, you simply need to specify a suitable
template.
@param string $txt HTML chunk | entailment |
public function js($when = null, $code = null, $instance = null)
{
// Create new jQuery_Chain object
if (!isset($this->app->jquery)) {
throw new BaseException('requires jQuery or jUI support');
}
/** @type App_Web $this->app */
// Substitute $when to make it bet... | Views in Agile Toolkit can assign javascript actions to themselves. This
is done by calling $view->js() method.
Method js() will return jQuery_Chain object which would record all calls
to it's non-existant methods and convert them into jQuery call chain.
js([action], [other_chain]);
Action can represent javascript e... | entailment |
public function on($event, $selector = null, $js = null)
{
/** @type App_Web $this->app */
if (!is_string($selector) && is_null($js)) {
$js = $selector;
$selector = null;
}
if (is_callable($js)) {
/** @type VirtualPage $p */
$p = $thi... | Views in Agile Toolkit can assign javascript actions to themselves. This
is done by calling $view->js() or $view->on().
on() method implements implementation of jQuery on() method.
on(event, [selector], [other_chain])
Returned is a javascript chain wich is executed when event is triggered
on specified selector (or a... | entailment |
public function init()
{
parent::init();
$that = $this;
if ($this->owner instanceof Controller_Validator) {
$this->owner->addHook('extraRules', array($this, 'extraRules'));
return; // no source, simply extend rules.
}
if ((
$this->owner... | {{{ Initialization method | entailment |
public function is()
{
$args = func_get_args();
// If only first argument is specified, then it's array of rulesets.
// We will call ourselves with every element.
if (count($args) == 1 && is_array($args[0])) {
foreach ($args[0] as $ruleset) {
// $ruleset ... | This method will go through all the rules you specify, expand
and normalize them and assign into array indexed by field name.
You do not need to have your fields defined at this point, unless
you specify wildcards.
This method takes various arguments as described in documentation. | entailment |
public function normalizeRules($rules)
{
// If you want to use a pipe in a regex, custom message etc,
// single-quote the string (escaping would be too confusing in regexes):
//
// This works with:
//
// 'foo?\'my piped | string\''
// "foo?'my piped | string'"... | Provided with string containing rules, this will convert it into
normal (array) form.
In: "int|required|alphanum|save" (Basic)
In: "int!|a-z|" (Advanced)
Out: array('int','required','alphanum','save') | entailment |
public function applyRulesets()
{
// List of fields which actually need validation at this time.
$fields = $this->getActualFields();
foreach ($fields as $field) {
$rulesets = $this->getRules($field);
$this->active_field = $field;
$this->prefix = '';
... | Go through the list of defined rules and call the corresponding
filters and convertors. | entailment |
public function pullRule($alias = false)
{
$v = array_shift($this->current_ruleset);
if ($alias && $v[0] == '$') {
$v = $this->get(substr($v, 1));
}
return $this->consumed[] = $v;
} | Pulls next rule out of the rule stack (current_ruleset)
May allow alias ($name). | entailment |
public function pushRule()
{
$args = func_get_args();
// TODO: this can probably be done by args+current_ruleset
foreach (array_reverse($args) as $arg) {
array_unshift($this->current_ruleset, $arg);
}
} | Adds new rule into a rule-set, which will be executed next.
You can specify single or multiple rules, this method accepts
variable arguments.
Rules must be normalized. | entailment |
public function fail()
{
$args = func_get_args();
$str = ucfirst(
$this->prefix.
($this->caption ?: str_replace('_', ' ', $this->active_field)).' '.
lcfirst(array_shift($args))
);
// Insert any args into placeholders
if (count($args) > 0) ... | {{{ Methods which are called by the rules | entailment |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.