Handle the slice

@return bool|PageSliceController
501743
public function handleSlice()
    {
        if (!$id = $this->owner->getRequest()->param('ID')) {
            return false;
        }

        $sliceRelations = array();
        if (!$hasManyRelations = $this->owner->data()->hasMany()) {
            return false;
        }

        foreach ($hasManyRelations as $relationName => $relationClass) {
            if ($relationClass == PageSlice::class || is_subclass_of($relationClass, PageSlice::class)) {
                $sliceRelations[] = $relationName;
            }
        }

        $slice = null;
        foreach ($sliceRelations as $sliceRelation) {
            if ($slice) {
                break;
            }
            /** @var PageSlice $slice */
            $slice = $this->owner->data()->$sliceRelation()->find('ID', $id);
        }

        if (!$slice) {
            user_error('No slice found', E_USER_ERROR);
        }

        return $slice->getController();
    }
1310886
public function paginate()
    {
        $this->total = $this->dataSource->getTotal($this->source);

        if (
            ($this->getPagesCount() > 0 && $this->getPage() > $this->getPagesCount()) ||
            $this->getPage() <= 0
        ) {
            $this->handler->wrongPageCallback();
        }

        $this->data = $this->dataSource->applyLimit(
            $this->source,
            $this->getPage(),
            $this->getPageSize()
        );

        return $this->data;
    }
256591
protected function pages_prepare(){
		//Cache some pages pre-counted data
		$limit=$this->getLimit();
		$count=$this->items_count;
		if(($limit<=0)||($count<=0)){
			return false;
			}
		$this->pages_count=(int)($count/$limit);
		if(($count%$limit==0)&&($this->pages_count>0)){
			$this->pages_count--;
			}
		$this->page_prev=$this->getPage()-1;
		$this->page_next=$this->getPage()+1;
		$this->page_active=$this->getPage();
		$this->pages=array();
		//Add links
		$this->pages_prepare_prev();
		$this->pages_prepare_middle();
		$this->pages_prepare_next();
		BRequest::setVar('page',$this->getPage());
		return true;
		}
989466
public function serve() {
        if(is_null($this->linkPath)) {
            $route = $this->fw->get('PARAMS.0');
            if($this->fw->exists('PARAMS.'.$this->routeKey))
                $route = preg_replace('/'.preg_quote($this->routeKeyPrefix.
                    $this->fw->get('PARAMS.'.$this->routeKey)).'$/','',$route);
            elseif(substr($route,-1) != '/')
                $route.= '/';
        } else
            $route = $this->linkPath;
        $this->fw->set('pg.route',$route);
        $this->fw->set('pg.prefix',$this->routeKeyPrefix);
        $this->fw->set('pg.currentPage',$this->current_page);
        $this->fw->set('pg.nextPage',$this->getNext());
        $this->fw->set('pg.prevPage',$this->getPrev());
        $this->fw->set('pg.firstPage',$this->getFirst());
        $this->fw->set('pg.lastPage',$this->getLast());
        $this->fw->set('pg.rangePages',$this->getInRange());
        $this->fw->set('pg.allPages',$this->getMax());
        $output = \Template::instance()->render($this->template);
        $this->fw->clear('pg');
        return $output;
    }
67309
public function handle()
    {
        $this->rebuild = !empty($this->input->getOption('rebuild'));

        $this->tables = $this->getTablesFromMWBFile();
        if ($this->tables === false) {
            return false;
        }

        $this->getAppJson();

        $this->spec = $this->getAPISpecFromOASFile();
        if ($this->spec === null) {
            return false;
        }

        $success = $this->validateAPIDefinition();
        if (!$success) {
            return false;
        }

        $this->databaseService = new DatabaseService($this->config, $this->files);
        $this->databaseService->resetDatabase();

        $this->generateFromDefinitions();
        $this->generateControllers();
        $this->generateRequests();
        $this->insertRoutes();
        $this->styleCode();

        $this->databaseService->dropDatabase();

        return true;
    }
1201662
public function handle()
    {
        try {
            $query = $this->di->request->getRoute();
            $parts = $this->di->request->getRouteParts();

            // Match predefined routes
            foreach ($this->routes as $route) {
                if ($route->match($query)) {
                    return $route->handle();
                }
            }

            // Default handling route as :controller/:action/:params using the dispatcher
            $dispatcher = $this->di->dispatcher;
            $dispatcher->setControllerName(isset($parts[0]) ? $parts[0] : 'index');

            if ($dispatcher->isValidController()) {
                $dispatcher->setActionName(isset($parts[1]) ? $parts[1] : 'index');

                $params = [];
                if (isset($parts[2])) {
                    $params = $parts;
                    array_shift($params);
                    array_shift($params);
                }
                $dispatcher->setParams($params);

                if ($dispatcher->isCallable()) {
                    return $dispatcher->dispatch();
                }
            }

            // Use the "catch-all" route
            if ($this->defaultRoute) {
                return $this->defaultRoute->handle();
            }

            // No route was matched
            $this->handleInternal('404');
        } catch (\Exception $e) {
            // Exception codes can match a route for a http status code
            $code = $e->getCode();
            $statusCodes = [403, 404, 500];
            if (in_array($code, $statusCodes)) {
                $this->di->flash->setMessage($e->getMessage());
                $this->handleInternal($code);
            } else {
                throw $e;
            }
        }
    }
183872
protected function executeHandler()/*# : bool */
    {
        try {
            $handler = $this->result->getHandler();
            $callable = $this->getResolver()->resolve($handler);

            if ($this->result->getRoute()) {
                return $this->callableWithRoute($callable);
            } else {
                call_user_func($callable, $this->result);
                return true;
            }
        } catch (\Exception $e) {
            $this->result->setHandler(null);
            return false;
        }
    }
1290083
protected function _handle()
    {
        $ids = $this->_processIds();
        $subject = $this->_constructSubject($ids);

        $event = $this->_trigger('beforeBulk', $subject);
        if ($event->isStopped()) {
            return $this->_stopped($subject);
        }

        if ($this->_bulk($subject->query)) {
            $this->_success($subject);
        } else {
            $this->_error($subject);
        }

        return $this->_redirect($subject, ['action' => 'index']);
    }
797314
public static function Slice($Slice) {
      $Result = self::Factory(self::AliasSlice);
      return $Result->Execute($Slice);
   }
490827
public function handle()
    {
        $router = $this->getRouter();
        $routeCollection = $router->getRoutes();
        $rows = array();

        foreach ($routeCollection as $route) {
            $rows[] = [
                'verb' => $route['method'],
                'path' => $route['uri'],
                'namedRoute' => $this->getNamedRoute($route['action']),
                'controller' => $this->getController($route['action']),
                'action' => $this->getAction($route['action']),
                'middleware' => $this->getMiddleware($route['action']),
            ];
        }

        if ($this->laravel->bound(Router::class)) {
            $routes = $this->laravel->make(Router::class)->getRoutes();

            foreach ($routes as $route) {
                foreach ($route->getRoutes() as $innerRoute) {
                    $rows[] = [
                        'verb' => implode($innerRoute->getMethods(), '|'),
                        'path' => $innerRoute->getPath(),
                        'namedRoute' => $innerRoute->getName(),
                        'controller' => get_class($innerRoute->getControllerInstance()),
                        'action' => $this->getAction($innerRoute->getAction()),
                        'middleware' => implode($innerRoute->getMiddleware(), '|'),
                    ];
                }
            }
        }

        $headers = array('Verb', 'Path', 'NamedRoute', 'Controller', 'Action', 'Middleware');
        $this->table($headers, $rows);
    }
641213
public function handle_get_data() {
        $url = new UrlHelper ();
        $pageNumber = $url->get('pageNumber', 1);
        $perPage = $url->get('perPage', 10);
        $filters = $url->get("filters_json", "[]");

        $params = array(
            'skip' => ($pageNumber - 1) * $perPage,
            'take' => $perPage,
            'filters_json' => $filters
        );
        return array(
            'type' => 'json',
            'data' => array (
                'rows' => $this->dataProvider->getData($params)
            )
        );
    }
419837
protected function execPageCycle()
    {
        /**
         * @event cms.page.start
         * Fires before all of the page & layout lifecycle handlers are run
         *
         * Example usage:
         *
         *     Event::listen('cms.page.start', function ((\Cms\Classes\Controller) $controller) {
         *         return Response::make('Taking over the lifecycle!', 200);
         *     });
         *
         * Or
         *
         *     $CmsController->bindEvent('page.start', function () {
         *         return Response::make('Taking over the lifecycle!', 200);
         *     });
         *
         */
        if ($event = $this->fireSystemEvent('cms.page.start')) {
            return $event;
        }

        /*
         * Run layout functions
         */
        if ($this->layoutObj) {
            CmsException::mask($this->layout, 300);
            $response = (
                ($result = $this->layoutObj->onStart()) ||
                ($result = $this->layout->runComponents()) ||
                ($result = $this->layoutObj->onBeforePageStart())
            ) ? $result : null;
            CmsException::unmask();

            if ($response) {
                return $response;
            }
        }

        /*
         * Run page functions
         */
        CmsException::mask($this->page, 300);
        $response = (
            ($result = $this->pageObj->onStart()) ||
            ($result = $this->page->runComponents()) ||
            ($result = $this->pageObj->onEnd())
        ) ? $result : null;
        CmsException::unmask();

        if ($response) {
            return $response;
        }

        /*
         * Run remaining layout functions
         */
        if ($this->layoutObj) {
            CmsException::mask($this->layout, 300);
            $response = ($result = $this->layoutObj->onEnd()) ? $result : null;
            CmsException::unmask();
        }

        /**
         * @event cms.page.end
         * Fires after all of the page & layout lifecycle handlers are run
         *
         * Example usage:
         *
         *     Event::listen('cms.page.end', function ((\Cms\Classes\Controller) $controller) {
         *         return Response::make('Taking over the lifecycle!', 200);
         *     });
         *
         * Or
         *
         *     $CmsController->bindEvent('page.end', function () {
         *         return Response::make('Taking over the lifecycle!', 200);
         *     });
         *
         */
        if ($event = $this->fireSystemEvent('cms.page.end')) {
            return $event;
        }

        return $response;
    }
466747
public function handle()
    {
        $input = $this->getCommandInput();
        $file = $this->getFilename($input->file);

        if (!$this->isFileExists($file)) {
            $this->error('The resource-file does not exists.');

            return false;
        }

        if (empty($input->fieldNames) && empty($input->relations) && empty($input->indexes)) {
            $this->noResourcesProvided();

            return false;
        }

        $resource = $this->getResources($file);
        $totalReducedFields = $this->reduceFields($resource, $input->fieldNames);
        $totalReducedRelations = $this->reduceRelations($resource, $input->relations);
        $totalReducedIndexes = $this->reduceIndexes($resource, $input->indexes);

        if ($resource->isEmpty()) {
            $this->callSilent(
                'resource-file:delete',
                [
                    'model-name' => $input->modelName,
                    '--resource-filename' => $input->file,
                ]
            );

            $this->info('All resources were removed from the resource-file. The file "' . basename($file) . '" was removed successfully!');

            return false;
        }

        $this->putContentInFile($file, Helpers::prettifyJson($resource->toArray()));
        $filename = basename($file);

        if (!empty($input->fieldNames)) {
            $this->info($totalReducedFields . ' field(s) where removed from the "' . $filename . '" file.');
        }

        if (!empty($input->relations)) {
            $this->info($totalReducedRelations . ' relation(s) where removed from the "' . $filename . '" file.');
        }

        if (!empty($input->indexes)) {
            $this->info($totalReducedIndexes . ' index(es) where removed from the "' . $filename . '" file.');
        }
    }
189425
public function handle()
    {
        return $this->dbTransaction(function () {
            $descendantsIds = $this->content->findDescendantsWithTrashed()->pluck('id');

            // First we need to delete all routes because it's polymorphic relation
            Route::where('routes.routable_type', '=', Content::class)
                ->whereIn('routable_id', $descendantsIds)
                ->delete();
            $lastAction = Content::withTrashed()->find($this->content->id)->forceDelete();

            event('content.force_deleted', [$this->content]);

            return $lastAction;
        });
    }
531839
public function execute() {
        global $DB;

        // Check if the category bin is disabled or there is no expiry time.
        $lifetime = get_config('tool_recyclebin', 'categorybinexpiry');
        if (!\tool_recyclebin\category_bin::is_enabled() || $lifetime <= 0) {
            return true;
        }

        // Get the items we can delete.
        $items = $DB->get_recordset_select('tool_recyclebin_category', 'timecreated <= :timecreated',
            array('timecreated' => time() - $lifetime));
        foreach ($items as $item) {
            mtrace("[tool_recyclebin] Deleting item '{$item->id}' from the category recycle bin ...");
            $bin = new \tool_recyclebin\category_bin($item->categoryid);
            $bin->delete_item($item);
        }
        $items->close();

        return true;
    }
1133931
public function doExecute()
	{
		// Check if we just want the help page.
		if ($this->input->get('h'))
		{
			$this->help();

			return;
		}

		// Check for debug mode.
		$this->debug = $this->input->getBool('d');

		// Set the maximum number of pages (and runaway failsafe).
		$cutoff = 100;
		$page = 1;

		// Check if we only want to get the latest version information.
		$latestOnly = $this->input->get('l');

		// Initialise the version cutoffs.
		$versions = array(
			0 => '1.0',
		);

		// Initialise arrays and metrics.
		$log = array();
		$userCount = array();
		$pullCount = 0;
		$mergedBy = array();
		$labelled = array();

		// Set the current version.
		$version = $versions[0];

		while ($cutoff--)
		{
			// Get a page of the closed issues.
			$issues = $this->getIssues($page++);

			// Check if we've gone past the last page.
			if (empty($issues))
			{
				break;
			}

			// Loop through each pull.
			foreach ($issues as $i => $issue)
			{
				$this->out(sprintf(' %03d ', $i + 1), false);

				// Check if the issue is a pull request.
				if (empty($issue->pull_request->html_url))
				{
					$this->out('Skipped; no pull request url.');
					continue;
				}

				// Change the version
				if (isset($versions[$issue->number]) || ($this->debug && $pullCount > 0))
				{
					// Populate buffers.
					$this->setBuffer("$version.userCount", $userCount);
					$this->setBuffer("$version.pullCount", $pullCount, false);
					$this->setBuffer("$version.mergedBy", $mergedBy);
					$this->setBuffer("$version.labelled", $labelled);

					// Reset counters.
					$pullCount = 0;
					$userCount = array();
					$mergedBy = array();
					$labelled = array();

					// Break if we only want the latest version.
					if ($latestOnly || $this->debug)
					{
						break 2;
					}

					// Increment version.
					$version = $versions[$issue->number];
				}

				// Get specific information about the pull request.
				$data = $this->getPull($issue->number);

				// Check if merged.
				if (!$data->merged || $data->commits == 0)
				{
					$this->out(' - not merged.');
					continue;
				}

				// Check if the issue is labelled.
				foreach ($issue->labels as $label)
				{
					if (!isset($labelled[$label->name]))
					{
						$labelled[$label->name] = array();
					}
					$labelled[$label->name][] = '<a href="' . $issue->html_url . '">' . $issue->title . '</a>';
				}

				// Prepare the link to the pull.
				$html = '[<a href="' . $issue->html_url . '" title="Closed ' . $issue->closed_at . '">';
				$html .= '#' . $issue->number;
				$html .= '</a>] <strong>' . $issue->title . '</strong>';
				$html .= ' (<a href="https://github.com/' . $issue->user->login . '">' . $issue->user->login . '</a>)';

				if (trim($data->body_html))
				{
					$html .= $data->body_html;
				}

				$this->setBuffer("$version.log", $html);

				if (!isset($userCount[$issue->user->login]))
				{
					$userCount[$issue->user->login] = 0;
				}
				$userCount[$issue->user->login]++;
				$pullCount++;

				if (!isset($mergedBy[$data->merged_by->login]))
				{
					$mergedBy[$data->merged_by->login] = 0;
				}
				$mergedBy[$data->merged_by->login]++;

				$this->out(' - ok');
			}
		}

		// Check if the output folder exists.
		if (!is_dir(__DIR__ . '/../docs'))
		{
			mkdir(__DIR__ . '/../docs');
		}

		// Write the file.
		file_put_contents(__DIR__ . '/../docs/changelog.html', $this->render($latestOnly ? array($versions[0]) : $versions));

		// Close normally.
		$this->close();
	}
179125
public function handle()
    {
        $exactFileContent = file_get_contents(base_path($this->routesFilePath));

        $preparedFileContent = $this->prepareFileContent($exactFileContent);

        $output = '';

        foreach (explode("\n", $preparedFileContent) as $line) {
            $preparedLine = $this->prepareLine($line);

            if (preg_match('/controller(?:[^s\(]*)\(([^,]*),([^,)]*)/', $preparedLine, $matches)) {
                if (count($matches) != 3) {
                    $this->error($preparedLine.' Looks weird, unable to parse it.');
                }

                preg_match('/^( *)/', $line, $spaces);

                $output .= $this->extractController(trim($matches[1], '\''), trim($matches[2], '\''), $spaces[1]);
            } elseif (preg_match('/controllers(?:[^\(]*)\((.*)\)/', $preparedLine, $matches)) {
                preg_match('/^( *)/', $line, $spaces);

                $output .= $this->extractControllers($matches[1], $spaces[1]);
            } else {
                $output .= $line."\n";
            }
        }

        file_put_contents(base_path($this->routesFilePath . '.generated'), $output);

        file_put_contents(base_path($this->routesFilePath . '.backup'), $preparedFileContent);

        $this->info('Done! Generated file was published in "'.base_path($this->routesFilePath . '.generated').'"');

        $this->info('Also a backup of '. basename('$this->routesFilePath') .' was published in "'.base_path($this->routesFilePath . '.backup').'"');
    }