Exemple #1
0
 protected function parseFile($file)
 {
     $tokens = token_get_all(file_get_contents($file));
     //  var_dump($tokens);die();
     $count = count($tokens) - 1;
     for ($i = 0; $i < $count; $i++) {
         $token = $tokens[$i];
         if ($token[0] == 307) {
             $method = $token[1];
             if ($method === 'getCss') {
                 $type = 'css';
             } elseif ($method === 'getJs') {
                 $type = 'js';
             } else {
                 $type = null;
             }
             if ($type !== null) {
                 $arg = $this->getArgument($tokens, $i);
                 $sourcePath = AssetResolver::resolveSourcePath($arg, \eBuildy\Helper\ResolverHelper::getModulePathFromView($file));
                 if ($sourcePath === null) {
                     // var_dump(array('file' => $file, 'type' => $type, 'source' => $arg));
                 } else {
                     $this->assets[$sourcePath] = $type;
                 }
             }
         }
     }
 }
Exemple #2
0
 public function __construct($container, $exposedMethods = array())
 {
     parent::__construct($container, $exposedMethods);
     if (!file_exists(TMP_PATH . '/volt/')) {
         mkdir(TMP_PATH . '/volt/', 0x755);
     }
     $this->voltView = new VoltView();
     $this->voltEngine = new \Phalcon\Mvc\View\Engine\Volt($this->voltView);
     $this->voltEngine->setOptions(array('compileAlways' => true, 'compiledPath' => function ($templatePath) {
         $root = TMP_PATH . '/volt/';
         return $root . trim(str_replace("/", "_", str_replace(ROOT, '', $templatePath)), '_') . '.php';
     }));
     $this->voltCompiler = $this->voltEngine->getCompiler();
     foreach ($this->exposedMethod as $methodName => $method) {
         if (isset($method['service'])) {
             $this->voltCompiler->addFunction($methodName, '$container->' . \eBuildy\Helper\ResolverHelper::resolveServiceMethodName($method['service']) . '()->' . $method['method']);
         } else {
             //$env->addFunction($methodName, new \Twig_SimpleFunction($methodName, '$this->' . $methodName));
         }
     }
     $defaultFunctions = array('str_replace');
     foreach ($defaultFunctions as $methodName) {
         $this->voltCompiler->addFunction($methodName, $methodName);
     }
 }
Exemple #3
0
 public function __call($name, $arguments)
 {
     if (isset($this->exposedMethod[$name])) {
         $method = $this->exposedMethod[$name];
         $service = call_user_func(array($this->container, ResolverHelper::resolveServiceMethodName($method['service'])));
         return call_user_func_array(array($service, $method['method']), $arguments);
     } else {
         throw new \eBuildy\Exception\NotFoundException('Method " ' . $name . ' " ');
     }
 }
Exemple #4
0
 protected function _compile()
 {
     $env = new \Twig_Environment(new \Twig_Loader_Filesystem(SOURCE_PATH), array('autoescape' => false, 'cache' => TMP_PATH . 'twig', 'debug' => true, 'base_template_class' => 'eBuildy\\Templating\\TwigBaseTemplate'));
     $env->registerUndefinedFunctionCallback(array($this, "undefinedFunctionCallback"));
     $env->addGlobal('__template_name', basename($this->templatePath));
     foreach ($this->exposedMethod as $methodName => $method) {
         if (isset($method['service'])) {
             $env->addFunction($methodName, new \Twig_SimpleFunction($methodName, '$this->container->' . \eBuildy\Helper\ResolverHelper::resolveServiceMethodName($method['service']) . '()->' . $method['method']));
         } else {
             $env->addFunction($methodName, new \Twig_SimpleFunction($methodName, '$this->' . $methodName));
         }
     }
     $template = $env->loadTemplate(str_replace(SOURCE_PATH, '', $this->templatePath));
     return $template;
 }
Exemple #5
0
 public function build($dir, $name)
 {
     $phpContent = '<?php ' . PHP_EOL . PHP_EOL . 'class ' . $name . ' extends \\eBuildy\\Container\\BaseContainer {' . PHP_EOL . PHP_EOL;
     // $frameworkDebug = $this->configuration['parameters']['ebuildy']['debug'];
     $services = $this->get('services');
     foreach ($services as $serviceName => $service) {
         $phpContent .= 'protected $' . $this->resolveServicePropertyName($serviceName) . ' = null;' . PHP_EOL;
     }
     $phpContent .= PHP_EOL . PHP_EOL;
     foreach ($this->get('parameters') as $parameterName => $parameter) {
         $method = $this->resolveParameterMethod($parameterName);
         $phpContent .= 'public function ' . $method . '() {' . PHP_EOL;
         $phpContent .= "\t" . 'return ' . var_export($parameter, true) . ';' . PHP_EOL;
         $phpContent .= '}' . PHP_EOL . PHP_EOL;
     }
     foreach ($services as $serviceName => $service) {
         $method = ResolverHelper::resolveServiceMethodName($serviceName);
         if (!isset($service['class'])) {
             continue;
         }
         $args = '';
         if (isset($service['containerAware'])) {
             $args .= '$this';
         }
         $phpContent .= '/**' . PHP_EOL . '* @public' . PHP_EOL . '* @return ' . $service['class'] . PHP_EOL . '*/' . PHP_EOL;
         $phpContent .= 'public function ' . $method . '() {' . PHP_EOL;
         $phpContent .= "\t" . 'if ($this->' . $this->resolveServicePropertyName($serviceName) . ' === null) {' . PHP_EOL;
         $phpContent .= "\t\t" . '$this->' . $this->resolveServicePropertyName($serviceName) . ' = new ' . $service['class'] . '(' . $args . ');' . PHP_EOL;
         if (isset($service['configurationNode'])) {
             $phpContent .= "\t\t" . '$this->' . $this->resolveServicePropertyName($serviceName) . '->initialize($this->' . $this->resolveParameterMethod($service['configurationNode']) . '());' . PHP_EOL;
         }
         if (isset($service['dependencies'])) {
             foreach ($service['dependencies'] as $property => $serviceToInject) {
                 $phpContent .= "\t\t" . '$this->' . $this->resolveServicePropertyName($serviceName) . '->' . $property . ' = $this->' . \eBuildy\Helper\ResolverHelper::resolveServiceMethodName($serviceToInject) . '();' . PHP_EOL;
             }
         }
         $phpContent .= "\t" . '}' . PHP_EOL;
         $phpContent .= "\t" . 'return $this->' . $this->resolveServicePropertyName($serviceName) . ';' . PHP_EOL;
         $phpContent .= '}' . PHP_EOL . PHP_EOL;
     }
     $phpContent .= '}';
     //         die($phpContent);
     file_put_contents($dir . DIRECTORY_SEPARATOR . $name . '.php', $phpContent);
     chmod($dir . DIRECTORY_SEPARATOR . $name . '.php', 0644);
     return $this;
 }
Exemple #6
0
 public function get($service)
 {
     $method = \eBuildy\Helper\ResolverHelper::resolveServiceMethodName($service);
     return $this->{$method}();
 }