*/ private $operations = array(); /** * Registers an operation. * * @param OperationInterface $operation Operation. * @return void */ public function register( OperationInterface $operation ) { $this->operations[ $operation->id() ] = $operation; } /** * Whether registered. * * @param string $id Id. * @return bool */ public function has( $id ) { return isset( $this->operations[ $id ] ); } /** * Returns an operation. * * @param string $id Id. * @return OperationInterface * @throws UnknownOperationException When unknown. */ public function get( $id ) { if ( ! isset( $this->operations[ $id ] ) ) { throw new UnknownOperationException( esc_html( sprintf( 'Unknown operation %s.', $id ) ) ); } return $this->operations[ $id ]; } /** * All operations by id. * * @return array */ public function all() { return $this->operations; } /** * Descriptors for the UI, hiding internal ones unless requested. * * @param bool $include_internal Include 'journal' and 'dev' groups. * @return array> */ public function descriptors( $include_internal = false ) { $out = array(); foreach ( $this->operations as $operation ) { $descriptor = $operation->describe(); if ( ! $include_internal && in_array( $descriptor->group, array( 'journal', 'dev' ), true ) ) { continue; } $out[] = $descriptor->to_array(); } return $out; } }