Пример #1
0
 public function test_array_pick()
 {
     $this->assertEquals(array(), array_pick(array(), array('foo', 'bar', 'baz')));
     $this->assertEquals(array(), array_pick(array('bzz' => 'bar'), array('foo', 'bar', 'baz')));
     $this->assertEquals(array('foo' => 'bar'), array_pick(array('foo' => 'bar'), array('foo', 'bar', 'baz')));
     $this->assertEquals(array('foo' => 'bar'), array_pick(array('foo' => 'bar'), 'foo', 'bar'));
     $this->assertEquals(array('foo' => 'bar'), array_pick(array('foo' => 'bar'), 'foo'));
 }
Пример #2
0
 public function send($random = NULL)
 {
     $messages = !empty($random) ? array_pick($this->messages, $random) : $this->messages;
     foreach ($messages as $value) {
         //Queue
         $job = (new WechatSend($this->user, $value))->onQueue('wechat');
         app('Illuminate\\Contracts\\Bus\\Dispatcher')->dispatch($job);
     }
     return true;
 }
Пример #3
0
 /**
  * 返回所有国家
  * @api /country/
  * @return [type] [description]
  */
 public function indexAction()
 {
     $countries = Countries::find();
     $requestCnt = array_pick($this->request->getAcceptableContent(), 'accept', true);
     if (in_array('application/json', $requestCnt)) {
         $response = new Response();
         $response->setHeader("Content-Type", "application/json");
         echo json_encode($countries->toArray());
         $this->view->disable();
     } else {
         $this->view->setVar('countries', $countries);
         $this->view->setVar('title', '世界国家');
     }
 }
Пример #4
0
 public function fire()
 {
     $newFeatures = [];
     $planIdentifier = $this->argument('plan');
     $plan = $this->planRepo->getPlanByIdentifier($planIdentifier);
     $tiers = $this->planRepo->getTiersByPlanIdentifier($planIdentifier);
     $this->represntPlanInTable($plan);
     $this->representPlanFeaturesInTable($tiers);
     $oldFeatures = $this->planRepo->getFeaturesByPlanIdentifier($planIdentifier);
     $oldFeatures = array_pick($oldFeatures, 'identifier');
     do {
         $newFeatures[] = $this->addFeatures($oldFeatures, $plan['id']);
     } while ($this->confirm('Do you wish to add more features ? [yes|no]'));
     $this->representFeaturesInTable($newFeatures);
     if (count($newFeatures) > 0) {
         $this->updateSubscribersForUpdatedPlan($plan['id'], $newFeatures);
     }
 }
Пример #5
0
function getHeroName($key)
{
    switch ($key) {
        case 'b':
            $value = array_pick(array('Ulfric', 'Ragnar', 'Wulf', 'Jorval', 'Ghankar', 'Skelf', 'Cromm'));
            break;
        case 'd':
            $value = array_pick(array('Gotrek', 'Skaggi', 'Mungrun', 'Thorgrim', 'Gummli', 'Hengist', 'Rorek')) . ' ' . array_pick(array('Gurnisson', 'Longbeard', 'Ironhammer', 'Cragbrow', 'Thunderer', 'Steelfist', 'Forkbeard'));
            break;
        case 'e':
            $value = array_pick(array('Caledor', 'Tethlis', 'Aenarion', 'Koradrel', 'Aethis', 'Unthwe', 'Talion'));
            break;
        case 'w':
            $value = array_pick(array('Calcazar', 'Wulfhir', 'Alric', 'Balthazar', 'Dieter', 'Magnus', 'Solkan')) . ' ' . array_pick(array('Firefist', 'the Green', 'Whitecloak', 'the Magnificent', 'the Black', 'the Red', 'Orcbane'));
            break;
        default:
            $value = 'Error in getHeroName: no name for ' . $key;
    }
    return $value;
}
Пример #6
0
 public function initialize()
 {
     $this->acceptType = array_pick($this->request->getAcceptableContent(), 'accept', true);
 }
Пример #7
0
 /**
  * Retrieves data from the object
  *
  * If $key is empty will return all the data as an array
  * Otherwise it will return value of the attribute specified by $key
  *
  * If $index is specified it will assume that attribute data is an array
  * and retrieve corresponding member.
  *
  * @since 4.8.1
  * @param string $key
  * @param string|int $index
  * @return mixed
  */
 public function getData($key = '', $index = null)
 {
     if ('' === $key) {
         return $this->_data;
     }
     if (is_array($key)) {
         return array_pick($this->_data, $key);
     }
     $default = null;
     // accept a/b/c as ['a']['b']['c']
     if (strpos($key, '/')) {
         $keyArr = explode('/', $key);
         $data = $this->_data;
         foreach ($keyArr as $i => $k) {
             if ($k === '') {
                 return $default;
             }
             if (is_array($data)) {
                 if (!isset($data[$k])) {
                     return $default;
                 }
                 $data = $data[$k];
             } elseif ($data instanceof Wp_Rss_SpinnerChief_Data_Object) {
                 $data = $data->getData($k);
             } else {
                 return $default;
             }
         }
         return $data;
     }
     // legacy functionality for $index
     if (isset($this->_data[$key])) {
         if (is_null($index)) {
             return $this->_data[$key];
         }
         $value = $this->_data[$key];
         if (is_array($value)) {
             //if (isset($value[$index]) && (!empty($value[$index]) || strlen($value[$index]) > 0)) {
             /**
              * If we have any data, even if it empty - we should use it, anyway
              */
             if (isset($value[$index])) {
                 return $value[$index];
             }
             return null;
         } elseif (is_string($value)) {
             $arr = explode("\n", $value);
             return isset($arr[$index]) && (!empty($arr[$index]) || strlen($arr[$index]) > 0) ? $arr[$index] : null;
         } elseif ($value instanceof Wp_Rss_SpinnerChief_Data_Object) {
             return $value->getData($index);
         }
         return $default;
     }
     return $default;
 }