_registry = $registry; $known_engines = apply_filters( 'ai1ec_register_import_export_engines', $core_engines ); $this->_params = $params; foreach ( $known_engines as $engine ) { $this->register( $engine ); } } /** * Register an import-export engine. * * @param string $engine */ public function register( $engine ) { $this->_engines[$engine] = true; } /** * Import events into the calendar. * * @param string $engine * @param array $args * * @throws Ai1ec_Engine_Not_Set_Exception If the engine is not set. * @throws Ai1ec_Parse_Exception If an error happens during parse. * * @return int The number of imported events */ public function import_events( $engine, array $args ) { if ( ! isset( $this->_engines[$engine] ) ) { throw new Ai1ec_Engine_Not_Set_Exception( 'The engine ' . $engine . 'is not registered.' ); } // external engines must register themselves into the registry. $engine = $this->_registry->get( 'import-export.' . $engine ); $exception = null; try { return $engine->import( $args ); } catch ( Ai1ec_Parse_Exception $parse_exception ) { $exception = $parse_exception; } throw $exception; } /** * Export the events using the specified engine. * * @param string $engine * @param array $args * * @throws Ai1ec_Engine_Not_Set_Exception */ public function export_events( $engine, array $args ) { if ( ! isset( $this->_engines[$engine] ) ) { throw new Ai1ec_Engine_Not_Set_Exception( 'The engine ' . $engine . 'is not registered.' ); } // external engines must register themselves into the registry. $engine = $this->_registry->get( 'import-export.' . $engine ); return $engine->export( $args, $this->_params ); } }