Best Prophecy code snippet using name.withKey
Tree.php
Source:Tree.php
...79 public $optionAttrs = [];80 /**81 * @var string å
³è表主é®å¼åç¼ï¼ä¸ºäºåºåå表ç主é®å¼82 */83 public $withKeyPrefix = 'cw-';84 /**85 * @var array å
³è表å
ç´ ç HTML 屿§86 */87 public $withOptions = [];88 /**89 * @var string|boolean æ¯å¦æ·»å æç¤ºä¿¡æ¯æ é¢90 * -string æå®çææ¬æç¤ºä¿¡æ¯91 * -false 䏿·»å æç¤ºä¿¡æ¯92 * -true èªå¨è®¾ç½®ï¼å¦æè®¾ç½®äºæ¨¡åï¼å°ä¼èªå¨å¡«å
ï¼å¦å使ç¨é»è®¤ææ¬ä¿¡æ¯93 */94 public $header = true;95 /**96 * @var array æç¤ºä¿¡æ¯æ é¢ç HTML 屿§97 */98 public $headerOptions = [];99 /**100 * @var Closure æ¯æ·»å ä¸ä¸ªå
ç´ åçåè°æ¹æ³101 */102 public $beforeItem = null;103104 /************************* 以ä¸å±æ§å为ç¨åºè¿ç®éè¦ï¼ä¸è¦å°è¯ä»å¤é¨è¿è¡å¤å¶ *************************/105 /**106 * @var array 䏿æ ç¾ä¸çå
ç´ æ°æ®107 */108 protected $items = [];109 /**110 * @var array æ°æ®åºç´æ¥æ¥è¯¢åºæ¥çæ°æ®111 */112 protected $data = [];113 /**114 * @var string selectæ ç¾çname屿§åç§°115 */116 protected $name = '';117 /**118 * @var array å
³èè¡¨çæ°æ®119 */120 protected $withData = [];121 /**122 * @var string å
³è表ç主é®123 */124 protected $withKey;125 /**126 * @var string å
³èè¡¨çæ¾ç¤ºåæ®µ127 */128 protected $withValue;129 /**130 * @var string name屿§çå¼131 */132 private $_name = null;133134 /**135 * åå§å136 */137 public function init()138 {139 parent::init();140 // åå§å模å141 if ($this->query instanceof \yii\db\ActiveQuery && $this->model === null) {142 $this->model = new $this->query->modelClass;143 }144 // 夿æ¯å¦è®¾ç½®å
³è表çå±çº§å
³ç³»è¾åº145 if ($this->with === null && $this->query->with) {146 $this->with = current($this->query->with);147 }148 // 设置å
³è表ç¸å
³ä¿¡æ¯149 if ($this->with) {150 if (!$this->withName) {151 throw new InvalidParamException("éè¿ \$query ç `with()` æ¹æ³è¿è¡å
³èæ¥è¯¢åï¼å¿
须设置 [withName]ï¼æå®è¦æ¾ç¤ºçå
³èè¡¨åæ®µï¼");152 } else {153 if (is_string($this->withName)) {154 $this->withKey = $this->key;155 $this->withName = (array) $this->withName;156 } else {157 $this->withKey = key($this->withName);158 }159 $this->withValue = current($this->withName);160 }161 162 if ($this->withQuery instanceof \yii\db\ActiveQuery) {163 $withModel = new $this->withQuery->modelClass;164 } else {165 $withFunc = 'get' . ucfirst($this->with);166 $withQuery = $this->model->{$withFunc}();167 $withModel = new $withQuery->modelClass;168 $withQuery = $withModel::find();169 if ($this->withQuery instanceof \Closure) {170 call_user_func($this->withQuery, $withQuery);171 }172 $this->withQuery = $withQuery;173 }174 }175 // 妿æè®¾ç½®æ¨¡åï¼è·åææå段176 if ($this->model !== null) {177 if ($this->with) {178 $attributes = $withModel->attributes();179 } else {180 $attributes = $this->model->attributes();181 }182 }183 // åæ®µåç§°è®¾ç½®æ£æ¥184 if (!empty($attributes)) {185 if (!in_array($this->pid, $attributes)) {186 $model = $this->model;187 throw new InvalidParamException("{$model::className()} 对åºçè¡¨ä¸æ²¡æ `{$this->pid}` åæ®µï¼");188 }189 if (!in_array($this->sort, $attributes)) {190 $this->sort = null;191 }192 // èªå¨æ ¡æ£ä¸»é®193 $this->key = current($this->model->primaryKey());194 }195 // å
¶ä»åæ°åå§å196 $this->select = array_unique(array_merge($this->select, $this->optionAttrs));197 }198199 /**200 * 以 select æ ç¾å½¢å¼è¾åºæ°æ®201 * 202 * @param string $field æ¾ç¤º<option>ç[html]å¼çåæ®µåç§°203 * @param mixed $selection éä¸å¼204 * @param array $options é
ç½®åæ°ï¼é
ç½®`name`æ¥ä¿®æ¹é»è®¤ç设å®å¼205 * @return string select æ ç¾ç HTML 代ç 206 */207 public function dropDownList($field, $selection = '', $options = [])208 {209 $this->name = $field;210211 $this->prepareItems();212213 $items = [];214 foreach ($this->items as $item) {215 $items[$item['key']] = $item['text'];216 $item['options'][$item['key']]['data-text'] = $item['value'];217 $options['options'][$item['key']] = $item['options'][$item['key']];218 foreach ($this->optionAttrs as $attr) {219 $options['options'][$item['key']]['data-' . $attr] = ArrayHelper::getValue($item, $attr, '');220 }221 }222 $options['encodeSpaces'] = true;223 $name = ArrayHelper::getValue($options, 'name', $this->getName());224225 return Html::dropDownList($name, $selection, $items, $options);226 }227228 /**229 * è·åå
æ°æ®230 * 231 * @param string $name ç¨ä½å½ [name] 屿§çåæ®µåç§°232 * @return array233 */234 public function getItems($name)235 {236 $this->name = $name;237238 $this->prepareItems();239240 return $this->items;241 }242243 /**244 * æ·»å æç¤ºä¿¡æ¯æ é¢245 */246 protected function addHeaderItem()247 {248 if ($this->header === true) {249 if ($this->model && method_exists($this->model, 'attributeLabels') && !empty($this->model->attributeLabels()[$this->getName()])) {250 $header = $this->model->attributeLabels()[$this->getName()];251 } else {252 $header = 'è¯·éæ©...';253 }254 array_unshift($this->items, ['key' => '', 'value' => $header, 'text' => $header, 'options' => ['' => $this->headerOptions]]);255 } elseif (is_string($this->header)) {256 array_unshift($this->items, ['key' => '', 'value' => $this->header, 'text' => $this->header, 'options' => ['' => $this->headerOptions]]);257 }258 }259260 /**261 * åå§åæ°æ®262 */263 protected function prepareItems()264 {265 if ($this->with) {266 if ($this->sort) {267 $this->withQuery->addOrderBy($this->sort);268 }269 $this->withData = $this->withQuery->indexBy($this->withKey)->asArray()->all();270 $this->data = $this->query->asArray()->all();271272 $pid = $this->getItemParentId($this->withData);273 $this->setWithItems($pid);274 } else {275 if ($this->sort) {276 $this->query->addOrderBy($this->sort);277 }278 $this->data = $this->query->indexBy($this->key)->asArray()->all();279280 $pid = $this->getItemParentId($this->data);281 $this->setItems($pid);282 }283284 $this->addHeaderItem();285 }286287 /**288 * 设置éå
³èåçå
ç´ 289 */290 protected function setItems($pid = '0', $recursionLevel = 0)291 {292 $recursionLevel++;293 foreach ($this->data as $key => $row) {294 if ($row[$this->pid] === $pid) {295 if ($this->beforeItem !== null && !call_user_func($this->beforeItem, $row)) {296 continue;297 }298 if ($recursionLevel === 1) {299 $prefix = 'â
';300 } else {301 $prefix = str_repeat(' ', ($recursionLevel - 2) * 3) . 'â ';302 }303 $value = $this->getNameValue($row);304 $item = [305 'key' => $row[$this->key],306 'text' => $prefix . $value,307 'value' => $value,308 ];309 foreach ($this->select as $select) {310 $item[$select] = $row[$select];311 }312 $this->items[] = $item;313 $this->setItems($row[$this->key], $recursionLevel);314 unset($this->data[$key]);315 }316 }317 }318319 /**320 * 设置å
³èåçå
ç´ 321 */322 protected function setWithItems($pid = '0', $recursionLevel = 0)323 {324 $recursionLevel++;325 foreach ($this->withData as $key => $row) {326 if ($row[$this->pid] === $pid) {327 $withPrefix = str_repeat(' ', ($recursionLevel - 1) * 3) . 'â
';328 $withKey = $this->withKeyPrefix . $row[$this->withKey];329 $withValue = $row[$this->withValue];330 $this->items[$withKey] = [331 'key' => $withKey,332 'text' => $withPrefix . $withValue,333 'value' => $withValue,334 'options' => [$withKey => $this->withOptions]335 ];336 foreach ($this->data as $k => $item) {337 if ($item[$this->with][$this->withKey] == $row[$this->withKey]) {338 $prefix = str_repeat(' ', ($recursionLevel - 1) * 3) . ' â ';339 $value = $this->getNameValue($item);340 $this->items[$item[$this->key]] = [341 'key' => $item[$this->key],342 'text' => $prefix . $value,343 'value' => $value344 ];345 foreach ($this->select as $select) {346 $this->items[$item[$this->key]][$select] = $item[$select];347 }348 unset($this->data[$k]);349 }350 }351 unset($this->withData[$key]);352 $this->setWithItems($row[$this->withKey], $recursionLevel);353 }354 }355 }356357 /**358 * è·åå
³è表对åºå段çå¼359 */360 protected function getNameValue($item)361 {362 if (strpos($this->name, '.') !== false) {363 $relations = explode('.', $this->name);364 $name = array_pop($relations);365 $row = $item;366 foreach ($relations as $relation) {
...
Index.php
Source:Index.php
...35 continue;36 }37 if (endsWith($field, '@')) {38 $field = substr($field, 0, -1);39 list($items, $withTable, $withKey) = explode("/", $condition);40 foreach ($allData[$items] as $keyNum => $item) {41 $data1 = clone $data;42 $data1 = $data1->where($field, $allData[$items][$keyNum][$withKey]);43 $allData[$items][$keyNum][$sub] = $data1->select();44 // $allData[$items][$keyNum][$sub] = $data->select();45 // $allData[$items][$keyNum][$sub] = $data->getLastSql();46 }47 continue;48 }49 }50 }51 continue;52 }53 // è¿éåºè¯¥ä½¿ç¨éå½ end54 $data = Db::table($table);55 // $data = clone $data1;56 foreach ($where as $field => $condition) {57 if (endsWith($field, '@')) {58 $field = substr($field, 0, -1);59 // list($withTable, $withKey) = explode("/", $condition);60 // list($items, $withTable, $withKey) = explode("/", $condition);61 $explodeArr = explode("/", $condition);62 if (count($explodeArr) == 3) {63 // list($items, $withTable, $withKey) = $explodeArr;64 // // $data = $data->where($field, $allData[$items][$withTable][$withKey]);65 // $allData['aaaaa'] = $allData[$items][$withTable][$withKey];66 $allData['aaaaa'] = $explodeArr;67 }elseif (count($explodeArr) == 2) {68 list($withTable, $withKey) = $explodeArr;69 $data = $data->where($field, $allData[$withTable][$withKey]);70 }71 continue;72 }73 if ($field === "@column") {74 $data = $data->field($condition);75 continue;76 }77 $data = $data->where($field, $condition);78 // $allData['dddd'] .= $allData['dddd'] ? $allData['dddd'] : $table;79 $allData['sub'] = $sub;80 $allData['table'] = $table;81 // $allData[$sub][$table] = $data->select();82 }83 // $allData[$sub][$table] = $data->select();...
LinkResolverSpec.php
Source:LinkResolverSpec.php
...13 DefinitionInterface $definition,14 \stdClass $object15 ) {16 $this->beConstructedWith($router, $identityResolver);17 $router->generate('bravesheep_crudify.index', Argument::withKey('mapping'))->will(function ($args) {18 return '/' . $args[1]['mapping'] . '/index';19 });20 $router->generate('bravesheep_crudify.new', Argument::withKey('mapping'))->will(function ($args) {21 return '/' . $args[1]['mapping'] . '/new';22 });23 $router->generate('bravesheep_crudify.create', Argument::withKey('mapping'))->will(function ($args) {24 return '/' . $args[1]['mapping'] . '/create';25 });26 $router27 ->generate(28 'bravesheep_crudify.edit',29 Argument::allOf(Argument::withKey('mapping'), Argument::withKey('id'))30 )31 ->will(function ($args) {32 return '/' . $args[1]['mapping'] . '/edit/' . $args[1]['id'];33 })34 ;35 $router36 ->generate(37 'bravesheep_crudify.update',38 Argument::allOf(Argument::withKey('mapping'),Argument::withKey('id'))39 )40 ->will(function ($args) {41 return '/' . $args[1]['mapping'] . '/update/' . $args[1]['id'];42 })43 ;44 $router45 ->generate(46 'bravesheep_crudify.delete',47 Argument::allOf(Argument::withKey('mapping'), Argument::withKey('id'))48 )49 ->will(function ($args) {50 return '/' . $args[1]['mapping'] . '/delete/' . $args[1]['id'];51 })52 ;53 $definition->getName()->willReturn('test');54 $identityResolver->getId($definition, $object)->willReturn(42);55 }56 function it_is_initializable()57 {58 $this->shouldHaveType('Bravesheep\CrudifyBundle\Resolver\LinkResolver');59 }60 function it_should_retrieve_the_index_link(DefinitionInterface $definition)61 {...
withKey
Using AI Code Generation
1$student = new Student;2$student->name->withKey('first', 'John');3$student->name->withKey('last', 'Smith');4echo $student->name->first . ' ' . $student->name->last;5$student = new Student;6$student->name->withKey('first', 'John');7$student->name->withKey('last', 'Smith');8echo $student->name->first . ' ' . $student->name->last;9$student = new Student;10$student->name->withKey('first', 'John');11$student->name->withKey('last', 'Smith');12echo $student->name->first . ' ' . $student->name->last;13$student = new Student;14$student->name->withKey('first', 'John');15$student->name->withKey('last', 'Smith');16echo $student->name->first . ' ' . $student->name->last;17$student = new Student;18$student->name->withKey('first', 'John');19$student->name->withKey('last', 'Smith');20echo $student->name->first . ' ' . $student->name->last;21$student = new Student;22$student->name->withKey('first', 'John');23$student->name->withKey('last', 'Smith');24echo $student->name->first . ' ' . $student->name->last;25$student = new Student;26$student->name->withKey('first', 'John');27$student->name->withKey('last', 'Smith');28echo $student->name->first . ' ' . $student->name->last;29$student = new Student;30$student->name->withKey('first', 'John');
withKey
Using AI Code Generation
1$person = new Person();2$person->withKey('name', 'Sally');3echo $person->name;4$person = new Person();5$person->withKey('age', 20);6echo $person->age;7$person = new Person();8$person->withKey('address', [9]);10echo $person->address->city;11$person = new Person();12$person->withKey('address', [13]);14echo $person->address->city;15$person = new Person();16$person->withKey('address', [17]);18echo $person->address->city;19$person = new Person();20$person->withKey('address', [21]);22echo $person->address->city;23$person = new Person();24$person->withKey('address', [25]);26echo $person->address->city;27$person = new Person();28$person->withKey('address', [29]);30echo $person->address->city;31$person = new Person();32$person->withKey('address
withKey
Using AI Code Generation
1require_once 'name.php';2$myName = new name();3$myName->withKey('test');4echo $myName->getFirstName();5echo $myName->getLastName();6require_once 'name.php';7$myName = new name();8$myName->withKey('test');9echo $myName->getFirstName();10echo $myName->getLastName();11require_once 'name.php';12$myName = new name();13$myName->withKey('test');14echo $myName->getFirstName();15echo $myName->getLastName();16require_once 'name.php';17$myName = new name();18$myName->withKey('test');19echo $myName->getFirstName();20echo $myName->getLastName();21require_once 'name.php';22$myName = new name();23$myName->withKey('test');24echo $myName->getFirstName();25echo $myName->getLastName();26require_once 'name.php';27$myName = new name();28$myName->withKey('test');29echo $myName->getFirstName();30echo $myName->getLastName();31require_once 'name.php';32$myName = new name();33$myName->withKey('test');34echo $myName->getFirstName();35echo $myName->getLastName();36require_once 'name.php';37$myName = new name();38$myName->withKey('test');39echo $myName->getFirstName();40echo $myName->getLastName();41require_once 'name.php';42$myName = new name();43$myName->withKey('test');44echo $myName->getFirstName();45echo $myName->getLastName();
withKey
Using AI Code Generation
1require_once('name.php');2$myname = new name('John', 'Doe');3$myname->withKey('first', 'Jane');4echo $myname->first . ' ' . $myname->last;5require_once('name.php');6$myname = new name('John', 'Doe');7$myname->withKey('last', 'Smith');8echo $myname->first . ' ' . $myname->last;9require_once('name.php');10$myname = new name('John', 'Doe');11$myname->withKey('middle', 'Paul');12echo $myname->first . ' ' . $myname->middle . ' ' . $myname->last;13require_once('name.php');14$myname = new name('John', 'Doe');15$myname->withKey('middle', 'Paul');16$myname->withKey('first', 'Jane');17$myname->withKey('last', 'Smith');18echo $myname->first . ' ' . $myname->middle . ' ' . $myname->last;19require_once('name.php');20$myname = new name('John', 'Doe');21$myname->withKey('middle', 'Paul');22$myname->withKey('first', 'Jane');23$myname->withKey('last', 'Smith');24$myname->withKey('middle', 'Mary');25echo $myname->first . ' ' . $myname->middle . ' ' . $myname->last;26require_once('name.php');27$myname = new name('John', 'Doe');28$myname->withKey('middle', 'Paul');29$myname->withKey('first', 'Jane');30$myname->withKey('last', '
withKey
Using AI Code Generation
1$names = new names();2$names->withKey('C')->withKey('A')->withKey('B');3$names->show();4$names = new names();5$names->withKey('C')->withKey('A')->withKey('B');6$names->show();7$names = new names();8$names->withKey('C')->withKey('A')->withKey('B');9$names->show();10$names = new names();11$names->withKey('C')->withKey('A')->withKey('B');12$names->show();13$names = new names();14$names->withKey('C')->withKey('A')->withKey('B');15$names->show();16$names = new names();17$names->withKey('C')->withKey('A')->withKey('B');18$names->show();19$names = new names();20$names->withKey('C')->withKey('A')->withKey('B');21$names->show();22$names = new names();23$names->withKey('C')->withKey('A')->withKey('B');24$names->show();25$names = new names();26$names->withKey('C')->withKey('A')->withKey('B');27$names->show();28$names = new names();29$names->withKey('C')->withKey('A')->withKey('B');30$names->show();31$names = new names();32$names->withKey('C')->withKey('A')->withKey('B');
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with withKey on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!