validate()->isOK(); } /** * Pretty-print JSON. * * If called before validation, it may return JSON "null". * * @return string */ public function beautifyJSON() { // @todo we should normalize entries in module.scripts and module.styles return FormatJson::encode( $this->getAssocArray(), "\t", FormatJson::UTF8_OK ); } /** * @return Status */ public function validate() { // Cache the validation result to avoid re-computations if ( !$this->validation ) { if ( !parent::isValid() ) { $this->validation = $this->getData(); } else { $validator = new GadgetDefinitionValidator(); $this->validation = $validator->validate( $this->getAssocArray() ); } } return $this->validation; } /** * Get the JSON content as an associative array with * all fields filled out, populating defaults as necessary. * * @return array * @suppress PhanUndeclaredMethod */ public function getAssocArray() { $info = wfObjectToArray( $this->getData()->getValue() ); /** @var GadgetDefinitionContentHandler $handler */ $handler = $this->getContentHandler(); $info = wfArrayPlus2d( $info, $handler->getDefaultMetadata() ); return $info; } /** * @inheritDoc */ protected function objectTable( $val ) { if ( $val instanceof GadgetDefinitionContentArmor ) { return (string)$val; } return parent::objectTable( $val ); } }