vendor/phpzlc/admin/Strategy/AdminStrategy.php line 387

Open in your IDE?
  1. <?php
  2. /**
  3.  * 后台策略
  4.  */
  5. namespace PHPZlc\Admin\Strategy;
  6. use Psr\Container\ContainerInterface;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. class AdminStrategy extends AbstractController
  9. {
  10.     /**
  11.      * 路由锚点session名
  12.      */
  13.     const URL_ANCHOR_POINT 'URL_ANCHOR_POINT';
  14.     /**
  15.      * 复杂模式
  16.      */
  17.     const menu_model_all 1;
  18.     /**
  19.      * 简单模式
  20.      */
  21.     const menu_model_simple 2;
  22.     /**
  23.      * 资源基础url
  24.      *
  25.      * @var string
  26.      */
  27.     private static $assetBaseUrl;
  28.     /**
  29.      * @var string 页面标记
  30.      */
  31.     private static $page_tag;
  32.     /**
  33.      * @var string 后台标题
  34.      */
  35.     private static $title;
  36.     /**
  37.      * @var string 后台favicon_ico图标
  38.      */
  39.     private static $favicon_ico;
  40.     /**
  41.      * @var string 后台logo
  42.      */
  43.     private static $logo '/bundles/phpzlcadmin/images/logo.png';
  44.     /**
  45.      * @var string 后台入口url
  46.      */
  47.     private static $entrance_url;
  48.     /**
  49.      * @var string 后台出口url
  50.      */
  51.     private static $end_url '#';
  52.     /**
  53.      * @var string 设置密码url
  54.      */
  55.     private static $setting_pwd_url '#';
  56.     /**
  57.      * @var string 清除缓存API地址url
  58.      */
  59.     private static $clear_cache_api_url '';
  60.     /**
  61.      * @var string 管理员名称
  62.      */
  63.     private static $admin_name 'admin';
  64.     /**
  65.      * @var string
  66.      */
  67.     private static $admin_avatar '/bundles/phpzlcadmin/images/admin_avatar.png';
  68.     /**
  69.      * @var static 管理员角色名称
  70.      */
  71.     private static $admin_role_name '超级管理员';
  72.     /**
  73.      * @var Menu[]
  74.      */
  75.     private static $menus = [];
  76.     /**
  77.      * @var integer
  78.      */
  79.     private static $menu_model self::menu_model_all;
  80.     /**
  81.      * @var string 登陆页面背景图片
  82.      */
  83.     private static $login_lack_ground_img '/bundles/phpzlcadmin/images/login_logo.png';
  84.     /**
  85.      * @var Navigation[]
  86.      */
  87.     private static $navigations = [];
  88.     /**
  89.      * @var TopMenu[]
  90.      */
  91.     private static $topMenus = [];
  92.     /**
  93.      * @var string
  94.      */
  95.     private static $hend_code '';
  96.     public function __construct(ContainerInterface $container)
  97.     {
  98.         $this->setContainer($container);
  99.         self::$assetBaseUrl $this->getBaseUrl();
  100.     }
  101.     public function setUrlAnchor()
  102.     {
  103.         $this->get('session')->set(self::URL_ANCHOR_POINT$this->get('request_stack')->getCurrentRequest()->getUri());
  104.         return $this;
  105.     }
  106.     public function getUrlAnchor()
  107.     {
  108.         return $this->get('session')->get(self::URL_ANCHOR_POINT);
  109.     }
  110.     public function setPageTag($tag)
  111.     {
  112.         static::$page_tag $tag;
  113.         return $this;
  114.     }
  115.     public function getPageTag()
  116.     {
  117.         return static::$page_tag;
  118.     }
  119.     public function setTitle($title)
  120.     {
  121.         static::$title $title;
  122.         return $this;
  123.     }
  124.     public function getTitle()
  125.     {
  126.         return static::$title;
  127.     }
  128.     public function setFaviconIco($favicon_ico)
  129.     {
  130.         static::$favicon_ico $favicon_ico;
  131.         return $this;
  132.     }
  133.     public function getFaviconIco()
  134.     {
  135.         if(substr(static::$favicon_ico04) == 'http'){
  136.             return static::$favicon_ico;
  137.         }else{
  138.             return $this->getAssetBaseUrl() . static::$favicon_ico;
  139.         }
  140.     }
  141.     public function setLogo($logo)
  142.     {
  143.         static::$logo $logo;
  144.         return $this;
  145.     }
  146.     public function getLogo()
  147.     {
  148.         if(substr(static::$logo04) == 'http'){
  149.             return static::$logo;
  150.         }else{
  151.             return $this->getAssetBaseUrl() . static::$logo;
  152.         }
  153.     }
  154.     public function setEndUrl($end_url)
  155.     {
  156.         static::$end_url $end_url;
  157.         return $this;
  158.     }
  159.     public function getEndUrl()
  160.     {
  161.         return static::$end_url;
  162.     }
  163.     public function setEntranceUrl($entrance_url)
  164.     {
  165.         static::$entrance_url $entrance_url;
  166.         return $this;
  167.     }
  168.     public function getEntranceUrl()
  169.     {
  170.         return static::$entrance_url;
  171.     }
  172.     public function setSettingPwdUrl($setting_pwd_url)
  173.     {
  174.         static::$setting_pwd_url  $setting_pwd_url;
  175.         return $this;
  176.     }
  177.     public function getSettingPwdUrl()
  178.     {
  179.         return static::$setting_pwd_url ;
  180.     }
  181.     public function setAdminName($admin_name)
  182.     {
  183.         self::$admin_name $admin_name;
  184.         return $this;
  185.     }
  186.     public function getAdminName()
  187.     {
  188.         return self::$admin_name;
  189.     }
  190.     public function setAdminRoleName($admin_role_name)
  191.     {
  192.         self::$admin_role_name $admin_role_name;
  193.         return $this;
  194.     }
  195.     public function getAdminRoleName()
  196.     {
  197.         return self::$admin_role_name;
  198.     }
  199.     /**
  200.      * @return Menu[]
  201.      */
  202.     public function getMenus(): array
  203.     {
  204.         return self::$menus;
  205.     }
  206.     /**
  207.      * @param array $menus
  208.      * @return $this
  209.      */
  210.     public function setMenus(array $menus)
  211.     {
  212.         self::$menus $menus;
  213.         return $this;
  214.     }
  215.     /**
  216.      * @return int
  217.      */
  218.     public function getMenuModel(): int
  219.     {
  220.         return self::$menu_model;
  221.     }
  222.     /**
  223.      * @param int $menu_model
  224.      *
  225.      * @return $this
  226.      */
  227.     public function setMenuModel(int $menu_model)
  228.     {
  229.         self::$menu_model $menu_model;
  230.         return $this;
  231.     }
  232.     public function getAdminEnv()
  233.     {
  234.         return $_ENV['ADMIN_ENV'];
  235.     }
  236.     /**
  237.      * @return string
  238.      */
  239.     public function getLoginLackGroundImg(): string
  240.     {
  241.         if(substr(static::$login_lack_ground_img04) == 'http'){
  242.             return static::$login_lack_ground_img;
  243.         }else{
  244.             return $this->getAssetBaseUrl() . static::$login_lack_ground_img;
  245.         }
  246.     }
  247.     /**
  248.      * @param string $login_lack_ground_img
  249.      * @return $this
  250.      */
  251.     public function setLoginLackGroundImg(string $login_lack_ground_img)
  252.     {
  253.         self::$login_lack_ground_img $login_lack_ground_img;
  254.         return $this;
  255.     }
  256.     /**
  257.      * @return Navigation[]
  258.      */
  259.     public function getNavigations(): array
  260.     {
  261.         return self::$navigations;
  262.     }
  263.     /**
  264.      * @param array $navigations
  265.      * @return $this
  266.      */
  267.     public function setNavigations(array $navigations)
  268.     {
  269.         self::$navigations $navigations;
  270.         return $this;
  271.     }
  272.     public function addNavigation(Navigation $navigation)
  273.     {
  274.         self::$navigations[] = $navigation;
  275.         return $this;
  276.     }
  277.     /**
  278.      * @return TopMenu[]
  279.      */
  280.     public static function getTopMenus(): array
  281.     {
  282.         return self::$topMenus;
  283.     }
  284.     /**
  285.      * @param TopMenu[] $topMenus
  286.      */
  287.     public function setTopMenus(array $topMenus)
  288.     {
  289.         self::$topMenus $topMenus;
  290.         return $this;
  291.     }
  292.     public function addTopMenu(TopMenu $topMenu)
  293.     {
  294.         self::$topMenus[] = $topMenu;
  295.         return $this;
  296.     }
  297.     public function setAssetBaseUrl($access_base_url)
  298.     {
  299.         self::$assetBaseUrl $access_base_url;
  300.         return $this;
  301.     }
  302.     public function getAssetBaseUrl()
  303.     {
  304.         return self::$assetBaseUrl;
  305.     }
  306.     public function getBaseUrl()
  307.     {
  308.         if($this->has('request_stack') && !empty($this->get('request_stack')->getCurrentRequest())){
  309.             return str_replace('/index.php''',  $this->get('request_stack')->getCurrentRequest()->getBaseUrl());
  310.         }
  311.         return '';
  312.     }
  313.     /**
  314.      * @return string
  315.      */
  316.     public function getClearCacheApiUrl()
  317.     {
  318.         return self::$clear_cache_api_url;
  319.     }
  320.     public function setClearCacheApiUrl(string $clear_cache_api_url)
  321.     {
  322.         self::$clear_cache_api_url $clear_cache_api_url;
  323.         return $this;
  324.     }
  325.     public function getHendCode() : string
  326.     {
  327.         return self::$hend_code;
  328.     }
  329.     /**
  330.      * @param $hend_code
  331.      */
  332.     public function setHendCode(string $hend_code)
  333.     {
  334.         self::$hend_code $hend_code;
  335.         return $this;
  336.     }
  337.     /**
  338.      * @return string
  339.      */
  340.     public function getAdminAvatar(): string
  341.     {
  342.         if(substr(static::$admin_avatar04) == 'http'){
  343.             return static::$admin_avatar;
  344.         }else{
  345.             return $this->getAssetBaseUrl() . static::$admin_avatar;
  346.         }
  347.     }
  348.     /**
  349.      * @param string $admin_avatar
  350.      */
  351.     public function setAdminAvatar(string $admin_avatar)
  352.     {
  353.         self::$admin_avatar $admin_avatar;
  354.         return $this;
  355.     }
  356. }