/** * Validator requires name, config and data from which it will validate given item * @param $name * @param $validatorConfig * @param $data * @return bool|mixed */ public function validate($name, $validatorConfig, $data) { $validator = isset($validatorConfig[$name]) ? $validatorConfig[$name] : false; if ($validator === false) { return $validator; } if ((!isset($data[$name]) || trim($data[$name]) == '') && isset($validator['default'])) { return $validator['default'] === 'null' ? null : $validator['default']; } if ((!isset($data[$name]) || trim($data[$name]) == '') && !isset($validator['default'])) { $response = new Response("Field {$name} is mandatory in data: " . serialize($data), 200, true); $response->toJSON(); } foreach ($validator['validators'] as $val) { $isValid = self::$val($data[$name]); if (!$isValid) { $response = new Response($name . ' is ' . $data[$name] . ' and must be a ' . $val, 200, true); $response->toJSON(); } } return $data[$name]; }
/** * Makes the CURL call to the TDMB API * * @param string $url * @param array $params * @return TMDb result array */ protected function call($url, $params = []) { $params = !empty($params) ? http_build_query($params, '', '&') : ''; $url = $this->apiUrl . '/' . $this->apiVersion . '/' . $url . '?api_key=' . $this->apiKey . '&' . $params; if (extension_loaded('curl')) { $curl = curl_init(); curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $url, CURLOPT_HTTPHEADER => ['Accept: application/json'])); $error_number = curl_errno($curl); $error_message = curl_error($curl); if ($error_number > 0) { $this->response->toJSON('Method failed: ' . $error_message); } $response = curl_exec($curl); $result = json_decode($response, TRUE); curl_close($curl); } else { throw new Exception('CURL-extension not loaded'); } if (!$result) { throw new Exception('Server error on: ' . $response); } return $result; }
* http://www.opensource.org/licenses/mit-license.php * * Visit http://www.popstop.io for more information * * @author Sebastian de Kok */ //Autoload all the controllers and classes spl_autoload_register(function ($class) { $directory = strpos($class, 'Controller') !== false ? 'Controllers' : 'Classes'; $location = getcwd() . "/app/src/{$directory}/{$class}.php"; if (is_file($location)) { require_once $location; } }); $request_method = getenv('REQUEST_METHOD'); //Catch the post|get request and call the related function if ($request_method === "POST" || $request_method === "GET") { $params = $request_method === "POST" ? filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING) : filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING); $function = $params['function']; $controller = new MovieController(); $response = new Response(); if (method_exists($controller, $function)) { try { $response->toJSON($controller->{$function}($params)); } catch (\Exception $e) { $response->toJSON($e->getMessage()); } } else { $response->toJSON("The Function does not exist: {$function}"); } }
// set header $mailer->isSMTP(); $mailer->Host = 'box729.bluehost.com'; $mailer->SMTPAuth = true; $mailer->Username = '******'; $mailer->Password = '******'; $mailer->SMTPSecure = 'ssl'; $mailer->Port = 465; // set from, to and carbon copy (hidden) $mailer->setFrom('*****@*****.**', 'Raiz do Brasil - MailMan'); $mailer->addAddress('Promafa', '*****@*****.**'); $mailer->addAddress('Diego Souza', '*****@*****.**'); $mailer->addAddress('Adrieli', '*****@*****.**'); $mailer->addAddress('SAC', '*****@*****.**'); $mailer->addBCC('*****@*****.**', 'Eduardo Barros'); // set type, subject and body $mailer->isHTML(true); $mailer->Subject = 'Requisição de contato - Raiz do Brasil'; $mailer->Body = $_GET['message']; $mailer->AltBody = $_GET['message']; // create new instance of response $response = new Response($_GET, $mailer); // send if (!$mailer->send()) { $response->setSent(false); } else { $response->setSent(true); } // print response JSON print_r($response->toJSON());