Getting Textmate to create PHP autoload class name from filepath
What I would like is a snippet that when executed, grabs the TM_FILEPATH output Explodes it on the slash / Then split out each part as a placeholder containing that part and an underscore (apart from the last part (the filename)) For Example: for 开发者_开发问答a file in directory path /Path/To/Original/file we would get
class ${1:Path_}${2:To_}${3:Original_}${4:File} {
// code here
}
Then I can step through and remove the parts I don't want ending with a className that fits the standard PHP autoloader
Does this sound possible?
Cheers, Chris
Have to add this final result as an answer to enable code display.
Just make sure you set 'output as snippet'
#!/usr/bin/php
<?php
$path = $_ENV['TM_FILEPATH'];
$path = trim($path, '/');
$path = trim($path, '.php');
$parts = explode('/', $path);
$lastPart = end($parts);
echo 'class ';
foreach ($parts as $id => $part) {
// textmate placeholders start at 1
$id = $id+1;
if ($lastPart == $part) {
echo '${'.$id.':'.$part.'}';
} else {
echo '${'.$id.':'.$part.'_}';
}
}
?>
精彩评论