sentence1 stringlengths 52 3.87M | sentence2 stringlengths 1 47.2k | label stringclasses 1
value |
|---|---|---|
protected function _generateTableColumns($model)
{
$model = TableRegistry::get($model);
$columns = ConnectionManager::get('default')->schemaCollection()->describe($model->table())->columns();
$result = [];
$counter = 0;
$max = 2;
if (in_array('id', $columns)) {
... | If no tablecolumns are given, this method will be called to generate a list of tablecolumns.
@param \Cake\ORM\Table $model Model to rely on.
@return array | entailment |
protected function _generateFormFields($model)
{
$model = TableRegistry::get($model);
$columns = ConnectionManager::get('default')->schemaCollection()->describe($model->table())->columns();
$ignoredFields = [
'created',
'modified',
'created_by',
... | If no formfields are given, this method will be called to generate a list of formfields.
@param \Cake\ORM\Table $model Model to rely on.
@return array | entailment |
protected function _normalizeFormFields($fields)
{
$_options = [
'on' => 'both'
];
$_defaults = [
'_create' => $_options
];
$result = [];
$result['_create'] = $_defaults['_create'];
foreach ($fields as $name => $options) {
... | Normalizes the formfields-array.
@param array $fields Fields to normalize.
@return array | entailment |
protected function _normalizeTableColumns($columns)
{
$_defaults = [
'get' => false,
'before' => '',
'after' => '',
];
$result = [];
foreach ($columns as $name => $options) {
if (is_array($options)) {
$_defaults['get'] ... | Normalizes the tablecolumns-array.
@param array $columns Columns to normalize.
@return array | entailment |
public function checkRecord($marc)
{
// Reset warnings:
$this->warnings = array();
// Fail if we didn't get a valid object:
if (!is_a($marc, 'File_MARC_Record')) {
$this->warn('Must pass a File_MARC_Record object to checkRecord');
} else {
$this->chec... | Check the provided MARC record and return an array of warning messages.
@param File_MARC_Record $marc Record to check
@return array | entailment |
protected function checkDuplicate1xx($marc)
{
$result = $marc->getFields('1[0-9][0-9]', true);
$count = count($result);
if ($count > 1) {
$this->warn(
"1XX: Only one 1XX tag is allowed, but I found $count of them."
);
}
} | Check for multiple 1xx fields.
@param File_MARC_Record $marc Record to check
@return void | entailment |
protected function standardFieldChecks($marc)
{
$fieldsSeen = array();
foreach ($marc->getFields() as $current) {
$tagNo = $current->getTag();
// if 880 field, inherit rules from tagno in subfield _6
if ($tagNo == 880) {
if ($sub6 = $current->getSu... | Check all fields against the standard rules encoded in the class.
@param File_MARC_Record $marc Record to check
@return void | entailment |
protected function checkIndicators($tagNo, $field, $rules)
{
for ($i = 1; $i <= 2; $i++) {
$ind = $field->getIndicator($i);
if ($ind === false || $ind == ' ') {
$ind = 'b';
}
if (!strstr($rules['ind' . $i]['values'], $ind)) {
//... | Check the indicators for the provided field.
@param string $tagNo Tag number being checked
@param File_MARC_Field $field Field to check
@param array $rules Rules to use for checking
@return void | entailment |
protected function checkSubfields($tagNo, $field, $rules)
{
$subSeen = array();
foreach ($field->getSubfields() as $current) {
$code = $current->getCode();
$data = $current->getData();
$subrules = isset($rules['sub' . $code])
? $rules['sub' . $co... | Check the subfields for the provided field.
@param string $tagNo Tag number being checked
@param File_MARC_Field $field Field to check
@param array $rules Rules to use for checking
@return void | entailment |
protected function check020($field)
{
foreach ($field->getSubfields() as $current) {
$data = $current->getData();
// remove any hyphens
$isbn = str_replace('-', '', $data);
// remove nondigits
$isbn = preg_replace('/^\D*(\d{9,12}[X\d])\b.*$/', '$1'... | Looks at 020$a and reports errors if the check digit is wrong.
Looks at 020$z and validates number if hyphens are present.
@param File_MARC_Field $field Field to check
@return void | entailment |
protected function check041($field)
{
// warn if length of each subfield is not divisible by 3 unless ind2 is 7
if ($field->getIndicator(2) != '7') {
foreach ($field->getSubfields() as $sub) {
$code = $sub->getCode();
$data = $sub->getData();
... | Warns if subfields are not evenly divisible by 3 unless second indicator is 7
(future implementation would ensure that each subfield is exactly 3 characters
unless ind2 is 7--since subfields are now repeatable. This is not implemented
here due to the large number of records needing to be corrected.). Validates
against ... | entailment |
protected function check043($field)
{
foreach ($field->getSubfields('a') as $suba) {
// warn if length of subfield a is not exactly 7
$data = $suba->getData();
if (strlen($data) != 7) {
$this->warn("043: Subfield _a must be exactly 7 characters, $data");
... | Warns if each subfield a is not exactly 7 characters. Validates each code
against the MARC code list for Geographic Areas (<http://www.loc.gov/marc/>).
@param File_MARC_Field $field Field to check
@return void | entailment |
protected function check245($field)
{
if (count($field->getSubfields('a')) == 0) {
$this->warn("245: Must have a subfield _a.");
}
// Convert subfields to array and set flags indicating which subfields are
// present while we're at it.
$tmp = $field->getSubfields... | -Makes sure $a exists (and is first subfield).
-Warns if last character of field is not a period
--Follows LCRI 1.0C, Nov. 2003 rather than MARC21 rule
-Verifies that $c is preceded by / (space-/)
-Verifies that initials in $c are not spaced
-Verifies that $b is preceded by :;= (space-colon, space-semicolon,
space-equa... | entailment |
protected function checkArticle($field)
{
// add articles here as needed
// Some omitted due to similarity with valid words (e.g. the German 'die').
static $article = array(
'a' => 'eng glg hun por',
'an' => 'eng',
'das' => 'ger',
'dem' => 'ger... | Check of articles is based on code from Ian Hamilton. This version is more
limited in that it focuses on English, Spanish, French, Italian and German
articles. Certain possible articles have been removed if they are valid
English non-articles. This version also disregards 008_language/041 codes
and just uses the list o... | entailment |
protected function parseRules()
{
// Break apart the rule data on line breaks:
$lines = explode("\n", $this->getRawRules());
// Each group of data is split by a blank line -- process one group
// at a time:
$currentGroup = array();
foreach ($lines as $currentLine) {
... | Support method for constructor to load MARC rules.
@return void | entailment |
protected function processRuleGroup($rules)
{
// The first line is guaranteed to exist and gives us some basic info:
list($tag, $repeatable, $description) = explode(' ', $rules[0]);
$this->rules[$tag] = array(
'repeatable' => $repeatable,
'desc' => $description
... | Support method for parseRules() -- process one group of lines representing
a single tag.
@param array $rules Rule lines to process
@return void | entailment |
protected function getHumanReadableIndicatorValues($rules)
{
// No processing needed for blank rule:
if ($rules == 'blank') {
return $rules;
}
// Create string:
$string = '';
$length = strlen($rules);
for ($i = 0; $i < $length; $i++) {
... | Turn a set of indicator rules into a human-readable list.
@param string $rules Indicator rules
@return string | entailment |
private function readData(string $refName, string $ext) : array
{
$majorReleases = array(
'core' => array(
'classes' => array('4', '5', '7', '71'),
'constants' => array('4', '5', '71'),
'functions' => array('4', '5', '7', '73'),
... | Reads splitted JSON data files | entailment |
public function convertToString($dom){
$html = $this->html5->saveHTML($dom);
$html = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>'."\n".$html;
// Library HTML5 always drop xmlns.
$html = str_replace('<html', '<html xmlns="http://www.w3.org/1999/xhtml"', $html);
// Convert entities
$html = str_rep... | Get HTML5 string
@return string | entailment |
public function saveDom( \DOMDocument $dom, $name ){
return $this->distributor->write($this->convertToString($dom), "OEBPS/Text/{$name}");
} | Save Dom as XHTML file.
@param \DOMDocument $dom
@param string $name
@return bool|string | entailment |
public function extractAssets(\DomDocument &$dom, $tag, $attr, $url_base, $doc_root ){
$paths = [];
foreach( $dom->getElementsByTagName($tag) as $elem ){
list($value) = explode('?', $elem->getAttribute($attr));
if( preg_match($url_base, $value) ){
$path = preg_replace($url_base, $doc_root, $value);
if... | Extract assets
@param \DomDocument $dom
@param string $tag
@param string $attr
@param string $url_base URL base to be replaced with $doc_root
@param string $doc_root
@return array | entailment |
public function pullRemoteAssets(\DomDocument &$dom){
$paths = [];
foreach(['img' => 'src', 'script' => 'src', 'link' => 'href'] as $tag => $attr){
foreach( $dom->getElementsByTagName($tag) as $elem ){
$url = $elem->getAttribute($attr);
if( !preg_match('/^(https?:)?\/\//', $url) ){
continue;
}
... | Extract remote assets and save it
@param \DomDocument $dom
@return array | entailment |
public function grabHeaders(Toc &$toc, &$dom, $add_id = true, $max_depth = 3, $min_level = 1){
$headers = [];
$max_depth = max(1, min($max_depth, 6));
$min_level = max(1, $min_level);
$xpath = new \DOMXPath($dom);
$query = sprintf("//*[%s]", implode(' or ', array_map(function($depth){
return sprintf("name... | @param Toc $toc
@param $dom
@param bool|true $add_id
@param int $max_depth
@param int $min_level
@return array|Toc | entailment |
private function recursiveToc(Toc &$toc, $src, array $headers){
foreach( $headers as $id => $header ){
$child = $toc->addChild($header['content'], $src.'#'.$id);
if( $header['children'] ){
$this->recursiveToc($child, $src, $header['children']);
}
}
} | Recursively add toc
@param Toc $toc
@param string $src
@param array $headers | entailment |
private function digToc($id, array $header, array &$headers){
$keys = array_keys($headers);
krsort($keys);
$done = false;
foreach( $keys as $key ){
if( $headers[$key]['level'] < $header['level'] ){
if( !$this->digToc($id, $header, $headers[$key]['children']) ){
$headers[$key]['children'][$id] = $hea... | Arrange toc elements
@param string $id
@param array $header
@param array $headers
@return bool | entailment |
public function retrieveBody($dom){
if( preg_match('/<body>(.*)<\/body>/s', $this->html5->saveHTML($dom), $match) ){
return $match[1];
}else{
return null;
}
} | @param $dom
@return null | entailment |
public function format($content){
// Add tcy
$content = $this->tcyiz($content);
// Add auto indent
$dom = $this->getDomFromString($content);
foreach( $dom->getElementsByTagName('p') as $p ){
if( !$this->need_indent($p->nodeValue) ){
$this->add_class($p, 'no-indent');
}
}
// Remove all tt, big, a... | Convert xml
@param string $content
@return mixed | entailment |
public function need_indent($string){
$first_letter = mb_substr($string, 0, 1, 'UTF-8');
$match = !preg_match('/[ 【《〔〝『「(”"\'’—\(\)]/u', $first_letter, $matches);
return (bool)$match;
} | Detect if auto-indent required
@param string $string
@return bool | entailment |
public function add_class( \DOMElement &$node, $classes){
$classes = (array)$classes;
if( $node->hasAttribute('class') ){
$classes = array_merge($classes, explode(' ', $node->getAttribute('classs')));
}
$node->setAttribute('class', implode(' ', $classes));
} | Add class to element
@param \DOMElement $node
@param array|string $classes | entailment |
public function getRemote($url){
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 5,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_FAILONERROR => true,
]);
$result = curl_exec($ch);
if( false === $result ){
return false;
}
$return = [
'info' =... | Get remote assets
@param string $url
@return array|false | entailment |
public function parseFromString($string){
$dom = $this->html5->loadHTML($string);
if( is_a($dom, 'DOMDocument') ){
return $dom;
}else{
return false;
}
} | Parse HTML5 and convert to Dom document
@param $string
@return false|\DomDocument | entailment |
function nextRaw()
{
if ($this->type == self::SOURCE_FILE) {
$record = stream_get_line($this->source, File_MARC::MAX_RECORD_LENGTH, File_MARC::END_OF_RECORD);
// Remove illegal stuff that sometimes occurs between records
$record = preg_replace('/^[\\x0a\\x0d\\x00]+/', ""... | Return the next raw MARC record
Returns the next raw MARC record, unless all records already have
been read.
@return string Either a raw record or false | entailment |
private function _decode($text)
{
$marc = new $this->record_class($this);
// fallback on the actual byte length
$record_length = strlen($text);
$matches = array();
if (preg_match("/^(\d{5})/", $text, $matches)) {
// Store record length
$record_length... | Decode a given raw MARC record
Port of Andy Lesters MARC::File::USMARC->decode() Perl function into PHP.
@param string $text Raw MARC record
@return File_MARC_Record Decoded File_MARC_Record object | entailment |
function toXMLFooter()
{
$this->xmlwriter->endElement(); // end collection
$this->xmlwriter->endDocument();
return $this->xmlwriter->outputMemory();
} | Returns the MARCXML collection footer
This method produces an XML representation of a MARC record that
attempts to adhere to the MARCXML standard documented at
http://www.loc.gov/standards/marcxml/
@return string representation of MARC record in MARCXML format | entailment |
public function set($file, $url, $title, $titles, $tocs, $ctime, array $depends)
{
foreach ($tocs as $toc) {
foreach ($toc as $child) {
$this->parents[$child] = $file;
if (isset($this->entries[$child])) {
$this->entries[$child]['parent'] = $fil... | Sets the meta for url, giving the title, the modification time and
the dependencies list | entailment |
public function get($url)
{
if (isset($this->entries[$url])) {
return $this->entries[$url];
} else {
return null;
}
} | Gets the meta for a given document reference url | entailment |
protected function render()
{
$this->display('* Rendering documents');
foreach ($this->documents as $file => &$document) {
$this->display(' -> Rendering '.$file.'...');
$target = $this->getTargetOf($file);
$directory = dirname($target);
if (!is_dir($d... | Renders all the pending documents | entailment |
protected function addToParseQueue($file)
{
$this->states[$file] = self::PARSE;
if (!isset($this->documents[$file])) {
$this->parseQueue[$file] = $file;
}
} | Adding a file to the parse queue | entailment |
protected function parseAll()
{
$this->display('* Parsing files');
while ($file = $this->getFileToParse()) {
$this->display(' -> Parsing '.$file.'...');
// Process the file
$rst = $this->getRST($file);
$parser = new Parser(null, $this->kernel);
... | Parses all the document that need to be parsed | entailment |
public function scan($file)
{
// If no decision is already made about this file
if (!isset($this->states[$file])) {
$this->display(' -> Scanning '.$file.'...');
$this->states[$file] = self::NO_PARSE;
$entry = $this->metas->get($file);
$rst = $this->get... | Scans a file, this will check the status of the file and tell if it
needs to be parsed or not | entailment |
public function scanMetas()
{
$entries = $this->metas->getAll();
foreach ($entries as $file => $infos) {
$this->scan($file);
}
} | Scans all the metas | entailment |
protected function saveMetas()
{
$metas = '<?php return '.var_export($this->metas->getAll(), true).';';
file_put_contents($this->getMetaFile(), $metas);
} | Saving the meta files | entailment |
public function getTargetOf($file)
{
$meta = $this->metas->get($file);
return $this->getTargetFile($meta['url']);
} | Gets the name of a target for a file, for instance /introduction/part1 could
be resolved into /path/to/introduction/part1.html | entailment |
public function getUrl($document)
{
$environment = $document->getEnvironment();
return $environment->getUrl() . '.' . $this->kernel->getFileExtension();
} | Gets the URL of a target file | entailment |
public function doCopy()
{
foreach ($this->toCopy as $copy) {
list($source, $destination) = $copy;
if (!$this->isAbsolute($source)) {
$source = $this->getSourceFile($source);
}
$destination = $this->getTargetFile($destination);
if ... | Run the copy | entailment |
public function copy($source, $destination = null)
{
if ($destination === null) {
$destination = basename($source);
}
$this->toCopy[] = array($source, $destination);
return $this;
} | Add a file to copy | entailment |
public function doMkdir()
{
foreach ($this->toMkdir as $mkdir) {
$dir = $this->getTargetFile($mkdir);
if (!is_dir($dir)) {
mkdir($dir, 0755, true);
}
}
} | Run the directories creation | entailment |
public function run()
{
Yii::$app->response->format = Response::FORMAT_RAW;
(new \elFinderConnector(new \elFinder($this->options)))->run();
} | {@inheritdoc} | entailment |
public function disconnect()
{
if (!$this->isConnected || $this->isDisconnecting) {
return new RejectedPromise(new \LogicException('The client is not connected.'));
}
$this->isDisconnecting = true;
$deferred = new Deferred();
$this->startFlow(new OutgoingDiscon... | Disconnects from a broker.
@return ExtendedPromiseInterface | entailment |
public function subscribe(Subscription $subscription)
{
if (!$this->isConnected) {
return new RejectedPromise(new \LogicException('The client is not connected.'));
}
return $this->startFlow(new OutgoingSubscribeFlow([$subscription], $this->identifierGenerator));
} | Subscribes to a topic filter.
@param Subscription $subscription
@return ExtendedPromiseInterface | entailment |
public function unsubscribe(Subscription $subscription)
{
if (!$this->isConnected) {
return new RejectedPromise(new \LogicException('The client is not connected.'));
}
return $this->startFlow(new OutgoingUnsubscribeFlow([$subscription], $this->identifierGenerator));
} | Unsubscribes from a topic filter.
@param Subscription $subscription
@return ExtendedPromiseInterface | entailment |
public function publish(Message $message)
{
if (!$this->isConnected) {
return new RejectedPromise(new \LogicException('The client is not connected.'));
}
return $this->startFlow(new OutgoingPublishFlow($message, $this->identifierGenerator));
} | Publishes a message.
@param Message $message
@return ExtendedPromiseInterface | entailment |
public function publishPeriodically($interval, Message $message, callable $generator)
{
if (!$this->isConnected) {
return new RejectedPromise(new \LogicException('The client is not connected.'));
}
$deferred = new Deferred();
$this->timer[] = $this->loop->addPeriodicTim... | Calls the given generator periodically and publishes the return value.
@param int $interval
@param Message $message
@param callable $generator
@return ExtendedPromiseInterface | entailment |
private function establishConnection($host, $port, $timeout)
{
$deferred = new Deferred();
$timer = $this->loop->addTimer(
$timeout,
function () use ($deferred, $timeout) {
$exception = new \RuntimeException(sprintf('Connection timed out after %d seconds.', $... | Establishes a network connection to a server.
@param string $host
@param int $port
@param int $timeout
@return ExtendedPromiseInterface | entailment |
private function registerClient(Connection $connection, $timeout)
{
$deferred = new Deferred();
$responseTimer = $this->loop->addTimer(
$timeout,
function () use ($deferred, $timeout) {
$exception = new \RuntimeException(sprintf('No response after %d seconds.... | Registers a new client with the broker.
@param Connection $connection
@param int $timeout
@return ExtendedPromiseInterface | entailment |
private function handleReceive($data)
{
if (!$this->isConnected && !$this->isConnecting) {
return;
}
$flowCount = count($this->receivingFlows);
$packets = $this->parser->push($data);
foreach ($packets as $packet) {
$this->handlePacket($packet);
... | Handles incoming data.
@param string $data | entailment |
private function handlePacket(Packet $packet)
{
switch ($packet->getPacketType()) {
case Packet::TYPE_PUBLISH:
/* @var PublishRequestPacket $packet */
$message = new DefaultMessage(
$packet->getTopic(),
$packet->getPayload()... | Handles an incoming packet.
@param Packet $packet | entailment |
private function handleSend()
{
$flow = null;
if ($this->writtenFlow !== null) {
$flow = $this->writtenFlow;
$this->writtenFlow = null;
}
if (count($this->sendingFlows) > 0) {
$this->writtenFlow = array_shift($this->sendingFlows);
$thi... | Handles outgoing packets. | entailment |
private function handleClose()
{
foreach ($this->timer as $timer) {
$this->loop->cancelTimer($timer);
}
$connection = $this->connection;
$this->isConnecting = false;
$this->isDisconnecting = false;
$this->isConnected = false;
$this->connection = ... | Handles closing of the stream. | entailment |
private function startFlow(Flow $flow, $isSilent = false)
{
try {
$packet = $flow->start();
} catch (\Exception $e) {
$this->emitError($e);
return new RejectedPromise($e);
}
$deferred = new Deferred();
$internalFlow = new ReactFlow($flow,... | Starts the given flow.
@param Flow $flow
@param bool $isSilent
@return ExtendedPromiseInterface | entailment |
private function continueFlow(ReactFlow $flow, Packet $packet)
{
try {
$response = $flow->next($packet);
} catch (\Exception $e) {
$this->emitError($e);
return;
}
if ($response !== null) {
if ($this->writtenFlow !== null) {
... | Continues the given flow.
@param ReactFlow $flow
@param Packet $packet | entailment |
private function finishFlow(ReactFlow $flow)
{
if ($flow->isSuccess()) {
if (!$flow->isSilent()) {
$this->emit($flow->getCode(), [$flow->getResult(), $this]);
}
$flow->getDeferred()->resolve($flow->getResult());
} else {
$result = new ... | Finishes the given flow.
@param ReactFlow $flow | entailment |
public function elementValue(FormRuntime $formRuntime, RootRenderableInterface $element)
{
$request = $formRuntime->getRequest();
/** @var Result $validationResults */
$validationResults = $formRuntime->getRequest()->getInternalArgument('__submittedArgumentValidationResults');
if ($v... | Returns the value of a given Form Element.
If there are validation errors for the element, the previously submitted value will be returned.
@param FormRuntime $formRuntime The current FormRuntime instance
@param RootRenderableInterface $element The element to fetch the value for
@return mixed|null | entailment |
private function getLastSubmittedFormData(ActionRequest $request, string $propertyPath)
{
$submittedArguments = $request->getInternalArgument('__submittedArguments');
if ($submittedArguments === null) {
return null;
}
return ObjectAccess::getPropertyPath($submittedArgumen... | Return the submitted data for a given $propertyPath
@see elementValue()
@param ActionRequest $request
@param string $propertyPath
@return mixed|null | entailment |
public function hasValidationErrors(FormRuntime $formRuntime, RootRenderableInterface $element): bool
{
return $this->getValidationResult($formRuntime, $element)->hasErrors();
} | Whether the given Form Element has validation errors
@param FormRuntime $formRuntime
@param RootRenderableInterface $element
@return bool | entailment |
public function validationErrors(FormRuntime $formRuntime, RootRenderableInterface $element): array
{
return $this->getValidationResult($formRuntime, $element)->getErrors();
} | Returns all validation errors for a given Form Element
@param FormRuntime $formRuntime
@param RootRenderableInterface $element
@return array | entailment |
private function getValidationResult(FormRuntime $formRuntime, RootRenderableInterface $element): Result
{
/** @var Result $validationResults */
$validationResults = $formRuntime->getRequest()->getInternalArgument('__submittedArgumentValidationResults');
if ($validationResults === null) {
... | Retrieves the validation result object for a given Form Element
@see hasValidationErrors()
@see validationErrors()
@param FormRuntime $formRuntime
@param RootRenderableInterface $element
@return Result | entailment |
public function identifier($object): string
{
if (is_array($object) && isset($object['__identity'])) {
return $object['__identity'];
}
if (is_string($object)) {
return $object;
}
if (!is_object($object)) {
return '';
}
retur... | Returns the persistence identifier for a given object (Or an empty string if the given $object is no entity)
@param mixed $object
@return string | entailment |
public function translateAndEscapeProperty(AbstractRenderable $element, string $property): string
{
return $this->escape($this->translateProperty($element, $property));
} | Translates the property of a given Form Element and htmlspecialchar's the result
@param AbstractRenderable $element
@param string $property
@return string | entailment |
public function translateProperty(AbstractRenderable $element, string $property): string
{
if ($property === 'label') {
$defaultValue = $element->getLabel();
if ($defaultValue === null) {
$defaultValue = '';
}
} elseif ($element instanceof FormElem... | Translates the property of a given Form Element
@param AbstractRenderable $element
@param string $property
@return string | entailment |
public function translate(RootRenderableInterface $element, string $translationId, string $defaultValue): string
{
$renderingOptions = $element->getRenderingOptions();
if (!isset($renderingOptions['translationPackage'])) {
return $defaultValue;
}
try {
$transl... | Translates arbitrary $tanslationIds using the package configured in the Form Element's renderingOptions
@param RootRenderableInterface $element
@param string $translationId
@param string $defaultValue
@return string | entailment |
public function run()
{
$id = Yii::$app->request->getQueryParam('id');
$id = Html::encode($id);
$multiple = Yii::$app->request->getQueryParam('multiple');
if (!empty($multiple)) {
$this->settings['commandsOptions']['getfile']['multiple'] = true;
$callback = ... | {@inheritdoc} | entailment |
public static function getFilePickerCallback($url, $popupSettings = [], $view = null)
{
$default = [
'title' => 'elFinder',
'width' => 900,
'height' => 500,
];
$settings = array_merge($default, $popupSettings);
$settings['file'] = Url::to($url);
... | Callback for TinyMCE 4 file_picker_callback
@param array|string $url Url to TinyMCEAction
@param array $popupSettings TinyMCE popup settings
@param \yii\web\View|null $view
@return JsExpression | entailment |
public function generate($random = null) {
$results = [];
$plaintext = $this->_convert($random ?: $this->_random(8));
// String is already normalized by used alphabet.
$part = $try = 0;
while (count($results) < $this->_parts) {
$result = substr($plaintext, $try * $this->_partLength, $this->_partLength - ... | Generates a coupon code using the format `XXXX-XXXX-XXXX`.
The 4th character of each part is a checkdigit.
Not all letters and numbers are used, so if a person enters the letter 'O' we
can automatically correct it to the digit '0' (similarly for I => 1, S => 5, Z
=> 2).
The code generation algorithm avoids 'undesira... | entailment |
public function validate($code) {
$code = $this->_normalize($code, ['clean' => true, 'case' => true]);
if (strlen($code) !== ($this->_parts * $this->_partLength)) {
return false;
}
$parts = str_split($code, $this->_partLength);
foreach ($parts as $number => $part) {
$expected = substr($part, -1);
$... | Validates given code. Codes are not case sensitive and
certain letters i.e. `O` are converted to digit equivalents
i.e. `0`.
@param $code string Potentially unnormalized code.
@return boolean | entailment |
protected function _checkdigitAlg1($partNumber, $value) {
$symbolsFlipped = array_flip($this->_symbols);
$result = $partNumber;
foreach (str_split($value) as $char) {
$result = $result * 19 + $symbolsFlipped[$char];
}
return $this->_symbols[$result % (count($this->_symbols) - 1)];
} | Implements the checkdigit algorithm #1 as used by the original library.
@param integer $partNumber Number of the part.
@param string $value Actual part without the checkdigit.
@return string The checkdigit symbol. | entailment |
public function normalize($string) {
$string = $this->_normalize($string, ['clean' => true, 'case' => true]);
return implode('-', str_split($string, $this->_partLength));
} | Normalizes a given code using dash separators.
@param string $string
@return string | entailment |
protected function _convert($string) {
$symbols = $this->_symbols;
$result = array_map(function($value) use ($symbols) {
return $symbols[ord($value) & (count($symbols) - 1)];
}, str_split(hash('sha1', $string)));
return implode('', $result);
} | Converts givens string using symbols.
@param string $string
@return string | entailment |
protected function _normalize($string, array $options = []) {
$options += [
'clean' => false,
'case' => false
];
if ($options['case']) {
$string = strtoupper($string);
}
$string = strtr($string, [
'I' => 1,
'O' => 0,
'S' => 5,
'Z' => 2,
]);
if ($options['clean']) {
$string = preg_... | Internal method to normalize given strings.
@param string $string
@param array $options
@return string | entailment |
protected function _random($bytes) {
if (is_readable('/dev/urandom')) {
$stream = fopen('/dev/urandom', 'rb');
$result = fread($stream, $bytes);
fclose($stream);
return $result;
}
if (function_exists('mcrypt_create_iv')) {
return mcrypt_create_iv($bytes, MCRYPT_DEV_RANDOM);
}
throw new Excepti... | Generates a cryptographically secure sequence of bytes.
@param integer $bytes Number of bytes to return.
@return string | entailment |
public function process($data)
{
$self = $this;
$environment = $this->parser->getEnvironment();
$span = $this->escape($data);
// Emphasis
$span = preg_replace_callback('/\*\*(.+)\*\*/mUsi', function ($matches) use ($self) {
return $self->strongEmphasis($matches[1]... | Processes some data in the context of the span, this will process the
**emphasis**, the nbsp, replace variables and end-of-line brs | entailment |
public function render()
{
$environment = $this->parser->getEnvironment();
$span = $this->process($this->span);
// Replacing tokens
if ($this->tokens) {
foreach ($this->tokens as $id => $value) {
switch ($value['type']) {
case 'raw':
... | Renders the span | entailment |
public function getHolidaysByYear($year)
{
$easter = $this->getEasterDates($year);
return array(
'01-01' => $this->createData('1. nyttårsdag'),
'05-01' => $this->createData('1. mai'),
'05-17' => $this->createData('Grunnlovsdagen'),
'12-25' => $this->c... | @param int $year
@return mixed | entailment |
private function createSunday($year)
{
$easterSunday = new \DateTime('21.03.' . $year);
$easterSunday->modify(sprintf('+%d days', easter_days($year)));
return $easterSunday;
} | Creating easter sunday
@param $year
@return \DateTime | entailment |
private function createOrthodoxSunday($year)
{
$a = $year % 4;
$b = $year % 7;
$c = $year % 19;
$d = (19 * $c + 15) % 30;
$e = (2 * $a + 4 * $b - $d + 34) % 7;
$month = floor(($d + $e + 114) / 31);
$day = (($d + $e + 114) % 31) + 1;
$sunday = mktime(0... | Creating Orthodox easter sunday
@param $year
@return \DateTime | entailment |
protected function getEasterDates($year, $orthodox = false)
{
$easterSunday = $orthodox ? $this->createOrthodoxSunday($year) : $this->createSunday($year);
$easterSunday->setTimezone(new \DateTimeZone(date_default_timezone_get()));
$easterMonday = clone $easterSunday;
$easterMonday... | Returns all dates calculated by easter sunday
@param int $year
@param boolean $orthodox
@return \DateTime[] | entailment |
public function getParent()
{
if (!$this->currentFileName || !$this->metas) {
return null;
}
$meta = $this->metas->get($this->currentFileName);
if (!$meta || !isset($meta['parent'])) {
return null;
}
$parent = $this->metas->get($meta['parent... | Get my parent metas | entailment |
public function getMyToc()
{
$parent = $this->getParent();
if ($parent) {
foreach ($parent['tocs'] as $toc) {
if (in_array($this->currentFileName, $toc)) {
$before = array();
$after = $toc;
while ($after) {
... | Get the docs involving this document | entailment |
public function registerReference(Reference $reference)
{
$name = $reference->getName();
$this->references[$name] = $reference;
} | Registers a new reference | entailment |
public function resolve($section, $data)
{
if (isset($this->references[$section])) {
$reference = $this->references[$section];
return $reference->resolve($this, $data);
}
$this->errorManager->error('Unknown reference section '.$section);
} | Resolves a reference | entailment |
public function createTitle($level)
{
for ($currentLevel=0; $currentLevel<16; $currentLevel++) {
if ($currentLevel > $level) {
$this->levels[$currentLevel] = 1;
$this->counters[$currentLevel] = 0;
}
}
$this->levels[$level] = 1;
... | Title level | entailment |
public function setLink($name, $url)
{
$name = trim(strtolower($name));
if ($name == '_') {
$name = array_shift($this->anonymous);
}
$this->links[$name] = trim($url);
} | Set the link url | entailment |
public function getLink($name, $relative = true)
{
$name = trim(strtolower($name));
if (isset($this->links[$name])) {
$link = $this->links[$name];
if ($relative) {
return $this->relativeUrl($link);
}
return $link;
}
r... | Get a link value | entailment |
public function relativeUrl($url)
{
// If string contains ://, it is considered as absolute
if (preg_match('/:\\/\\//mUsi', $url)) {
return $url;
}
// If string begins with "/", the "/" is removed to resolve the
// relative path
if (strlen($url) && $url[0... | Resolves a relative URL using directories, for instance, if the
current directory is "path/to/something", and you want to get the
relative URL to "path/to/something/else.html", the result will
be else.html. Else, "../" will be added to go to the upper directory | entailment |
protected function samePrefix($url)
{
$partsA = explode('/', $url);
$partsB = explode('/', $this->currentFileName);
$n = count($partsA);
if ($n != count($partsB)) {
return false;
}
unset($partsA[$n-1]);
unset($partsB[$n-1]);
return $part... | Returns true if the given url have the same prefix as the
current document | entailment |
protected function canonicalize($url)
{
$parts = explode('/', $url);
$stack = array();
foreach ($parts as $part) {
if ($part == '..') {
array_pop($stack);
} else {
$stack[] = $part;
}
}
return implode('/', ... | Canonicalize a path, a/b/c/../d/e will become
a/b/d/e | entailment |
public function canonicalUrl($url)
{
if (strlen($url)) {
if ($url[0] == '/') {
// If the URL begins with a "/", the following is the
// canonical URL
return substr($url, 1);
} else {
// Else, the canonical name is under ... | Gets a canonical URL from the given one | entailment |
public function init()
{
parent::init();
if ($this->connectorRoute === null) {
throw new InvalidConfigException('Connector route must be specified.');
}
$this->settings['url'] = Url::toRoute($this->connectorRoute);
if (!isset($this->settings['lang'])) {
... | {@inheritdoc}
@throws InvalidConfigException | entailment |
public function run()
{
$id = $this->getId();
$view = $this->getView();
if ($this->buttonNoConflict) {
$view->registerJs('if (jQuery.fn.button.noConflict) { jQuery.fn.btn = jQuery.fn.button.noConflict(); }');
}
$bundle = ElFinderAsset::register($view);
... | {@inheritdoc} | entailment |
protected function checkLanguage($language)
{
$full_language = mb_strtolower($language);
$lang = substr($full_language, 0, 2);
if ($lang == 'jp') {
$lang = 'ja';
} elseif ($lang == 'pt') {
$lang = 'pt_BR';
} elseif ($lang == 'ug') {
$lang =... | Set elFinder's correct "lang" param
@param string $language
@return string | entailment |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.