Skip to content

Instantly share code, notes, and snippets.

@codenamegary
Created March 22, 2012 03:15
Show Gist options
  • Save codenamegary/2155375 to your computer and use it in GitHub Desktop.
Save codenamegary/2155375 to your computer and use it in GitHub Desktop.
PSR-0 Compatible regex class loader
<?php
echo "<PRE>";
$regex = "^\\\([a-zA-Z_]+){1}\\\([a-zA-Z_]+){1}\\\?([a-zA-Z]+)?_?([a-zA-Z]+)?_?([a-zA-Z]+)?_?([a-zA-Z]+)?$";
echo "Regex: " . $regex . "\r\n";
// Change Class name to test accordingly for whatever your class name is
if (isset($_GET['classname'])) { $className = $_GET['classname']; } else { $className = "\\Vendor\\Namespace\\Class"; }
echo "Class Name: " . $className . "\r\n";
preg_match('/'.$regex.'/',$className,$matches) or die('invaid class name');
//print_r($matches);
unset($matches[0]);
$filename = implode(DIRECTORY_SEPARATOR,$matches) . '.php';
echo "Filename: " . $filename;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment