Browse Source

:hammer: 统一方法命名风格

jqh 4 years ago
parent
commit
f57bcf7c08

+ 3 - 3
src/Form.php

@@ -900,7 +900,7 @@ class Form implements Renderable
         }
 
         $resourcesPath = $this->builder->isCreating() ?
-            $this->getResource(0) : $this->getResource(-1);
+            $this->resource(0) : $this->resource(-1);
 
         if ($this->request->get('after-save') == 1) {
             // continue editing
@@ -1520,7 +1520,7 @@ class Form implements Renderable
      *
      * @return string
      */
-    public function getResource($slice = -2)
+    public function resource($slice = -2)
     {
         $path = $this->resource ?: $this->request->getUri();
 
@@ -1540,7 +1540,7 @@ class Form implements Renderable
      *
      * @return $this
      */
-    public function resource(string $resource)
+    public function setResource(string $resource)
     {
         if ($resource) {
             $this->resource = admin_url($resource);

+ 1 - 5
src/Form/Field/KeyValue.php

@@ -11,11 +11,7 @@ class KeyValue extends Field
     const DEFAULT_FLAG_NAME = '_def_';
 
     /**
-     * Fill data to the field.
-     *
-     * @param array $data
-     *
-     * @return array
+     * {@inheritdoc}
      */
     public function formatFieldData($data)
     {

+ 1 - 5
src/Form/Field/ListField.php

@@ -54,11 +54,7 @@ class ListField extends Field
     }
 
     /**
-     * Fill data to the field.
-     *
-     * @param array $data
-     *
-     * @return array
+     * {@inheritdoc}
      */
     public function formatFieldData($data)
     {

+ 1 - 1
src/Form/Tools.php

@@ -134,7 +134,7 @@ class Tools implements Renderable
      */
     protected function getListPath()
     {
-        return $this->form->getResource();
+        return $this->form->resource();
     }
 
     /**

+ 1 - 1
src/Grid/Filter/Presenter/Text.php

@@ -166,7 +166,7 @@ class Text extends Presenter
 
         $options = json_encode($options);
 
-        Admin::script("$('#{$this->filter->getParent()->filterID()} input.{$this->filter->getId()}').inputmask($options);");
+        Admin::script("$('#{$this->filter->parent()->filterID()} input.{$this->filter->getId()}').inputmask($options);");
 
         $this->icon = $icon;
 

+ 1 - 1
src/Http/Controllers/MenuController.php

@@ -35,7 +35,7 @@ class MenuController extends AdminController
                     $roleModel = config('admin.database.roles_model');
 
                     $form->select('parent_id', trans('admin.parent_id'))->options($menuModel::selectOptions());
-                    $form->text('title', trans('admin.title'))->required()->disable();
+                    $form->text('title', trans('admin.title'))->required();
                     $form->icon('icon', trans('admin.icon'))->help($this->iconHelp());
                     $form->text('uri', trans('admin.uri'));
 

+ 17 - 19
src/Show.php

@@ -575,27 +575,9 @@ class Show implements Renderable
     }
 
     /**
-     * Set resource path.
-     *
-     * @param string $resource
-     *
-     * @return $this
-     */
-    public function resource(string $resource)
-    {
-        if ($resource) {
-            $this->resource = admin_url($resource);
-        }
-
-        return $this;
-    }
-
-    /**
-     * Get resource path.
-     *
      * @return string
      */
-    public function getResource()
+    public function resource()
     {
         if (empty($this->resource)) {
             $path = request()->path();
@@ -609,6 +591,22 @@ class Show implements Renderable
         return $this->resource;
     }
 
+    /**
+     * Set resource path.
+     *
+     * @param string $path
+     *
+     * @return $this
+     */
+    public function setResource($path)
+    {
+        if ($path) {
+            $this->resource = admin_url($path);
+        }
+
+        return $this;
+    }
+
     /**
      * Add field and relation dynamically.
      *

+ 1 - 1
src/Show/Panel.php

@@ -80,7 +80,7 @@ class Panel implements Renderable
      *
      * @return Show
      */
-    public function getParent()
+    public function parent()
     {
         return $this->parent;
     }

+ 6 - 6
src/Show/Tools.php

@@ -122,7 +122,7 @@ class Tools implements Renderable
     protected function prepareTool($tool)
     {
         if ($tool instanceof AbstractTool) {
-            $tool->setParent($this->panel->getParent());
+            $tool->setParent($this->panel->parent());
         }
     }
 
@@ -131,10 +131,10 @@ class Tools implements Renderable
      *
      * @return string
      */
-    public function getResource()
+    public function resource()
     {
         if (is_null($this->resource)) {
-            $this->resource = $this->panel->getParent()->getResource();
+            $this->resource = $this->panel->parent()->resource();
         }
 
         return $this->resource;
@@ -212,7 +212,7 @@ class Tools implements Renderable
      */
     protected function getListPath()
     {
-        $url = $this->getResource();
+        $url = $this->resource();
 
         return url()->isValidUrl($url) ? $url : '/'.trim($url, '/');
     }
@@ -224,7 +224,7 @@ class Tools implements Renderable
      */
     protected function getEditPath()
     {
-        $key = $this->panel->getParent()->getKey();
+        $key = $this->panel->parent()->getKey();
 
         return $this->getListPath().'/'.$key.'/edit';
     }
@@ -236,7 +236,7 @@ class Tools implements Renderable
      */
     protected function getDeletePath()
     {
-        $key = $this->panel->getParent()->getKey();
+        $key = $this->panel->parent()->getKey();
 
         return $this->getListPath().'/'.$key;
     }

+ 13 - 9
src/Tree.php

@@ -487,19 +487,23 @@ class Tree implements Renderable
     }
 
     /**
+     * @return string
+     */
+    public function resource()
+    {
+        return $this->url;
+    }
+
+    /**
+     * Set resource path.
+     *
      * @param string $path
      *
-     * @return $this|string
+     * @return $this
      */
-    public function resource(string $path = null)
+    public function setResource($path)
     {
-        if ($path === null) {
-            return $this->url;
-        }
-
-        if (! empty($path)) {
-            $this->url = admin_url($path);
-        }
+        $this->url = admin_url($path);
 
         return $this;
     }

+ 2 - 2
src/Tree/RowAction.php

@@ -25,7 +25,7 @@ class RowAction extends Action
      */
     public function getKey()
     {
-        return $this->row->{$this->actions->getParent()->getKeyName()};
+        return $this->row->{$this->actions->parent()->getKeyName()};
     }
 
     /**
@@ -45,7 +45,7 @@ class RowAction extends Action
      */
     public function resource()
     {
-        return $this->actions->getParent()->resource();
+        return $this->actions->parent()->resource();
     }
 
     public function getActions()