I have the following Model class:
<?php
namespace Tropa\Model;
use Zend\InputFilter\Factory as InputFactory;
use Zend\InputFilter\InputFilter;
use Zend\InputFilter\InputFilterAwareInterface;
class Setor
{
public $codigo;
public $nome;
protected $inputFilter;
public function exchangeArray($data)
{
$this->codigo = (isset($data['codigo'])) ? $data['codigo'] : null;
$this->nome = (isset($data['nome'])) ? $data['nome'] : null;
}
public function getInputFilter()
{
if (!$this->inputFilter) {
$inputFilter = new InputFilter();
$factory = new InputFactory();
$inputFilter->add($factory->createInput(array(
'name' => 'codigo',
'required' => false,
'filters' => array(
array('name' => 'ToInt'), ## It was Int, but in PHP 7 it not works anymore, so I replaced it as suggest the zend documentation https://framework.zend.com/apidoc/2.4/classes/Zend.Filter.Int.html
),
'validators' => array(
array(
'name' => 'Between',
'options' => array(
'min' => 0,
'max' => 3600
)
),
),
)));
$inputFilter->add($factory->createInput(array(
'name' => 'nome',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 2,
'max' => 30,
)
)
),
)));
$this->inputFilter = $inputFilter;
}
return $this->inputFilter;
}
}
When I run this class I get the message:
Zend\Filter\FilterPluginManager::get was unable to fetch or create an instance for ToInt
Anybody knows how to validate Integers now that PHP 7 reserved the word Int?
Added:
After installing the zendframework/zend-filter version 2.7.1 the error message had changed to:
Fatal error: Uncaught TypeError: Argument 1 passed to Zend\ServiceManager\AbstractPluginManager::__construct() must implement interface Zend\ServiceManager\ConfigInterface, instance of Zend\ServiceManager\ServiceManager given, called in C:\xampp\htdocs\corps\vendor\zendframework\zend-filter\src\FilterChain.php on line 112 and defined in C:\xampp\htdocs\corps\vendor\zendframework\zendframework\library\Zend\ServiceManager\AbstractPluginManager.php:60 Stack trace: #0 C:\xampp\htdocs\corps\vendor\zendframework\zend-filter\src\FilterChain.php(112): Zend\ServiceManager\AbstractPluginManager->__construct(Object(Zend\ServiceManager\ServiceManager)) #1 C:\xampp\htdocs\corps\vendor\zendframework\zend-filter\src\FilterChain.php(183): Zend\Filter\FilterChain->getPluginManager() #2 C:\xampp\htdocs\corps\vendor\zendframework\zendframework\library\Zend\InputFilter\Factory.php(358): Zend\Filter\FilterChain->attachByName('\Zend\Filter\To...', NULL, 1000) #3 C:\xampp\htdocs\corps\vendor\zendframework\zendframework\library\Zend\InputFilt in C:\xampp\htdocs\corps\vendor\zendframework\zendframework\library\Zend\ServiceManager\AbstractPluginManager.php on line 60
composer show zendframework/zend-filter
.) – gscFilterPluginManager
belongs to this package as well, it wouldn’t be able to give you an error if not installed. – gsc'ToInt'
with\Zend\Filter\ToInt::class
? Doescomposer show
output any filter/validator-related packages? In which versions? Do you runcomposer
commands from the project’s root directory? – gsc