/**
  * Returns base class for filename
  *
  * @param string $filename file name
  * @return string base class
  * @author Konstantin Kudryashov <*****@*****.**>
  */
 public static function getBaseClassForCurrentFile()
 {
     $filename = TextMate::getEnv('filename');
     if (false !== strpos($filename, 'actions.class.php')) {
         return 'sfActions';
     } elseif (false !== strpos($filename, 'Action.class.php')) {
         return 'sfAction';
     } elseif (false !== strpos($filename, 'components.class.php')) {
         return 'sfComponents';
     } elseif (false !== strpos($filename, 'Component.class.php')) {
         return 'sfComponent';
     } elseif (false !== strpos($filename, 'Form.class.php')) {
         return 'sfForm';
     } elseif (false !== strpos($filename, 'FormDoctrine.class.php')) {
         return 'sfFormDoctrine';
     } elseif (false !== strpos($filename, 'FormPropel.class.php')) {
         return 'sfFormPropel';
     } elseif (false !== strpos($filename, 'FormFilter.class.php')) {
         return 'sfFormFilter';
     } elseif (false !== strpos($filename, 'Filter.class.php')) {
         return 'sfFilter';
     } elseif (false !== strpos($filename, 'ProjectConfiguration.class.php')) {
         return 'sfProjectConfiguration';
     } elseif (false !== strpos($filename, 'PluginConfiguration.class.php')) {
         return 'sfPluginConfiguration';
     } elseif (false !== strpos($filename, 'Configuration.class.php')) {
         return 'sfApplicationConfiguration';
     } elseif (false !== strpos($filename, 'sfWidgetForm')) {
         return 'sfWidgetForm';
     }
 }
/**
 * Returns snippet for Class of the current file
 *
 * @param string $filename returns file name
 * @param string $filepath returns file path
 * @return string snippet
 * @author Konstantin Kudryashov <*****@*****.**>
 */
function getSnippet()
{
    $baseClass = sfBundle::getBaseClassForCurrentFile();
    $packageName = getPackageName($baseClass);
    $snippet = sprintf(<<<SNIPPET
/*
 * This file is part of the \$1.
 * (c) \${2:%s} \${3:\${TM_ORGANIZATION_NAME}}
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/**
 * \${4:%s} \${5:does things}.
 *
 * @package    \${6:\$1}
 * @subpackage \${7:%s}
 * @author     \$3
 * @version    \${8:1.0.0}
 */
class \$4%s
{
  \$0
}
SNIPPET
, date('Y', time()), getClassName(TextMate::getEnv('filename'), TextMate::getEnv('filepath')), $packageName ? $packageName : 'custom', $baseClass ? sprintf(" extends \${9:%s}", $baseClass) : '');
    return $snippet;
}
<?php

require_once dirname(__FILE__) . '/../Lib/sfBundle.class.php';
// Getting partial name from inputbox
$partialName = TextMate::getCocoaDialogData('inputbox', array('title' => 'Move HTML into partial', 'informative-text' => 'Enter partial name (without \'_\' and \'.php\'):', 'button1' => "Ok", 'button2' => "Cancel"));
if (!$partialName) {
    TextMate::exitDiscard();
}
// Partial name is global or relative?
if (count($nameParts = explode('/', $partialName)) > 1) {
    $path = sprintf('%s/%s/templates', dirname(dirname(dirname(TextMate::getEnv('filepath')))), $nameParts[0]);
    $renderedPartialName = $nameParts[1];
} else {
    $path = dirname(TextMate::getEnv('filepath'));
    $renderedPartialName = $partialName;
}
// Getting partial path by it's name & checking if it exists
$partialPath = sprintf('%s/_%s.php', $path, $renderedPartialName);
if (file_exists($partialPath)) {
    TextMate::drawCocoaDialog('msgbox', array('title' => 'Partial already exists', 'text' => 'Partial already exists', 'informative-text' => $partialPath, 'button1' => "Ok"));
    TextMate::exitDiscard();
}
// Path exists ? If not - create one
if (!is_dir($path)) {
    mkdir($path, 0755, true);
}
// Getting content of partial & splitting spaces from start
$content = file_get_contents('php://stdin');
if ($splittableSpacesCount = sfBundle::getSplittableSpacesCount($content)) {
    $content = sfBundle::splitSpacesAtStart($content, $splittableSpacesCount);
}