访问其他类的函数的变量

时间:2016-12-12 01:09:11

标签: php laravel laravel-5

我有一个类调用VSE,我有超过 50 的功能。 在每个函数中,我都有一个变量调用$url

<?php
namespace App;
use Request, Cache, App\Helper;


class VSE {

    .
    .
     public static function wifi_device_state_all($cpe_mac, $wifi_index) {
        $url = env('API_HOST').'vse/vcpe/'.$cpe_mac.'/wifi_index/'.$wifi_index.'/wifi_device_state.all';
        return Helper::getData($url);
    }
    .
    .

}

我想列出所有这些$url个变量。

我已经

$functions = get_class_methods(\App\VSE::class);
    foreach ($functions as $function) {
        dd($function); // I got function name printed
    }

PHP中是否提供了一个开箱即用的功能?

或者我是否必须制造一些hacky来获得它?

有关于此的任何提示吗?

@Machavity:

由于您已将我的发布标记为重复。我已经尝试了你建议的链接:

我没有真正看到我要访问的$url变量。

我在这里遗漏了什么吗?

ReflectionClass {#444 ▼
  +name: "App\VSE"
  implements: []
  constants: []
  methods: array:86 [▼
    "account" => ReflectionMethod {#452 ▼
      +name: "account"
      +class: "App\VSE"
      parameters: array:1 [▼
        "$id" => ReflectionParameter {#542 ▼
          +name: "id"
          position: 0
        }
      ]
      modifiers: "public static"
    }
    "account_all" => ReflectionMethod {#453 ▼
      +name: "account_all"
      +class: "App\VSE"
      modifiers: "public static"
    }
    "count_accounts" => ReflectionMethod {#454 ▼
      +name: "count_accounts"
      +class: "App\VSE"
      modifiers: "public static"
    }
    "locations" => ReflectionMethod {#455 ▼
      +name: "locations"
      +class: "App\VSE"
      modifiers: "public static"
    }
    "location" => ReflectionMethod {#456 ▼
      +name: "location"
      +class: "App\VSE"
      parameters: array:1 [▼
        "$id" => ReflectionParameter {#547 ▼
          +name: "id"
          position: 0
        }
      ]
      modifiers: "public static"
    }
    "follow_me" => ReflectionMethod {#457 ▼
      +name: "follow_me"
      +class: "App\VSE"
      parameters: array:1 [▼
        "$id" => ReflectionParameter {#549 ▼
          +name: "id"
          position: 0
        }
      ]
      modifiers: "public static"
    }
    "vcpe" => ReflectionMethod {#458 ▶}
    "cpe" => ReflectionMethod {#459 ▶}
    "vcpes_all" => ReflectionMethod {#460 ▶}
    "vcpes_in_account" => ReflectionMethod {#461 ▶}
    "cpe_name" => ReflectionMethod {#462 ▶}
    "ipv6_portforward" => ReflectionMethod {#463 ▶}
    "ipv6_enable" => ReflectionMethod {#464 ▶}
    "ipv4_block_fragment_packets" => ReflectionMethod {#465 ▶}
    "ipv6_block_fragment_packets" => ReflectionMethod {#466 ▶}
    "ipv6_firewall" => ReflectionMethod {#467 ▶}
    "acl" => ReflectionMethod {#468 ▶}
    "tunnel_states" => ReflectionMethod {#469 ▶}
    "tunnel_state" => ReflectionMethod {#470 ▶}
    "cgnat" => ReflectionMethod {#471 ▶}
    "cpe_location" => ReflectionMethod {#472 ▶}
    "vcpes_account_count" => ReflectionMethod {#473 ▶}
    "vcpes_count" => ReflectionMethod {#474 ▶}
    "count_tunnel_states" => ReflectionMethod {#475 ▶}
    "count_tunnel_state" => ReflectionMethod {#476 ▶}
    "count_device_states" => ReflectionMethod {#477 ▶}
    "count_device_state" => ReflectionMethod {#478 ▶}
    "count_device" => ReflectionMethod {#479 ▶}
    "private_devices" => ReflectionMethod {#480 ▶}
    "guest_devices" => ReflectionMethod {#481 ▶}
    "device_state" => ReflectionMethod {#482 ▶}
    "private_groups" => ReflectionMethod {#483 ▶}
    "group_devices" => ReflectionMethod {#484 ▶}
    "private_bandwidth" => ReflectionMethod {#485 ▶}
    "this_bandwidth" => ReflectionMethod {#486 ▶}
    "guest_bandwidth" => ReflectionMethod {#487 ▶}
    "total_bandwidth" => ReflectionMethod {#488 ▶}
    "device" => ReflectionMethod {#489 ▶}
    "device_rate_limit" => ReflectionMethod {#490 ▶}
    "device_acl_all" => ReflectionMethod {#491 ▶}
    "device_acl" => ReflectionMethod {#492 ▶}
    "schedule_use_data" => ReflectionMethod {#493 ▶}
    "schedule_use" => ReflectionMethod {#494 ▶}
    "bandwidth" => ReflectionMethod {#495 ▶}
    "wan" => ReflectionMethod {#496 ▶}
    "wan_bandwidth" => ReflectionMethod {#497 ▶}
    "wan_vlan_bandwidth" => ReflectionMethod {#498 ▶}
    "wan_bandwidth2" => ReflectionMethod {#499 ▶}
    "portforward" => ReflectionMethod {#500 ▶}
    "cpe_lan" => ReflectionMethod {#501 ▶}
    "lan" => ReflectionMethod {#502 ▶}
    "this_lan_acl" => ReflectionMethod {#503 ▶}
    "lan_acl" => ReflectionMethod {#504 ▶}
    "this_lan_acl_device" => ReflectionMethod {#505 ▶}
    "lan_acl_device" => ReflectionMethod {#506 ▶}
    "dnsbridge" => ReflectionMethod {#507 ▶}
    "device_dnsbridge" => ReflectionMethod {#508 ▶}
    "p_dnsbridge" => ReflectionMethod {#509 ▶}
    "g_dnsbridge" => ReflectionMethod {#510 ▶}
    "security_level_vlan" => ReflectionMethod {#511 ▶}
    "security_level_device" => ReflectionMethod {#512 ▶}
    "security_level_group" => ReflectionMethod {#513 ▶}
    "this_acl" => ReflectionMethod {#514 ▶}
    "guest_acl" => ReflectionMethod {#515 ▶}
    "this_devicebandwidth" => ReflectionMethod {#516 ▶}
    "devicebandwidth" => ReflectionMethod {#517 ▶}
    "this_network_bandwidth" => ReflectionMethod {#518 ▶}
    "guest_network_bandwidth" => ReflectionMethod {#519 ▶}
    "this_lan" => ReflectionMethod {#520 ▶}
    "lan_guest" => ReflectionMethod {#521 ▶}
    "hour_vlan" => ReflectionMethod {#522 ▶}
    "week_vlan" => ReflectionMethod {#523 ▶}
    "month_vlan" => ReflectionMethod {#524 ▶}
    "device_hour" => ReflectionMethod {#525 ▶}
    "device_week" => ReflectionMethod {#526 ▶}
    "device_month" => ReflectionMethod {#527 ▶}
    "wifi_device_state" => ReflectionMethod {#528 ▶}
    "wifi_device_passphrase" => ReflectionMethod {#529 ▶}
    "wifi_device_ssid" => ReflectionMethod {#530 ▶}
    "wifi_device_list" => ReflectionMethod {#531 ▶}
    "wifi_device_state_all" => ReflectionMethod {#532 ▶}
    "cloud_security" => ReflectionMethod {#533 ▶}
    "mirror_server" => ReflectionMethod {#534 ▶}
    "facebook" => ReflectionMethod {#535 ▶}
    "volume_limit" => ReflectionMethod {#536 ▶}
    "volume_limit_current" => ReflectionMethod {#537 ▶}
  ]
  extra: array:4 [▼
    "file" => "/Applications/MAMP/htdocs/code/site/portal/app/VSE.php"
    "line" => "14 to 609"
    "docComment" => """
      /**\n
       * Test Default Value\n
       * env('API_HOST') = 172.16.200.204\n
       * $cpe_mac = 000D6751560C\n
       * $account_id = 1002\n
       *\n
       */
      """
    "isUserDefined" => true
  ]
}

1 个答案:

答案 0 :(得分:0)

听起来你想动态调用类方法。您也可以使用反射API,请参阅此处了解语法:

https://stackoverflow.com/a/251512/7281447