Beispiel #1
0
 protected function getDiagramImage($appName)
 {
     $dependencyDiagramImage = sprintf('dependency_diagram_%s_%s.png', $appName, time());
     $dependencyDiagramImageFullPath = dmOs::join(sfConfig::get('sf_web_dir'), 'cache', $dependencyDiagramImage);
     $dotFile = tempnam(sys_get_temp_dir(), 'dm_dependency_');
     if (!$this->context->getFilesystem()->mkdir(dirname($dependencyDiagramImageFullPath))) {
         throw new dmException(sprintf('Can not mkdir %s', $dependencyDiagramImageFullPath));
     }
     $configFiles = array(dmOs::join(sfConfig::get('dm_core_dir'), 'config/dm/services.yml'), dmOs::join(dm::getDir(), sprintf('dm%sPlugin/config/dm/services.yml', dmString::camelize($appName))));
     $projectFile = dmOs::join(sfConfig::get('sf_config_dir'), 'dm/services.yml');
     if (file_exists($projectFile)) {
         $configFiles[] = $projectFile;
     }
     $appFile = dmOs::join(sfConfig::get('sf_apps_dir'), $appName, 'config/dm/services.yml');
     if (file_exists($appFile)) {
         $configFiles[] = $appFile;
     }
     $sc = new sfServiceContainerBuilder();
     $loader = new sfServiceContainerLoaderFileYaml($sc);
     $loader->load($configFiles);
     $sc->setService('dispatcher', $this->context->getEventDispatcher());
     $sc->setService('user', $this->context->getUser());
     $sc->setService('response', $this->context->getResponse());
     $sc->setService('i18n', $this->getI18n());
     $sc->setService('routing', $this->context->getRouting());
     $sc->setService('config_cache', $this->context->getConfigCache());
     $sc->setService('controller', $this->context->getController());
     $sc->setService('logger', $this->context->getLogger());
     $sc->setService('module_manager', $this->context->getModuleManager());
     $sc->setService('context', $this->context);
     $sc->setService('doctrine_manager', Doctrine_Manager::getInstance());
     $dumper = new dmServiceContainerDumperGraphviz($sc);
     $dumper->enableDispatcherLinks($this->withDispatcherLinks);
     file_put_contents($dotFile, $dumper->dump(array('graph' => array('overlap' => 'false', 'splines' => 'true', 'epsilon' => '0.5', 'maxiter' => '30000', 'concentrate' => 'false', 'bgcolor' => 'transparent', 'ratio' => 'fill', 'size' => '25,12'), 'node' => array('fontsize' => 20, 'fontname' => 'Arial', 'shape' => 'Mrecord'), 'edge' => array('fontsize' => 9, 'fontname' => 'Arial', 'color' => 'grey', 'arrowhead' => 'open', 'arrowsize' => 1), 'node.instance' => array('fillcolor' => '#ffffff', 'style' => 'filled', 'shape' => 'component'), 'node.definition' => array('fillcolor' => 'transparent'), 'node.missing' => array('fillcolor' => '#ffaaaa', 'style' => 'filled', 'shape' => 'record'))));
     $filesystem = $this->context->getFileSystem();
     //$return = $filesystem->exec(sprintf('dot -Tpng %s > %s', $dotFile, $dependencyDiagramImageFullPath));
     //$return = $filesystem->exec(sprintf('twopi -Granksep=5 -Tpng %s > %s', $dotFile, $dependencyDiagramImageFullPath));
     $return = $filesystem->exec(sprintf('neato -Tpng %s > %s', $dotFile, $dependencyDiagramImageFullPath));
     unlink($dotFile);
     if (!$return) {
         $this->getUser()->logError(sprintf('Diem can not generate the %s dependency diagram. Probably graphviz is not installed on the server.', $appName), false);
         $this->getUser()->logAlert($filesystem->getLastExec('command') . "\n" . $filesystem->getLastExec('output'), false);
     }
     return '/cache/' . $dependencyDiagramImage;
 }
Beispiel #2
0
 protected function initializeContainer()
 {
     $name = 'SonataProject_' . md5($this->appDir . $this->isDebug . $this->environment) . 'ServiceContainer';
     $file = sys_get_temp_dir() . '/' . $name . '.php';
     if (!$this->isDebug && is_readable($file)) {
         require_once $file;
         $container = new $name();
     } else {
         $serviceConfig = $this->paths['config'] . '/services.yml';
         if (!is_readable($serviceConfig)) {
             throw new RuntimeException(sprintf("The service config file in '%s' does not exist or is not readable", $serviceConfig));
         }
         $container = new sfServiceContainerBuilder();
         $loader = new sfServiceContainerLoaderFileYaml($container);
         $loader->load($serviceConfig);
         if (!$this->isDebug) {
             $dumper = new sfServiceContainerDumperPhp($container);
             file_put_contents($file, $dumper->dump(array('class' => $name)));
         }
     }
     return $container;
 }
Beispiel #3
0
 protected function dumpServiceContainer($name, $file)
 {
     foreach (array(sfConfig::get('dm_cache_dir'), dirname($file)) as $dir) {
         if (!is_dir($dir)) {
             $oldUmask = umask(0);
             mkdir($dir, 0777);
             umask($oldUmask);
         }
     }
     $this->loadServiceContainerExtraStuff();
     $sc = new sfServiceContainerBuilder();
     $configPaths = $this->configuration->getConfigPaths('config/dm/services.yml');
     $loader = new sfServiceContainerLoaderFileYaml($sc);
     $loader->load($configPaths);
     $loader = new dmServiceContainerLoaderConfiguration($sc, $this->dispatcher);
     $loader->load(dmConfig::getAll());
     /*
      * Allow listeners of dm.service_container.pre_dump event
      * to modify the loader
      */
     $sc = $this->dispatcher->filter(new sfEvent($this, 'dm.service_container.pre_dump'), $sc)->getReturnValue();
     $dumper = new sfServiceContainerDumperPhp($sc);
     $baseClass = sfConfig::get('dm_service_container_base_class', 'dm' . ucfirst(sfConfig::get('dm_context_type')) . 'BaseServiceContainer');
     file_put_contents($file, $dumper->dump(array('class' => $name, 'base_class' => $baseClass)));
     $oldUmask = umask(0);
     @chmod($file, 0777);
     umask($oldUmask);
     if (!file_exists($file)) {
         throw new dmException('Can not write the generated service container to ' . $file);
     }
     unset($dumper, $loader, $sc);
 }
Beispiel #4
0
 /**
  * Loads Sympal's service container
  * 
  * @link http://components.symfony-project.org/dependency-injection/trunk/book/06-Speed
  */
 protected function loadServiceContainer()
 {
     $autoloaderPath = $this->getSymfonyContext()->getConfiguration()->getPluginConfiguration('sfSympalPlugin')->getRootDir() . '/lib/vendor/service_container/lib/sfServiceContainerAutoloader.php';
     if (!file_exists($autoloaderPath)) {
         throw new sfException(sprintf('Cannot find the service container library at %s.
     
     If you are including sfSympalPlugin as a git submodule, be sure to run the following commands from inside the plugins/sfSympalPlugin directory:
     
      git submodule init
      git submodule update', $autoloaderPath));
     }
     sfServiceContainerAutoloader::register();
     $app = $this->getSymfonyContext()->getConfiguration()->getApplication();
     $name = 'sfSympal' . $app . 'ServiceContainer';
     $path = sfConfig::get('sf_app_cache_dir') . '/' . $name . '.php';
     if (!sfConfig::get('sf_debug') && file_exists($path)) {
         require_once $path;
         $this->_serviceContainer = new $name();
     } else {
         // build the service container dynamically
         $this->_serviceContainer = new sfServiceContainerBuilder();
         $loader = new sfServiceContainerLoaderFileYaml($this->_serviceContainer);
         $configPaths = $this->getSymfonyContext()->getConfiguration()->getConfigPaths('config/sympal_services.yml');
         $loader->load($configPaths);
         // if not in debug, write the service container to file
         if (!sfConfig::get('sf_debug')) {
             $dumper = new sfServiceContainerDumperPhp($this->_serviceContainer);
             file_put_contents($path, $dumper->dump(array('class' => $name, 'base_class' => sfSympalConfig::get('service_container', 'base_class', 'sfServiceContainer'))));
         }
     }
 }
Beispiel #5
0
 * THE SOFTWARE.
 */
require_once __DIR__ . DIRECTORY_SEPARATOR . 'autoload.php';
use pantr\pantr;
if (!class_exists('pantr\\pantr')) {
    exit("pantr has not been installed properly!\n");
}
// load dependency injection container
sfServiceContainerAutoloader::register();
if (file_exists(__DIR__ . '/pantr/core/services.php')) {
    require_once __DIR__ . '/pantr/core/services.php';
    $sc = new pantrContainer();
} else {
    $sc = new sfServiceContainerBuilder();
    $loader = new sfServiceContainerLoaderFileYaml($sc);
    $loader->load(__DIR__ . '/pantr/core/services.yml');
}
// drop script name from args
$args = $_SERVER['argv'];
array_shift($args);
// setup pantr
pantr::setTaskRepository($sc->taskRepository);
pantr::setApplication($sc->application);
pantr::setHomePathProvider($sc->homePathProvider);
pantr::loadProperties();
// load pantr.yml
// load standard tasks
include_once __DIR__ . '/pantr/std_tasks.php';
// include bundles
$bundleManager = $sc->bundleManager;
$bundleManager->registerIncludePath();
 /**
  * Create a container object.
  * The configuration may be specified in the 'config_file'
  * component of the options. If not specified, an empty container
  * will be generated.
  * If 'dump_file' is specified and we did not generate an empty
  * container, the specification is compiled into a PHP file that
  * can later be loaded instead of the configuration (performance).
  *
  * @return sfServiceContainerInterface The container
  */
 public function makeContainer()
 {
     if (!isset($this->_options['config_file'])) {
         return new sfServiceContainer();
     }
     /**
      * Attempt to load the generated PHP file, if defined
      * and exists. If succesful, the class we need should be
      * defined, so create and return it.
      */
     $file = $this->_options['config_file'];
     $class = isset($this->_options['class']) ? $this->_options['class'] : 'Container';
     if (isset($this->_options['dump_file'])) {
         $dumpFile = $this->_options['dump_file'];
         if (file_exists($dumpFile)) {
             require_once $dumpFile;
             return new $class();
         }
     }
     /**
      * Create a builder to which we attach a loader so
      * we can load the configuration file.
      */
     $parameters = $this->getParameters();
     $sc = new sfServiceContainerBuilder($parameters);
     $ext = pathinfo($file, PATHINFO_EXTENSION);
     switch ($ext) {
         case 'xml':
             $loader = new sfServiceContainerLoaderFileXml($sc);
             break;
         case 'init':
             $loader = new sfServiceContainerLoaderFileIni($sc);
             break;
         case 'yaml':
             $loader = new sfServiceContainerLoaderFileYaml($sc);
             break;
         default:
             throw new Exception("No loader available for extension '{$ext}'");
             break;
     }
     $loader->load($file);
     /**
      * If a dump file was specified, make the dump
      * so that it can be loaded in the future.
      */
     if (isset($dumpFile)) {
         $dumper = new sfServiceContainerDumperPhp($sc);
         file_put_contents($dumpFile, $dumper->dump(array('class' => $class)));
     }
     return $sc;
 }
Beispiel #7
0
});
/**
 * Creates a PEAR package
 *
 * @dependsOn test, build:init
 * @before config:deploy-local
 */
task('build:package', function () {
    $spec = PackageSpec::in('build')->setName('pantr')->setChannel(property('pear.channel'))->setSummary('pantr is a simple php build tool.')->setDescription('pantr is a simple php build tool.')->setNotes('n/a')->setVersion(property('pantr.version'))->setStability('beta')->setLicense(PackageSpec::LICENSE_MIT)->addMaintainer('lead', 'Patrick Gotthardt', 'pago', '*****@*****.**')->setDependsOnPHPVersion('5.3.0')->addFiles(fileset()->ignore_version_control()->relative()->in('build'))->addFiles(array('bin/pantr', 'bin/pantr.bat'))->addExecutable('bin/pantr')->addExecutable('bin/pantr.bat', null, PackageSpec::PLATFORM_WIN)->createPackage('dist');
});
// compilation
File::task('build:services', 'build/pantr/pantr/core/services.yml', ':dirname/:filename.php')->dependsOn('build:init')->run(function ($src, $target) {
    // compile dependency injection layer
    $sc = new \sfServiceContainerBuilder();
    $loader = new \sfServiceContainerLoaderFileYaml($sc);
    $loader->load($src);
    $dumper = new \sfServiceContainerDumperPhp($sc);
    $code = $dumper->dump(array('class' => 'pantrContainer'));
    file_put_contents($target, $code);
});
/**
 * Updates the version number in the pantr.php file
 * 
 * @hidden
 * @dependsOn build:init
 */
task('build:version', function () {
    // update version number
    replace_in('build/pantr/pantr/pantr.php', function ($f, $c) {
        writeAction('rewrite', $f);
        return str_replace("const VERSION='DEV';", "const VERSION='" . property('pantr.version') . "';", $c);