Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Deprecate the PostCode::setService() and PostCode::getService() method #107

Open
froschdesign opened this issue Feb 17, 2019 · 1 comment
Assignees
Milestone

Comments

@froschdesign
Copy link
Member

froschdesign commented Feb 17, 2019

Problem

The PostCode validator allows additional validations via an optional service callback. The callback runs before the standard validation of the PostCode class.
Internally, the additional validation is done by zend-validator's Callback class.

But:

  • this functionality was never documented
  • the usage of a validator within another validator is confusing
  • this functionality is not available in other validators

Alternative

As an alternative to the additional validation, a validator chain should be used.

Deprecation

It should be deprecated in the next minor version (2.11.0) and removed with the next major version (3.0.0).

Code Reference

/**
* Returns the actual set service
*
* @return mixed|null
*/
public function getService()
{
return $this->service;
}
/**
* Sets a new callback for service validation
*
* @param mixed $service
* @return PostCode Provides fluid interface
*/
public function setService($service)
{
$this->service = $service;
return $this;
}

if (! empty($service)) {
if (! is_callable($service)) {
throw new Exception\InvalidArgumentException('Invalid callback given');
}
try {
$callback = new Callback($service);
$callback->setOptions([
'format' => $format,
'locale' => $locale,
]);
if (! $callback->isValid($value)) {
$this->error(self::SERVICE, $value);
return false;
}
} catch (\Exception $e) {
$this->error(self::SERVICEFAILURE, $value);
return false;
}
}

@weierophinney
Copy link
Member

This repository has been closed and moved to laminas/laminas-i18n; a new issue has been opened at laminas/laminas-i18n#6.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants