sentence1 stringlengths 52 3.87M | sentence2 stringlengths 1 47.2k | label stringclasses 1
value |
|---|---|---|
public function isEligible(PromotionSubjectInterface $subject, array $configuration)
{
if (!$subject instanceof OrderInterface) {
throw new UnsupportedTypeException($subject, OrderInterface::class);
}
if (null === $address = $subject->getShippingAddress()) {
return f... | {@inheritdoc} | entailment |
public function releaseLock($name)
{
if (isset($this->locks[$name]) && $this->memcached->delete($name)) {
unset($this->locks[$name]);
return true;
}
return false;
} | Release lock
@param string $name name of lock
@return bool | entailment |
public function bootstrap($app)
{
$models = Yii::$app->getModule('vote')->models;
foreach ($models as $value) {
$modelId = Rating::getModelIdByName($value);
$modelName = Rating::getModelNameById($modelId);
Event::on($modelName::className(), $modelName::EVENT_INIT, function ($event) {
if (null ==... | Bootstrap method to be called during application bootstrap stage.
@param Application $app the application currently running | entailment |
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('enhavo_grid');
$rootNode
->children()
->arrayNode('render')
->children()
->arrayNode('sets')
... | {@inheritDoc} | entailment |
public function getBackButton(bool $json_serialized = true)
{
// Create the button
$inline_keyboard = [ 'inline_keyboard' =>
[
[
[
'text' => $this->bot->local->getStr('Back_Button'),
'callback_data' => 'b... | \brief Get a simple Back button with back as <code>callback_data</code>.
@param $json_serialized return a json serialized string, or an array.
@return string|array A button with written "back". | entailment |
public function getBackSkipKeyboard(bool $json_serialized = true)
{
// Create the keyboard
$inline_keyboard = [ 'inline_keyboard' =>
[
[
[
'text' => $this->bot->local->getStr('Back_Button'),
'callback_dat... | \brief Get a Back and a Skip buttons inthe same row.
\details Back button has callback_data "back" and Skip button has callback_data "skip".
@param bool $json_serialized return a json serialized string, or an array.
@return string|array A button with written "back" and one with written "Skip". | entailment |
public function getChooseLanguageKeyboard(string $prefix = 'cl', bool $json_serialized = true)
{
$inline_keyboard = ['inline_keyboard' => array()];
// $bot->local is an object of type Localization
// $local->local is the array where the localizated strings are saved
... | \brief Get various buttons for set various languages.
\details Create a button for each language contained in <code>$localization['languages']</code> variable of $bot object.
There will be a button per row.
The button's label will include the target language and the current one.
The callback data for each button will ... | entailment |
public function addToc(\Enhavo\Bundle\ProjectBundle\Entity\Content $toc)
{
$toc->setMagazine($this);
$this->toc[] = $toc;
return $this;
} | Add toc
@param \Enhavo\Bundle\ProjectBundle\Entity\Content $toc
@return Magazine | entailment |
public function removeToc(\Enhavo\Bundle\ProjectBundle\Entity\Content $toc)
{
$toc->setMagazine(null);
$this->toc->removeElement($toc);
} | Remove toc
@param \Enhavo\Bundle\ProjectBundle\Entity\Content $toc | entailment |
public function addPicture(\Enhavo\Bundle\MediaBundle\Entity\File $pictures)
{
$this->pictures[] = $pictures;
return $this;
} | Add pictures
@param \Enhavo\Bundle\MediaBundle\Entity\File $pictures
@return Magazine | entailment |
public function removePicture(\Enhavo\Bundle\MediaBundle\Entity\File $pictures)
{
$this->pictures->removeElement($pictures);
} | Remove pictures
@param \Enhavo\Bundle\MediaBundle\Entity\File $pictures | entailment |
public function offsetGet($offset)
{
// Get name of the method, the class should have. Like "getText"
$method = Text::camelCase("get $offset");
// If it exists, call it and return its return value
if (method_exists($this, $method)) {
return $this->{$method}();
}
... | \brief Get the given offset.
@param $offset The given offset.
@return Data relative to the offset. | entailment |
public function oldDispatch()
{
// For each update type
foreach (BasicBot::$update_types as $offset => $class) {
// Check if the bot has an inherited method
if (method_exists($this, 'process' . $class)) {
// Wrap it in a closure to make it works with the 3.0 v... | \brief Set compatibilityu mode for old processes method.
\details If your bot uses `processMessage` or another deprecated function, call this method to make the old version works. | entailment |
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->addModelTransformer(new CallbackTransformer(
function ($originalDescription) use ($options) {
if(true === $originalDescription) {
return self::VALUE_TRUE;
}
... | {@inheritdoc} | entailment |
public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->vars['message'] = $this->translator->trans($options['message'], $options['parameters'], $options['translation_domain']);
$view->vars['type'] = $options['type'];
} | {@inheritdoc} | entailment |
public function setChatLog(string $chat_id, bool $skip_check = false)
{
// Check that the bot can write in that chat
if (!$skip_check && $this->getChat($chat_id) !== false) {
$this->chat_log = $chat_id;
}
} | \brief Set chat_id choosed for logging.
@param string $chat_id Chat_id choosed.
@param bool $skip_check Skip checking if the chat is valid (set true only if the bot is using webhook to get updates). | entailment |
public function addChild(\Enhavo\Bundle\NavigationBundle\Model\NodeInterface $children)
{
$this->children[] = $children;
$children->setParent($this);
return $this;
} | Add children
@param \Enhavo\Bundle\NavigationBundle\Model\NodeInterface $children
@return Node | entailment |
public function removeChild(\Enhavo\Bundle\NavigationBundle\Model\NodeInterface $children)
{
$children->setParent(null);
$this->children->removeElement($children);
} | Remove children
@param \Enhavo\Bundle\NavigationBundle\Model\NodeInterface $children | entailment |
public function setParent(\Enhavo\Bundle\NavigationBundle\Model\NodeInterface $parent = null)
{
$this->parent = $parent;
return $this;
} | Set parent
@param \Enhavo\Bundle\NavigationBundle\Model\NodeInterface $parent
@return Node | entailment |
protected function generateAnnotations() {
// set-up the dispatcher
$dispatcherInstance = Dispatcher::getInstance();
// note the start of the operation
$dispatcherInstance->dispatch("builder.generateAnnotationsStart");
// default var
$publicDir = Config::getOption("publicDir");
// encode the content s... | Generates the annotations js file | entailment |
protected function generateIndex() {
/**
* Handle missing index.html. Solves https://github.com/drupal-pattern-lab/patternlab-php-core/issues/14
* Could also be used to re-add missing styleguidekit assets with a few edits?
*
* 1. @TODO: Figure out a better way to future-proof path resolution for style... | Generates the data that powers the index page | entailment |
protected function generatePatterns($options = array()) {
// set-up the dispatcher
$dispatcherInstance = Dispatcher::getInstance();
// note the beginning of the operation
$dispatcherInstance->dispatch("builder.generatePatternsStart");
// set-up common vars
$exportFiles = (isset($options["exportFiles... | Generates all of the patterns and puts them in the public directory
@param {Array} various options that might affect the export. primarily the location. | entailment |
protected function generateStyleguide() {
// set-up the dispatcher
$dispatcherInstance = Dispatcher::getInstance();
// note the beginning of the operation
$dispatcherInstance->dispatch("builder.generateStyleguideStart");
// default var
$publicDir = Config::getOption("publicDir");
// load the pattern l... | Generates the style guide view | entailment |
protected function generateViewAllPages() {
// set-up the dispatcher
$dispatcherInstance = Dispatcher::getInstance();
// note the beginning of the operation
$dispatcherInstance->dispatch("builder.generateViewAllPagesStart");
// default vars
$patternPublicDir = Config::getOption("patternPublicDir");
$ht... | Generates the view all pages | entailment |
public function beforeValidate()
{
foreach ($this->attributes as $attribute) {
$this->owner->$attribute = HtmlPurifier::process($this->owner->$attribute, $this->config);
}
} | Before validate event | entailment |
public static function updateChangeTime() {
if (is_dir(Config::getOption("publicDir"))) {
file_put_contents(Config::getOption("publicDir")."/latest-change.txt",time());
} else {
Console::writeError("the public directory for Pattern Lab doesn't exist...");
}
} | Write out the time tracking file so the content sync service will work. A holdover
from how I put together the original AJAX polling set-up. | entailment |
public function create(UserInterface $user)
{
if($user == null || $user->getAuthIdentifier() == null) {
return false;
}
$token = $this->generateAuthToken();
$token->setAuthIdentifier( $user->getAuthIdentifier() );
$t = new \DateTime;
$insertData = array_merge($token->toArray(), array(
... | Creates an auth token for user.
@param \Illuminate\Auth\UserInterface $user
@return \TAppleby\AuthToken\AuthToken|false | entailment |
public function find($serializedAuthToken)
{
$authToken = $this->deserializeToken($serializedAuthToken);
if($authToken == null) {
return null;
}
if(!$this->verifyAuthToken($authToken)) {
return null;
}
$res = $this->db()
->where('auth_identifier', $authToken->get... | Find user id from auth token.
@param $serializedAuthToken string
@return \TAppleby\AuthToken\AuthToken|null | entailment |
public function register()
{
$app = $this->app;
$app->bindShared('tappleby.auth.token', function ($app) {
return new AuthTokenManager($app);
});
$app->bindShared('tappleby.auth.token.filter', function ($app) {
$driver = $app['tappleby.auth.token']->driver();
$events = $app['events'];
... | Register the service provider.
@return void | entailment |
protected static function buildFileList($initialList) {
$fileList = array();
// see if it's an array. loop over the multiple items if it is
if (is_array($initialList)) {
foreach ($initialList as $listItem) {
$fileList[$listItem] = $listItem;
}
} else {
$fileList[$listItem] = $listItem;
}
... | Move the component files from the package to their location in the patternlab-components dir
@param {String/Array} the items to create a fileList for
@return {Array} list of files destination and source | entailment |
protected static function init() {
// start the timer
Timer::start();
// initialize the console to print out any issues
Console::init();
// initialize the config for the pluginDir
$baseDir = __DIR__."/../../../../../";
Config::init($baseDir,false);
// make sure the source dir is set-up
$so... | Common init sequence | entailment |
protected static function moveFiles($source,$destination,$packageName,$sourceBase,$destinationBase) {
$fs = new Filesystem();
// make sure the destination base exists
if (!is_dir($destinationBase)) {
$fs->mkdir($destinationBase);
}
// clean any * or / on the end of $destination
$destination = ((... | Parse the component types to figure out what needs to be moved and added to the component JSON files
@param {String} file path to move
@param {String} file path to move to
@param {String} the name of the package
@param {String} the base directory for the source of the files
@param {String} the base ... | entailment |
public static function parseComposerExtraList($composerExtra, $name, $pathDist) {
// move assets to the base directory
if (isset($composerExtra["dist"]["baseDir"])) {
self::parseFileList($name,$pathDist,Config::getOption("baseDir"),$composerExtra["dist"]["baseDir"]);
}
// move assets to the public dire... | Parse the extra section from composer.json
@param {Object} the JSON for the composer extra section | entailment |
protected static function parseComponentList($packageName,$sourceBase,$destinationBase,$componentFileList,$templateExtension,$onready,$callback) {
/*
iterate over a source or source dirs and copy files into the componentdir.
use file extensions to add them to the appropriate type arrays below. so...
"patter... | Parse the component types to figure out what needs to be added to the component JSON files
@param {String} the name of the package
@param {String} the base directory for the source of the files
@param {String} the base directory for the destination of the files (publicDir or sourceDir)
@param {Array} t... | entailment |
protected static function parseFileList($packageName,$sourceBase,$destinationBase,$fileList) {
foreach ($fileList as $fileItem) {
// retrieve the source & destination
$source = self::removeDots(key($fileItem));
$destination = self::removeDots($fileItem[$source]);
// depending on the source... | Move the files from the package to their location in the public dir or source dir
@param {String} the name of the package
@param {String} the base directory for the source of the files
@param {String} the base directory for the destintation of the files (publicDir or sourceDir)
@param {Array} the list ... | entailment |
protected static function pathExists($packageName,$path) {
$fs = new Filesystem;
if ($fs->exists($path)) {
// set-up a human readable prompt
$humanReadablePath = str_replace(Config::getOption("baseDir"), "./", $path);
// set if the prompt should fire
$prompt = true;
// are we checki... | Check to see if the path already exists. If it does prompt the user to double-check it should be overwritten
@param {String} the package name
@param {String} path to be checked
@return {Boolean} if the path exists and should be overwritten | entailment |
protected static function promptStarterKitInstall($starterKitSuggestions) {
Console::writeLine("");
// suggest starterkits
Console::writeInfo("suggested starterkits that work with this edition:", false, true);
foreach ($starterKitSuggestions as $i => $suggestion) {
$num = $i + 1;
Console::writeLine(... | Prompt the user to install a starterkit
@param {Array} the starterkit suggestions | entailment |
protected static function removeDots($path) {
$parts = array();
foreach (explode("/", $path) as $chunk) {
if ((".." !== $chunk) && ("." !== $chunk) && ("" !== $chunk)) {
$parts[] = $chunk;
}
}
return implode("/", $parts);
} | Remove dots from the path to make sure there is no file system traversal when looking for or writing files
@param {String} the path to check and remove dots
@return {String} the path minus dots | entailment |
protected static function packagesInstall($installerInfo, $event) {
// mark if this is an interactive call or not
self::$isInteractive = $event->getIO()->isInteractive();
// initialize a bunch of stuff like config and console
self::init();
// reorder packages so the starterkit is first if it's being ... | Handle some Pattern Lab specific tasks based on what's found in the package's composer.json file on install
@param {Array} the info culled from installing various pattern lab-related packages | entailment |
public static function packageRemove($packageInfo) {
// run the console and config inits
self::init();
// see if the package has a listener and remove it
self::scanForListener($packageInfo["pathBase"],true);
// see if the package is a pattern engine and remove the rule
if ($packageInfo["type"] == "... | Handle some Pattern Lab specific tasks based on what's found in the package's composer.json file on uninstall
@param {Array} the info culled from a pattern lab-related package that's being removed | entailment |
protected static function scanForListener($pathPackage,$remove = false) {
// get listener list path
$pathList = Config::getOption("configDir")."/listeners.json";
// make sure listeners.json exists. if not create it
if (!file_exists($pathList)) {
file_put_contents($pathList, "{ \"listeners\": [ ] }");
... | Scan the package for a listener
@param {String} the path for the package | entailment |
protected static function scanForPatternEngineRule($pathPackage,$remove = false) {
// get listener list path
$pathList = Config::getOption("configDir")."/patternengines.json";
// make sure patternengines.json exists. if not create it
if (!file_exists($pathList)) {
file_put_contents($pathList, "{ \"patt... | Scan the package for a pattern engine rule
@param {String} the path for the package | entailment |
public function setSlugAttribute($value)
{
array_set($this->attributes, $this->getSlugKey(), $this->makeSlug($value));
} | Mutate the value to a slug format and assign to the sluggable key.
@param string $value | entailment |
public function getDates()
{
$defaults = [static::CREATED_AT, static::UPDATED_AT, $this->getDeletedAtColumn()];
return array_merge($this->dates, $defaults);
} | Get the attributes that should be converted to dates.
Overwriting this method here allows the developer to
extend the dates using the $dates property without
needing to maintain the "deleted_at" column.
@return array | entailment |
public static function checkPathFromConfig($path, $configPath, $configOption = "") {
if (!isset($path)) {
Console::writeError("please make sure ".$configOption." is set in <path>".Console::getHumanReadablePath($configPath)."</path> by adding '".$configOption."=some/path'. sorry, stopping pattern lab... :(");
... | Check that a dir from the config exists and try to build it if needed
@param {String} directory to be checked/built
@param {String} the config path
@param {String} the config option that would help them | entailment |
public static function makeDir($dir) {
$fs = new Filesystem();
try {
$fs->mkdir($dir);
} catch (IOExceptionInterface $e) {
Console::writeError("an error occurred while creating your directory at <path>".$e->getPath()."</path>...");
}
unset($fs);
} | Make a directory
@param {String} directory to be made | entailment |
protected static function moveFile($s,$p) {
// default vars
$sourceDir = Config::getOption("sourceDir");
$publicDir = Config::getOption("publicDir");
$fs = new Filesystem();
$fs->copy($sourceDir.DIRECTORY_SEPARATOR.$s,$publicDir.DIRECTORY_SEPARATOR.$p);
} | Copies a file from the given source path to the given public path.
THIS IS NOT FOR PATTERNS
@param {String} the source file
@param {String} the public file | entailment |
public static function moveStaticFile($fileName,$copy = "", $find = "", $replace = "") {
self::moveFile($fileName,str_replace($find, $replace, $fileName));
Util::updateChangeTime();
if ($copy != "") {
Console::writeInfo($fileName." ".$copy."...");
}
} | Moves static files that aren't directly related to Pattern Lab
@param {String} file name to be moved
@param {String} copy for the message to be printed out
@param {String} part of the file name to be found for replacement
@param {String} the replacement | entailment |
public static function ignoreDir($fileName) {
$id = Config::getOption("id");
foreach ($id as $dir) {
$pos = strpos(DIRECTORY_SEPARATOR.$fileName,DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR);
if ($pos !== false) {
return true;
}
}
return false;
} | Check to see if a given filename is in a directory that should be ignored
@param {String} file name to be checked
@return {Boolean} whether the directory should be ignored | entailment |
public static function cleanExport() {
// default var
$exportDir = Config::getOption("exportDir");
if (is_dir($exportDir)) {
$files = scandir($exportDir);
foreach ($files as $file) {
if (($file == "..") || ($file == ".")) {
array_shift($files);
} else {
$key = array_keys($files,$... | Delete everything in export/ | entailment |
public static function cleanPublic() {
// set-up the dispatcher
$dispatcherInstance = Dispatcher::getInstance();
// dispatch that the data gather has started
$dispatcherInstance->dispatch("fileUtil.cleanPublicStart");
// default var
$patternPublicDir = Config::getOption("patternPublicDir");
//... | Delete patterns and user-created directories and files in public/ | entailment |
public static function exportStatic() {
// default vars
$exportDir = Config::getOption("exportDir");
$publicDir = Config::getOption("publicDir");
$sourceDir = Config::getOption("sourceDir");
if (!is_dir($exportDir)) {
mkdir($exportDir);
}
if (is_dir($publicDir)) {
// decide which files ... | moves user-generated static files from public/ to export/ | entailment |
public static function findCommand($args) {
$args = explode("|",$args);
foreach ($args as $arg) {
if (isset(self::$options[$arg])) {
return true;
}
}
return false;
} | See if a particular command was passed to the script via the command line and return a boolean. Can either be the short or long version
@param {String} list of arguments to check
@return {Boolean} if the command has been passed to the script via the command line | entailment |
public static function findCommandValue($args) {
$args = explode("|",$args);
foreach ($args as $arg) {
if (isset(self::$options[$arg])) {
return self::$options[$arg];
}
}
return false;
} | See if a particular command was passed to the script via the command line and return a value. Can either be the short or long version
@param {String} list of arguments to check
@return {String} the value that was passed via the command line | entailment |
public static function findCommandLong($arg) {
foreach (self::$commands as $command => $commandOptions) {
if (($commandOptions["commandLong"] == $arg) || ($commandOptions["commandShort"] == $arg)) {
return $command;
}
}
return false;
} | Find the short command for a given long gommand
@param {String} long command to search for
@return {String} the search command | entailment |
public static function getCommand() {
foreach (self::$commands as $command => $attributes) {
if (isset(self::$options[$command]) || isset(self::$options[$attributes["commandShort"]])) {
return $command;
}
}
return false;
} | Return the command that was given in the command line arguments
@return {String} the command. passes false if no command was found | entailment |
public static function getPathPHP() {
$manualPHP = Config::getOption("phpBin");
$autoPHP = new PhpExecutableFinder();
$path = $manualPHP ? $manualPHP : $autoPHP->find();
if (!$path) {
$configPath = Console::getHumanReadablePath(Config::getOption("configPath"));
$examplePHP = (DIRECTORY_SEPARA... | Get the path to PHP binary
@return {String} the path to the PHP executable | entailment |
public static function getPathConsole() {
$console = isset($_SERVER["SCRIPT_NAME"]) ? $_SERVER["SCRIPT_NAME"] : Config::getOption("phpScriptName");
if (!$console) {
$configPath = Console::getHumanReadablePath(Config::getOption("configPath"));
Console::writeError("please add the option `phpScriptName` wi... | Get the path to the calling script. Should be core/console but let's not make that assumption
@return {String} the path to the calling script | entailment |
public static function loadCommands() {
foreach (glob(__DIR__."/Console/Commands/*.php") as $filename) {
$command = str_replace(".php","",str_replace(__DIR__."/Console/Commands/","",$filename));
if ($command[0] != "_") {
$commandClass = "\PatternLab\Console\Commands\\".$command;
self::$commandInstances[... | Load all of the rules related to Pattern Data | entailment |
public static function setCommand($long,$desc,$help,$short = "") {
if (!empty($short)) {
self::$optionsShort .= $short;
}
self::$optionsLong[] = $long;
$short = str_replace(":","",$short);
$long = str_replace(":","",$long);
self::$commands[$long] = array("commandShort" => $short, "commandLong" => $long,... | Set-up the command so it can be used from the command line
@param {String} the single character version of the command
@param {String} the long version of the command
@param {String} the description to be used in the "available commands" section of writeHelp()
@param {String} the description... | entailment |
public static function setCommandSample($command,$sample,$extra) {
$command = str_replace(":","",$command);
self::$commands[$command]["commandExamples"][] = array("exampleSample" => $sample, "exampleExtra" => $extra);
} | Set a sample for a specific command
@param {String} the long version of the command that this option is related to
@param {String} the sample to be used in the "sample" section of writeHelpCommand()
@param {String} the extra info to be used in the example command for the "sample" section of writeHe... | entailment |
public static function setCommandOption($command,$long,$desc,$sample,$short = "",$extra = "") {
if (($short != "") && ($short != "z") && (strpos(self::$optionsShort,$short) === false)) {
self::$optionsShort .= $short;
}
if (!in_array($long,self::$optionsLong)) {
self::$optionsLong[] = $long;
}
$short = ... | Set-up an option for a given command so it can be used from the command line
@param {String} the long version of the command that this option is related to
@param {String} the long version of the option
@param {String} the description to be used in the "available options" section of writeHelpComman... | entailment |
public static function writeHelp() {
/*
The generic help follows this format:
Pattern Lab Console Options
Usage:
php core/console command [options]
Available commands:
--build (-b) Build Pattern Lab
--watch (-w) Build Pattern Lab and watch for changes and rebuild as necess... | Write out the generic help | entailment |
public static function writeHelpCommand($command = "") {
/*
The command help follows this format:
Build Command Options
Usage:
php core/console --build [--patternsonly|-p] [--nocache|-n] [--enablecss|-c]
Available options:
--patternsonly (-p) Build only the patterns. Does NOT clean p... | Write out the command-specific help
@param {String} the single character of the command that this option is related to | entailment |
public static function getSpacer($lengthLong,$itemLongLength) {
$i = 0;
$spacer = " ";
$spacerLength = $lengthLong - $itemLongLength;
while ($i < $spacerLength) {
$spacer .= " ";
$i++;
}
return $spacer;
} | Make sure the space is properly set between long command options and short command options
@param {Integer} the longest length of the command's options
@param {Integer} the character length of the given option | entailment |
public static function addTags($line,$tag) {
$lineFinal = "<".$tag.">".preg_replace("/<[A-z0-9-_]{1,}>[^<]{1,}<\/[A-z0-9-_]{1,}>/","</".$tag.">$0<".$tag.">",$line)."</".$tag.">";
return $lineFinal;
} | Modify a line to include the given tag by default
@param {String} the content to be written out | entailment |
public static function writeError($line,$doubleSpace = false,$doubleBreak = false) {
$lineFinal = self::addTags($line,"error");
self::writeLine($lineFinal,$doubleSpace,$doubleBreak);
exit(1);
} | Write out a line to the console with error tags. It forces an exit of the script
@param {String} the content to be written out
@param {Boolean} if there should be two spaces added to the beginning of the line
@param {Boolean} if there should be two breaks added to the end of the line | entailment |
public static function writeInfo($line,$doubleSpace = false,$doubleBreak = false) {
$lineFinal = self::addTags($line,"info");
self::writeLine($lineFinal,$doubleSpace,$doubleBreak);
} | Write out a line to the console with info tags
@param {String} the content to be written out
@param {Boolean} if there should be two spaces added to the beginning of the line
@param {Boolean} if there should be two breaks added to the end of the line | entailment |
public static function log($line,$doubleSpace = false,$doubleBreak = false) {
self::writeInfo($line,$doubleSpace = false,$doubleBreak = false);
} | Alias for writeInfo because I keep wanting to use it
@param {String} the content to be written out
@param {Boolean} if there should be two spaces added to the beginning of the line
@param {Boolean} if there should be two breaks added to the end of the line | entailment |
public static function writeLine($line,$doubleSpace = false,$doubleBreak = false) {
$break = ($doubleBreak) ? PHP_EOL.PHP_EOL : PHP_EOL;
if (strpos($line,"<nophpeol>") !== false) {
$break = "";
$line = str_replace("<nophpeol>","",$line);
}
$space = ($doubleSpace) ? " " : "";
$c = self::$color;
p... | Write out a line to the console
@param {String} the content to be written out
@param {Boolean} if there should be two spaces added to the beginning of the line
@param {Boolean} if there should be two breaks added to the end of the line | entailment |
public static function writeTag($tag,$line,$doubleSpace = false,$doubleBreak = false) {
$lineFinal = self::addTags($line,$tag);
self::writeLine($lineFinal,$doubleSpace,$doubleBreak);
} | Write out a line to the console with a specific tag
@param {String} the tag to add to the line
@param {String} the content to be written out
@param {Boolean} if there should be two spaces added to the beginning of the line
@param {Boolean} if there should be two breaks added to the end of ... | entailment |
public static function promptInput($prompt = "", $options = "", $default = "", $lowercase = true, $tag = "info") {
// check prompt
if (empty($prompt)) {
Console::writeError("an input prompt requires prompt text...");
}
// if there are suggested options add them
if (!empty($options)) {
$prompt .= "... | Prompt the user for some input
@param {String} the text for the prompt
@param {String} the text for the options
@param {String} the text for the default option
@param {Boolean} if we should lowercase the input before sending it back
@param {String} the tag that should be used when... | entailment |
protected static function loadListeners() {
// default var
$configDir = Config::getOption("configDir");
// make sure the listener data exists
if (file_exists($configDir."/listeners.json")) {
// get listener list data
$listenerList = json_decode(file_get_contents($configDir."/listeners.json"), tr... | Load listeners that may be a part of plug-ins that should be notified by the dispatcher | entailment |
public function watch($options = array()) {
// double-checks options was properly set
if (empty($options)) {
Console::writeError("need to pass options to generate...");
}
// set default attributes
$moveStatic = (isset($options["moveStatic"])) ? $options["moveStatic"] : true;
$noCacheBuster = (is... | Watch the source/ directory for any changes to existing files. Will run forever if given the chance.
@param {Boolean} decide if the reload server should be turned on
@param {Boolean} decide if static files like CSS and JS should be moved | entailment |
private function updateSite($fileName,$message,$verbose = true) {
$watchMessage = "";
if ($verbose) {
if ($message == "added") {
$watchMessage = "<warning>".$fileName." was added to Pattern Lab. reload the website to see this change in the navigation...</warning>";
} elseif ($message == "removed") {
... | Updates the Pattern Lab Website and prints the appropriate message
@param {String} file name to included in the message
@param {String} a switch for decided which message isn't printed
@return {String} the final message | entailment |
protected function getDynamicRelationship($name)
{
// Dynamically get the relationship
if ($this->isRelationship($name)) {
// Use the relationship already loaded
if (array_key_exists($name, $this->getRelations())) {
return $this->getRelation($name);
... | Get a dynamically resolved relationship.
@param string $name
@return mixed | entailment |
public function getRelationship($name)
{
// If relationship does not exist throw an exception
if ( ! $this->isRelationship($name)) {
$exception = new ModelNotFoundException();
$exception->setModel($name);
throw $exception;
}
return $this->relation... | Return the relationship configurations.
@param string $name of related model
@throws Illuminate\Database\Eloquent\ModelNotFoundException
@return array | entailment |
protected function callRelationship($name)
{
// Get the relationship arguments
$args = $this->getRelationship($name);
// Build the relationship
$method = array_shift($args);
$relationship = call_user_func_array([$this, $method], $args);
// Check to see if this relat... | Proxy call a relationship method using the
configuration arguments of the relationship.
@param string $name of related model
@return mixed | entailment |
public function scopeWithout($query, $relations)
{
$relations = is_array($relations) ? $relations : array_slice(func_get_args(), 1);
$relationships = array_dot($query->getEagerLoads());
foreach ($relations as $relation) {
unset($relationships[$relation]);
}
retur... | Set the relationships that should not be eager loaded.
@param Illuminate\Database\Query\Builder $query
@param mixed $relations
@return $this | entailment |
public function generate($options = array()) {
// double-checks options was properly set
if (empty($options)) {
Console::writeError("need to pass options to generate...");
}
// set the default vars
$moveStatic = (isset($options["moveStatic"])) ? $options["moveStatic"] : true;
$noCacheBuster =... | Pulls together a bunch of functions from builder.lib.php in an order that makes sense
@param {Boolean} decide if CSS should be parsed and saved. performance hog.
@param {Boolean} decide if static files like CSS and JS should be moved | entailment |
protected function moveStatic() {
// set-up the dispatcher
$dispatcherInstance = Dispatcher::getInstance();
// note the start of the operation
$dispatcherInstance->dispatch("generator.moveStaticStart");
// common values
$publicDir = Config::getOption("publicDir");
$sourceDir = Config::getOption("... | Move static files from source/ to public/ | entailment |
public static function hasError() {
$error = json_last_error();
$errorMessage = array_key_exists($error, self::$errors) ? self::$errors[$error] : "Unknown error ({$error})";
return $errorMessage;
} | Returns the last error message when building a JSON file. Mimics json_last_error_msg() from PHP 5.5
@param {String} the file that generated the error | entailment |
public static function lastErrorMsg($file,$message,$data) {
Console::writeLine(PHP_EOL."<error>The JSON file, ".$file.", wasn't loaded. The error: ".$message."</error>");
if ($message == "Syntax error, malformed JSON") {
Console::writeLine("");
$parser = new JsonLint\JsonParser();
$error = $parser->lint($... | Returns the last error message when building a JSON file. Mimics json_last_error_msg() from PHP 5.5
@param {String} the file that generated the error | entailment |
protected function findLineages($data) {
if (preg_match_all("/".$this->lineageMatch."/",$data,$matches)) {
return array_unique($matches[$this->lineageMatchKey]);
}
return array();
} | Get the lineage for a given pattern by parsing it and matching mustache partials
@param {String} the data from the raw pattern
@return {Array} a list of patterns | entailment |
public static function configure() {
$config = \BoletoSimples::$configuration;
$oauth2 = new Oauth2Subscriber();
$oauth2->setAccessToken($config->access_token);
self::$client = new Client([
'base_url' => $config->baseUri(),
'defaults' => [
'headers' => [
'User-Agent' => $... | Configure the GuzzleHttp\Client with default options. | entailment |
protected function getDynamicEncrypted($attribute)
{
// Dynamically get the encrypted attributes
if ($this->isEncryptable($attribute)) {
// Decrypt only encrypted values
if ($this->isEncrypted($attribute)) {
return $this->getEncryptedAttribute($attribute);
... | Get an encrypted attribute dynamically.
@param string $attribute
@return mixed | entailment |
protected function setDynamicEncryptable($attribute, $value)
{
// Dynamically set the encryptable attribute
if ($this->isEncryptable($attribute)) {
// Encrypt only decrypted values
if ($this->isDecrypted($attribute)) {
$this->setEncryptingAttribute($attribute,... | Set an encryptable attribute dynamically.
@param string $attribute
@param mixed $value
@return bool | entailment |
public function isEncrypted($attribute)
{
if ( ! array_key_exists($attribute, $this->attributes)) {
return false;
}
try {
$this->decrypt(array_get($this->attributes, $attribute));
} catch (DecryptException $exception) {
return false;
}
... | Returns whether the attribute is encrypted.
@param string $attribute name
@return bool | entailment |
public function encryptAttributes()
{
foreach ($this->getEncryptable() as $attribute) {
$this->setEncryptingAttribute($attribute, array_get($this->attributes, $attribute));
}
} | Encrypt attributes that should be encrypted. | entailment |
public function getEncryptedAttribute($attribute)
{
$value = array_get($this->attributes, $attribute);
return $this->isEncrypted($attribute) ? $this->decrypt($value) : $value;
} | Get the decrypted value for an encrypted attribute.
@param string $attribute name
@return string | entailment |
public function setEncryptingAttribute($attribute, $value)
{
array_set($this->attributes, $attribute, $this->encrypt($value));
} | Set an encrypted value for an encryptable attribute.
@param string $attribute name
@param string $value to encrypt | entailment |
public function migrate($diffVersion = false) {
$migrations = new \DirectoryIterator(__DIR__."/../../migrations/");
$migrationsValid = array();
foreach ($migrations as $migration) {
$filename = $migration->getFilename();
if (!$migration->isDot() && $migration->isFile() && ($filename[0] != "_")) {... | Read through the migrations and move files as needed
@param {Boolean} is this a different version | entailment |
protected function runMigration($filename, $sourcePath, $destinationPath, $singleFile) {
$filename = str_replace(".json","",$filename);
print "starting the ".$filename." migration...\n";
if ($singleFile) {
copy($sourcePath.$fileName,$destinationPath.$fileName);
} else {
if (strpos($sourc... | Run any migrations found in core/migrations that match the approved types
@param {String} the filename of the migration
@param {String} the path of the source directory
@param {String} the path to the destination
@param {Boolean} moving a single file or a directory | entailment |
public function attributesToCarbon($event)
{
foreach ($this->attributes as $attribute) {
$value = $this->owner->$attribute;
if (!empty($value)) {
// If this value is an integer, we will assume it is a UNIX timestamp's value
// and format a Carbon objec... | Convert the model's attributes to an Carbon instance.
@param $event
@return static | entailment |
public function attributesToDefaultFormat($event)
{
$oldAttributes = $this->owner->oldAttributes;
foreach ($this->attributes as $attribute) {
$oldAttributeValue = $oldAttributes[$attribute];
if ($this->owner->$attribute instanceof Carbon) {
//If old attribute... | Handles owner 'beforeUpdate' event for converting attributes values to the default format
@param $event
@return bool | entailment |
protected function getDynamicJuggle($key, $value)
{
if ($this->isJugglable($key)) {
return $this->juggle($value, $this->getJuggleType($key));
}
return $value;
} | If juggling is active, it returns the juggleAttribute.
If not it just returns the value as it was passed.
@param string $key
@param mixed $value
@return mixed | entailment |
protected function setDynamicJuggle($key, $value)
{
// Check that the attribute is jugglable
if ( ! is_null($value) && $this->isJugglable($key)) {
// Cast the value to the type set for the attribute
$this->juggleAttribute($key, $value);
}
} | If juggling is active, it sets the attribute in the model
by type juggling the value first.
@param string $key
@param mixed $value | entailment |
public function setJugglable(array $attributes)
{
// Check that each of the types are indeed jugglable types
foreach ($attributes as $attribute => $type) {
$this->checkJuggleType($type);
}
// Set the juggle attributes
$this->jugglable = $attributes;
} | Set the jugglable attributes.
@param array $attributes to juggle
@throws InvalidArgumentException | entailment |
public function removeJugglable($attributes)
{
// Make sure we are dealing an associative array
if ( ! is_array($attributes)) {
$attributes = func_get_args();
}
$attributes = array_flip($attributes);
// Get the remaining jugglables
$jugglables = array_dif... | Remove an attribute or several attributes from the jugglable array.
@example removeJugglable( string $attribute, ... )
@param mixed $attributes | entailment |
public function isJuggleType($type)
{
// Construct a normalized juggle method from the type
$method = $this->buildJuggleMethod($type);
// Any type that does map to a model method is invalid
if ( ! method_exists($this, $method)) {
return false;
}
return t... | Returns whether the type is a type that can be juggled to.
@param string $type to cast
@return bool | entailment |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.