public function getTweet($idStr) { $timelineKey = $this->cacheKey('timeline'); if ($this->cache->contains($timelineKey)) { $statuses = $this->cache->fetch($timelineKey); $statusFoundInCache = Arrays::find($statuses, function ($status) use($idStr) { return $status->id_str === $idStr; }); if ($statusFoundInCache) { return new Tweet($statusFoundInCache); } } $status = $this->loadTweet($idStr); return new Tweet($status); }
/** * [processContent description] * @param [type] $ctype [description] * @param [type] $data [description] * @return [type] [description] */ public function processContent($ctype, $data) { $processedData = []; $filePath = \Yii::getAlias('@app/workspace/elements') . DIRECTORY_SEPARATOR . $this->entryPoint['ctype'] . '.json'; $definitionPath = \Yii::getAlias('@app/workspace/elements') . DIRECTORY_SEPARATOR . $ctype . '.json'; $elementDefinition = \yii\helpers\Json::decode(file_get_contents($definitionPath), false); if ($data) { foreach ($data as $key => $content) { $fieldType = Arrays::find($elementDefinition->fields, function ($value) use($key) { return $value->key == $key; }); if (is_object($fieldType)) { $fieldType = $fieldType->type; } if (!empty($fieldType)) { // Get processor class. $processorClass = 'giantbits\\crelish\\plugins\\' . strtolower($fieldType) . '\\' . ucfirst($fieldType) . 'ContentProcessor'; if (strpos($fieldType, "widget_") !== false) { $processorClass = str_replace("widget_", "", $fieldType) . 'ContentProcessor'; } if (class_exists($processorClass)) { $processorClass::processData($this, $key, $content, $processedData); } else { $processedData[$key] = $content; } } } } return $processedData; }
public function testCanFindAValueInAnArray() { $under = Arrays::find($this->arrayNumbers, function ($value) { return $value % 2 == 0; }); $this->assertEquals(2, $under); $unfound = Arrays::find($this->arrayNumbers, function ($value) { return $value == 5; }); $this->assertNull($unfound); }