PHP code example of seffeng / nacos

1. Go to this page and download the library: Download seffeng/nacos library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

seffeng / nacos example snippets


/**
 * Test
 */
class NacosConfig
{
    /**
     * 获取配置
     */
    public function testGet()
    {
        try {
            $conf = $this->getConfig()->getConfig();
            var_dump($conf);
        } catch (\Exception $e) {
            throw $e;
        }
    }

    /**
     * 监听配置
     */
    public function testListener()
    {
        try {
            $conf = $this->getConfig()->listenerConfig();
            var_dump($conf);
        } catch (\Exception $e) {
            throw $e;
        }
    }

    private function getConfig()
    {
        $host = 'http://nacos.io';
        $nacos = new Nacos($host, 'nacos', 'nacos');
        $config = new Configs($nacos, 'test-01');
        return $config;
    }
}

├───src
│   │   Nacos.php
│   ├───Exceptions
│   │       NacosException.php
│   └───Handlers
│           Configs.php
│           Instances.php
│           Log.php
├───tests
│       NacosConfig.php
│       NacosInstance.php