/** * Retrieves the last $postCount articles from vdm and saves them into the database * * @param int $postCount : the number of entries to retrieve * @return array<Post> */ public function scrap($postCount) { $articles = Scraper::getLatestPosts($postCount); return Arrays::each($articles, function ($article) { return Scraper::persistPost($article); }); }
/** * Execute the console command. * * @return mixed */ public function handle() { $this->scraper = new Scraper(); $this->postRepository = new PostRepository(new Post()); $this->info("Fetching posts from vdm..."); $posts = $this->scraper->scrap(200); $this->info(sprintf("Saving %d posts.", Arrays::size($posts))); Arrays::each($posts, function ($post) { $this->postRepository->create($post->toArray()); }); $this->info("Done."); }
public function testCanActOnEachValueFromArray() { $closure = function ($value, $key) { return $key . ':' . $value; }; $under = Arrays::each($this->array, $closure); $result = array('foo' => 'foo:bar', 'bis' => 'bis:ter'); $this->assertEquals($result, $under); }
/** * Get a list of folders to clear * * @return array */ private function getFoldersToClear() { $folders = $this->argument('folder'); $folders = $folders ? explode(',', $folders) : null; // If no folders provided, get all folders if (!$folders) { $storage = $this->app->path . '/storage/*'; $folders = $this->files->glob($storage); $folders = Arrays::each($folders, function ($folder) { return basename($folder); }); } return $folders; }
function validate_format() { return Object::values(Arrays::clean(Arrays::each($this->values(), function ($value, $key) { $field = $this->get_fields()[$key]; if (empty($value)) { if (isset($field['required']) && $field['required']) { return $this->build_error('invalid', array('%field%' => $field['label'])); } } else { switch ($field['type']) { case 'string': if (isset($field['maxlength'])) { $maxlength = $field['maxlength']; if (strlen($value) > $maxlength) { return $this->build_error('invalid', array('%field%' => $field['label'], '%maxlength%' => $maxlength)); } } break; case 'email': if (!filter_var($value, FILTER_VALIDATE_EMAIL)) { return $this->build_error('invalid', array('%field%' => $field['label'])); } break; case 'number': if (!is_numeric($value)) { return $this->build_error('invalid', array('%field%' => $field['label'])); } else { $value = intval($value); if (isset($field['minvalue']) && isset($field['maxvalue'])) { $min = $field['minvalue']; $max = $field['maxvalue']; if ($value < $min || $max < $value) { return $this->build_error('range', array('%field%' => $field['label'], '%minvalue%' => $min, '%maxvalue%' => $max)); } } else { if (isset($field['minvalue'])) { $min = $field['minvalue']; if ($value < $min) { return $this->build_error('minvalue', array('%field%' => $field['label'], '%minvalue%' => $min)); } } else { if (isset($field['maxvalue'])) { $max = $field['maxvalue']; if ($max < $value) { return $this->build_error('maxvalue', array('%field%' => $field['label'], '%maxvalue%' => $max)); } } else { if (isset($field['select'])) { if (!Arrays::contains($field['select'], $value)) { return $this->build_error('select', array('%field%' => $field['label'], '%select%' => implode(', ', $field['select']))); } } } } } } break; } } }))); }