Check the view syntax and save it.

@return Request|Exception
176587
private function _setView()
	{
		if (preg_match('/^[a-z0-9_-]+$/', $this->_requestVars[1])) {
			$this->_view = $this->_requestVars[1];
        } else {
        	$this->_view = $this->_requestVars[1] = self::DEFAULT_VIEW;
        }

        return $this;
	}
616232
public function postAction()
    {
        $data = json_decode($this->getRequest()->getRawBody());
        if (!is_array($data)) $data = array($data);

        $ret = array();
        foreach ($data as $d) {
            $row = $this->_model->createRow();
            if (isset($d->id) && $d->id) {
                $row->id = $d->id;
            }

            $this->_validateInsert((array)$d);
            $this->_validateSave((array)$d);
            $this->_fillRowInsert($row, $d);
            $this->_beforeInsert($row);
            $this->_beforeSave($row);
            $row->save();
            $this->_afterSave($row, $d);
            $this->_afterInsert($row, $d);

            $ret[] = $this->_loadDataFromRow($row);
        }
        if (count($ret) == 1) $ret = reset($ret);

        $this->view->data = $ret;
    }
49063
protected function handleCreateView()
    {
        $input = $this->getCommandInput();
        $resources = Resource::fromFile($input->resourceFile, $input->languageFileName);
        $destenationFile = $this->getDestinationViewFullname($input->viewsDirectory, $input->prefix);

        if ($this->canCreateView($destenationFile, $input->force, $resources)) {
            $stub = $this->getStub();

            $this->createLanguageFile($input->languageFileName, $input->resourceFile, $input->modelName)
                ->createMissingViews($input)
                ->replaceCommonTemplates($stub, $input, $resources->fields)
                ->replaceFileUpload($stub, $resources->fields)
                ->replacePrimaryKey($stub, $this->getPrimaryKeyName($resources->fields))
                ->replaceModelHeader($stub, $this->getHeaderFieldAccessor($resources->fields, $input->modelName))
                ->replaceFormId($stub, $this->getFormId($input->modelName))
                ->replaceFormName($stub, $this->getFormName($input->modelName))
                ->createFile($destenationFile, $stub)
                ->info('Edit view was crafted successfully.');
        }
    }
1213819
public function get()
	{
		$__data = $this->data();

		// The contents of each view file is cached in an array for the
		// request since partial views may be rendered inside of for
		// loops which could incur performance penalties.
		$__contents = $this->load();

		ob_start() and extract($__data, EXTR_SKIP);

		// We'll include the view contents for parsing within a catcher
		// so we can avoid any WSOD errors. If an exception occurs we
		// will throw it out to the exception handler.
		try
		{
			eval('?>'.$__contents);
		}

		// If we caught an exception, we'll silently flush the output
		// buffer so that no partially rendered views get thrown out
		// to the client and confuse the user with junk.
		catch (\Exception $e)
		{
			ob_get_clean(); throw $e;
		}

		$content = ob_get_clean();

		// The view filter event gives us a last chance to modify the
		// evaluated contents of the view and return them. This lets
		// us do something like run the contents through Jade, etc.
		if (Event::listeners('view.filter'))
		{
			return Event::first('view.filter', array($content, $this->path));
		}

		return $content;
	}
2997
public function render()
    {
        switch ($this->type) {
            case "file":
                if (!is_readable($this->template)) {
                    throw new \Exception("Could not find template file: " . $this->template);
                }

                extract($this->templateData);
                include $this->template;

                break;

            case "callback":
                if (!isset($this->template["callback"]) || !is_callable($this->template["callback"])) {
                    throw new \Exception("View missing callback.");
                }

                echo call_user_func($this->template["callback"]);

                break;

            case "string":
                echo $this->template;

                break;

            default:
                throw new \Exception("Not a valid template type: " . $this->type);
        }
    }
933915
public function postAction(Request $request)
    {
        $document = $this->documentManager->create(Structure::TYPE_SNIPPET);
        $form = $this->processForm($request, $document);

        return $this->handleView($form->getData());
    }
133045
public function save()
    {
        $str = $this->prepareForSave($this->toArray());
        if (empty($this->__path)) {
            throw new Exception('Empty path for config save');
        }
        file_put_contents($this->__path, '<?php' . PHP_EOL . PHP_EOL . 'return ' . $str . ';');
        return $this;
    }
588214
public function verifyView()
    {
        // Fetch view definition from database
        try
        {
            $view = self::fetchById( '_design/' . $this->getViewName() );
        }
        catch ( phpillowResponseNotFoundErrorException $e )
        {
            // If the view does not exist yet, recreate it from current view
            $view = $this;
        }

        // Force setting of view definitions
        $views = array();
        foreach ( $this->viewFunctions as $name => $functions )
        {
            $views[$name]['map'] = file_get_contents( $functions['map'] );

            // Check if there is also a reduce function for the given view
            // function.
            if ( isset( $functions['reduce'] ) )
            {
                $views[$name]['reduce'] = file_get_contents( $functions['reduce'] );
            }
        }

        $view->views = $views;
        $view->save();
    }
1072892
private static function view()
    {
        $files = ['View'];
        $folder = static::$root.'MVC/View'.'/';

        self::call($files, $folder);

        $files = ['Template', 'Views'];
        $folder = static::$root.'MVC/View/Libs'.'/';

        self::call($files, $folder);

        $files = ['ViewNotFoundException'];
        $folder = static::$root.'MVC/View/Exceptions'.'/';

        self::call($files, $folder);
    }
243604
public function save() 
    {
        try {
            $m = self::getByAlias($this->alias);
        } catch (\Exception $e) {}
        
        if ($m && $m->id != $this->id) throw new Exception\CMS('Меню c таким алиасом уже существует.');
        
		self::getDbConnection()->update('menus',
			array(
				'alias' => $this->alias,
				'name'  => $this->name,
				'data'  => serialize($this->data),
			),
			array('id' => $this->id)
		);
  	}
983498
public function render()
    {
        if ($this->cssIdentifier === null) {
            throw new Exception("All UIControls must set a cssIdentifier property");
        }

        if ($this->jsClass === null) {
            throw new Exception("All UIControls must set a jsClass property");
        }

        return parent::render();
    }
64920
private function checkMethod() {
        if (strpos(self::$currentRoute['method'], '|') !== false) {
            if (!in_array($_SERVER['REQUEST_METHOD'], explode('|', self::$currentRoute['method']))) {
                throw new RouteException(_message(ExceptionMessages::INCORRECT_METHOD, $_SERVER['REQUEST_METHOD']));
            }
        } else if ($_SERVER['REQUEST_METHOD'] != self::$currentRoute['method']) {
            throw new RouteException(_message(ExceptionMessages::INCORRECT_METHOD, $_SERVER['REQUEST_METHOD']));
        }
    }
846044
public function render()
	{
		$path = $this->template;
		if (array_key_exists($path, ViewModel::$availableTemplates)) {
			$path = 'src/' . ViewModel::$availableTemplates[$this->template];
		}
		if (file_exists($path)) {
			ob_start();
			include($path);
			$output = ob_get_contents();
			ob_end_clean();
			return $output;
		} else {
			throw new \Exception("The requested template (" . $path . ") not found!");
		}
	}
1295452
public function create(): Response
    {
        $request = $this->request->getPost();

        if (empty($request)) {
            $request = $this->request->getJsonRawBody(true);
        }

        //we need even if empty the custome fields
        if (empty($request)) {
            throw new Exception('No valie info sent');
        }

        //set the custom fields to update
        $this->model->setCustomFields($request);

        //try to save all the fields we allow
        if ($this->model->save($request, $this->createFields)) {
            return $this->getById($this->model->id);
        } else {
            //if not thorw exception
            throw new Exception($this->model->getMessages()[0]);
        }
    }
334774
public function handle(View $view, Request $request = null)
    {
        if (null === $request) {
            $request = $this->requestStack->getCurrentRequest();
        }

        $format = $view->getFormat() ?: $request->getRequestFormat();

        if (!$this->supports($format)) {
            $msg = "Format '$format' not supported, handler must be implemented";

            throw new UnsupportedMediaTypeHttpException($msg);
        }

        if (isset($this->customHandlers[$format])) {
            return call_user_func($this->customHandlers[$format], $this, $view, $request, $format);
        }

        return $this->createResponse($view, $request, $format);
    }
1012068
public function getView()
    {
        if(!$this->_view instanceof ViewInterface)
        {
            //Make sure we have a view identifier
            if(!($this->_view instanceof ObjectIdentifier)) {
                $this->setView($this->_view);
            }

            //Create the view
            $config = array(
                'url'        => clone $this->getObject('request')->getUrl(),
                'layout'     => $this->getRequest()->getQuery()->get('layout', 'identifier'),
            );

            $this->_view = $this->getObject($this->_view, $config);

            //Make sure the view implements ViewInterface
            if(!$this->_view instanceof ViewInterface)
            {
                throw new \UnexpectedValueException(
                    'View: '.get_class($this->_view).' does not implement ViewInterface'
                );
            }
        }

        return $this->_view;
    }
839926
public function process()
	{
		$view = $this->getView();
		$context = $this->_getContext();

		try
		{
			parent::process();
		}
		catch( Client_Html_Exception $e )
		{
			$error = array( $this->_getContext()->getI18n()->dt( 'client/html', $e->getMessage() ) );
			$view->standardErrorList = $view->get( 'standardErrorList', array() ) + $error;
		}
		catch( Controller_Frontend_Exception $e )
		{
			$error = array( $this->_getContext()->getI18n()->dt( 'controller/frontend', $e->getMessage() ) );
			$view->standardErrorList = $view->get( 'standardErrorList', array() ) + $error;
		}
		catch( MShop_Plugin_Provider_Exception $e )
		{
			$errors = array( $this->_getContext()->getI18n()->dt( 'mshop', $e->getMessage() ) );
			$errors = array_merge( $errors, $this->_translatePluginErrorCodes( $e->getErrorCodes() ) );

			$view->summaryErrorCodes = $e->getErrorCodes();
			$view->standardErrorList = $view->get( 'standardErrorList', array() ) + $errors;
		}
		catch( MShop_Exception $e )
		{
			$error = array( $this->_getContext()->getI18n()->dt( 'mshop', $e->getMessage() ) );
			$view->standardErrorList = $view->get( 'standardErrorList', array() ) + $error;
		}
		catch( Exception $e )
		{
			$context->getLogger()->log( $e->getMessage() . PHP_EOL . $e->getTraceAsString() );

			$error = array( $context->getI18n()->dt( 'client/html', 'A non-recoverable error occured' ) );
			$view->standardErrorList = $view->get( 'standardErrorList', array() ) + $error;
		}
	}