View PHP Class Code Examples

This page contains top rated real world PHP examples of class View extracted from open source projects. You can rate examples to help us improve the quality of examples

Example #1
Show file File: app.class.php Project: seletskyy/blog_mvc
0
 public static function run($uri)
 {
     self::$router = new Router($uri);
     self::$db = new DB(config::get('db.host'), config::get('db.name'), config::get('db.user'), config::get('db.password'));
     Lang::load(self::$router->getLanguage());
     if ($_POST and (isset($_POST['username_in']) and isset($_POST['password_in'])) or isset($_POST['exit'])) {
         $us = new RegisterController();
         if (isset($_POST['exit'])) {
             $us->LogOut();
         } else {
             $us->Login($_POST);
         }
     }
     if (self::$router->getController() == 'admin' and !Session::getSession('root') or self::$router->getController() == 'myblog' and !Session::getSession('id')) {
         self::$router->setController(Config::get('default_controller'));
         self::$router->setAction(Config::get('default_action'));
         Session::setSession('message', 'Отказ в доступе');
     }
     $controller_class = ucfirst(self::$router->getController()) . 'Controller';
     $controller_method = strtolower(self::$router->getMethodPrefix() . self::$router->getAction());
     $controller_object = new $controller_class();
     if (method_exists($controller_object, $controller_method)) {
         $controller_object->{$controller_method}();
         $view_object = new View($controller_object->getData());
         $content = $view_object->render();
     } else {
         throw new Exception('Method ' . $controller_method . ' of class ' . $controller_class . ' does not exist');
     }
     $layout = self::$router->getRoute();
     $layout_path = VIEWS_PATH . DS . $layout . '.html';
     $layout_view_object = new View(compact('content'), $layout_path);
     echo $layout_view_object->render();
 }
Example #2
Show file File: router.php Project: moomot/Simple-MVC-CMS
0
 /**
  * Получаем имя контроллера и имя его метода
  * через URL вида: example.ru/contacts/feedback
  */
 public static function start()
 {
     $controller_name = 'Index';
     $page_name = 'index';
     $model_name = $controller_name;
     $link_parts = array();
     $link_parts = explode('/', $_SERVER['REQUEST_URI']);
     if (!empty($link_parts[2])) {
         $controller_name = $link_parts[2];
         $model_name = $link_parts[2];
     }
     if (!empty($link_parts[3])) {
         $page_name = $link_parts[3];
     }
     if (!empty($link_parts[4])) {
         $param = $link_parts[4];
     }
     $model_file = strtolower($model_name) . '.php';
     $model_name = $model_name . 'Model';
     $controller_file = strtolower($controller_name) . '.php';
     $controller_name = $controller_name . 'Controller';
     $page_name = $page_name . 'Page';
     /*$model_path = "application/models/".$model_file;
     		if(file_exists($model_path))
     		{
     			include $model_path;
     		}*/
     //echo $controller_file;
     $controller_path = "application/controllers/" . $controller_file;
     if (file_exists($controller_path)) {
         include $controller_path;
     } else {
         $view = new View();
         $view->generatePage('error/404.php');
         exit;
     }
     $controller = new $controller_name();
     $controller->getModel($model_file);
     if (method_exists($controller, $page_name)) {
         if (isset($param)) {
             $controller->{$page_name}($param);
         } else {
             $controller->{$page_name}();
         }
     } else {
         $view = new View();
         $view->generatePage('error/404.php');
         exit;
     }
 }
Example #3
Show file File: ViewCollector.php Project: drickferreira/rastreador
0
 /**
  * Add a View instance to the Collector
  *
  * @param \Illuminate\View\View $view
  */
 public function addView(View $view)
 {
     $name = $view->getName();
     $path = $view->getPath();
     if (!is_object($path)) {
         if ($path) {
             $path = ltrim(str_replace(base_path(), '', realpath($path)), '/');
         }
         if (substr($path, -10) == '.blade.php') {
             $type = 'blade';
         } else {
             $type = pathinfo($path, PATHINFO_EXTENSION);
         }
     } else {
         $type = get_class($view);
         $path = '';
     }
     if (!$this->collect_data) {
         $params = array_keys($view->getData());
     } else {
         $data = array();
         foreach ($view->getData() as $key => $value) {
             $data[$key] = $this->exporter->exportValue($value);
         }
         $params = $data;
     }
     $this->templates[] = array('name' => $path ? sprintf('%s (%s)', $name, $path) : $name, 'param_count' => count($params), 'params' => $params, 'type' => $type);
 }
Example #4
Show file File: Mvc.php Project: suyuanen/trotri
0
 /**
  * 设置模板解析类
  * @param \tfc\mvc\interfaces\View $view
  * @return void
  */
 public static function setView(interfaces\View $view = null)
 {
     if ($view === null) {
         $view = new View();
     }
     self::$_view = $view;
 }
Example #5
Show file File: hooks.php Project: hjimmy/owncloud
0
 /**
  * @brief if the file was really deleted we remove the encryption keys
  * @param array $params
  * @return boolean
  */
 public static function postDelete($params)
 {
     if (!isset(self::$deleteFiles[$params[\OC\Files\Filesystem::signal_param_path]])) {
         return true;
     }
     $deletedFile = self::$deleteFiles[$params[\OC\Files\Filesystem::signal_param_path]];
     $path = $deletedFile['path'];
     $user = $deletedFile['uid'];
     // we don't need to remember the file any longer
     unset(self::$deleteFiles[$params[\OC\Files\Filesystem::signal_param_path]]);
     $view = new \OC\Files\View('/');
     // return if the file still exists and wasn't deleted correctly
     if ($view->file_exists('/' . $user . '/files/' . $path)) {
         return true;
     }
     // Disable encryption proxy to prevent recursive calls
     $proxyStatus = \OC_FileProxy::$enabled;
     \OC_FileProxy::$enabled = false;
     // Delete keyfile & shareKey so it isn't orphaned
     if (!Keymanager::deleteFileKey($view, $path, $user)) {
         \OCP\Util::writeLog('Encryption library', 'Keyfile or shareKey could not be deleted for file "' . $user . '/files/' . $path . '"', \OCP\Util::ERROR);
     }
     Keymanager::delAllShareKeys($view, $user, $path);
     \OC_FileProxy::$enabled = $proxyStatus;
 }
Example #6
Show file File: FilterTest.php Project: tboloo/figdice
0
 public function testHtmlEntitiesBuiltin()
 {
     $view = new View();
     $view->loadString('<test><span fig:text="htmlentities(/data)"/></test>');
     $view->mount('data', '<TAG>');
     $this->assertEquals('<test><span>&lt;TAG&gt;</span></test>', $view->render());
 }
Example #7
Show file File: ContentMatcherFactory.php Project: michalpipa/CommentsBundle
0
 public function match(View $view)
 {
     if ($this->alwaysMatch === true) {
         return array('enabled' => true);
     }
     return parent::match($view);
 }
Example #8
Show file File: Controller.php Project: dorelljames/piwik
0
 public function detection()
 {
     Piwik::checkUserHasSomeAdminAccess();
     $view = new View('@DevicesDetection/detection');
     $this->setBasicVariablesView($view);
     ControllerAdmin::setBasicVariablesAdminView($view);
     $userAgent = Common::getRequestVar('ua', $_SERVER['HTTP_USER_AGENT'], 'string');
     $uaParser = new DeviceDetector($userAgent);
     $uaParser->parse();
     $view->userAgent = $userAgent;
     $view->browser_name = $uaParser->getClient('name');
     $view->browser_short_name = $uaParser->getClient('short_name');
     $view->browser_version = $uaParser->getClient('version');
     $view->browser_logo = getBrowserLogo($uaParser->getClient('short_name'));
     $view->browser_family = \DeviceDetector\Parser\Client\Browser::getBrowserFamily($uaParser->getClient('short_name'));
     $view->browser_family_logo = getBrowserFamilyLogo($view->browser_family);
     $view->os_name = $uaParser->getOs('name');
     $view->os_logo = getOsLogo($uaParser->getOs('short_name'));
     $view->os_short_name = $uaParser->getOs('short_name');
     $view->os_family = \DeviceDetector\Parser\OperatingSystem::getOsFamily($uaParser->getOs('short_name'));
     $view->os_family_logo = getOsFamilyLogo($view->os_family);
     $view->os_version = $uaParser->getOs('version');
     $view->device_type = getDeviceTypeLabel($uaParser->getDeviceName());
     $view->device_type_logo = getDeviceTypeLogo($uaParser->getDeviceName());
     $view->device_model = $uaParser->getModel();
     $view->device_brand = getDeviceBrandLabel($uaParser->getBrand());
     $view->device_brand_logo = getBrandLogo($uaParser->getBrand());
     return $view->render();
 }
Example #9
Show file File: citations.php Project: mined-gatech/hubzero-cms
0
 /**
  * Return data on a resource view (this will be some form of HTML)
  *
  * @param      object  	$publication 	Current publication
  * @param      string  	$option    		Name of the component
  * @param      array   	$areas     		Active area(s)
  * @param      string  	$rtrn      		Data to be returned
  * @param      string 	$version 		Version name
  * @param      boolean 	$extended 		Whether or not to show panel
  * @return     array
  */
 public function onPublication($publication, $option, $areas, $rtrn = 'all', $version = 'default', $extended = true)
 {
     $arr = array('html' => '', 'metadata' => '');
     // Check if our area is in the array of areas we want to return results for
     if (is_array($areas)) {
         if (!array_intersect($areas, $this->onPublicationAreas($publication)) && !array_intersect($areas, array_keys($this->onPublicationAreas($publication)))) {
             $rtrn = 'metadata';
         }
     }
     if (!$publication->_category->_params->get('plg_citations')) {
         return $arr;
     }
     $database = App::get('db');
     // Get a needed library
     include_once PATH_CORE . DS . 'components' . DS . 'com_citations' . DS . 'tables' . DS . 'citation.php';
     include_once PATH_CORE . DS . 'components' . DS . 'com_citations' . DS . 'tables' . DS . 'association.php';
     include_once PATH_CORE . DS . 'components' . DS . 'com_citations' . DS . 'tables' . DS . 'author.php';
     include_once PATH_CORE . DS . 'components' . DS . 'com_citations' . DS . 'tables' . DS . 'secondary.php';
     // Get citations for this publication
     $c = new \Components\Citations\Tables\Citation($database);
     $citations = $c->getCitations('publication', $publication->id);
     $arr['count'] = $citations ? count($citations) : 0;
     $arr['name'] = 'citations';
     // Are we returning HTML?
     if ($rtrn == 'all' || $rtrn == 'html') {
         $config = Component::params($option);
         // Instantiate a view
         $view = new \Hubzero\Plugin\View(array('folder' => 'publications', 'element' => 'citations', 'name' => 'browse'));
         // Pass the view some info
         $view->option = $option;
         $view->publication = $publication;
         $view->citations = $citations;
         $view->format = $config->get('citation_format', 'apa');
         if ($this->getError()) {
             $view->setError($this->getError());
         }
         // Return the output
         $arr['html'] = $view->loadTemplate();
     }
     // Are we returning metadata?
     if ($rtrn == 'all' || $rtrn == 'metadata') {
         $view = new \Hubzero\Plugin\View(array('folder' => $this->_type, 'element' => $this->_name, 'name' => 'metadata'));
         $view->url = Route::url('index.php?option=' . $option . '&' . ($publication->alias ? 'alias=' . $publication->alias : 'id=' . $publication->id) . '&active=citations&v=' . $publication->version_number);
         $view->citations = $citations;
         $arr['metadata'] = $view->loadTemplate();
     }
     // Return results
     return $arr;
 }
Example #10
Show file File: ViewHandlerTest.php Project: francescolaffi/FOSRestBundle
0
 /**
  * @dataProvider exceptionWrapperSerializeResponseContentProvider
  *
  * @param string $format
  */
 public function testCreateResponseWithFormErrorsAndSerializationGroups($format)
 {
     // BC hack for Symfony 2.7 where FormType's didn't yet get configured via the FQN
     $formType = method_exists('Symfony\\Component\\Form\\AbstractType', 'getBlockPrefix') ? 'Symfony\\Component\\Form\\Extension\\Core\\Type\\TextType' : 'text';
     $form = Forms::createFormFactory()->createBuilder()->add('name', $formType)->add('description', $formType)->getForm();
     $form->get('name')->addError(new FormError('Invalid name'));
     $exceptionWrapper = new ExceptionWrapper(['status_code' => 400, 'message' => 'Validation Failed', 'errors' => $form]);
     $view = new View($exceptionWrapper);
     $view->getSerializationContext()->addGroups(['Custom']);
     $wrapperHandler = new ExceptionWrapperSerializeHandler();
     $translatorMock = $this->getMock('Symfony\\Component\\Translation\\TranslatorInterface', ['trans', 'transChoice', 'setLocale', 'getLocale']);
     $translatorMock->expects($this->any())->method('trans')->will($this->returnArgument(0));
     $formErrorHandler = new FormErrorHandler($translatorMock);
     $serializer = SerializerBuilder::create()->configureHandlers(function (HandlerRegistry $handlerRegistry) use($wrapperHandler, $formErrorHandler) {
         $handlerRegistry->registerSubscribingHandler($wrapperHandler);
         $handlerRegistry->registerSubscribingHandler($formErrorHandler);
     })->build();
     $adapter = $this->getMock('FOS\\RestBundle\\Context\\Adapter\\SerializationContextAdapterInterface');
     $container = $this->getMock(Container::class, ['get']);
     $container->expects($this->any())->method('get')->with($this->logicalOr($this->equalTo('fos_rest.serializer'), $this->equalTo('fos_rest.context.adapter.chain_context_adapter')))->will($this->returnCallback(function ($method) use($serializer, $adapter) {
         switch ($method) {
             case 'fos_rest.serializer':
                 return $serializer;
             case 'fos_rest.context.adapter.chain_context_adapter':
                 return $adapter;
         }
     }));
     $viewHandler = new ViewHandler([]);
     $viewHandler->setSerializationContextAdapter($this->getMock('FOS\\RestBundle\\Context\\Adapter\\SerializationContextAdapterInterface'));
     $viewHandler->setContainer($container);
     $response = $viewHandler->createResponse($view, new Request(), $format);
     $serializer2 = SerializerBuilder::create()->configureHandlers(function (HandlerRegistry $handlerRegistry) use($wrapperHandler, $formErrorHandler) {
         $handlerRegistry->registerSubscribingHandler($formErrorHandler);
     })->build();
     $container2 = $this->getMock(Container::class, ['get']);
     $container2->expects($this->any())->method('get')->with($this->logicalOr($this->equalTo('fos_rest.serializer'), $this->equalTo('fos_rest.context.adapter.chain_context_adapter')))->will($this->returnCallback(function ($method) use($serializer2, $adapter) {
         switch ($method) {
             case 'fos_rest.serializer':
                 return $serializer2;
             case 'fos_rest.context.adapter.chain_context_adapter':
                 return $adapter;
         }
     }));
     $viewHandler = new ViewHandler([]);
     $viewHandler->setSerializationContextAdapter($this->getMock('FOS\\RestBundle\\Context\\Adapter\\SerializationContextAdapterInterface'));
     $viewHandler->setContainer($container2);
     $view2 = new View($exceptionWrapper);
     $response2 = $viewHandler->createResponse($view2, new Request(), $format);
     $this->assertEquals($response->getContent(), $response2->getContent());
 }
Example #11
Show file File: app.class.php Project: Skynet2004x/SkynetPR
0
 public static function run($uri)
 {
     self::$router = new Router($uri);
     self::$db = DB::getInstance(Config::get('db.host'), Config::get('db.user'), Config::get('db.password'), Config::get('db.db_name'));
     Lang::load(self::$router->getLanguage());
     $controller_class = ucfirst(self::$router->getController()) . 'controller';
     $controller_method = strtolower(self::$router->getMethod_prefix() . self::$router->getAction());
     $controller_parametr = self::$router->getParams();
     $layout = self::$router->getRoute();
     if ($layout == 'admin' && Session::get('role') != 'admin') {
         if ($controller_method != 'admin_login') {
             Router::redirect('/admin/users/login');
         }
     }
     //Calling conrollers method
     $controller_object = new $controller_class();
     if (method_exists($controller_object, $controller_method)) {
         $view_path = $controller_object->{$controller_method}();
         $view_object = new View($controller_object->getData(), $view_path);
         $content = $view_object->render();
     } else {
         throw new Exception('Метод ' . $controller_method . ' в классе ' . $controller_class . 'не найден');
     }
     $layout_path = VIEW_PATH . DS . $layout . '.html';
     $layout_view_object = new View(compact('content'), $layout_path);
     // основной рендер вывода страниц
     echo $layout_view_object->render();
 }
Example #12
Show file File: class.BaseController.php Project: bryan-gilbert/WordPress-Domain-Changer
0
 public function render($view_name)
 {
     $this->beforeRender();
     $layout = new View(realpath(dirname(__FILE__) . "/../../views/_layout.php"));
     $view = new View(realpath(dirname(__FILE__) . "/../../views/" . $view_name . ".php"));
     $this->data["current_user"] = (object) array("authenticated" => $this->isAuthenticated(), "session" => $this->getSession());
     $this->data["request"] = (object) array("url" => $this->getRequestUrl(), "verb" => $this->getRequestVerb(), "path" => $this->getRequestPath(), "protected" => $this->isRequestProtected(), "authenticated" => $this->isAuthenticated(), "route" => $this->getRequestRoute(), "assets_url" => $this->getAssetsUrl(), "root_route_url" => $this->getRootRouteUrl(), "base_url" => $this->getBaseUrl(), "base_route_url" => $this->getBaseRouteUrl(), "post" => $this->getPost());
     $this->data["flash"] = $this->getFlash();
     $this->data["body"] = $view->render($this->data);
     $this->data["flash"] = $this->getFlash();
     // catch any flash messages added from view (usually an error)
     $html = $layout->render($this->data);
     return $html;
 }
Example #13
Show file File: Controller.php Project: FluentDevelopment/piwik
0
 private function prepareWidgetView($template)
 {
     if (!$this->canGenerateInsights()) {
         $view = new View('@Insights/cannotDisplayReport.twig');
         $this->setBasicVariablesView($view);
         return $view;
     }
     $view = new View('@Insights/' . $template);
     $this->setBasicVariablesView($view);
     $view->properties = array('order_by' => InsightReport::ORDER_BY_ABSOLUTE);
     return $view;
 }
Example #14
Show file File: Controller.php Project: FluentDevelopment/piwik
0
 public function runUpdaterAndExit($doDryRun = null)
 {
     $updater = new DbUpdater();
     $componentsWithUpdateFile = $updater->getComponentUpdates();
     if (empty($componentsWithUpdateFile)) {
         throw new NoUpdatesFoundException("Everything is already up to date.");
     }
     SettingsServer::setMaxExecutionTime(0);
     $welcomeTemplate = '@CoreUpdater/runUpdaterAndExit_welcome';
     $doneTemplate = '@CoreUpdater/runUpdaterAndExit_done';
     $viewWelcome = new View($welcomeTemplate);
     $this->addCustomLogoInfo($viewWelcome);
     $this->setBasicVariablesView($viewWelcome);
     $viewDone = new View($doneTemplate);
     $this->addCustomLogoInfo($viewDone);
     $this->setBasicVariablesView($viewDone);
     $doExecuteUpdates = Common::getRequestVar('updateCorePlugins', 0, 'integer') == 1;
     if (is_null($doDryRun)) {
         $doDryRun = !$doExecuteUpdates;
     }
     if ($doDryRun) {
         $viewWelcome->queries = $updater->getSqlQueriesToExecute();
         $viewWelcome->isMajor = $updater->hasMajorDbUpdate();
         $this->doWelcomeUpdates($viewWelcome, $componentsWithUpdateFile);
         return $viewWelcome->render();
     }
     // Web
     if ($doExecuteUpdates) {
         $this->warningMessages = array();
         $this->doExecuteUpdates($viewDone, $updater, $componentsWithUpdateFile);
         $this->redirectToDashboardWhenNoError($updater);
         return $viewDone->render();
     }
     exit;
 }
Example #15
Show file File: ApplicationMvcTest.php Project: aisuhua/phalcon-php
0
 public function testApplicationModulesDefinitionClosure()
 {
     // Creates the autoloader
     $loader = new \Phalcon\Loader();
     $loader->registerNamespaces(array('Frontend\\Controllers' => __DIR__ . '/modules/frontend/controllers/', 'Backend\\Controllers' => __DIR__ . '/modules/backend/controllers/'));
     $loader->register();
     $_GET['_url'] = '/login';
     Phalcon\DI::reset();
     $di = new Phalcon\DI\FactoryDefault();
     $di->set('router', function () {
         $router = new Phalcon\Mvc\Router(false);
         $router->add('/index', array('controller' => 'index', 'module' => 'frontend', 'namespace' => 'Frontend\\Controllers\\'));
         $router->add('/login', array('controller' => 'login', 'module' => 'backend', 'namespace' => 'Backend\\Controllers\\'));
         return $router;
     });
     $application = new Phalcon\Mvc\Application();
     $view = new \Phalcon\Mvc\View();
     $application->registerModules(array('frontend' => function ($di) use($view) {
         $di->set('view', function () use($view) {
             $view = new \Phalcon\Mvc\View();
             $view->setViewsDir(__DIR__ . '/modules/frontend/views/');
             return $view;
         });
     }, 'backend' => function ($di) use($view) {
         $di->set('view', function () use($view) {
             $view->setViewsDir(__DIR__ . '/modules/backend/views/');
             return $view;
         });
     }));
     $application->setDi($di);
     $this->assertEquals($application->handle()->getContent(), '<html>here</html>' . PHP_EOL);
     $loader->unregister();
 }
Example #16
Show file File: SteamFormRow.php Project: AsteriaGamer/steamdriven-kohana
0
 /**
  * show a full row
  *
  * @param boolean $submitted 
  * @return void
  * @author Andy Bennett
  */
 function full($submitted)
 {
     $n = $this->p->name;
     $nm = (string) $this->p->row->name;
     $e = $n . '_error';
     // if submitted CVAL = the value from the validation system
     // otherwise if there is a current value, use that
     // otherwise use the row value
     $this->p->cval = $submitted && !isset($this->form->validation->{$e}) ? Kohana::instance()->input->post($n) : ($this->p->current !== false ? $this->p->current : $this->p->row->value);
     // $this->p->cval = prepfordb( $this->p->cval );
     $data = array('o' => $this, 'ename' => $n . '_error');
     if (!isset($this->p->row->type) || (string) $this->p->row->type == '') {
         return;
     }
     $vw = new View('parts/form/' . strtolower($this->p->row->type));
     foreach ($data as $k => $v) {
         $vw->{$k} = $v;
     }
     $data['item'] = $vw->render();
     $view = new View('parts/form/row');
     foreach ($data as $k => $v) {
         $view->{$k} = $v;
     }
     $view->render(TRUE);
 }
Example #17
Show file File: sharedstorage.php Project: evanjt/core
0
 public function testNameConflict()
 {
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     $view1 = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files');
     $view1->mkdir('foo');
     $folderInfo1 = $view1->getFileInfo('foo');
     self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
     $view3 = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER3 . '/files');
     $view3->mkdir('foo');
     $folderInfo2 = $view3->getFileInfo('foo');
     // share a folder with the same name from two different users to the same user
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     \OCP\Share::shareItem('folder', $folderInfo1['fileid'], \OCP\Share::SHARE_TYPE_GROUP, self::TEST_FILES_SHARING_API_GROUP1, 31);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
     \OCP\Share::shareItem('folder', $folderInfo2['fileid'], \OCP\Share::SHARE_TYPE_GROUP, self::TEST_FILES_SHARING_API_GROUP1, 31);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $view2 = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
     $this->assertTrue($view2->file_exists('/foo'));
     $this->assertTrue($view2->file_exists('/foo (2)'));
     $mount = $view2->getMount('/foo');
     $this->assertInstanceOf('\\OCA\\Files_Sharing\\SharedMount', $mount);
     /** @var \OC\Files\Storage\Shared $storage */
     $storage = $mount->getStorage();
     $source = $storage->getFile('');
     $this->assertEquals(self::TEST_FILES_SHARING_API_USER1, $source['uid_owner']);
 }
Example #18
Show file File: ViewHandlerTest.php Project: mgldev/coffeetrack
0
 /**
  * @dataProvider exceptionWrapperSerializeResponseContentProvider
  * @param string $format
  */
 public function testCreateResponseWithFormErrorsAndSerializationGroups($format)
 {
     $form = Forms::createFormFactory()->createBuilder()->add('name', 'text')->add('description', 'text')->getForm();
     $form->get('name')->addError(new FormError('Invalid name'));
     $exceptionWrapper = new ExceptionWrapper(array('status_code' => 400, 'message' => 'Validation Failed', 'errors' => $form));
     $view = new View($exceptionWrapper);
     $view->getSerializationContext()->setGroups(array('Custom'));
     $wrapperHandler = new ExceptionWrapperSerializeHandler();
     $translatorMock = $this->getMock('Symfony\\Component\\Translation\\TranslatorInterface', array('trans', 'transChoice', 'setLocale', 'getLocale'));
     $translatorMock->expects($this->any())->method('trans')->will($this->returnArgument(0));
     $formErrorHandler = new FormErrorHandler($translatorMock);
     $serializer = SerializerBuilder::create()->configureHandlers(function (HandlerRegistry $handlerRegistry) use($wrapperHandler, $formErrorHandler) {
         $handlerRegistry->registerSubscribingHandler($wrapperHandler);
         $handlerRegistry->registerSubscribingHandler($formErrorHandler);
     })->build();
     $container = $this->getMock('Symfony\\Component\\DependencyInjection\\Container', array('get'));
     $container->expects($this->once())->method('get')->with('fos_rest.serializer')->will($this->returnValue($serializer));
     $viewHandler = new ViewHandler(array());
     $viewHandler->setContainer($container);
     $response = $viewHandler->createResponse($view, new Request(), $format);
     $serializer2 = SerializerBuilder::create()->configureHandlers(function (HandlerRegistry $handlerRegistry) use($wrapperHandler, $formErrorHandler) {
         $handlerRegistry->registerSubscribingHandler($formErrorHandler);
     })->build();
     $container2 = $this->getMock('Symfony\\Component\\DependencyInjection\\Container', array('get'));
     $container2->expects($this->once())->method('get')->with('fos_rest.serializer')->will($this->returnValue($serializer2));
     $viewHandler = new ViewHandler(array());
     $viewHandler->setContainer($container2);
     $view2 = new View($exceptionWrapper);
     $response2 = $viewHandler->createResponse($view2, new Request(), $format);
     $this->assertEquals($response->getContent(), $response2->getContent());
 }
Example #19
Show file File: ViewSimpleTest.php Project: UqiOnline/cphalcon7
0
 public function testRenderWithCache()
 {
     // Create cache at first run
     $view = new View();
     $view->setViewsDir('unit-tests/views/');
     $this->assertFalse($view->getCache());
     // No cache before DI is set
     $view->setDI($this->_getDI());
     $this->assertEquals($view, $view->cache(array('key' => 'view_simple_cache')));
     $cache = $view->getCache();
     $this->assertInstanceOf('Phalcon\\Cache\\BackendInterface', $cache);
     if ($cache instanceof BackendInterface == false) {
         $this->fail('Expected BackendInterface');
     }
     $timeNow = time();
     $view->setParamToView('a_cool_var', $timeNow);
     $this->assertEquals("<p>{$timeNow}</p>", $view->render('test3/coolVar'));
     unset($view, $cache);
     // Re-use the cached contents
     $view = new View();
     $view->setViewsDir('unit-tests/views/');
     $view->setDI($this->_getDI());
     $view->cache(array('key' => 'view_simple_cache'));
     $this->assertEquals("<p>{$timeNow}</p>", $view->render('test3/coolVar'));
     // Cache should expire
     $this->assertEquals("<p></p>", @$view->render('test3/coolVar'));
 }
Example #20
Show file File: BootstrapHtmlHelper.php Project: edukondaluetg/cakephp3-bootstrap-helpers
0
 public function __construct(\Cake\View\View $view, array $config = [])
 {
     if (isset($config['useFontAwesome'])) {
         $this->_useFontAwesome = $config['useFontAwesome'];
     }
     parent::__construct($view, $config);
 }
Frequently Used Methods