_category = $category; $this->_user_entity = $user_entity; } final protected function getMyStorage() { if ($this->_myStorage === null) { $this->_myStorage = new MangboardStorage($this->_category, $this->_user_entity); } return $this->_myStorage; } //작성내용 //
protected function detail_page(array $listInfo): array { $response = $this->getMySocket()->getContent($listInfo['detail_url']); $tag = getenv("yamap.view.content.tag"); return $this->getMediaUrls($response, $tag, $listInfo); } protected function list_page(): array { if ($this->getDebug()) { return [ 'title' => getenv("yamap.view.test.title"), 'nickname' => getenv("yamap.view.test.nickname"), 'detail_url' => getenv("yamap.view.test.url"), 'time' => date("Y-m-d H:i:s"), 'hit' => 1, ]; } $listInfos = []; $response = $this->getMySocket()->getContent(getenv("yamap.list.url.{$this->_category}")); $selector = $this->getSelector($response, getenv("yamap.list.tag")); //div.bbs_item를 가진 객체를 찾아서 같은 형식의 객체(sibling)를 배열로 넘김 // log_message("debug", sprintf("\n-------------MainPage------------\n%s\n--------------------------\n", $selector->html())); $selector->filter(getenv("yamap.list.item.tag"))->each( function (Crawler $node) use (&$listInfos): void { //bbs_item에서 span.g_nickname 객체를 찾아서 작성자가 "관리자" 아닌지 확인 후 Return Bool $nickname = $node->filter(getenv("yamap.list.item.nickname.tag"))->text(); $hit = $node->filter(getenv("yamap.list.item.hit.tag"))->text(); $date = $node->filter(getenv("yamap.list.item.date.tag"))->text(); if ($nickname != getenv("yamap.list.item.nickname.except")) { //작성자가 "관리자"가 아니 게시물이면 해당 bbs_item에서 a.list_subject 객체를 찾아서 $link_node = $node->filter(getenv("yamap.list.item.link.tag")); $detail_url = $link_node->attr("href"); $title = $link_node->children()->last()->text(); $listInfos[] = ['title' => $title, 'nickname' => $nickname, 'detail_url' => $detail_url, 'date' => $date, 'hit' => $hit]; } } ); if (!count($listInfos)) { throw new \Exception("Target URL이 없습니다."); } log_message("notice", __FUNCTION__ . " 작업 완료"); return $listInfos; } protected function backend_process(int $i, array $listInfo, array $storages) { //File DB 및 Board DB 등록작업 $board_entity = $this->getMyStorage()->getBoard()->createByCrawler($i, $listInfo, $storages); $this->getMyStorage()->getFile()->createByCrawler($board_entity, $storages); $this->getMyStorage()->getImage()->createByCrawler($board_entity, $storages); } public function execute(int $max_limit): void { $listInfos = $this->list_page(); $this->main_process($max_limit, $listInfos); log_message("notice", __FUNCTION__ . " 작업이 완료되었습니다."); } }