<?php
spl_autoload_register( function ( $class_name ) {

    // If the class being requested does not start with our prefix
    // we know it's not one in our project.
    if ( 0 !== strpos( $class_name, 'orderflow' ) ) {
        return;
    }

    // Convert the class name to a file path.
    $file_name = strtolower(
        preg_replace(
            array( '/^orderflow\\\/', '/([a-z])([A-Z])/', '/_/', '/\\\/' ),
            array( '', '$1-$2', '-', DIRECTORY_SEPARATOR ),
            $class_name
        )
    );


    // Build the full path to the file.
    $file = ADS_PLUGIN_PATH . 'includes' . DIRECTORY_SEPARATOR . $file_name . '.php';
    // If the file exists, require it.
    if ( file_exists( $file ) ) {
        require_once $file;
    }

} );
