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() { if ( !parent::isValid() ) { return $this->getData(); } $validator = new GadgetDefinitionValidator(); return $validator->validate( $this->getAssocArray() ); } /** * 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 ); } }