factory = $factory; $this->factory->add_route( $this ); } public function add( $class_name ) { add_action( self::ACTION_PREFIX . $class_name, array( $this, 'do_ajax' ) ); } public function do_ajax() { $action = current_filter(); $class_name = substr( $action, self::ACTION_PREFIX_LENGTH ); $ajax_handler = $this->factory->create( $class_name ); $ajax_response = $ajax_handler->run(); $ajax_response->send_json(); } }