/** * Set response body * * @param mixed $body Response body * @return void * @throws InvalidResponseException */ public function setBody($body) { if ($body !== false && (empty($body) || !is_array($body) || count($body) % 2 !== 0)) { throw new InvalidResponseException($this->command, $body); } parent::setBody($body); }
/** * getInstance * * Get a singleton instance of the class * * @return Response */ public static function getInstance() { if (!self::$_instance instanceof self) { self::$_instance = new self(); } return self::$_instance; }
/** * Factory - create the response * * @param $data * * @return self|boolean */ public function create($data) { $parent = parent::create($data); $data = $parent->getData(); $response = new self(); $response->setStatus($parent->getStatus()); $response->setErrorMessage($parent->getErrorMessage()); $response->setUserExists((int) $data > 0); return $response; }
/** * Factory - create the response * * @param $data * * @return self|boolean */ public function create($data) { $parent = parent::create($data); $data = $parent->getData(); $response = new self(); $response->setStatus($parent->getStatus()); $response->setErrorMessage($parent->getErrorMessage()); if (isset($data['count'])) { $response->setCount($data['count']); if ($response->getCount() > 0) { $response->setSubscribers($data['subscriberlist']['item']); } } return $response; }
/** * Set response body * * @param mixed $body Response body * @return void * @throws InvalidResponseException */ public function setBody($body) { switch ($this->type) { case self::TYPE_INT: $error = !is_numeric($body); break; case self::TYPE_STRING: default: $error = !is_string($body); break; } if ($error) { throw new InvalidResponseException($this->command, $body); } parent::setBody($body); }
public function __construct($message, array $payload = null) { parent::__construct($message, $payload); $this->success = false; }
public function __construct() { parent::__construct(); }
<?php require_once '../../../wp-config.php'; require_once './includes/parser/video_parser.php'; require_once './includes/Model/BaseResponse.php'; global $wpdb; $VParser = new VParser(); $response = new BaseResponse(); if ($_POST) { $parse_sites = $_POST['sites']; $parse_categories = $_POST['categories']; $parse_title_generator = $_POST['title_gnerator']; $posts_count = $_POST['posts_count'] ? $_POST['posts_count'] * 1 : 10; } elseif ($_GET) { if (isset($_SERVER['REMOTE_ADDR'])) { exit; } $parse_sites = 'all'; $parse_categories = 'all'; $parse_title_generator = 'auto'; $posts_count = 'auto'; } if ($parse_sites === 'all') { $parse_sites = []; $sites = $VParser->getSites(); foreach ($sites as $site) { $parse_sites[] = $site->getName(); } } if ($parse_categories === 'all') { $parse_categories = [];
/** * Constructor * * @param boolean $successful * @param Response $response * @param array $errors */ public function __construct($successful = false, Response $response = null, array $errors = array()) { $this->success = $successful; $this->errors = $errors; parent::__construct($response); }
private function createContent() { $content = array('errorCode' => $this->errorCode, 'errors' => $this->errors); parent::setContent($content); }
<?php require_once '../../../wp-config.php'; require_once './includes/parser/video_parser.php'; require_once './includes/parser/text_generator.php'; require_once './includes/Model/BaseResponse.php'; global $wpdb; $VParser = new VParser(); $response = new BaseResponse(); $action = strip_tags($_GET['action']); if ($action == 'random_video') { $category_id = $_GET['category_id'] * 1; if ($category_id) { $wp_category = get_terms('category', ['include' => $category_id, 'hide_empty' => false]); if (count($wp_category)) { $base_sites = $VParser->getSites(); $rand_site = rand(0, count($base_sites) - 1); if ($random_video = $VParser->getRandomVideo($base_sites[$rand_site]->getName(), $wp_category)) { $response->success($random_video); } else { $response->error("Не удалось найти видео"); } } else { $response->error("Категория с id #{$category_id} не найдена"); } } else { $response->error("Не найдено параметра 'category_id'"); } } elseif ($action == 'add_post') { $params = $_POST['params']; $result = $VParser->addNewPost($params);