gios-asu/nectary

View on GitHub
src/requests/fail-fast-request.php

Summary

Maintainability
A
25 mins
Test Coverage
<?php

namespace Nectary;

/**
 * A request will validate based on a set of rules
 *
 * A request can also be used to take in options and
 * pull in the data required to fulfill a request.
 */
abstract class Fail_Fast_Request extends Request {
    public function validate( $error_callback ) {
        $rules = $this->validation_rules();

        foreach ( $rules as $name => $check ) {
            if ( true !== $check ) {
                if ( \is_array( $error_callback ) ) {
                    return \call_user_func_array( $error_callback, [ $check, $this ] );
                }

                return $error_callback( $check, $this );
            }
        }
    }
}