Пример #1
0
 public function executeAsset($request)
 {
     try {
         $name = $this->getRequest()->getParameter('name');
         $this->forward404Unless(sfDynamicsPackageDefinition::checkIsValidPackageName($name));
         $extensionPosition = strrpos($name, '.');
         $assetExtension = substr($name, $extensionPosition + 1);
         $assetType = sfDynamics::getTypeFromExtension($assetExtension);
         $name = substr($name, 0, $extensionPosition);
         $this->package = sfDynamics::getManager()->getPackage($name);
         $this->{'pre' . ucfirst($assetType)}();
         return $this->renderText(sfDynamics::getRenderer()->getAsset($name, $this->package, $assetType, $assetExtension));
     } catch (Exception $e) {
         throw new sfError404Exception($e->getMessage());
     }
 }
Пример #2
0
<?php

require_once dirname(__FILE__) . '/../bootstrap/unit.php';
require_once dirname(__FILE__) . '/../../lib/sfDynamics.class.php';
$testCount = 1;
class ManagerMock extends sfDynamicsManager
{
}
$t = new lime_test($testCount, new lime_output_color());
$t->comment('::getManager()');
if (!sfContext::hasInstance()) {
    require_once $_SERVER['SYMFONY'] . '/autoload/sfCoreAutoload.class.php';
    sfCoreAutoload::register();
    require_once dirname(__FILE__) . '/../fixtures/project/config/ProjectConfiguration.class.php';
    sfContext::createInstance(ProjectConfiguration::getApplicationConfiguration('frontend', 'test', isset($debug) ? $debug : true));
    if (!sfContext::hasInstance()) {
        $t->error('A context instance is required');
        die;
    }
    $t->info('A frontend context has been initialized for tests');
}
sfConfig::set('app_sfDynamicsPlugin_manager', 'ManagerMock');
$t->isa_ok(sfDynamics::getManager(), 'ManagerMock', '::getManager() the manager class can be customized in app.yml');
    public function getPanelContent()
    {
        $controller = sfContext::getInstance()->getController();
        try {
            $html = '
      <style type="text/css">
        div#sfWebDebugDynamics table ul,
        div#sfWebDebugDynamics table ul li
        {
          margin: 0;
          padding: 0;
          list-style-type: dash;
        }
        div#sfWebDebugDynamics table ul
        {
          padding-left: 16px;

        }
      </style>

      <table class="sfWebDebugLogs">
        <tr>
          <td>&nbsp;</td>
          <th>Javascript items</th>
          <th>Generated javascript</th>
          <th>Stylesheet items</th>
          <th>Generated stylesheet</th>
        </tr>' . "\n";
            $line_nb = 0;
            $manager = sfDynamics::getManager();
            foreach ($manager->getPackages() as $packageName => $package) {
                $html .= '<tr>';
                $html .= '<th>' . $packageName . '</th>';
                foreach (array('Javascripts' => 'js', 'Stylesheets' => 'css') as $assetType => $extension) {
                    if ($package->{'has' . $assetType}()) {
                        $html .= '<td>';
                        $html .= '<ul>';
                        foreach ($package->{'get' . $assetType}() as $javascript) {
                            $html .= '<li>' . $javascript . '</li>';
                        }
                        $html .= '</ul>';
                        $html .= '</td>';
                        $html .= '<td>';
                        $url = $controller->genUrl(sfDynamicsRouting::uri_for($packageName, $extension));
                        $html .= sprintf('<a href="%s" target="_blank">%s</a>', $url, basename($url));
                        $html .= '</td>';
                    } else {
                        $html .= '<td colspan="2" align="center">not available</td>';
                    }
                }
                $html .= '</tr>';
            }
            $html .= '</table><br />';
        } catch (Exception $e) {
            $html = '
        <div>
          An exception occured while trying to render debug information for
          loaded packages.
          <br /><br />
          This may have happened because your current application is not ready
          to use sfDynamics. Please read the exception detail to understand the
          problem.
          <br /><br />
          <b>Check-list</b>:
          <ul>
            <li>make sure %sf_web_dir%/dynamics/ exists and is writable by your
            web-server user.</li>
            <li>make sure sfDynamicsPlugin is activated in
            %sf_root_dir%/config/ProjectConfiguration.class.php</li>
            <li>make sure sfDynamics module is enabled in your current
            application\'s settings.yml file.</li>
          </ul>
        </div>
        <br />
      ';
        }
        return '<div id="sfWebDebugDynamics">' . $html . '</div>';
    }
  </body>
</html>
END;
    $waited = <<<END
<html>
  <head>
<script type="text/javascript" src="/dynamics/foo.js"></script>
<link rel="stylesheet" type="text/css" media="screen" href="/dynamics/foo.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="/bar.css" />
    <script type="text/javascript" src="/bar.js"></script>
  </head>
  <body>
    <p>Lorem ipsum</p>
  </body>
</html>
END;
    $t->is($manager->filterContent(new sfEvent('lorem', 'event.name'), $content), $waited, '->addSfDynamicsTags() inserts tags at the beginning of <head> if position "prepend" and placeholder not found');
}
$t->comment('->getTag()');
$manager = sfDynamics::getManager();
sfWidget::setXhtml(false);
$t->is($manager->getTag('foo.js', 'javascript'), '<script type="text/javascript" src="foo.js"></script>', '->getTag() returns a "<script>" tag for the js type');
$t->is($manager->getTag('foo.css', 'stylesheet'), '<link rel="stylesheet" type="text/css" media="all" href="foo.css" >', '->getTag() returns a "<style media="screen">" tag for the css type');
sfWidget::setXhtml(true);
$t->is($manager->getTag('foo.css', 'stylesheet'), '<link rel="stylesheet" type="text/css" media="all" href="foo.css" />', '->getTag() uses the sfWidget::getXhtml() config');
try {
    $manager->getTag('foo.swf', 'swf');
    $t->fail('->getTag() throws an exception if type isn’t stylesheet or javascript');
} catch (Exception $e) {
    $t->pass('->getTag() throws an exception if type isn’t stylesheet or javascript');
}
 public function __construct($behavior)
 {
     $this->behavior = $behavior;
     $this->configuration = sfDynamics::getManager()->getConfiguration($behavior);
 }