Loader Class

The Loader class is a simple autoloader utility for dynamically including class files from the myPOS IPC SDK. It ensures the necessary class is loaded when accessed, helping maintain clean and modular code.

Class Details

  • Class: Mypos\IPC\Loader
  • Namespace: Mypos\IPC
  • Located at: Loader.php
  • Purpose: Automatically locates and loads SDK classes based on their names.

Method Summary

MethodReturn TypeDescription
loader(string $class_name)boolLocates and includes the file corresponding to the specified class name. Returns true if successful, false otherwise.

Example Usage

<?php

  namespace Mypos\IPC;

  /**
   * Library classes loader
   */
  class Loader{

     /**
      * Find and include required class file
      * @param string $class_name
      * @return boolean
      */
     static public function loader($class_name){

         if(preg_match('/^' . str_replace('\\', '\\\\', __NAMESPACE__) . '\\\/', $class_name)){
             $filePath = dirname(__FILE__) . DIRECTORY_SEPARATOR . str_replace(array(__NAMESPACE__ . '\\', '\\'), array('', DIRECTORY_SEPARATOR), $class_name) . '.php';
             if(is_file($filePath) && is_readable($filePath)){
                 require_once $filePath;
                 return true;
             }
         }
     }

 }

 spl_autoload_register('\Mypos\IPC\Loader::loader');

Use Cases

Use the Loader class when:

  • You’re not using Composer or another autoloader
  • You want to include classes on-demand without manually requiring each file
  • You’re building a custom integration with minimal setup

Tip: If you are using Composer, the SDK may already be autoloaded. This class is primarily for manual or legacy integration scenarios.