protected static function loadClass($entity, $type) { if (strpos($type, '.')) { list($prefix, $type) = explode('.', $type); } else { $prefix = 'M'; } $class = MString::ucfirst($prefix, '_') . 'Form' . MString::ucfirst($entity, '_') . MString::ucfirst($type, '_'); if (class_exists($class)) { return $class; } // Get the field search path array. $paths = MFormHelper::addPath($entity); // If the type is complex, add the base type to the paths. if ($pos = strpos($type, '_')) { // Add the complex type prefix to the paths. for ($i = 0, $n = count($paths); $i < $n; $i++) { // Derive the new path. $path = $paths[$i] . '/' . strtolower(substr($type, 0, $pos)); // If the path does not exist, add it. if (!in_array($path, $paths)) { $paths[] = $path; } } // Break off the end of the complex type. $type = substr($type, $pos + 1); } // Try to find the class file. $type = strtolower($type) . '.php'; foreach ($paths as $path) { if ($file = MPath::find($path, $type)) { require_once $file; if (class_exists($class)) { break; } } } // Check for all if the class exists. return class_exists($class) ? $class : false; }