Пример #1
0
 function __construct()
 {
     $this->app = \Raptor\Raptor::getInstance();
     session_set_save_handler($this, false);
     register_shutdown_function('session_write_close');
     if (!$this->app->getStore()->getManager()->getConnection()->getSchemaManager()->tablesExist(array('raptor_session'))) {
         $this->app->getStore()->generateSchema('systemBundle', array('RaptorSession'));
     }
 }
Пример #2
0
 /**
  * 
  * Retorna una instancia de los servicios privados en el bundle especificado o FALSE sino se encontro ninguno
  * @param string $bundle The name of the Bundle where is the PrivateService
  * @return PrivateService
  */
 public function getPrivate($bundle)
 {
     $bundles = \Raptor\Raptor::getInstance()->getConfigurationLoader()->getOptions();
     if (isset($bundles['specifications'][$bundle])) {
         if (file_exists($bundles['specifications'][$bundle]['location'] . DIRECTORY_SEPARATOR . 'Services' . DIRECTORY_SEPARATOR . 'PrivateService.php')) {
             $class = $bundles['specifications'][$bundle]['namespace'] . '\\Services\\PrivateService';
             return new $class();
         } else {
             return FALSE;
         }
     } else {
         return FALSE;
     }
 }
Пример #3
0
 public function createScript()
 {
     $app = \Raptor\Raptor::getInstance();
     if (strpos($app->response()->headers->get('Content-Type'), 'text/html') === false) {
         return;
     }
     $user = '******';
     if ($app->getSecurity()->isAuthenticated()) {
         $array = $app->getSecurity()->getUser();
         $user = $array['username'];
     }
     $data = array('token' => $app->getSecurity()->getToken(), 'front' => $app->request()->getRootUri(), 'bundle' => dirname($_SERVER['SCRIPT_NAME']) . '/bundles', 'file' => $app->getLanguage()->getBundleFile(), 'lang' => $app->getLanguage()->getUserCurrentLanguage(), 'user' => $user);
     $core = $app->render('@systemBundle/client/client.core.html.twig', $data);
     $app->response()->write($core . $app->response()->getBody(), true);
 }
Пример #4
0
 /**
  * [USO DEL SISTEMA]
  * @return boolean
  */
 public function call()
 {
     $cmp_str = $this->bundle;
     $cmp = new $cmp_str();
     if (\Raptor\Raptor::getInstance()->config('debug')) {
         Publisher\Publisher::run($cmp, true);
     }
     call_user_func_array(array($cmp, 'entrance'), array(\Raptor\Raptor::getInstance()));
     $app = \Raptor\Raptor::getInstance();
     $app->getLanguage()->setCurrentBundle($cmp);
     $return = call_user_func_array(array(new $this->instance(), $this->action), array($app->request(), $app->response(), $app->router()->getCurrentRoute()));
     if ($return != false || $return != null || !$return instanceof \Slim\Http\Response) {
         $app->response()->write($return);
     }
     return true;
 }
Пример #5
0
 public function registerLastPerformance()
 {
     $app = \Raptor\Raptor::getInstance();
     $time = round($app->getTimer()->getExecutionTime(), 2);
     $cache = new \Raptor\Cache\Cache('performance');
     if (!$cache->hasCache()) {
         $performance = new \Raptor\Util\ItemList();
     } else {
         $performance = $cache->getData();
     }
     if ($performance->size() < 20) {
         $performance->add($time);
     } else {
         $performance->shift();
         $performance->add($time);
     }
     $cache->setData($performance);
     $cache->save();
 }
Пример #6
0
 /**
  * 
  * [USADA POR EL SISTEMA]
  */
 public function register()
 {
     $asset = new Twig_SimpleFunction('asset', function ($val) {
         if (dirname($_SERVER['SCRIPT_NAME']) == '/' or dirname($_SERVER['SCRIPT_NAME']) == '\\') {
             return '/bundles/' . $val;
         } else {
             return dirname($_SERVER['SCRIPT_NAME']) . '/bundles/' . $val;
         }
     });
     $this->twig->addFunction($asset);
     $path = new Twig_SimpleFunction('path', function ($val) {
         $route = \Raptor\Raptor::getInstance()->router()->getNamedRoute($val);
         if ($route == NULL) {
             return "";
         }
         $pattern = $route->getPattern();
         return \Raptor\Raptor::getInstance()->request()->getRootUri() . $pattern;
     });
     $this->twig->addFunction($path);
     $plugin = new Twig_SimpleFunction('plugin', function ($key) {
         $app = \Raptor\Raptor::getInstance();
         $result = $app->getViewPlugin($key);
         if ($result == false) {
             return "";
         }
         return join("", $result);
     });
     $this->twig->addFunction($plugin);
     $locale = new Twig_SimpleFunction('locale', function () {
         $params = \Raptor\Raptor::getInstance()->getConfigurationLoader()->getConfOption();
         if (isset($params['raptor']['language'])) {
             return $params['raptor']['language'];
         } else {
             return false;
         }
     });
     $this->twig->addFunction($locale);
     $langFilter = new Twig_SimpleFilter('lang', function ($val) {
         return \Raptor\Raptor::getInstance()->getLanguage()->getBundleLanguage($val);
     });
     $enviroment = new \Twig_SimpleFunction('conf', function ($val) {
         return \Raptor\Raptor::getInstance()->config($val);
     });
     $this->twig->addFunction($enviroment);
     $this->twig->addFilter($langFilter);
     $lang = new \Twig_SimpleFunction('lang', function ($val) {
         return \Raptor\Raptor::getInstance()->getLanguage()->getBundleLanguage($val);
     });
     $this->twig->addFunction($lang);
 }
Пример #7
0
 /**
  * Devuelve la logica de validacion para el formulario
  * @return string
  */
 function render()
 {
     return \Raptor\Raptor::getInstance()->render('@systemBundle/form/validation.html.twig', array('fields' => json_encode($this->fields), 'formId' => $this->formId));
 }
Пример #8
0
 /**
  * 
  * Setea para el usuario en la sesion actual, el lenguaje del agente de usuario
  * @return string
  */
 public function setUserPreferedLanguage()
 {
     $prefer = $this->getPreferedLanguage();
     \Raptor\Raptor::getInstance()->getSession()->set('rpt_lang', $prefer);
     return $prefer;
 }
Пример #9
0
 /**
  * Retorna la Sesion para este SessionStore
  * @return \Raptor\Security\Sessions\NativeSession
  */
 public function getSession()
 {
     return \Raptor\Raptor::getInstance()->getSession();
 }
Пример #10
0
 private static function getRemoteManifiest($url)
 {
     $array = array();
     try {
         $bufer = file_get_contents($url);
     } catch (\Exception $exc) {
         \Raptor\Raptor::getInstance()->response()->write("<h3 style='text-align:center;background: #ff9999;padding:5px;'>Cannot connect with remote repository</h3>");
         return array();
     }
     $array = json_decode(utf8_encode($bufer), true);
     if ($array === NULL) {
         \Raptor\Raptor::getInstance()->response()->write("<h3 style='text-align:center;background: #ff9999;padding:5px;'>The repository metadata has some errors</h3>");
     }
     if (!$array) {
         return array();
     }
     return $array;
 }
Пример #11
0
 /**
  * 
  * Retorna el texto del tag especificado en el idioma actual del sistema.
  * 
  * Si el tag o el idioma no han sido definidos devuelve una cadena vacia
  * 
  * @param string $tag
  * @param string $scope Espacio de variables del bundle donde se ejecutara la accion de lectura
  * @return string
  */
 public function lang($tag, $scope = null)
 {
     return \Raptor\Raptor::getInstance()->getLanguage()->getBundleLanguage($tag, $scope);
 }
Пример #12
0
 public function getTutorial($name)
 {
     $route = str_replace('.', '/', $name);
     $lang = \Raptor\Raptor::getInstance()->getLanguage()->getUserCurrentLanguage();
     if (isset($this->tags[$name])) {
         $tutorial = new \Raptor\Util\ItemList($this->tags[$name]);
         if (!file_exists($this->tags[$name]['bundle'] . "/Tutorials/{$lang}")) {
             $default = $this->getDefault();
             $default['found'] = FALSE;
             return $default;
         }
         if (file_exists($this->tags[$name]['bundle'] . "/Tutorials/{$lang}/docs/{$route}.html")) {
             $tutorial->set('text', file_get_contents($this->tags[$name]['bundle'] . "/Tutorials/{$lang}/docs/{$route}.html"));
             $tutorial->set('bundle', '');
         }
         if ($this->tags[$name]['author'] == NULL) {
             $tutorial->set('author', array('img' => 'Raptor/img/logo.png'));
         } else {
             $author = str_replace('.', '/', $this->tags[$name]['author']);
             $obj = json_decode(file_get_contents($this->tags[$name]['bundle'] . "/Tutorials/{$lang}/authors/{$author}.json"));
             $result = array();
             if ($obj->img == '') {
                 $obj->img = 'Raptor/img/accountblue.png';
             }
             foreach ($obj as $key => $value) {
                 $result[$key] = $value;
             }
             $tutorial->set('author', $result);
         }
         if ($tutorial->get('next') == NULL) {
             $tutorial->set('next', $this->getConditionalTutorial($name));
         }
         if ($tutorial->has('pointer')) {
             $pointerOrig = $tutorial->get('pointer');
             $pointer = array();
             if (preg_match('/^arrow:((up)|(down)|(left)|(right)) /', $pointerOrig)) {
                 if (count(explode('arrow:up', $pointerOrig)) > 1) {
                     $pointer['arrow'] = 'up';
                     $pointer['selector'] = str_replace('arrow:up', '', $pointerOrig);
                 }
                 if (count(explode('arrow:down', $pointerOrig)) > 1) {
                     $pointer['arrow'] = 'down';
                     $pointer['selector'] = str_replace('arrow:down', '', $pointerOrig);
                 }
                 if (count(explode('arrow:left', $pointerOrig)) > 1) {
                     $pointer['arrow'] = 'left';
                     $pointer['selector'] = str_replace('arrow:left', '', $pointerOrig);
                 }
                 if (count(explode('arrow:right', $pointerOrig)) > 1) {
                     $pointer['arrow'] = 'right';
                     $pointer['selector'] = str_replace('arrow:right', '', $pointerOrig);
                 }
             } else {
                 $pointer = array('selector' => $pointerOrig, 'arrow' => 'up');
             }
             $tutorial->set('pointer', $pointer);
         }
         return $tutorial;
     }
     $default = $this->getDefault();
     $default['next'] = $this->getConditionalTutorial($name);
     return new \Raptor\Util\ItemList($default);
 }
Пример #13
0
 private function read()
 {
     if (!$this->cacheautoinstaller->isDirty()) {
         $this->autoinstaller = $this->cacheautoinstaller->getData();
     }
     if ($this->cache->isDirty()) {
         $this->monitor->execute();
         $this->checkForGhosts();
         $app = Location::get(Location::APP);
         $this->options['options'] = \Raptor\Yaml\Yaml::parse($app . '/conf/options.yml');
         $this->options['bundles'] = \Raptor\Yaml\Yaml::parse($app . '/conf/bundles.yml');
         /**
          * Add the system routes and the bundles
          * check fot enviroment
          * if(development)
          */
         $this->options['bundles'] = array_merge(\Raptor\Yaml\Yaml::parse(__DIR__ . '/../Component/bundles.yml'), $this->options['bundles']);
         /**
          * Must call this before the Reader
          */
         //           \Raptor\Raptor::getInstance()->getAppAspectKernel()->resetContainer();
         foreach ($this->options['bundles'] as $bundle) {
             $cmp_str = $bundle;
             $cmp = new $cmp_str();
             call_user_func_array(array($cmp, 'init'), array());
             $container = \Raptor\Raptor::getInstance()->getAppAspectKernel()->getContainer();
             $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
             $refClass = new \ReflectionObject($cmp);
             $container->addResource($trace[1]['file']);
             $container->addResource($refClass->getFileName());
         }
         $this->reader->setBundles($this->options['bundles']);
         $this->reader->load();
         $this->options['routes'] = $this->reader->getDefinitions();
         $this->options['location'] = $this->reader->getLocation();
         $this->options['specifications'] = $this->reader->getSpecifications();
         $this->options['description'] = $this->reader->getDescriptions();
         $this->cache->setData($this->options);
         $this->cache->save();
         /**
          * Save the API to access in the main Raptor class
          */
         $api = new \Raptor\Cache\Cache('api');
         $api->setData($this->reader->getApi());
         $api->save();
         /**
          * Save the Auto Install Cache to know the trace of installed bundled
          */
         $this->cacheautoinstaller->setData($this->autoinstaller);
         $this->cacheautoinstaller->save();
     } else {
         $this->options = $this->cache->getData();
         foreach ($this->options['bundles'] as $bundle) {
             $cmp_str = $bundle;
             $cmp = new $cmp_str();
             call_user_func_array(array($cmp, 'init'), array());
             $container = \Raptor\Raptor::getInstance()->getAppAspectKernel()->getContainer();
             $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
             $refClass = new \ReflectionObject($cmp);
             $container->addResource($trace[1]['file']);
             $container->addResource($refClass->getFileName());
         }
     }
 }
Пример #14
0
 public function init()
 {
     $container = \Raptor\Raptor::getInstance()->getAppAspectKernel()->getContainer();
     $this->registerBundleAspect($container);
 }
Пример #15
0
 * Raptor - Integration PHP 5 framework
 *
 * @author      William Amed <*****@*****.**>, Otto Haus <*****@*****.**>
 * @copyright   2014 
 * @link        http://dinobyte.net
 * @version     2.0.1
 * @package     Raptor
 *
 * MIT LICENSE
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
$data = new \Raptor\Util\ItemList(\Raptor\Raptor::getInstance()->getStore()->getManager()->getRepository('exampleBundle:Persona')->findAll());
file_put_contents(__DIR__ . '/mas', $data->toJson());
Пример #16
0
 /**
  * Establece directivas y rutinas de proteccion contra ataques
  * [USADA POR EL SISTEMA]
  */
 public static function directives()
 {
     $options = \Raptor\Raptor::getInstance()->getConfigurationLoader()->getConfOption();
     if (isset($options['raptor']['session_expire'])) {
         ini_set('session.cookie_lifetime', intval($options['raptor']['session_expire']));
     } else {
         ini_set('session.cookie_lifetime', 0);
     }
     ini_set('session.cookie_httponly', true);
     ini_set('session.use_only_cookies', true);
     $savePath = \Raptor\Core\Location::get(\Raptor\Core\Location::APP) . '/Sessions';
     if (!file_exists($savePath)) {
         @mkdir($savePath);
     }
     session_save_path($savePath);
     if (isset($options['raptor']['proxy'])) {
         $parts = explode('@', $options['raptor']['proxy']);
         $header = array();
         $proxy = '';
         if (count($parts) == 2) {
             $auth = base64_encode($parts[0]);
             $header[] = "Proxy-Authorization: Basic {$auth}";
             $proxy = $parts[1];
         } else {
             $proxy = $parts[0];
         }
         stream_context_set_default(array('http' => array('proxy' => "tcp://{$proxy}", 'request_fulluri' => true, 'method' => "GET", 'user_agent' => 'Mozilla/5.0', 'header' => $header)));
     }
 }
Пример #17
0
 public function run()
 {
     $this->timer = new Util\Timer();
     $this->timer->start();
     $this->plugins = array();
     $this->appAspectKernel = \App\AppAspectKernel::getInstance();
     if (!file_exists(Core\Location::get(Core\Location::CACHE))) {
         @mkdir(Core\Location::get(Core\Location::CACHE));
     }
     $this->appAspectKernel->init(array('debug' => $this->config('debug'), 'appDir' => Core\Location::get(Core\Location::SRC), 'cacheDir' => Core\Location::get(Core\Location::CACHE) . '/AOP'));
     $this->ruleContainer = new Bundle\Route\RuleContainer();
     $this->configuration = new Configuration\ConfigurationLoader();
     /**
      * Verify if the framework was moved of location
      */
     $locations = \Raptor\Raptor::getInstance()->getConfigurationLoader()->getOptions();
     $bundles = $locations['location'];
     $counting = 0;
     $onefile = NULL;
     foreach ($bundles as $value) {
         if (!file_exists($value)) {
             $counting++;
             $onefile = $value;
         } else {
             break;
         }
     }
     if ($counting == count($bundles) and $counting > 0) {
         $this->configuration->forceLoad();
     }
     $secret = $this->configuration->getConfOption();
     if (isset($secret['raptor']['secret'])) {
         $this->config('cookies.secret_key', $secret['raptor']['secret']);
     }
     Security\Security::directives();
     $this->add(new Core\Routing());
     $this->add(new \App\Main());
     $this->add(new Language\Language());
     $this->add(new Security\Security());
     $this->add(new Persister\Store());
     $this->add(new Exception\Listener\RaptorExceptions());
     $this->inyector = new Core\Inyector\Container();
     parent::run();
 }