sentence1 stringlengths 52 3.87M | sentence2 stringlengths 1 47.2k | label stringclasses 1
value |
|---|---|---|
public function getPlaceholder($imagestyle_id = null, $absolute = false)
{
$placeholder = $this->getPlaceholderPath();
return $this->getUrl($placeholder, $imagestyle_id, $absolute);
} | Returns a string containing image placeholder URL
@param integer|null $imagestyle_id
@param boolean $absolute
@return string | entailment |
public function getUrl($path, $imagestyle_id = null, $absolute = false)
{
if (empty($path)) {
return $this->getPlaceholder($imagestyle_id, $absolute);
}
if (isset($imagestyle_id)) {
$suffix = preg_replace('/^image\//', '', gplcart_path_normalize($path));
... | Returns a string containing the image cache URL
@param string $path
@param null|string|int $imagestyle_id
@param bool $absolute
@return string | entailment |
public function up()
{
Schema::create('cms_postmeta', function (Blueprint $table) {
$table->bigIncrements('id');
$table->bigInteger('post_id', false, true);
$table->string('meta_key');
$table->longText('meta_value')->nullable();
$table->longText('c... | Run the migrations.
@return void | entailment |
public function registeredToAdmin(array $user)
{
$store = $this->store->get($user['store_id']);
$vars = array(
'@name' => $user['name'],
'@store' => $store['name'],
'@email' => $user['email'],
'@user_id' => $user['user_id'],
'@status' => e... | Sent to an admin when a user has been registered
@param array $user
@return array | entailment |
public function registeredToCustomer(array $user)
{
$store = $this->store->get($user['store_id']);
$options = $this->store->getConfig(null, $store);
$store_name = $this->store->getTranslation('title', $this->translation->getLangcode(), $store);
$base = $this->store->getUrl($store);
... | Sent to the user when his account has been created
@param array $user
@return array | entailment |
public function resetPassword(array $user)
{
$store = $this->store->get($user['store_id']);
$options = $this->store->getConfig(null, $store);
$store_name = $this->store->getTranslation('title', $this->translation->getLangcode(), $store);
$base = $this->store->getUrl($store);
... | Sent when a user wants to reset his password
@param array $user
@return array | entailment |
public function changedPassword(array $user)
{
$store = $this->store->get($user['store_id']);
$options = $this->store->getConfig(null, $store);
$store_name = $this->store->getTranslation('title', $this->translation->getLangcode(), $store);
$vars = array('@store' => $store_name, '@na... | Sent to the user whose password has been changed
@param array $user
@return array | entailment |
public function onWidgetDetailGenerate(WidgetDetailEvent $event)
{
// Share cache directories between users if appropriate.
if ($this->settingsHelper->getShareCaches()) {
$cacheDir = $this->coreParametersHelper->getParameter(
'cached_data_dir',
$this->path... | Set a widget detail when needed.
@param WidgetDetailEvent $event | entailment |
public static function deserializeObject(array $arr)
{
/** @var Filter $result */
$result = parent::deserializeObject($arr);
$result->maxResults = $arr['maxResults'];
return $result;
} | @param array $arr
@return Filter | entailment |
public function getList(array $options = array())
{
$options += array('index' => 'product_bundle_id');
$result = &gplcart_static(gplcart_array_hash(array('product.bundle.list' => $options)));
if (isset($result)) {
return $result;
}
$this->hook->attach('product.... | Returns an array of bundled products
@param array $options
@return array | entailment |
public function set($product_id, array $products)
{
$this->delete(array('product_id' => $product_id));
$added = $count = 0;
foreach ($products as $product) {
$count++;
$data = array(
'product_id' => $product_id,
'item_product_id' => ... | Delete old and add new bundled items for the product
@param int $product_id
@param array $products
@return bool | entailment |
public function getItems($product_id)
{
$product_ids = array();
foreach ($this->getList(array('product_id' => $product_id)) as $item) {
$product_ids[] = $item['item_product_id'];
}
return $product_ids;
} | Returns an array of bundled product IDs for the product
@param int $product_id
@return array | entailment |
public function outputCacheImage()
{
try {
$this->setUrlPathImage();
$this->setFileImage();
$this->setDirectoryImage();
$this->tryOutputImage();
$this->checkCacheDirectoryImage();
$this->applyActionsImage();
$this->tryOutput... | Outputs processed images | entailment |
protected function setUrlPathImage()
{
$parts = explode('files/image/cache/', urldecode(strtok($this->server->requestUri(), '?')));
if (empty($parts[1])) {
throw new OutOfRangeException('Second segment is empty in the image cache path');
}
$parts = explode('/', $parts[1... | Parse the current URL path
@throws OutOfRangeException | entailment |
protected function setDirectoryImage()
{
$imagestyle_directory = GC_DIR_IMAGE_CACHE . "/$this->data_imagestyle_id";
$image_directory = pathinfo($this->data_path, PATHINFO_DIRNAME);
if (!empty($image_directory)) {
$imagestyle_directory = GC_DIR_IMAGE_CACHE . "/$this->data_imagest... | Set the current image style directory | entailment |
protected function tryOutputImage()
{
if (is_file($this->data_cached_file)) {
$this->response->addHeader('Last-Modified', gmdate('D, d M Y H:i:s T', filemtime($this->data_cached_file)))
->addHeader('Content-Length', filesize($this->data_cached_file))
->addHeader(... | Try to output existing image | entailment |
protected function applyActionsImage()
{
$actions = $this->image_style->getActions($this->data_imagestyle_id);
if (empty($actions)) {
throw new RuntimeException('No image style actions to apply');
}
$this->image_style->applyActions($actions, $this->data_source_file, $th... | Apply all defined actions to the source image
@throws RuntimeException | entailment |
public function priceRule(array &$submitted, array $options = array())
{
$this->options = $options;
$this->submitted = &$submitted;
$this->validatePriceRule();
$this->validateName();
$this->validateWeight();
$this->validateBool('status');
$this->validateUsedP... | Performs full price rule validation
@param array $submitted
@param array $options
@return array|boolean | entailment |
protected function validatePriceRule()
{
$id = $this->getUpdatingId();
if ($id === false) {
return null;
}
$data = $this->price_rule->get($id);
if (empty($data)) {
$this->setErrorUnavailable('update', $this->translation->text('Price rule'));
... | Validates a price rule to be updated
@return boolean|null | entailment |
protected function validateValueTypePriceRule()
{
$field = 'value_type';
if ($this->isExcluded($field)) {
return null;
}
$value = $this->getSubmitted($field);
if ($this->isUpdating() && !isset($value)) {
$this->unsetSubmitted($field);
re... | Validates a price rule value type
@return boolean|null | entailment |
protected function validateCodePriceRule()
{
$field = 'code';
$value = $this->getSubmitted($field);
if (empty($value)) {
return null;
}
$updating = $this->getUpdating();
if (isset($updating['code']) && $updating['code'] === $value) {
return ... | Validates a price rule code
@return boolean|null | entailment |
protected function validateValuePriceRule()
{
$field = 'value';
if ($this->isExcluded($field) || $this->isError('value_type')) {
return null;
}
$value = $this->getSubmitted($field);
if ($this->isUpdating() && !isset($value)) {
$this->unsetSubmitted(... | Validates a price rule value
@return boolean|null | entailment |
public function validateValuePercentPriceRule($value)
{
$field = 'value';
$label = $this->translation->text('Value');
if (!is_numeric($value)) {
$this->setErrorNumeric($field, $label);
return false;
}
if ($value == 0 || abs($value) > 100) {
... | Validates the value of percent type
@param string $value
@return boolean | entailment |
public function validateValueFixedPriceRule($value)
{
$field = 'value';
$label = $this->translation->text('Value');
if (!is_numeric($value)) {
$this->setErrorNumeric($field, $label);
return false;
}
if (strlen($value) > 8) {
$this->setErr... | Validates the value of fixed type
@param string $value
@return boolean | entailment |
private function _filter()
{
$html = '';
$search = false;
foreach($this->setting['column'] as $column){
if(isset($column['filter'])){
$search = true;
$html .= '<span style="display: inline-block; margin: 2px 12px 2px 0;">'; // 不换行
$... | 过滤panel的header内容 | entailment |
private function _table()
{
$columnNum = 0; // 列数
$head = '<thead><tr>';
$foot = '<tfoot><tr>';
foreach($this->setting['column'] as $column){
if(!$this->_displayColumn($column)) continue;
$columnNum++;
// 排序
if(isset($column['sort'])){
... | 表格头部和底部 | entailment |
public function listCart()
{
$this->actionListCart();
$this->setTitleListCart();
$this->setBreadcrumbListCart();
$this->setFilterListCart();
$this->setPagerlListCart();
$this->setData('carts', $this->getListCart());
$this->outputListCart();
} | Displays the shopping cart overview page | entailment |
protected function actionListCart()
{
list($selected, $action) = $this->getPostedAction();
$deleted = 0;
foreach ($selected as $id) {
if ($action === 'delete' && $this->access('cart_delete')) {
$deleted += (int) $this->cart->delete($id);
}
}
... | Applies an action to the selected shopping cart items | entailment |
protected function setPagerlListCart()
{
$options = $this->query_filter;
$options['count'] = true;
$total = (int) $this->cart->getList($options);
$pager = array(
'total' => $total,
'query' => $this->query_filter
);
return $this->data_limit = ... | Sets pager
@return array | entailment |
protected function getListCart()
{
$conditions = $this->query_filter;
$conditions['limit'] = $this->data_limit;
$list = (array) $this->cart->getList($conditions);
$this->prepareListCart($list);
return $list;
} | Returns an array of shopping cart items
@return array | entailment |
protected function prepareListCart(array &$items)
{
foreach ($items as &$item) {
$this->setItemUrlEntity($item, $this->store, 'product');
}
} | Prepare an array of cart items
@param array $items | entailment |
public function setJob($job_model)
{
if ($this->isCanceledJob($job_model)) {
return null;
}
$job_id = $this->getQuery('job_id');
if (empty($job_id)) {
return null;
}
$job = $job_model->get($job_id);
if (empty($job['status'])) {
... | Processes the current job
@param \gplcart\core\models\Job $job_model
@return null | entailment |
public function getWidgetJob($job_model, $job = null)
{
if (!isset($job)) {
$job = $job_model->get($this->getQuery('job_id', ''));
}
$rendered = '';
if (!empty($job['status'])) {
$job += array('widget' => 'common/job');
$rendered = $this->render(... | Returns the rendered job widget
@param \gplcart\core\models\Job $job_model
@param null|array $job
@return string | entailment |
public function isCanceledJob($job_model)
{
$cancel_job_id = $this->getQuery('cancel_job');
if (empty($cancel_job_id)) {
return false;
}
$job_model->delete($cancel_job_id);
return true;
} | Whether the current job is canceled
@param \gplcart\core\models\Job $job_model
@return boolean | entailment |
public function getChallenge()
{
if (empty($this->_challenge))
{
$output = $this->postRequest(
'identification/securitytoken/challenge',
[
'useEasyLogin' => false,
'generateEasyLoginId' => false,
... | Fetch control number
For security token with control number and response code.
@return string|null Control number. Null if the security token only requires a generated one time code.
@throws Exception | entailment |
public function login($challengeResponse = '')
{
if (!empty($challengeResponse))
$this->setChallengeResponse($challengeResponse);
if (is_null($this->_challenge))
$this->getChallenge();
if (empty($this->_challengeResponse))
throw new UserException('One ti... | Sign in
It is a good idea to check security token type before sign in with getChallenge() and isUseOneTimePassword().
@param string $challengeResponse One time code or response code from security token
@return bool True on successful sign in
@throws Exception | entailment |
public function set($path, $create = false)
{
$zip = $this->zip;
$flag = $create ? $zip::CREATE : null;
if ($this->zip->open($path, $flag) !== true) {
throw new RuntimeException("Failed to open ZIP file $path");
}
return $this;
} | Sets a file path
@param string $path
@param bool $create
@throws RuntimeException
@return $this | entailment |
public function directory($source, $destination, $wrapper = '')
{
$files = gplcart_file_scan_recursive($source);
if (empty($files)) {
return false;
}
$this->set($destination, true);
$added = 0;
foreach ($files as $file) {
if (is_dir($file))... | Zip a whole folder
@param string $source
@param string $destination
@param string $wrapper Wrapping local directory in the archive
@return boolean | entailment |
public function file($source, $destination)
{
settype($source, 'array');
$this->set($destination, true);
$added = 0;
foreach ($source as $file) {
$added += (int) $this->zip->addFile($file, basename($file));
}
$this->zip->close();
return count($... | Create a ZIP archive
@param array|string $source
@param string $destination
@return bool | entailment |
public function extract($path, $files = array())
{
if (empty($files)) {
return $this->zip->extractTo($path);
}
return $this->zip->extractTo($path, $files);
} | Extract the complete archive or the given files to the specified destination
@param string $path
@param array $files
@return boolean | entailment |
public function getList()
{
$items = array();
for ($i = 0; $i < $this->zip->numFiles; $i++) {
$items[] = $this->zip->getNameIndex($i);
}
return $items;
} | Returns an array of files in the archive
@return array | entailment |
public function getMeta($file)
{
$content = file_get_contents($file);
$matches = array();
preg_match('~<!--(.*?)-->~msi', $content, $matches);
if (empty($matches[1])) {
return array();
}
$meta = json_decode(trim($matches[1]), true);
if (!is_arr... | Extracts meta data from a help file
@param string $file
@return array | entailment |
public function get($file)
{
$result = null;
$this->hook->attach('help.get.before', $file, $result, $this);
if (isset($result)) {
return (array) $result;
}
$result = $this->getMeta($file);
if (empty($result)) {
return array();
}
... | Returns an array of help data from the file
@param string $file
@return array | entailment |
public function getList($langcode = '')
{
if (empty($langcode)) {
$langcode = 'en';
}
$result = &gplcart_static("help.list.$langcode");
if (isset($result)) {
return $result;
}
$this->hook->attach('help.list.before', $langcode, $result, $this... | Returns an array of help items
@param string
@return array | entailment |
public function getByPattern($pattern, $langcode)
{
$prepared = strtr($pattern, array('/' => '-', '*' => '_', '/*' => '_'));
foreach (array($langcode, 'en') as $code) {
$dir = $this->getDirectory($code);
if (is_file("$dir/$prepared.php")) {
return $this->get(... | Returns a help data using a simple path pattern, e.g admin/*
@param string $pattern
@param string $langcode
@return array | entailment |
public function parse($file)
{
$result = null;
$this->hook->attach('help.render.before', $file, $result, $this);
if (isset($result)) {
return (string) $result;
}
$result = $this->markdown->render(file_get_contents($file));
$this->hook->attach('help.rende... | Render a help file
@param string $file
@return string | entailment |
public function getElements()
{
if (self::$elements === null) {
self::$elements = $this->loadJson($this->resource('OptionalElements.json'))->elements;
}
return self::$elements;
} | Get the optional html elments.
@throws \ArjanSchouten\HtmlMinifier\Exception\FileNotFoundException
@return mixed | entailment |
public static function calculateHashSecure($jumpUrl, $locationData, $mimeType)
{
$data = [(string)$jumpUrl, (string)$locationData, (string)$mimeType];
return GeneralUtility::hmac(serialize($data));
} | Calculates the hash for the given jump URL secure data.
@param string $jumpUrl The URL to the file
@param string $locationData Information about the record that rendered the jump URL, format is [pid]:[table]:[uid]
@param string $mimeType Mime type of the file or an empty string
@return string The calculated hash | entailment |
public function process(MinifyContext $context)
{
$context->setContents($this->trailingWhitespaces($context->getContents()));
$context->setContents($this->runMinificationRules($context->getContents()));
$context->setContents($this->removeSpacesAroundPlaceholders($context->getContents()));
... | Minify redundant whitespaces.
@param \ArjanSchouten\HtmlMinifier\MinifyContext $context
@return \ArjanSchouten\HtmlMinifier\MinifyContext | entailment |
public function runMinificationRules($contents)
{
do {
$originalContents = $contents;
$contents = preg_replace(array_keys($this->minifyRules), array_values($this->minifyRules), $contents);
} while ($originalContents != $contents);
return $contents;
} | Loop over the minification rules as long as changes in output occur.
@param string $contents
@return string | entailment |
public function maxHtmlLineLength($contents, $maxHtmlLineLength)
{
if (strlen($contents) <= $maxHtmlLineLength) {
return $contents;
}
$result = '';
$splits = str_split($contents, $maxHtmlLineLength);
foreach ($splits as $split) {
$pos = strrpos($split... | Old browsers, firewalls and more can't handle to long lines.
Therefore add a linebreak after specified character length.
@param int $maxHtmlLineLength
@param string $contents
@return string | entailment |
public function process($context, $url, array $configuration, ContentObjectRenderer $contentObjectRenderer, &$keepProcessing)
{
if (!$this->isEnabled($context, $configuration)) {
return $url;
}
$this->contentObjectRenderer = $contentObjectRenderer;
// Strip the absRefPr... | Generates the JumpURL for the given parameters.
@see \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::processUrlModifiers()
@param string $context The context in which the URL is generated (e.g. "typolink").
@param string $url The URL that should be processed.
@param array $configuration The link configuration... | entailment |
protected function isEnabled($context, array $configuration = [])
{
if (!empty($configuration['jumpurl.']['forceDisable'])) {
return false;
}
$enabled = !empty($configuration['jumpurl']);
// if jumpurl is explicitly set to 0 we override the global configuration
... | Returns TRUE if jumpurl was enabled in the global configuration
or in the given configuration
@param string $context separate check for the MAIL context needed
@param array $configuration Optional jump URL configuration
@return bool TRUE if enabled, FALSE if disabled | entailment |
protected function build($url, array $configuration)
{
$urlParameters = ['jumpurl' => $url];
// see if a secure File URL should be built
if (!empty($configuration['secure'])) {
$secureParameters = $this->getParametersForSecureFile(
$url,
isset($co... | Builds a jump URL for the given URL
@param string $url The URL to which will be jumped
@param array $configuration Optional TypoLink configuration
@return string The generated URL | entailment |
protected function getParametersForSecureFile($jumpUrl, array $configuration)
{
$parameters = [
'juSecure' => 1,
'locationData' => $this->getTypoScriptFrontendController()->id . ':' . $this->getContentObjectRenderer()->currentRecord
];
$pathInfo = pathinfo($jumpUrl);... | Returns a URL parameter array containing parameters for secure downloads by "jumpurl".
Helper function for filelink()
The array returned has the following structure:
juSecure => is always 1,
locationData => information about the record that created the jumpUrl,
juHash => the hash that will be checked before the file i... | entailment |
protected function getTypoLinkParameter(array $configuration)
{
$linkParameter = $this->getContentObjectRenderer()->stdWrapValue('parameter', $configuration);
if (empty($linkParameter)) {
$frontendController = $this->getTypoScriptFrontendController();
$linkParameter = $front... | Checks if an alternative link parameter was configured and if not
a default parameter will be generated based on the current page
ID and type.
When linking to a file this method is needed
@param array $configuration Data from the TypoLink jumpurl configuration
@return string The parameter for the jump URL TypoLink | entailment |
public function run(MinifyContext $context, $options = [])
{
$context->addMinificationStep($context->getContents(), 'Initial step');
$context = $this->placeholders($context);
$context = $this->minifiers($context, $options);
return $this->restore($context);
} | @param \ArjanSchouten\HtmlMinifier\MinifyContext $context
@param array $options
@return \ArjanSchouten\HtmlMinifier\MinifyContext | entailment |
protected function placeholders(MinifyContext $context)
{
foreach ($this->placeholders as $placeholder) {
$placeholder = new $placeholder();
$context = $placeholder->process($context);
}
return $context;
} | @param \ArjanSchouten\HtmlMinifier\MinifyContext $context
@return \ArjanSchouten\HtmlMinifier\MinifyContext | entailment |
protected function minifiers(MinifyContext $context, $options = [])
{
foreach ($this->minifiers as $minifier) {
$minifier = new $minifier();
$provides = $minifier->provides();
if ($this->runAll($options) || $this->isOptionSet($provides, $options)) {
$cont... | @param \ArjanSchouten\HtmlMinifier\MinifyContext $context
@param array $options
@return \ArjanSchouten\HtmlMinifier\MinifyContext | entailment |
protected function isOptionSet($provides, $options = [])
{
if (isset($options[$provides]) && $options[$provides] === true) {
return true;
} elseif (!isset($options[$provides]) && Options::options()[$provides]->isDefault()) {
return true;
}
return false;
} | Check whether an option is set in the options aray.
@param string $provides
@param array $options
@return bool | entailment |
protected function restore(MinifyContext $context)
{
$withoutPlaceholders = $context->getPlaceholderContainer()->restorePlaceholders($context->getContents());
return $context->setContents($withoutPlaceholders);
} | Restore placeholders with their original content.
@param \ArjanSchouten\HtmlMinifier\MinifyContext $context
@return \ArjanSchouten\HtmlMinifier\MinifyContext | entailment |
public function addPlaceholder($placeholder)
{
if (!isset(class_implements($placeholder)[PlaceholderInterface::class])) {
throw new InvalidArgumentException('The class ['.$placeholder.'] should be a member of the ['.PlaceholderInterface::class.']');
} elseif (in_array($placeholder, $this... | Add a placeholder strategy to the registered placeholders.
@param string $placeholder
@return \ArjanSchouten\HtmlMinifier\Placeholders\PlaceholderInterface[] | entailment |
public function addMinifier($minifier)
{
if (!isset(class_implements($minifier)[MinifierInterface::class])) {
throw new InvalidArgumentException('The class ['.$minifier.'] should be a member of the ['.MinifierInterface::class.']');
} elseif (in_array($minifier, $this->minifiers)) {
... | Add a placeholder strategy to the registered placeholders.
@param string $minifier
@return \ArjanSchouten\HtmlMinifier\Minifiers\MinifierInterface[] | entailment |
private function getClassName($object)
{
$class = get_class($object);
if (($index = strrpos($class, '\\'))) {
$fixForTrailingBackslash = 1;
return substr($class, $index + $fixForTrailingBackslash);
}
return $class;
} | Get the classname without the namespace.
@param $object
@return string | entailment |
public function toJson()
{
$contents = array();
foreach ($this->data as $key => $value) {
$outputKey = $this->outputKeys[$key];
$contents[] = sprintf('"%s":%s', $outputKey, $value->toJson());
}
return sprintf("{%s}", implode(",", $contents));
} | /*
========== IDataType ========== | entailment |
public function process(MinifyContext $context)
{
return $context->setContents(preg_replace_callback(
'/
<! # search for the start of a comment
[^>]* # search for everything without a ">"
> # match the end of the comment
... | Replace remaining comments.
@param \ArjanSchouten\HtmlMinifier\MinifyContext $context
@return \ArjanSchouten\HtmlMinifier\MinifyContext | entailment |
public function offsetExists($offset)
{
$offset = $this->convertOffset($offset);
$this->checkOffset($offset);
return isset($this->data[$offset]);
} | /*
========== ArrayAccess ========== | entailment |
public function process($context)
{
$contents = $context->getContents();
$contents = preg_replace_callback('/<\?=((?!\?>).)*\?>/s', function ($match) use ($context) {
return $context->getPlaceholderContainer()->createPlaceholder($match[0]);
}, $contents);
$contents = preg... | Replace PHP tags with a temporary placeholder.
@param \ArjanSchouten\HtmlMinifier\MinifyContext $context
@return \ArjanSchouten\HtmlMinifier\MinifyContext | entailment |
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$this->currentFile = $phpcsFile;
$tokens = $phpcsFile->getTokens();
$type = strtolower($tokens[$stackPtr]['content']);
$errorData = array($type);
$find = PHP_CodeSniffer_Tokens::$methodPrefixes;... | Processes this test, when one of its tokens is encountered.
@param PHP_CodeSniffer_File $phpcsFile The file being scanned.
@param int $stackPtr The position of the current token
in the stack passed in $tokens.
@return void | entailment |
public function call($callback, array $parameters = [])
{
$this->_events[] = $event = new CallbackEvent($callback, $parameters);
return $event;
} | Add a new callback event to the schedule.
@param string $callback
@param array $parameters
@return Event | entailment |
public function process($context)
{
$context->setContents($this->setCDataPlaceholder($context->getContents(), $context->getPlaceholderContainer()));
return $context->setContents($this->setConditionalCommentsPlaceholder($context->getContents(), $context->getPlaceholderContainer()));
} | Replace critical content with a temp placeholder for integrity.
@param \ArjanSchouten\HtmlMinifier\MinifyContext $context
@return \ArjanSchouten\HtmlMinifier\MinifyContext | entailment |
protected function setCDataPlaceholder($contents, PlaceholderContainer $placeholderContainer)
{
return preg_replace_callback('/<!\[CDATA\[((?!\]\]>).)*\]\]>/s', function ($match) use ($placeholderContainer) {
return $placeholderContainer->createPlaceholder($match[0]);
}, $contents);
... | Replace CData with a temporary placeholder.
@param string $contents
@param \ArjanSchouten\HtmlMinifier\PlaceholderContainer $placeholderContainer
@return string | entailment |
protected function setConditionalCommentsPlaceholder($contents, PlaceholderContainer $placeholderContainer)
{
return preg_replace_callback(
'/
(
<! # Match the start of a comment
(-{2})? # IE can understand comm... | Replace conditional placeholders used by Internet Explorer.
@param string $contents
@param \ArjanSchouten\HtmlMinifier\PlaceholderContainer $placeholderContainer
@return string | entailment |
public function addMinificationStep($input, $keyName = null)
{
if ($this->statistics === null) {
$this->statistics = new Statistics($input, $keyName);
return;
}
$this->statistics->createReferencePoint($this->placeholderContainer->getContentSize($input), $keyName);
... | Add a minification step.
@param string $input
@param string $keyName | entailment |
public function restorePlaceholders($contents)
{
foreach ($this->all() as $placeholder => $original) {
$contents = str_replace($placeholder, $original, $contents);
}
return $contents;
} | @param string $contents
@return string | entailment |
public function addPlaceholder($value, $content)
{
$placeholder = $this->createPlaceholder($value);
return str_replace($value, $placeholder, $content);
} | Replace ```$value``` with a placeholder and store it in the container.
@param string $value
@param string $content
@return string $contents | entailment |
public function createPlaceholder($value)
{
if (($key = array_search($value, $this->all()))) {
$placeholder = $key;
} else {
$placeholder = $this->createUniquePlaceholder();
}
$value = $this->removeNestedPlaceholders($value);
$this->items[$placeholder... | Create a unique placeholder for the given contents.
@param string $value
@return string $placeholder | entailment |
public function getContentSize($contentsWithPlaceholders)
{
$placeholderSize = $this->map(function ($value, $key) use (&$contentsWithPlaceholders){
$count = substr_count($contentsWithPlaceholders, $key);
return strlen($key) * $count - strlen($value) * $count;
})->sum();
... | Calculate the byte size of the placeholders.
@param string $contentsWithPlaceholders
@return int | entailment |
protected function removeNestedPlaceholders($originalContent)
{
return preg_replace_callback('/'.Constants::PLACEHOLDER_PATTERN.'/', function ($match) {
return $this->pull($match[0]);
}, $originalContent);
} | Remove nested placeholders so no nested placholders remain in the original contents.
@param string $originalContent
@return string | entailment |
public static function newResources($credentials)
{
if ((!isset($credentials[self::USERNAME])) || (!isset($credentials[self::PASSWORD]))) {
throw new Exception('Invalid credentials');
}
$restClient = new Client($credentials[self::USERNAME], $credentials[self::PASSWORD]);
... | Creates a new Resources object
Creates a new Rest Client based on the credentials
and returns a new Resources instance based on that Rest Client instance.
@param array $credentials
@return IResources
@throws Exception | entailment |
public static function options()
{
if (self::$options === null) {
self::$options = [
self::WHITESPACES => new Option(self::WHITESPACES, 'Remove redundant whitespaces', true),
self::COMMENTS => new Option(self::COMMENTS, 'Remove comments', true),
... | Get all the options available for this minifier.
@return array | entailment |
private function createFlagDefinition($name, Reference $reference, $default)
{
return new Definition(
Flag::class,
[
(string) $name,
$reference,
(bool) $default
]
);
} | @param string $name
@param Reference $reference
@param bool $default
@return Definition | entailment |
public function process(MinifyContext $context)
{
return $context->setContents(preg_replace_callback(
'/
(\s*'.Constants::ATTRIBUTE_NAME_REGEX.'\s*) # Match the attribute name
=\s* # Match the equal sign with optional... | Execute the minification rule.
@param \ArjanSchouten\HtmlMinifier\MinifyContext $context
@return \ArjanSchouten\HtmlMinifier\MinifyContext | entailment |
private function isBooleanAttribute($attribute)
{
return array_search(trim($attribute), $this->repository->getAttributes()) || Html::isDataAttribute($attribute);
} | Check if an attribute is a boolean attribute.
@param string $attribute
@return bool | entailment |
public function process(MinifyContext $context)
{
return $context->setContents(preg_replace_callback(
'/
= # start matching by a equal sign
\s* # its valid to use whitespaces after the equals sign
(["\'])? # match a single or d... | Execute the minification rule.
@param \ArjanSchouten\HtmlMinifier\MinifyContext $context
@return \ArjanSchouten\HtmlMinifier\MinifyContext | entailment |
protected function minifyAttribute($match)
{
if (Str::contains($match[2], $this->prohibitedChars)) {
return $match[0];
} elseif (preg_match('/'.Constants::PLACEHOLDER_PATTERN.'/is', $match[2])) {
return $match[0];
}
return '='.$match[2];
} | Minify the attribute quotes if allowed.
@param array $match
@return string | entailment |
protected function offsetIsAllowed($offset)
{
return (is_null($offset) || (((string)(int)$offset) == $offset) || is_int($offset));
} | /*
========== MagicArray ========== | entailment |
public function toJson()
{
$contents = array();
foreach ($this->data as $value) {
$contents[] = $value->toJson();
}
return sprintf("[%s]", implode(",", $contents));
} | /*
========== IDataType ========== | entailment |
protected function processReturn(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $commentStart)
{
$tokens = $phpcsFile->getTokens();
// Skip constructor and destructor.
$methodName = $phpcsFile->getDeclarationName($stackPtr);
$isSpecialMethod = ($methodName === '__construct' || $me... | Process the return comment of this function comment.
@param PHP_CodeSniffer_File $phpcsFile The file being scanned.
@param int $stackPtr The position of the current token
in the stack passed in $tokens.
@param int $commentStart The position in the stack where the comment starte... | entailment |
protected function functionHasReturnStatement(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $continueSearch = null)
{
$tokens = $phpcsFile->getTokens();
$sFunctionToken = $tokens[$stackPtr];
$returnStatement = false;
if (isset($sFunctionToken['scope_closer']) and isset($sFunctionToken... | Search if Function has a Return Statement
@param PHP_CodeSniffer_File $phpcsFile The file being scanned.
@param int $stackPtr The position of the current token
in the stack passed in $tokens.
@param int $continueSearch If found a return in Condition of a closure
than contin... | entailment |
protected function isInterface(PHP_CodeSniffer_File $phpcsFile) {
$checkFile = "". $phpcsFile->getFilename();
if (isset($this->isFileInterface[$checkFile])) {
return (bool) $this->isFileInterface[$checkFile];
}
$interface = $phpcsFile->findNext(T_INTERFACE, 0);
retu... | Test if this a PHP Interface File
@param PHP_CodeSniffer_File $phpcsFile
@return bool | entailment |
public function process(MinifyContext $context)
{
$elements = (new OptionalElementsRepository())->getElements();
$contents = $context->getContents();
foreach ($elements as $element) {
$contents = $this->removeElement($element, $contents);
}
return $context->setC... | Execute the minification rule.
@param \ArjanSchouten\HtmlMinifier\MinifyContext $context
@return \ArjanSchouten\HtmlMinifier\MinifyContext | entailment |
protected function removeElement($element, $contents)
{
$newContents = preg_replace('@'.$element->regex.'@xi', '', $contents);
if ($newContents !== $contents && isset($element->elements)) {
foreach ($element->elements as $element) {
$newContents = $this->removeElement($e... | Remove an optional element.
@param object $element
@param string $contents
@return string | entailment |
public function process(MinifyContext $context)
{
$contents = preg_replace_callback(
'/'.
Constants::$htmlEventNamePrefix.Constants::ATTRIBUTE_NAME_REGEX.' # Match an on{attribute}
\s*=\s* # Match equals sign with optional whitespaces around it
... | Minify javascript prefixes on html event attributes.
@param \ArjanSchouten\HtmlMinifier\MinifyContext $context
@return \ArjanSchouten\HtmlMinifier\MinifyContext | entailment |
public function process($context)
{
$contents = $context->getContents();
$contents = $this->whitespaceBetweenInlineElements($contents, $context->getPlaceholderContainer());
$contents = $this->whitespaceInInlineElements($contents, $context->getPlaceholderContainer());
$contents = $th... | Replace critical content with a temporary placeholder.
@param \ArjanSchouten\HtmlMinifier\MinifyContext $context
@return \ArjanSchouten\HtmlMinifier\MinifyContext | entailment |
protected function whitespaceBetweenInlineElements($contents, PlaceholderContainer $placeholderContainer)
{
$elementsRegex = $this->getInlineElementsRegex();
return preg_replace_callback(
'/
(
<('.$elementsRegex.') # Match the start tag and capt... | Whitespaces between inline html elements must be replaced with a placeholder because
a browser is showing that whitespace.
@param string $contents
@param \ArjanSchouten\HtmlMinifier\PlaceholderContainer $placeholderContainer
@return string | entailment |
protected function whitespaceInInlineElements($contents, PlaceholderContainer $placeholderContainer)
{
$elementsRegex = $this->getInlineElementsRegex();
return preg_replace_callback(
'/
(
<('.$elementsRegex.') # Match an inline element
... | Whitespaces in an inline element have a function so we replace it.
@param string $contents
@param \ArjanSchouten\HtmlMinifier\PlaceholderContainer $placeholderContainer
@return string | entailment |
private function replaceWhitespacesInInlineElements($element, PlaceholderContainer $placeholderContainer)
{
return preg_replace_callback('/>\s/', function ($match) use ($placeholderContainer) {
return '>'.$placeholderContainer->createPlaceholder(' ');
}, $element);
} | Replace the whitespaces in inline elements with a placeholder.
@param string $element
@param \ArjanSchouten\HtmlMinifier\PlaceholderContainer $placeholderContainer
@return string | entailment |
protected function replaceElementContents($contents, PlaceholderContainer $placeholderContainer)
{
$htmlTags = implode('|', $this->htmlPlaceholderTags);
$pattern = '/
(
<(' . $htmlTags . ') # Match html start tag and capture
(?:
... | @param string $contents
@param \ArjanSchouten\HtmlMinifier\PlaceholderContainer $placeholderContainer
@return string | entailment |
public function getAttributes()
{
if (self::$attributes === null) {
self::$attributes = $this->loadJson($this->resource('HtmlBooleanAttributes.json'))->attributes;
}
return self::$attributes;
} | Get the html boolean attributes.
@throws \ArjanSchouten\HtmlMinifier\Exception\FileNotFoundException
@return \Illuminate\Support\Collection | entailment |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.