Project.php 955 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace Spider\Lib;
  3. use Dever;
  4. class Project
  5. {
  6. private $config;
  7. public function __construct($id)
  8. {
  9. if (!$id) {
  10. Dever::alert('id不存在');
  11. }
  12. $this->config = Dever::db('spider/project')->one($id);
  13. $this->check();
  14. $this->runing();
  15. }
  16. public function get()
  17. {
  18. return $this->config;
  19. }
  20. private function check()
  21. {
  22. if (!$this->config) {
  23. Dever::alert('项目未定义');
  24. }
  25. if ($this->config['status'] != 1) {
  26. //Dever::alert('项目不是待机状态');
  27. }
  28. }
  29. private function runing()
  30. {
  31. Dever::db('spider/project')->update(['status' => 2, 'where_id' => $this->config['id']]);
  32. $this->setting();
  33. }
  34. private function setting()
  35. {
  36. $this->config['col'] = Dever::db('spider/col')->state(['project_id' => $this->config['id']]);
  37. $this->config['url'] = explode("\r\n", $this->config['site']);
  38. $this->config['queue'] = new Queue();
  39. array_walk($this->config['url'], [$this->config['queue'], 'push']);
  40. }
  41. }