cweagans\Composer\Patches::grabPatches PHP Method

grabPatches() public method

Get the patches from root composer or external file
public grabPatches ( ) : Patches
return Patches
    public function grabPatches()
    {
        // First, try to get the patches from the root composer.json.
        $extra = $this->composer->getPackage()->getExtra();
        if (isset($extra['patches'])) {
            $this->io->write('<info>Gathering patches for root package.</info>');
            $patches = $extra['patches'];
            return $patches;
        } elseif (isset($extra['patches-file'])) {
            $this->io->write('<info>Gathering patches from patch file.</info>');
            $patches = file_get_contents($extra['patches-file']);
            $patches = json_decode($patches, TRUE);
            $error = json_last_error();
            if ($error != 0) {
                switch ($error) {
                    case JSON_ERROR_DEPTH:
                        $msg = ' - Maximum stack depth exceeded';
                        break;
                    case JSON_ERROR_STATE_MISMATCH:
                        $msg = ' - Underflow or the modes mismatch';
                        break;
                    case JSON_ERROR_CTRL_CHAR:
                        $msg = ' - Unexpected control character found';
                        break;
                    case JSON_ERROR_SYNTAX:
                        $msg = ' - Syntax error, malformed JSON';
                        break;
                    case JSON_ERROR_UTF8:
                        $msg = ' - Malformed UTF-8 characters, possibly incorrectly encoded';
                        break;
                    default:
                        $msg = ' - Unknown error';
                        break;
                }
                throw new \Exception('There was an error in the supplied patches file:' . $msg);
            }
            if (isset($patches['patches'])) {
                $patches = $patches['patches'];
                return $patches;
            } elseif (!$patches) {
                throw new \Exception('There was an error in the supplied patch file');
            }
        } else {
            return array();
        }
    }