本文整理汇总了PHP中Respect\Validation\Validator::arr方法的典型用法代码示例。如果您正苦于以下问题:PHP Validator::arr方法的具体用法?PHP Validator::arr怎么用?PHP Validator::arr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Respect\Validation\Validator
的用法示例。
在下文中一共展示了Validator::arr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: post
public function post()
{
try {
$newManufacturer = (object) (['id' => null] + $_POST);
v::arr()->key('name', v::string()->notEmpty()->length(1, 300))->assert($_POST);
if ($_FILES['files']['error'] == 4) {
throw new Exception('O campo imagem é obrigatório');
}
if (empty($newManufacturer->manufacturer_featured)) {
$newManufacturer->manufacturer_featured = null;
}
$this->collection->persist($newManufacturer);
$this->collection->flush();
foreach ($_FILES as $file) {
$this->uploaderService->setFile($_POST['name'], 'files');
$image = (object) ['name' => $this->uploaderService->getFile()->getNameWithExtension(), 'title' => $_POST['name'], 'type' => $this->uploaderService->getFile()->getMimetype(), 'manufacturer_id' => $newManufacturer->id];
$this->imageCollection->persist($image);
$this->imageCollection->flush();
$this->uploaderService->upload();
}
header('HTTP/1.1 303 See Other');
header('Location: /catalog/manufacturers');
} catch (NestedValidationExceptionInterface $e) {
return $this->get() + ['manufacturer/addManufacturer' => $newManufacturer, 'messages' => $e->findMessages(['name' => 'O nome deve ser entre 1 e 300 caracteres'])];
}
}
示例2: OrderTable
function OrderTable($ordersProducts, $connection)
{
foreach ($ordersProducts as $arrayNumber => $orders_data) {
echo "<tr class='product'>";
foreach ($orders_data as $data_key => $data_value) {
//echo "data-key: ".$data_key." data-value: ".$data_value."<br>";
switch ($data_key) {
case "product_id":
$product = \App\DB\Products::get($data_value, $connection);
$flag = v::arr()->notEmpty()->validate($product);
if ($flag) {
printProduct($product);
} else {
echo "<td class='deleted-product' colspan='2'>Товар удален из базы данных</td>";
}
break;
case "amount":
echo "<td data-amount='{$data_value}'>" . $data_value . "</td></tr>";
break;
default:
break;
}
}
}
}
示例3: send
private function send($type, array $to, $subject, $template, $params)
{
if (!Validator::arr()->each(Validator::email())->validate($to)) {
throw new InvalidArgumentException('to', 'format_invalid');
}
$html = Application::get('templating')->render($template, array_merge(['SUBJECT' => $subject], $params));
$this->provider->send($type, $to, $subject, $html);
}
示例4: setData
/**
* Set the data content of Response, now the $data variable can be a array or a
* ArrayObject instaces, in the future I provide to allow to set a StandardClass obj
*
* @param mixed $data, the value of data
* @return
*/
public function setData($data)
{
if (Validator::arr()->validate($data)) {
$this->data = $data;
} else {
throw new InvalidArgumentException("make sure you have passed an array or ArrayObject istances for {$data} parameter", 1);
}
}
示例5: checkUsernameExists
public static function checkUsernameExists(Connection $connection, $username)
{
$stmt = $connection->prepare('SELECT * FROM `users`
WHERE `user_name` = :user_name');
$stmt->execute([':user_name' => $username]);
$result = $stmt->fetch(\PDO::FETCH_ASSOC);
if (v::arr()->notEmpty()->validate($result)) {
return true;
} else {
return false;
}
}
示例6: postChild
protected function postChild($categoryId)
{
try {
v::arr()->key('name', v::string()->notEmpty()->length(1, 300))->key('parent_category', v::notEmpty()->int()->equals($categoryId))->assert($_POST);
$newCategory = (object) (['id' => null] + $_POST);
$this->collection->persist($newCategory);
$this->collection->flush();
header('HTTP/1.1 303 See Other');
header('Location: ' . $_SERVER['REQUEST_URI']);
} catch (NestedValidationExceptionInterface $e) {
return ['category/editCategory' => $editProduct, 'messages' => $e->findMessages(['name' => 'Name must have between 1 and 300 chars'])];
}
}
示例7: post
public function post()
{
try {
v::arr()->key('name', v::string()->notEmpty()->length(1, 300))->key('description', v::string()->length(1, 300))->key('internal_code', v::string()->length(1, 30))->key('about', v::string())->assert($_POST);
$newProduct = (object) (['id' => null] + $_POST);
$this->collection->persist($newProduct);
$this->collection->flush();
header('HTTP/1.1 303 See Other');
header('Location: ' . $this->singleProduct->createUri($newProduct->id));
return $this->get();
} catch (NestedValidationExceptionInterface $e) {
return ['category/singleProduct' => $editProduct, 'messages' => $e->findMessages(['name' => 'Name must have between 1 and 300 chars', 'internal_code' => 'Internal Code must have between 1 and 300 chars', 'description' => 'Description must a maximum of 300 chars', 'enabled' => 'Could not enable product', 'about' => 'Invalid description'])];
}
}
示例8: post
public function post()
{
try {
v::arr()->key('name', v::string()->notEmpty()->length(1, 300))->assert($_POST);
$newCategory = (object) (['id' => null] + $_POST);
$this->collection->persist($newCategory);
$this->collection->flush();
header('HTTP/1.1 303 See Other');
header('Location: ' . $this->singleFeature->createUri($newCategory->id));
return $this->get();
} catch (NestedValidationExceptionInterface $e) {
return $e->findMessages(['name']);
}
}
示例9: foreach
if (!isset($params['address']) || !Validation::string()->length(null, 50)->validate($params['address'])) {
array_push($invalids, 'address');
}
if (!isset($params['deliver']) || !Validation::int()->min(0, true)->max(1, true)->validate($params['deliver'])) {
array_push($invalids, 'deliver');
}
if (!isset($params['timeFrom']) || !Validation::date('H:i')->validate($params['timeFrom'])) {
array_push($invalids, 'timeFrom');
}
if (!isset($params['timeTo']) || !Validation::date('H:i')->validate($params['timeTo'])) {
array_push($invalids, 'timeTo');
}
if (!isset($params['paid']) || !Validation::int()->min(0, true)->max(1, true)->validate($params['paid'])) {
array_push($invalids, 'paid');
}
if (!isset($params['items']) || !Validation::arr()->length(1, null)->validate($params['items'])) {
array_push($invalids, 'items');
}
foreach ($params['items'] as $index => $product) {
if (!isset($product['productId']) || !Validation::int()->min(0, true)->validate($product['productId'])) {
array_push($invalids, 'productId-' . $index);
}
if (!isset($product['plu']) || !Validation::int()->max(999999)->validate($product['plu'])) {
array_push($invalids, 'plu-' . $index);
}
if (!isset($product['amount']) || !Validation::int()->validate($product['amount'])) {
array_push($invalids, 'amount-' . $index);
}
}
if (empty($invalids)) {
$queryValues = array('userId' => $params['userId'], 'name' => $params['name'], 'phone' => $params['phone'], 'address' => $params['address'], 'dateFrom' => date('Y-m-d'), 'timeFrom' => $params['timeFrom'], 'dateTo' => date('Y-m-d'), 'timeTo' => $params['timeTo'], 'paid' => $params['paid'], 'deliver' => $params['deliver'], 'src' => 'orders/' . date('Y-m-d-H-i-U') . '.txt');
示例10: header
<div class="breadcrumbs">
<a href="/">Магазин</a>
<p>Удаление категории</p>
</div>
<div class="row clearfix">
<?php
use Respect\Validation\Validator as v;
include_once $src_path . 'autoload.php';
$connection = new \App\DB\Connection('root', '');
if (isset($_GET['id'])) {
$id = $_GET['id'];
} else {
$id = 'error';
}
$category = \App\DB\Categories::get($id, $connection);
$flag = v::arr()->notEmpty()->validate($category);
if (!$flag) {
echo "Такой категории не существует";
} else {
$deleteCategory = \App\DB\Categories::deleteCategory($id, $connection);
if ($deleteCategory) {
$deleteCategoryId = \App\DB\Products::deleteCategoryId($id, $connection);
}
// Back to previous page
header('Location: ' . \App\Utilities\Options::URL . '/edit-cat-all');
}
?>
</div>
</div>
</div>
</div>
示例11: catNameValidate
}
?>
</p>
</div>
<div class="row clearfix">
<?php
if (empty($_POST)) {
if (!$flag) {
echo "<h2>Такой категории не существует";
} else {
include_once 'templates/_edit_category.php';
}
} else {
$errors = [];
$catName = catNameValidate($errors, $_POST['category']);
if (!v::arr()->notEmpty()->validate($errors)) {
// Check if this category already exists
$flag = ifCatExists($connection, $catName);
if ($flag) {
include_once "templates/_edit_category.php";
echo "<p>Такая категория уже существует</p>";
} else {
$newCategory = \App\DB\Categories::update($id, $catName, $connection);
header('Refresh: 0; url=/edit-cat-all');
}
} else {
include_once "templates/_edit_category.php";
include_once "templates/_form-errors.php";
}
}
?>
示例12:
<?php
use Respect\Validation\Validator as v;
include_once __DIR__ . '/templates/_header.php';
include_once __DIR__ . '/templates/_top_menu.php';
$flag = false;
if (isset($_GET['id']) && is_numeric($_GET['id'])) {
$id = $_GET['id'];
$order = \App\DB\Orders::getById($id, $connection);
if (v::arr()->notEmpty()->validate($order)) {
$flag = true;
}
}
?>
<section>
<div class="container">
<div class="row clearfix">
<!-- боковое меню -->
<?php
include_once '/templates/_menu.php';
?>
<div class="column column9">
<div class="catalog">
<!-- хлебные крошки -->
<div class="breadcrumbs">
<a href="/">Магазин</a>
<p>Просмотр заказа</p>
</div>
<div class="row orders clearfix">
<?php
示例13:
use Respect\Validation\Validator as v;
$category = \App\DB\Categories::get($products[$i]['category_id'], $connection);
?>
<table class="table-products">
<tbody>
<tr>
<td><?php
echo $products[$i]['id'];
?>
</td>
<td><?php
echo $products[$i]['title'];
?>
</td>
<td><?php
if (v::arr()->notEmpty()->validate($category)) {
echo $category['title'];
} else {
echo "Не указана";
}
?>
</td>
<td><a href="<?php
echo \App\Utilities\Options::URL;
?>
/edit/?id=<?php
echo $products[$i]['id'];
?>
" class='edit adm-btn'>Изменить</a></td>
<td>
<a href="<?php
示例14: array
/**
* This halde every non-declared class method called on XenConnectionObj
*
* @param mixed $name the name of method and $args the argument of method,
*
*
* @return XenResponse
*/
function __call($name, $args)
{
if (!Validator::arr()->validate($args)) {
$args = array();
}
list($mod, $method) = explode('__', $name);
$response = $this->xenrpc_parseresponse($this->xenrpc_request($this->getUrl(), $this->xenrpc_method($mod . '.' . $method, array_merge(array($this->getSessionId()), $args))));
return $response;
}
示例15: isArray
/**
* 检测输入是否为数组
*
* @param mixed $value
* @return bool
*/
public static function isArray($value)
{
return Validator::arr()->validate($value);
}