_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
33
8k
language
stringclasses
1 value
meta_information
dict
q25600
Asset.enqueueStyle
train
protected function enqueueStyle() { wp_enqueue_style( $this->getHandle(), $this->getUrl(), $this->getDependencies(), $this->getVersion(), $this->getArgument() );
php
{ "resource": "" }
q25601
Asset.localize
train
public function localize(string $name, array $data): AssetInterface {
php
{ "resource": "" }
q25602
Asset.inline
train
public function inline(string $code, bool $after = true): AssetInterface { $this->inline[] = [ 'code' => $code,
php
{ "resource": "" }
q25603
Asset.attributes
train
public function attributes(array $attributes): AssetInterface { if (is_null($this->getType())) { throw new AssetException('The asset must have a type.'); } $hook = 'script' === $this->getType() ? 'script_loader_tag' : 'style_loader_tag'; $key = strtolower(trim($this->get...
php
{ "resource": "" }
q25604
TaxonomyFieldRepository.add
train
public function add($field) { if (is_array($field)) { foreach ($field as $item) { $this->add($item); }
php
{ "resource": "" }
q25605
TaxonomyFieldRepository.getFieldByName
train
public function getFieldByName(string $name) { $found = array_filter($this->fields, function ($field) use ($name) { /** @var FieldTypeInterface $field */ return $name === $field->getBaseName(); }); if
php
{ "resource": "" }
q25606
WordPress.getFilters
train
public function getFilters() { return [ /** * Formatting filters. */ new \Twig_Filter('wpantispam', function ($email, $encoding = 0) { return antispambot($email, $encoding); }), new \Twig_Filter('wpautop', function ($t...
php
{ "resource": "" }
q25607
WordPressBodyClass.dispatchBodyClass
train
protected function dispatchBodyClass(Route $route) { return function ($classes) use ($route) { if ($route->hasCondition()) { return $classes; } $tokens = array_filter(array_map(function ($token) use ($route) { switch ($type = $token[0]) { ...
php
{ "resource": "" }
q25608
VendorPublishCommand.parseChoice
train
protected function parseChoice($choice) { list($type, $value) = explode(': ', strip_tags($choice));
php
{ "resource": "" }
q25609
Support.parse
train
protected function parse(array $features) { $allowed = []; foreach ($features as $feature => $value) { if (is_int($feature)) { // Allow theme features without options. // Though post formats must be added with properties. // Here we first ...
php
{ "resource": "" }
q25610
Support.register
train
public function register() { if (! function_exists('add_theme_support') || empty($this->features)) {
php
{ "resource": "" }
q25611
FieldTransformer.transform
train
public function transform(FieldTypeInterface $field) { return [ 'attributes' => $field->getAttributes(), 'basename' => $field->getBaseName(), 'component' => $field->getComponent(), 'data_type' => $field->getOption('data_type', ''), 'default' => $fi...
php
{ "resource": "" }
q25612
CollectionFieldTransformer.getOptions
train
protected function getOptions(FieldTypeInterface $field) { $options = parent::getOptions($field); $options['items'] = array_map(function ($id) { return [ 'attributes' => wp_prepare_attachment_for_js($id),
php
{ "resource": "" }
q25613
Form.setPrefix
train
public function setPrefix(string $prefix): FieldTypeInterface { $this->prefix = $prefix; // Update all attached fields with the
php
{ "resource": "" }
q25614
Form.setTheme
train
public function setTheme(string $theme): FieldTypeInterface { $this->options['theme'] = $theme; // Update all attached fields with the given theme. foreach ($this->repository->all() as $field) { /** @var FieldTypeInterface $field */ $field->setTheme($theme); ...
php
{ "resource": "" }
q25615
Form.handleRequest
train
public function handleRequest(Request $request): FormInterface { $fields = $this->repository->all(); $this->validator = $this->validation->make( $request->all(), $this->getFormRules($fields), $this->getFormMessages($fields), $this->getFormPlaceholders...
php
{ "resource": "" }
q25616
Form.getFormRules
train
protected function getFormRules(array $fields) { $rules = []; foreach ($fields as $field) { /** @var FieldTypeInterface $field */
php
{ "resource": "" }
q25617
Form.getFormMessages
train
protected function getFormMessages(array $fields) { // Each message is defined by field and its own rules. // In our case, we need to prepend the field name (attribute) // using a "dot" notation. Ex.: email.required $messages = []; foreach ($fields as $field) {
php
{ "resource": "" }
q25618
Form.error
train
public function error(string $name = '', bool $first = false) { $errors = $this->errors(); if (empty($name)) { // Return all errors messages by default if the // name argument is not specified. return $errors->all();
php
{ "resource": "" }
q25619
Form.render
train
public function render(): string { $view = $this->viewer->make($this->getView(), $this->getFormData()); // Indicates that the form has been rendered at least
php
{ "resource": "" }
q25620
Form.setGroupView
train
public function setGroupView(string $view, string $group = 'default'): FormInterface { // Verify that the form has the mentioned group. // If not, throw an error.
php
{ "resource": "" }
q25621
Form.getView
train
public function getView(bool $prefixed = true): string { if ($prefixed) {
php
{ "resource": "" }
q25622
Form.validateOptions
train
protected function validateOptions(array $options) { $validated = []; foreach ($options as $name => $option) { if (! in_array($name, $this->getAllowedOptions())) {
php
{ "resource": "" }
q25623
Form.parseOptions
train
protected function parseOptions(array $options) { // Make sure to keep defined default attributes on the form. $options['attributes'] = array_merge($this->getAttributes(), $options['attributes']); // Define nonce default values if "method" attribute is set to "post". if (isset($opti...
php
{ "resource": "" }
q25624
Form.addAttribute
train
public function addAttribute(string $name, string $value, $overwrite = false): FieldTypeInterface { if (isset($this->options['attributes'][$name]) && ! $overwrite) { $this->options['attributes'][$name] .=
php
{ "resource": "" }
q25625
FormBuilder.validateOptions
train
protected function validateOptions(array $options, FieldTypeInterface $field) { $parsed = []; foreach ($options as $key => $value) { if (! in_array($key, $field->getAllowedOptions(), true)) {
php
{ "resource": "" }
q25626
FormBuilder.add
train
public function add(FieldTypeInterface $field): FormBuilderInterface { /** @var BaseType $field */ $opts = $this->validateOptions(array_merge([ 'errors' => $this->form->getOption('errors'), 'theme' => $this->form->getOption('theme') ], $field->getOptions()), $field); ...
php
{ "resource": "" }
q25627
SetRequestForConsole.bootstrap
train
public function bootstrap(Application $app) { $uri = $app->make('config')->get('app.url', 'http://localhost'); $components = parse_url($uri); $server = $_SERVER; if (isset($components['path'])) {
php
{ "resource": "" }
q25628
UserServiceProvider.registerUserField
train
protected function registerUserField() { $this->app->bind('themosis.user.field', function ($app) { $viewFactory = $app['view']; $viewFactory->addLocation(__DIR__.'/views'); return new UserField( new FieldsRepository(),
php
{ "resource": "" }
q25629
ModelMakeCommand.createController
train
protected function createController() { $controller = Str::studly(class_basename($this->argument('name'))); $modelName = $this->qualifyClass($this->getNameInput()); $this->call('make:controller', [
php
{ "resource": "" }
q25630
ImageSize.parse
train
protected function parse(array $sizes) { $images = []; foreach ($sizes as $slug => $properties) { list($width, $height, $crop, $label) = $this->parseProperties($properties, $slug); $images[$slug] = [ 'width' => $width,
php
{ "resource": "" }
q25631
ImageSize.parseProperties
train
protected function parseProperties(array $properties, string $slug) { switch (count($properties)) { case 1: // Square with defaults. return [$properties[0], $properties[0], false, false]; break; case 2: // Custom size wi...
php
{ "resource": "" }
q25632
ImageSize.addToDropDown
train
public function addToDropDown(array $options) { foreach ($this->sizes as $slug => $props) { if ($props['label'] && ! isset($options[$slug])) {
php
{ "resource": "" }
q25633
RouteCacheCommand.getFreshApplicationRoutes
train
protected function getFreshApplicationRoutes() { return tap($this->getFreshApplication()['router']->getRoutes(), function ($routes)
php
{ "resource": "" }
q25634
RouteCacheCommand.getFreshApplication
train
protected function getFreshApplication() { return tap(require $this->laravel->bootstrapPath('app.php'), function
php
{ "resource": "" }
q25635
MediaFieldTransformer.getOptions
train
protected function getOptions(FieldTypeInterface $field) { $options = parent::getOptions($field); $attachedFile = get_attached_file($field->getValue()); $options['media'] = [
php
{ "resource": "" }
q25636
Url.toInternal
train
public static function toInternal(array $routeParams, $scheme = false) { if ($scheme) { return Yii::$app->getUrlManager()->internalCreateAbsoluteUrl($routeParams);
php
{ "resource": "" }
q25637
Url.toAjax
train
public static function toAjax($route, array $params = []) { $routeParams = ['/'.$route]; foreach ($params as $key => $value) {
php
{ "resource": "" }
q25638
HtmlEncodeBehavior.afterFind
train
public function afterFind($event) { foreach ($this->attributes as $attribute) {
php
{ "resource": "" }
q25639
DurationValue.timeToIso8601Duration
train
protected function timeToIso8601Duration($time) { $units = array( "Y" => 365*24*3600, "D" => 24*3600, "H" => 3600, "M" => 60, "S" => 1, ); $str = "P"; $istime = false; ...
php
{ "resource": "" }
q25640
RegistryTrait.has
train
public static function has($name) { return (self::find()->where([self::getNameAt
php
{ "resource": "" }
q25641
RegistryTrait.get
train
public static function get($name, $defaultValue = null) { $model = self::find()->where([self::getNameAttribute() => $name])->asArray()->one();
php
{ "resource": "" }
q25642
RegistryTrait.remove
train
public static function remove($name) { $model = self::find()->where([self::getNameAttribute() => $name])->one(); if ($model) {
php
{ "resource": "" }
q25643
ResponseCache.callActionCallable
train
private function callActionCallable($action, $result) { if (isset($this->actionsCallable[$action]) && is_callable($this->actionsCallable[$action])) {
php
{ "resource": "" }
q25644
TextValue.truncate
train
public function truncate($length) { $this->_text = StringHelper::truncate($this->_text,
php
{ "resource": "" }
q25645
Controller.getViewPath
train
public function getViewPath() { if ($this->module instanceof Module) { if ($this->module->useAppViewPath) { return '@app/views/' . $this->module->id . '/' . $this->id; } elseif (is_array($this->module->viewMap)) { $currentAction = $this->id . '/' . ($t...
php
{ "resource": "" }
q25646
Controller.render
train
public function render($view, $params = []) { if (!empty($this->module->context) && empty($this->layout)) {
php
{ "resource": "" }
q25647
Bootstrap.beforeRun
train
public function beforeRun($app) { foreach ($app->tags as $name => $config) { TagParser::inject($name, $config); } foreach ($this->getModules() as $id => $module) { foreach ($module->urlRules as $key => $rule) { if (is_string($key)) { ...
php
{ "resource": "" }
q25648
Bootstrap.run
train
public function run($app) { if (!$app->request->getIsConsoleRequest()) { if ($this->hasModule('admin') && $app->request->isAdmin) { // When admin context, change csrf token, this will not terminate the frontend csrf token: // @see https://github.com/luyadev/luya/i...
php
{ "resource": "" }
q25649
Rating.getRatingValue
train
public function getRatingValue() { if ($this->_ratingValue === null) { return null; } $range = new RangeValue($this->_ratingValue);
php
{ "resource": "" }
q25650
RobotsFilter.setRenderTime
train
protected function setRenderTime($time) { $merge = Yii::$app->session->get(self::ROBOTS_FILTER_SESSION_IDENTIFIER, []);
php
{ "resource": "" }
q25651
RobotsFilter.getSessionKeyByOwner
train
protected function getSessionKeyByOwner() { if ($this->sessionKey) { return $this->sessionKey; }
php
{ "resource": "" }
q25652
StringHelper.typeCast
train
public static function typeCast($string) { if (is_numeric($string)) { return static::typeCastNumeric($string); } elseif (is_array($string)) {
php
{ "resource": "" }
q25653
StringHelper.typeCastNumeric
train
public static function typeCastNumeric($value) { if (!self::isFloat($value)) { return $value; } if (intval($value) == $value) {
php
{ "resource": "" }
q25654
StringHelper.contains
train
public static function contains($needle, $haystack, $strict = false) { $needles = (array) $needle; $state = false; foreach ($needles as $item) {
php
{ "resource": "" }
q25655
StringHelper.minify
train
public static function minify($content, array $options = []) { $min = preg_replace(['/[\n\r]/', '/\>[^\S ]+/s', '/[^\S ]+\</s', '/(\s)+/s', ], ['', '>', '<', '\\1'], trim($content));
php
{ "resource": "" }
q25656
StringHelper.highlightWord
train
public static function highlightWord($content, $word, $markup = '<b>%s</b>') { $word = (array) $word; $content = strip_tags($content); $latest = null; foreach ($word as $needle) { preg_match_all("/".preg_quote($needle, '/')."+/i", $content, $matches); if (is_a...
php
{ "resource": "" }
q25657
StringHelper.mb_str_split
train
public static function mb_str_split($string, $length = 1) { $array = []; $stringLength = mb_strlen($string, 'UTF-8'); for ($i = 0; $i < $stringLength; $i += $length) {
php
{ "resource": "" }
q25658
EventTrait.setAttendee
train
public function setAttendee($attendee) { ObjectHelper::isInstanceOf($attendee, [Organization::class, PersonInterface::class]);
php
{ "resource": "" }
q25659
EventTrait.setComposer
train
public function setComposer($composer) { ObjectHelper::isInstanceOf($author, [Organization::class, PersonInterface::class]);
php
{ "resource": "" }
q25660
EventTrait.setContributor
train
public function setContributor($contributor) { ObjectHelper::isInstanceOf($contributor, [Organization::class, PersonInterface::class]);
php
{ "resource": "" }
q25661
EventTrait.setOrganizer
train
public function setOrganizer($organizer) { ObjectHelper::isInstanceOf($organizer, [Organization::class, PersonInterface::class]);
php
{ "resource": "" }
q25662
EventTrait.setTranslator
train
public function setTranslator($translator) { ObjectHelper::isInstanceOf($translator, [Organization::class, PersonInterface::class]);
php
{ "resource": "" }
q25663
Bootstrap.run
train
public function run($app) { foreach ($app->getApplicationModules() as $id => $module) { $folder = $module->basePath . DIRECTORY_SEPARATOR . 'commands'; if (file_exists($folder) && is_dir($folder)) { foreach (FileHelper::findFiles($folder) as $file) { ...
php
{ "resource": "" }
q25664
BaseDevCommand.actionConfigInfo
train
public function actionConfigInfo() { $this->outputInfo("dev config file: " . Yii::getAlias($this->configFile)); $config = $this->readConfig(); if (!$config) { return $this->outputError("Unable to open
php
{ "resource": "" }
q25665
BaseDevCommand.readConfig
train
protected function readConfig() { $data = FileHelper::getFileContent($this->configFile);
php
{ "resource": "" }
q25666
BaseDevCommand.getConfig
train
protected function getConfig($key, $defaultValue = null) { $config = $this->readConfig();
php
{ "resource": "" }
q25667
BaseDevCommand.saveConfig
train
protected function saveConfig($key, $value) { $content = $this->readConfig(); if (!$content) { $content = []; } $content[$key] = $value; $save = FileHelper::writeFile($this->configFile, Json::encode($content));
php
{ "resource": "" }
q25668
View.init
train
public function init() { // call parent initializer parent::init(); // auto register csrf
php
{ "resource": "" }
q25669
View.getAssetUrl
train
public function getAssetUrl($assetName) { $assetName = ltrim($assetName, '\\'); if (!isset($this->assetBundles[$assetName])) { throw new Exception("The AssetBundle '$assetName'
php
{ "resource": "" }
q25670
EmailLink.setEmail
train
public function setEmail($email) { $validator = new EmailValidator(); if ($validator->validate($email))
php
{ "resource": "" }
q25671
HealthController.actionIndex
train
public function actionIndex() { $error = false; @chdir(Yii::getAlias('@app')); $this->output('The directory the health commands is applying to: ' . Yii::getAlias('@app')); foreach ($this->folders as $folder => $writable) { $mode = ($writable) ? 0777 : 0775; ...
php
{ "resource": "" }
q25672
JsonLd.addGraph
train
public static function addGraph($data) { self::registerView(); if (is_scalar($data)) { throw new Exception("Data must be either an array
php
{ "resource": "" }
q25673
JsonLd.registerView
train
protected static function registerView() { if (self::$_view === null) { Yii::$app->view->on(View::EVENT_BEGIN_BODY, function ($event) {
php
{ "resource": "" }
q25674
FloatValidator.validateAttribute
train
public function validateAttribute($model, $attribute) { $value = $model->$attribute; if (!is_numeric($value) &&
php
{ "resource": "" }
q25675
TelTag.parse
train
public function parse($value, $sub) { return Html::a(empty($sub) ? $value :
php
{ "resource": "" }
q25676
WebsiteLink.setHref
train
public function setHref($href) { if (StringHelper::startsWith($href, '//')) {
php
{ "resource": "" }
q25677
Json.isJson
train
public static function isJson($value) { if (!is_scalar($value)) { return false; } $firstChar = substr($value, 0, 1); if ($firstChar !== '{' && $firstChar !== '[')
php
{ "resource": "" }
q25678
RepoController.actionUpdate
train
public function actionUpdate() { foreach ($this->repos as $repo) { $this->rebaseRepo($repo, $this->getFilesystemRepoPath($repo)); }
php
{ "resource": "" }
q25679
RepoController.actionRemove
train
public function actionRemove($repo) { FileHelper::removeDirectory($this->getFilesystemRepoPath($repo)); $clones = $this->getConfig(self::CONFIG_VAR_CUSTOMCLONES, []); if (isset($clones[$repo])) { unset($clones[$repo]);
php
{ "resource": "" }
q25680
Hook.on
train
public static function on($name, $value, $prepend = false) { $object = new HookEvent(['handler' => $value]);
php
{ "resource": "" }
q25681
Hook.string
train
public static function string($name) { $buffer = []; foreach (self::trigger($name) as
php
{ "resource": "" }
q25682
Hook.iterate
train
public static function iterate($name) { $buffer = []; foreach (self::trigger($name) as $hook) { $buffer = array_merge($buffer,
php
{ "resource": "" }
q25683
LinkTag.parse
train
public function parse($value, $sub) { if (substr($value, 0, 2) == '//') { $value = StringHelper::replaceFirst('//', Url::base(true) . '/', $value); $external = false;
php
{ "resource": "" }
q25684
ModuleController.renderReadme
train
public function renderReadme($folders, $name, $ns) { return $this->view->render('@luya/console/commands/views/module/readme.php', [ 'folders' => $folders, 'name' => $name,
php
{ "resource": "" }
q25685
Composition.isHostAllowed
train
public function isHostAllowed($allowedHosts) { $currentHost = $this->request->hostName; $rules = (array) $allowedHosts;
php
{ "resource": "" }
q25686
Composition.getKeys
train
public function getKeys() { if ($this->_keys === null) { $this->_keys
php
{ "resource": "" }
q25687
Composition.getKey
train
public function getKey($key, $defaultValue = false) { $this->getKeys(); return
php
{ "resource": "" }
q25688
Composition.createRouteEnsure
train
public function createRouteEnsure(array $overrideKeys = []) { if (isset($overrideKeys['langShortCode'])) { $langShortCode = $overrideKeys['langShortCode']; } else { $langShortCode = $this->langShortCode; }
php
{ "resource": "" }
q25689
Boot.getIsCli
train
public function getIsCli() { if ($this->_isCli === null) {
php
{ "resource": "" }
q25690
Boot.getConfigArray
train
public function getConfigArray() { if ($this->_configArray === null) { if (!file_exists($this->configFile)) { if (!$this->getIsCli()) { throw new Exception("Unable to load the config file '".$this->configFile."'."); } ...
php
{ "resource": "" }
q25691
Boot.applicationConsole
train
public function applicationConsole() { $this->setIsCli(true); $config = $this->getConfigArray(); $config['defaultRoute'] = 'help'; if (isset($config['components'])) { if (isset($config['components']['composition'])) { unset($config['components']['compositi...
php
{ "resource": "" }
q25692
Boot.applicationWeb
train
public function applicationWeb() { $config = $this->getConfigArray(); $this->includeYii(); $mergedConfig = ArrayHelper::merge($config, ['bootstrap' => ['luya\web\Bootstrap']]);
php
{ "resource": "" }
q25693
Boot.includeYii
train
private function includeYii() { if (file_exists($this->_baseYiiFile)) { defined('LUYA_YII_VENDOR') ?: define('LUYA_YII_VENDOR', dirname($this->_baseYiiFile)); $baseYiiFolder = LUYA_YII_VENDOR . DIRECTORY_SEPARATOR; $luyaYiiFile = $this->getCoreBasePath() . DI...
php
{ "resource": "" }
q25694
Widget.getViewPath
train
public function getViewPath() { if (!$this->useAppViewPath) { return parent::getViewPath(); } // get reflection $class = new ReflectionClass($this); //
php
{ "resource": "" }
q25695
NextPrevModel.getPrev
train
public function getPrev() { return self::find()->where(['<',
php
{ "resource": "" }
q25696
ApplicationTrait.init
train
public function init() { parent::init(); // add trace info Yii::trace('initialize
php
{ "resource": "" }
q25697
ApplicationTrait.getPackageInstaller
train
public function getPackageInstaller() { $file = Yii::getAlias('@vendor/luyadev/installer.php'); $data
php
{ "resource": "" }
q25698
ApplicationTrait.getApplicationModules
train
public function getApplicationModules() { $modules = []; foreach ($this->getModules() as $id => $obj) { if ($obj instanceof Module) {
php
{ "resource": "" }
q25699
ApplicationTrait.getFrontendModules
train
public function getFrontendModules() { $modules = []; foreach ($this->getModules() as $id => $obj) { if ($obj instanceof Module && !$obj instanceof AdminModuleInterface && !$obj
php
{ "resource": "" }