예제 #1
0
파일: Fenom.php 프로젝트: cti/core
 /**
  * @param Project $project
  */
 public function init(Project $project)
 {
     $this->build = $project->getPath('build fenom');
     $filesystem = new Filesystem();
     $filesystem->mkdir($this->build);
     $this->source[] = $project->getPath('resources fenom');
 }
예제 #2
0
파일: Compiler.php 프로젝트: cti/sencha
 public function build($script)
 {
     $dependencies = array_merge($this->dependency->getList($this->project->getPath("resources coffee {$script}.coffee")), $this->dependency->getList($this->sencha->getPath('src coffee Cti.coffee')));
     $fs = new Filesystem();
     $result = '';
     $sourceList = array();
     $stopwatch = new Stopwatch();
     foreach (array_reverse($dependencies) as $coffee) {
         $sourceList[] = $coffee;
         $local = $this->source->getLocalPath($coffee);
         $local_js = dirname($local) . DIRECTORY_SEPARATOR . basename($local, 'coffee') . 'js';
         $javascript = $this->project->getPath(sprintf('build js %s', $local_js));
         if (!file_exists($javascript) || filemtime($coffee) >= filemtime($javascript)) {
             if ($this->debug) {
                 $stopwatch->start($local);
                 echo '- compile ' . $local;
             }
             $code = \CoffeeScript\Compiler::compile(file_get_contents($coffee), array('filename' => $coffee, 'bare' => true, 'header' => false));
             if ($this->debug) {
                 $event = $stopwatch->stop($local);
                 echo ' (' . String::formatMilliseconds($event->getDuration()) . ' using ' . String::formatBytes($event->getMemory()) . ')' . PHP_EOL;
             }
             $fs->dumpFile($javascript, $code);
         } else {
             $code = file_get_contents($javascript);
         }
         $result .= $code . PHP_EOL;
     }
     $this->hash[$script] = $sourceList;
     $this->cache->set(__CLASS__, $this->hash);
     $filename = $this->project->getPath("public js {$script}.js");
     $fs->dumpFile($filename, $result);
     return $filename;
 }
예제 #3
0
파일: View.php 프로젝트: cti/core
 /**
  * render template
  * @param string $name
  * @param array $data 
  * @return string 
  */
 public function render($name, $data = array())
 {
     try {
         extract($data);
         ob_start();
         include $this->project->getPath('resources php view ' . func_get_arg(0) . '.php');
         return ob_get_clean();
     } catch (\Exception $e) {
         return $e->getMessage();
     }
 }
예제 #4
0
파일: Web.php 프로젝트: cti/core
 /**
  * collect controllers list
  * @param Project $project
  * @throws \Cti\Core\Exception
  */
 public function init(Project $project)
 {
     foreach ($project->getClasses('Controller') as $controller) {
         $location = '/';
         $name = Reflection::getReflectionClass($controller)->getShortName();
         $slug = String::camelCaseToUnderScore(substr($name, 0, -1 * strlen('Controller')));
         if ($slug != 'default') {
             $location = '/' . $slug;
         }
         $this->add($location, $controller);
     }
     // validate base
     if ($this->base != '/') {
         if ($this->base[0] != '/') {
             throw new Exception('Base url not begins with /');
         } elseif ($this->base[strlen($this->base) - 1] != '/') {
             throw new Exception('Base url not ends with /');
         }
         if (strpos($_SERVER['REQUEST_URI'], $this->base) !== 0) {
             throw new Exception(sprintf('Base url (%s) is incorrect', $this->base));
         }
     }
     // define method
     $this->method = strtolower($_SERVER['REQUEST_METHOD']);
     // define location
     $this->location = '/' . substr($_SERVER['REQUEST_URI'], strlen($this->base));
     if ($this->location[strlen($this->location) - 1] != '/') {
         $this->location .= '/';
     }
     // process controllers
     $controllers = $this->controllers;
     $this->controllers = array();
     foreach ($controllers as $path => $controller) {
         if (is_numeric($path)) {
             $class = Reflection::getReflectionClass($controller)->getShortName();
             if (substr($class, -10) == 'Controller') {
                 $class = substr($class, 0, -10);
                 $slug = String::camelCaseToUnderScore($class);
                 if ($slug == 'default' || !$slug) {
                     $path = '/';
                 } else {
                     $path = '/' . $slug . '/';
                 }
             }
         }
         $this->add($path, $controller);
     }
 }
예제 #5
0
파일: Sencha.php 프로젝트: cti/sencha
 public function warm(Application $application)
 {
     parent::warm($application);
     $fs = new Filesystem();
     $schema = $application->getStorage()->getSchema();
     $entities = array();
     foreach ($this->getClasses('Generator') as $class) {
         $reflection = Reflection::getReflectionClass($class);
         if (!$reflection->isAbstract() && $reflection->isSubclassOf('Cti\\Sencha\\Generator\\Generator')) {
             $entities[] = $reflection->getShortName();
         }
     }
     foreach ($schema->getModels() as $model) {
         foreach ($entities as $entity) {
             if ($model->hasBehaviour('link') && $entity != 'Model' && $entity != 'Editor' || !$model->hasBehaviour('link') && $entity == 'Editor') {
                 continue;
             }
             $generator = $this->application->getManager()->create('Cti\\Sencha\\Generator\\' . $entity, array('model' => $model, 'schema' => $schema));
             $path = $this->application->getProject()->getPath('build coffee Generated ' . $entity . ' ' . $model->getClassName() . '.coffee');
             $code = $generator->getGeneratedCode();
             if (!file_exists($path) || md5(file_get_contents($path)) != md5($code)) {
                 $fs->dumpFile($path, $code);
             }
             $path = $this->application->getProject()->getPath('build coffee ' . $entity . ' ' . $model->getClassName() . '.coffee');
             $code = $generator->getFinalCode();
             if (!file_exists($path) || md5(file_get_contents($path)) != md5($code)) {
                 $fs->dumpFile($path, $code);
             }
         }
         echo '- generate ' . $model->getClassName() . PHP_EOL;
     }
     $generator = $this->application->getManager()->create('Cti\\Sencha\\Generator\\Master', array('model' => $model));
     $path = $this->application->getProject()->getPath('build coffee Generated Master.coffee');
     $code = $generator->getGeneratedCode();
     if (!file_exists($path) || md5(file_get_contents($path)) != md5($code)) {
         $fs->dumpFile($path, $code);
     }
     $path = $this->application->getProject()->getPath('build coffee Master.coffee');
     $code = $generator->getFinalCode();
     if (!file_exists($path) || md5(file_get_contents($path)) != md5($code)) {
         $fs->dumpFile($path, $code);
     }
     $finder = new Finder();
     $this->getCoffeeCompiler()->setDebug(true);
     $source = $application->getProject()->getPath('resources coffee');
     if (is_dir($source)) {
         $finder->files()->name("*.coffee")->in($source);
         foreach ($finder as $file) {
             $script = substr($file, strlen($source) + 1, -7);
             echo '- processing ' . $script . '.coffee' . PHP_EOL;
             $this->getCoffeeCompiler()->build($script);
         }
     }
 }
예제 #6
0
파일: Console.php 프로젝트: cti/core
 /**
  * Initialize console application
  * @param Core $core
  * @param Project $project
  * @throws \Cti\Di\Exception
  */
 function init(Core $core, Project $project)
 {
     $commands = array_merge($project->getClasses('Command'), $core->getClasses('Command'));
     array_walk($commands, array($this, 'processClass'));
 }
예제 #7
0
파일: Storage.php 프로젝트: cti/storage
 public function init(\Cti\Core\Module\Cache $cache)
 {
     parent::init($cache);
     $this->path = dirname(dirname(__DIR__));
 }
예제 #8
0
파일: Coffee.php 프로젝트: cti/core
 public function init()
 {
     $this->addSource($this->project->getPath('src coffee'));
     $this->addSource($this->project->getPath('resources coffee'));
 }
예제 #9
0
파일: FenomTest.php 프로젝트: cti/core
 function addSource(Fenom $fenom, Project $project)
 {
     $fenom->addSource($project->getPath('resources another-fenom'));
 }