RedBeanPHP\Repository::check PHP Method

check() public method

If the type is not valid or the ID is not valid it will throw an exception: Security.
public check ( redbeanphp\OODBBean $bean ) : void
$bean redbeanphp\OODBBean the bean that needs to be checked
return void
    public function check(OODBBean $bean)
    {
        //Is all meta information present?
        if (!isset($bean->id)) {
            throw new RedException('Bean has incomplete Meta Information id ');
        }
        if (!$bean->getMeta('type')) {
            throw new RedException('Bean has incomplete Meta Information II');
        }
        //Pattern of allowed characters
        $pattern = '/[^a-z0-9_]/i';
        //Does the type contain invalid characters?
        if (preg_match($pattern, $bean->getMeta('type'))) {
            throw new RedException('Bean Type is invalid');
        }
        //Are the properties and values valid?
        foreach ($bean as $prop => $value) {
            if (is_array($value) || is_object($value)) {
                throw new RedException("Invalid Bean value: property {$prop}");
            } else {
                if (strlen($prop) < 1 || preg_match($pattern, $prop)) {
                    throw new RedException("Invalid Bean property: property {$prop}");
                }
            }
        }
    }

Usage Example

示例#1
0
 /**
  * Checks whether a OODBBean bean is valid.
  * If the type is not valid or the ID is not valid it will
  * throw an exception: Security.
  *
  * @param OODBBean $bean the bean that needs to be checked
  *
  * @return void
  */
 public function check(OODBBean $bean)
 {
     $this->repository->check($bean);
 }