startSetup(); $this->applyUpgradeFunctions( $setup, $context ); $setup->endSetup(); } private function getUpgradeFunctions( $low_version = '1.0.0' ) { $methods = get_class_methods( $this ); foreach ( $methods as $key => $method ) { if ( preg_match( '/^upgrade_(.+)$/i', $method, $matches ) ) { if ( version_compare( $low_version, $matches[ 1 ], '<' ) ) { continue; } } unset( $methods[ $key ] ); } $methods = array_filter( $methods ); $methods = array_unique( $methods ); sort( $methods ); return $methods; } private function applyUpgradeFunctions( ModuleDataSetupInterface $setup, ModuleContextInterface $context ) { $methods = $this->getUpgradeFunctions( $context->getVersion() ); foreach ( $methods as $method ) { call_user_func_array( [ $this, $method ], [ $setup, $context ] ); } } }