Check the page is valid and return a json response

@return JsonModel
542136
public function getList()
    {
        $pageType = $this->params('pageType', PageTypes::NORMAL);
        $pageId = $this->params('pageId', null);

        /** @var \Rcm\Validator\Page $validator */
        $validator = clone($this->getServiceLocator()->get(\Rcm\Validator\Page::class));
        $validator->setPageType($pageType);

        $return = [
            'valid' => true
        ];

        if (!$validator->isValid($pageId)) {
            $return['valid'] = false;
            $return['error'] = $validator->getMessages();

            /** @var \Zend\Http\Response $response */
            $response = $this->response;

            $errorCodes = array_keys($return['error']);

            foreach ($errorCodes as &$errorCode) {
                if ($errorCode == $validator::PAGE_EXISTS) {
                    $response->setStatusCode(409);
                    break;
                } elseif ($errorCode == $validator::PAGE_NAME) {
                    $response->setStatusCode(417);
                }
            }
        }

        return new JsonModel($return);
    }
849676
public function validate_api_url() {

		$index = @file_get_contents( $this->api_url );

		// check for HTTP 404 response (file_get_contents() returns false when encountering 404)
		// this usually means:
		// 1) the store URL is not correct (missing sub-directory path, etc)
		// 2) pretty permalinks are disabled
		if ( false === $index ) {
			throw new WC_API_Client_Exception( sprintf( 'Invalid URL, no WC API found at %s -- ensure your store URL is correct and pretty permalinks are enabled.', $this->api_url ), 404 );
		}

		// older versions of WC (2.0 and under) will simply return a "1"
		if ( '1' === $index ) {
			throw new WC_API_Client_Exception( sprintf( 'Please upgrade the WooCommerce version on %s to v2.2 or greater.', $this->api_url ) );
		}

		// strip invalid leading/trailing characters from JSON
		$json_start = strpos( $index, '{' );
		$json_end = strrpos( $index, '}' ) + 1; // inclusive

		$index = json_decode( substr( $index, $json_start, ( $json_end - $json_start ) ) );

		// check for invalid JSON, an error here usually means:
		// 1) there's some garbage in the JSON output, WP Super Cache is notorious for adding an HTML comment to non-cached pages
		if ( null === $index ) {
			throw new WC_API_Client_Exception( sprintf( 'WC API found, but JSON is corrupt -- ensure the index at %s is valid JSON.', $this->api_url ) );
		}

		// check if the site URL returned is SSL, but SSL is not enabled
		if ( 'https' === parse_url( $index->store->URL, PHP_URL_SCHEME ) && ! $index->store->meta->ssl_enabled ) {

			// override the user-entered URL with the SSL version
			$this->api_url = str_replace( 'http://', 'https://', $this->api_url );
		}
	}
771509
public function verifyPage(): ResponseInterface
    {
        $this->checkRegistrationAllowed();

        $title = I18N::translate('User verification');

        return $this->viewResponse('register-page', [
            'title' => $title,
        ]);
    }
373002
public function checkJsonRequest(Request $request, Response $response, DocumentModel $model, $content = '')
    {
        if (empty($content)) {
            $content = $request->getContent();
        }

        if (is_resource($content)) {
            throw new BadRequestHttpException('unexpected resource in validation');
        }

        // is request body empty
        if ($content === '') {
            $e = new NoInputException();
            $e->setResponse($response);
            throw $e;
        }

        $input = json_decode($content, true);
        if (JSON_ERROR_NONE !== json_last_error()) {
            $e = new MalformedInputException($this->getLastJsonErrorMessage());
            $e->setErrorType(json_last_error());
            $e->setResponse($response);
            throw $e;
        }
        if (!is_array($input)) {
            $e = new MalformedInputException('JSON request body must be an object');
            $e->setResponse($response);
            throw $e;
        }

        if ($request->getMethod() == 'PUT' && array_key_exists('id', $input)) {
            // we need to check for id mismatches....
            if ($request->attributes->get('id') != $input['id']) {
                $e = new MalformedInputException('Record ID in your payload must be the same');
                $e->setResponse($response);
                throw $e;
            }
        }

        if ($request->getMethod() == 'POST' &&
            array_key_exists('id', $input) &&
            !$model->isIdInPostAllowed()
        ) {
            $e = new MalformedInputException(
                '"id" can not be given on a POST request. Do a PUT request instead to update an existing record.'
            );
            $e->setResponse($response);
            throw $e;
        }
    }
1252823
public function it_returns_valid_json_when_cast_to_string()
    {
        $this->__toString()->shouldBeString();
        $json = \json_decode((string) $this->getWrappedObject(), true);
//        $this->shouldBeBool(is_null($json));
//        $this->shouldEqual(JSON_ERROR_NONE, \json_last_error());
    }
416171
public function valid() {
        return $this->page && $this->page->valid() && !$this->overLimit() && !$this->overPageLimit();
    }
1267619
public function jsonVal()
    {
        $json = $this->propertyVal();
        if (!is_string($json)) {
            $json = json_encode($json);
        }
        if (!$json || $json == 'null') {
            $json = '';
        }
        return $json;
    }
467351
public function render()
    {
        $responseData = array(
            "status" => $this->_statusCode,
            "body"   => $this->_content,
            "errors" => $this->_errors
        );
        
        return json_encode($responseData);
    }
1051908
public function validateAction()
    {
        // Check for a valid POST request
        if (!$this->getRequest()->isPost()) {
            // Return a "405 Method Not Allowed" response
            $this->getResponse()->setHttpResponseCode(405);
            return;
        }

        $data = $this->getRequest()->getPost();

        // Check that all of the required fields are present
        if (empty($data) || !isset($data['country_id'], $data['region_id'], $data['street'], $data['city'], $data['postcode'])) {
            // Return a "400 Bad Request" response
            $this->getResponse()->setHttpResponseCode(400);
            return;
        }

        $country = Mage::getModel('directory/country')->load($data['country_id'])->getName();
        $region = Mage::getModel('directory/region')->load($data['region_id'])->getCode();

        $result = Mage::helper('australia/address')->validate(
            $data['street'],
            $region,
            $data['city'],
            $data['postcode'],
            $country
        );

        $this->getResponse()->setHeader('Content-type', 'application/json');
        $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
    }
716365
public function toJSON()
    {
        $result = [
            'Status' => $this->Status(),
            'ShouldPass' => $this->ShouldPass(),
            'Checks' => []
        ];
        foreach ($this->details as $detail) {
            $result['Checks'][] = $detail->toMap();
        }
        return json_encode($result);
    }
309971
public function parseJsonResponse(): self
    {
        $jsonResponse = $this->_response;
        if (!is_array($jsonResponse)) {
            throw new RuntimeException('Response must be a scalar value');
        }

        if (array_key_exists('quantity', $jsonResponse)) {
            $this->_quantity = $jsonResponse['quantity'];
        }

        if (array_key_exists('receiptId', $jsonResponse)) {
            $this->_transaction_id = $jsonResponse['receiptId'];
        }

        if (array_key_exists('productId', $jsonResponse)) {
            $this->_product_id = $jsonResponse['productId'];
        }

        if (array_key_exists('purchaseDate', $jsonResponse) && !empty($jsonResponse['purchaseDate'])) {
            $this->_purchase_date = Carbon::createFromTimestampUTC(intval(round($jsonResponse['purchaseDate'] / 1000)));
        }

        if (array_key_exists('cancelDate', $jsonResponse) && !empty($jsonResponse['cancelDate'])) {
            $this->_cancellation_date = Carbon::createFromTimestampUTC(
                intval(round($jsonResponse['cancelDate'] / 1000))
            );
        }

        if (array_key_exists('renewalDate', $jsonResponse) && !empty($jsonResponse['renewalDate'])) {
            $this->_renewal_date = Carbon::createFromTimestampUTC(intval(round($jsonResponse['renewalDate'] / 1000)));
        }

        return $this;
    }
647141
public function getValidationMessage()
    {
        $json = $this->getJsonResponse();
        if ($json && $json->errors && $json->errors->message) {
            return $json->errors->message;
        } else {
            return 'Unknown validation error';
        }
    }
449040
public function modelList()
    {
        $this->action = self::API_ACTION_LIST;
        $code = 200;
        list($return, $total, $pages) = $this->getList();
        $message = null;
        if(!$total) {
            $message = t('No se han encontrado elementos para la búsqueda');
        }

        return $this->json(new JsonResponse($return, $code === 200, $total, $pages, $message), $code);
    }
301914
public function valid()
    {
        $page = $this->pageIterator->current();

        if (isset($page[$this->pageIndex])) {
            return true;
        }

        // If there are no results, but a token for the next page
        // exists let's continue paging until there are results.
        while ($this->nextResultToken()) {
            $this->pageIterator->next();
            $page = $this->pageIterator->current();

            if (isset($page[$this->pageIndex])) {
                return true;
            }
        }

        return false;
    }
930773
protected function decodeResponseJson()
    {
        $decodedResponse = json_decode($this->response->getContent(), true);

        if (is_null($decodedResponse) || $decodedResponse === false) {
            $this->fail('Invalid JSON was returned from the route. Perhaps an exception was thrown?');
        }

        return $decodedResponse;
    }
108155
public function json() {
			$json = parent::json();

			$is_contact_visible = $this->fs->is_page_visible( 'contact' );
			$is_support_visible = $this->fs->is_page_visible( 'support' );

			$json['theme_title'] = $this->fs->get_plugin_name();

			if ( $is_contact_visible && $is_support_visible ) {
				$json['theme_title'] .= ' ' . $this->fs->get_text_inline( 'Support', 'support' );
			}

			if ( $is_contact_visible ) {
				$json['contact'] = array(
					'label' => $this->fs->get_text_inline( 'Contact Us', 'contact-us' ),
					'url'   => $this->fs->contact_url(),
				);
			}

			if ( $is_support_visible ) {
				$json['support'] = array(
					'label' => $this->fs->get_text_inline( 'Support Forum', 'support-forum' ),
					'url'   => $this->fs->get_support_forum_url()
				);
			}

			return $json;
		}
334855
public function generatepage_json(){
		$status=200;
		foreach($this->rules as &$c){
			$this->positions[$c->position]=$c->output;
			if($c->status!=200){
				$status=$c->status;
				}
			}
		header('Content-type: text/json');
		if($status==403){
			header($_SERVER['SERVER_PROTOCOL'].' 403 Forbidden');
			}
		if($status==404){
			header($_SERVER['SERVER_PROTOCOL'].' 404 Page Not Found');
			}
		if($status==500){
			header($_SERVER['SERVER_PROTOCOL'].' 500 Server Error!');
			}
		echo $this->positions['content'];	
		}