/** * Save and Get data into a database * @Route /new/example/persisting * */ public function persistingAction() { /** * $this->getStoreManager() is a shortcut of $this->getStore()->getManagerManager() and can be * accesed like this $this->app->getStore()->getManager() * * We need to check if the persona table exist and create it if not exist [this is only for examples purposes] */ if (!$this->getStoreManager()->getConnection()->getSchemaManager()->tablesExist(array('persona'))) { $this->getStore()->generateSchema('exampleBundle', array('Persona')); } /** * Save a Person entity * */ $persona = new \examples\exampleBundle\Model\Entity\Persona(); $persona->setNombre('Liams'); $persona->setApellidos('Adam'); $persona->setSexo(true); $persona->setEdad(25); $this->getStoreManager()->persist($persona); $this->getStoreManager()->flush(); /** * Accessing to the previusly save entity * and return an array of results * exampleBundle:Persona is the alias for \examples\exampleBundle\Model\Entity\Persona */ $list = new \Raptor\Util\ItemList($this->getStoreManager()->getRepository('exampleBundle:Persona')->findAll()); return $list->toJson(); }
public function gc($maxlifetime) { $sessions = new \Raptor\Util\ItemList($this->app->getStore()->getManager()->getRepository('systemBundle:RaptorSession')->getGarvage($maxlifetime)); if ($sessions->size() > 0) { foreach ($sessions as $session) { $this->app->getStore()->getManager()->remove($session); } $this->app->getStore()->getManager()->flush(); return true; } else { return true; } }
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); }
/** * Render response body * @param array $env * @param \Exception $exception * @return string */ protected function renderGeneric(&$env, $exception) { $title = 'Ups something was wrong !!'; $html = sprintf('<div style="background-color: #402878 ;color: white;padding: 25px;width:100%s"><h1>%s</h1></div>', "%", $title); $html .= '<div style="background:gray;color:white;margin-top:0;padding:25px;overflow-x:scroll;width:100%">'; $html .= '<p>Please go to your administrator</p>'; $html .= '</div>'; if ($this->app->request()->isXhr()) { $this->app->contentType(\Raptor\Raptor::JSON); $response = new \Raptor\Util\ItemList(); $response->set('cod', 5); $response->set('msg', '<h2>Ups something was wrong !!</h2>'); return $response->toJson(); } return sprintf("<html><head><title>%s</title><style>body{margin:0;padding:30px;font:12px/1.5 Helvetica,Arial,Verdana,sans-serif;}h1{margin:0;font-size:48px;font-weight:normal;line-height:48px;}strong{display:inline-block;width:65px;}</style></head><body>%s</body></html>", $title, $html); }
* 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());
/** * Default Error handler */ protected function defaultError($e) { $this->getLog()->error($e); if ($this->request()->isXhr()) { $this->contentType(\Raptor\Raptor::JSON); $response = new \Raptor\Util\ItemList(); $response->set('cod', 5); $response->set('msg', "<h2>Error</h2>" . '<h4>A website error has occurred. The website administrator has been notified of the issue. Sorry for the temporary inconvenience.</h4>'); echo $response->toJson(); return; } echo self::generateTemplateMarkup('Error', '<p>A website error has occurred. The website administrator has been notified of the issue. Sorry for the temporary inconvenience.</p>'); }