1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 
<?php
namespace Omeka\Api\Exception;

use Omeka\Stdlib\ErrorStore;

class ValidationException extends BadRequestException
{
    /**
     * @var ErrorStore
     */
    protected $errorStore;

    /**
     * Set the error store containing validation errors.
     *
     * @param ErrorStore $errorStore
     */
    public function setErrorStore(ErrorStore $errorStore)
    {
        $this->errorStore = $errorStore;
    }

    /**
     * Get the error store.
     *
     * @return ErrorStore
     */
    public function getErrorStore()
    {
        // Set an error store instance in case one hasn't been set.
        if (!$this->errorStore instanceof ErrorStore) {
            $this->errorStore = new ErrorStore;
        }
        return $this->errorStore;
    }

    /**
     * Include underlying errors in exception string output
     *
     * @return string
     */
    public function __toString()
    {
        $format = "exception '%s' in %s:%s\nErrors:\n%s\nStack trace:\n%s";
        return sprintf($format,
            get_class($this),
            $this->getFile(),
            $this->getLine(),
            json_encode($this->getErrorStore()->getErrors(), JSON_PRETTY_PRINT),
            $this->getTraceAsString()
        );
    }
}