大佬教程收集整理的这篇文章主要介绍了Laravel 在加载类“语法错误,意外......”时崩溃,但仅限于生产服务器,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这个类的代码有问题。我检查了缺少的括号等,但我找不到问题所在。奇怪的是,它在本地运行良好,只有在推送到生产服务器时,它才会崩溃(这也使得修复起来很尴尬)。
它在类声明 public ?String $header;
的第一行崩溃
它说“语法错误,意外”? (T_StriNG),期望函数 (T_FUNCTION) 或常量 (T_CONST)'
<?php
namespace App\http\Navigation;
use App\Models\category;
use App\Models\Genus;
use App\Models\Quarter;
use App\Models\User;
use Illuminate\Support\Facades\DB;
use phpdocumentor\Reflection\Types\This;
/*
|--------------------------------------------------------------------------
| SIDebar Class
|--------------------------------------------------------------------------
|
| Construct and load the SIDebar object as part of the vIEw in the
| vIEw controller to be processed by an included navigation/sIDebar.blade
|
*/
/** @package App\http\Navigation */
class SIDebar
{
public ?String $header; <- IT CRASHES HERE
public ?array $menu_array;
public ?String $route_prefix;
public ?object $categorIEs;
public ?String $section;
public ?String $translation_type;
public ?object $owner;
public function __construct($vIEw)
{
$this->section = $vIEw->section;
$this->resource = $resource ?? null;
$this->owner = owner() ?? User::first();
}
// =========================================================================
// PUBliC STATIC FUNCTIONS
// =========================================================================
/** Create a SIDebar object and load all necessary data
*
* @param object $vIEw
* @return object
*/
public static function construct($vIEw)
{
// dd('SIDebar@create() vIEw',$vIEw);
if (!self::checkHasSIDebar($vIEw)) {
return null;
}
$sIDebar = new SIDebar($vIEw);
$sIDebar->loadActiveMenus($vIEw);
$sIDebar->loadMenuArray($vIEw);
// dd('SIDebar@construct() return',$sIDebar);
return $sIDebar;
}
// =========================================================================
// PRIVATE FUNCTIONS
// =========================================================================
public function loadActiveMenus($vIEw)
{
if (isset($vIEw->SELEction) && is_object($vIEw->SELEction)) {
switch ($vIEw->SELEction->resource_Name) {
case 'categorIEs':
if ($vIEw->SELEction->tIEr == 1) {
$this->active_top_menu = $vIEw->SELEction->name;
} elseif ($vIEw->SELEction->tIEr == 2) {
$this->active_menu = $vIEw->SELEction->name;
$this->active_top_menu = $vIEw->SELEction->parent->name;
} else {
$this->active_item = $vIEw->SELEction->name;
$this->active_menu = $vIEw->SELEction->parent->name;
$this->active_top_menu = $vIEw->SELEction->parent->parent->name;
}
break;
case 'genera':
$this->active_menu = $vIEw->SELEction->slug;
$this->active_top_menu = $vIEw->SELEction->subfamily->slug;
break;
case 'quarters':
$this->active_menu = $vIEw->SELEction->code;
$this->active_top_menu = $vIEw->SELEction->year;
break;
}
}
}
/** Get the data for the sIDebar menus based on the given vIEw
*
* @param object $vIEw
* @return String // returns updated resource key
*/
private function loadMenuArray($vIEw)
{
// dd('SIDebar@loadMenuArray,parameters',$vIEw);
switch ($vIEw->section) {
// BACKOFFICE
case 'BACkoffice':
switch ($vIEw->resource_Name) {
// ACTIVE/QUARTERS
case 'orders':
case 'payments':
case 'purchases':
case 'shipments':
$menu_array = $this->generateMenuArrayBACkofficeQuarters($vIEw,$vIEw->resource_Name);
$this->translation_type = 'language_files';
break;
// CATEGORIES
case 'items':
case 'products':
case 'suppliers':
$menu_array = $this->generateMenuArrayBACkofficeCategorIEs($vIEw,$vIEw->resource_Name);
$this->translation_type = 'translations';
break;
}
break;
// WEBSTORE
case 'webstore':
$menu_array = $this->generateMenuArrayWebstore($vIEw);
$this->translation_type = 'translations';
break;
}
// dd('SIDebar@loadMenuArray return',$menu_array,$this,$vIEw);
return $this->menu_array = $menu_array;
}
// =========================================================================
// MENU ARRAY FUNCTIONS
// =========================================================================
/** Generate menu array for BACkoffice resources using CategorIEs
*
* @param object $vIEw
* @param String $resource_name
* @return array
*/
private function generateMenuArrayBACkofficeCategorIEs($vIEw,$resource_Name)
{
$sIDebar_categorIEs = category::where('type',$resource_Name)->where('tIEr',1)->orderBy('sorTing_order')->with(['children'])->get();
// Year topmenu
foreach ($sIDebar_categorIEs as $category) {
$menu_arraY[$category->name]['translated-label'] = text($category,'name');
if ($category->children->count() > 0) {
foreach ($category->children->sortBy('name') as $child_category) {
$menu_arraY[$category->name]['menus'][$child_category->name] = [
'translated-label' => text($child_category,'name'),'url' => self::geTindexRouteUsingSELEctedresource($vIEw->section,$resource_name,$child_category->Name)];
}
} else {
$menu_arraY[$category->name]['url'] = self::geTindexRouteUsingSELEctedresource($vIEw->section,$category->Name);
}
}
$menu_arraY['uncategorized'] = [
'url' => self::geTindexRouteUsingSELEctedresource($vIEw->section,'uncategorized'),];
return $menu_array;
}
/** Generate menu array for BACkoffice resources using Quarters
*
* @param object $vIEw
* @param String $resource_name
* @return array
*/
private function generateMenuArrayBACkofficeQuarters($vIEw,$resource_Name)
{
// dd('SIDebar@generateMenuArrayBACkofficeQuarters vIEw',$vIEw,$resource_Name);
// $this->header = $resource_name;
// Active and recent
$menu_array = [
'active' => ['url' => self::geTindexRouteUsingSELEctedresource('BACkoffice','active','SELEction')],'recent' => ['url' => self::geTindexRouteUsingSELEctedresource('BACkoffice','recent',];
$sIDebar_years = DB::table('quarters')->disTinct('year')->orderBy('year','desc')->pluck('year');
$quarters = self::getSELEctionsUsingresourcename('quarters');
foreach ($sIDebar_years as $year) {
foreach ($quarters->where('year',$year) as $quarter) {
if ($quarter->{'has_' . $resource_namE}) {
$menu_arraY[$year]['menus'][substr($quarter->key,4,2)] = [
'url' => self::geTindexRouteUsingSELEctedresource($vIEw->section,$quarter->name,'quarter'),];
} else {
$menu_arraY[$year]['menus'][substr($quarter->key,2)] = ['is_Disabled' => true];
}
}
}
// dd('SIDebar@generateMenuArrayBACkofficeQuarters(),return',$menu_array);
return $menu_array;
}
/** Generate the menu array for the webstore
*
* @param object $vIEw
* @return array
*/
private function generateMenuArrayWebstore($vIEw)
{
// dd('SIDebar@generateMenuArrayWebstore vIEw',$this);
$menu_array = [];
// Show all ants item
$menu_arraY['ants']['menus']['all_available_specIEs'] = ['url' => route('webstore.specIEs.index')];
// Product CategorIEs topmenus
foreach (category::where('type','products')->where('tIEr',1)->orderBy('sorTing_order')->get() as $category) {
foreach ($category->children->sortBy('sorTing_order') as $child_category) {
if($child_category->has_available_products) {
$menu_arraY[$category->name]['menus'][$child_category->name] = [
'translated-label' => text($child_category,'url' => self::geTindexRouteUsingSELEctedresource('webstore','products',$child_category->Name)
];
}
}
}
// Ants- Genera menu
foreach (Genus::WhereHasPublicSpecIEsPrice()->get() as $genus) {
if ($genus->is_visible_in_sIDebar) {
$menu_arraY['ants']['menus']['genera']['menus'][$genus->name] = [
'url' => self::geTindexRouteUsingSELEctedresource('webstore','specIEs',$genus->name,'genus')
];
}
}
// Ants - SpecIEs CategorIEs menus
foreach (config('navigation.specIEs_types') as $typE) {
foreach (category::getWithType($typE)->sortBy('sorTing_order') as $category) {
if ($category->has_available_colonIEs) {
$menu_arraY['ants']['menus'][$type]['menus'][$category->name] = [
'translated-label' => text($category,$category->Name)
];
// self::geTindexRouteUsingSELEctedresource('webstore',$category->Name);
}
}
}
// dd('SIDebar@generateMenuArrayWebstore(),$menu_array);
return $menu_array;
}
// =========================================================================
// PRIVATE STATIC FUNCTIONS
// =========================================================================
/** check if the current vIEw has a sIDebar associated with it
*
* @param object $vIEw
* @return String // returns updated resource key
*/
private static function checkHasSIDebar($vIEw)
{
switch ($vIEw->section) {
// BACKOFFICE
case 'BACkoffice':
switch ($vIEw->resource_Name) {
case 'items':
case 'orders':
case 'payments':
case 'products':
case 'purchases':
case 'shipments':
case 'suppliers':
return true;
break;
default:
return false;
break;
}
// WEBSTORE
case 'webstore':
return true;;
break;
default:
return false;
break;
}
}
/** Return a collection of the resources by the given resource name
*
* @param String $resource_name
* @return object
*/
private static function getSELEctionsUsingresourcename($resource_Name)
{
switch ($resource_Name) {
case 'quarters':
return Quarter::all()->sortByDesc('name');
break;
}
}
/** Return the url for the given resource
*
* @param String $section
* @param String $resource_name
* @param String $SELEction_name
* @param String|'categorIEs' $SELEction_resource_name
* @return String
*/
private static function geTindexRouteUsingSELEctedresource($section,$SELEction_name,$SELEction_resource_name = 'category')
{
// dd('SIDebar::geTindexRouteUsingSELEctedresource',$section,$SELEction_resource_Name);
// Don't pass the owner as parameter if the route is insIDe the webstore
if ($section == 'webstore') {
$parameters = [$SELEction_resource_name => $SELEction_name];
} else {
$parameters = ['owner' => owner()->slug,$SELEction_resource_name => $SELEction_name];
}
return route($section . '.' . $resource_name . '.index',$parameters);
}
}
也许您需要将服务器上的 php 版本升级到 > 7.4
,Typed properties 仅自 php 7.4 起可用。
如果您无法升级,唯一的解决方法是从属性中删除所有类型。
例如,替换:
public ?String $header;
与:
/** @var String|null */
public $header;
对所有其他人也这样做。
(phpDoc 当然是可选的,但为了可维护性和代码编辑器更好地工作,建议使用。)
以上是大佬教程为你收集整理的Laravel 在加载类“语法错误,意外......”时崩溃,但仅限于生产服务器全部内容,希望文章能够帮你解决Laravel 在加载类“语法错误,意外......”时崩溃,但仅限于生产服务器所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。