Example #1
0
 public function indexAction()
 {
     echo "<h3 style='color:red;font-weight:bold'>" . __DIR__ . "</h3>";
     $configArr = array("website" => "<h3>zend.vn</h3>", "account" => array("email" => "*****@*****.**", "password" => "12345", "title" => "zendConfig"));
     // 01 --Convert mảng config thành đối tượng config
     // $config = new \Zend\Config\Config($configArr);
     // echo "<pre>";
     // print_r($config->get("account")->get("email"));
     // echo "</pre>";
     // 02 --Convert mảng config thành đối tượng config
     //$config = new \Zend\Config\Config(include __DIR__."/../../../config/module.config.php");
     // 03 --\Zend\Config\Process thực hiện một số hành động trên đối tượng config
     //-- \Zend\Config\Process\Constant ---- định nghĩa hằng số trong $config
     // define("MYCONST","this is my constant");
     // $config = new \Zend\Config\Config(array("const"=>"MYCONST"),true);
     // $process = new \Zend\Config\Processor\Constant();
     // echo "<pre style='font-weight:bold'>";
     // print_r($process->process($config));
     // echo "</pre>";
     //-- \Zend\Config\Process\Filter
     // $config = new \Zend\Config\Config($configArr,true);
     // $filterUp = new \Zend\Filter\StringToUpper();
     // $process = new \Zend\Config\Processor\Filter($filterUp);
     // $process->process($config);
     // echo "<pre style='font-weight:bold'>";
     // print_r($config);
     // echo "</pre>";
     //-- \Zend\Config\Process\Queue
     //--Rule--queue--FIFO(first In First Out)
     // $config            = new \Zend\Config\Config($configArr,true);
     // $filterStripTags   = new \Zend\Filter\StripTags();
     // $filterUp          = new \Zend\Filter\StringToUpper();
     // $proccessStripTags = new \Zend\Config\Processor\Filter($filterStripTags);
     // $proccessUp        = new \Zend\Config\Processor\Filter($filterUp);
     // $queue = new \Zend\Config\Processor\Queue();
     // $queue->insert($proccessStripTags);
     // $queue->insert($proccessUp);
     // $queue->process($config);
     //-- \Zend\Config\Process\Tonken-----thay thế ký tự trong chuỗi
     $config = new \Zend\Config\Config(array("TOKEN" => "this is a Token"), true);
     $token = new \Zend\Config\Processor\Token();
     $token->addToken("To", "1234");
     $token->process($config);
     echo "<pre style='font-weight:bold'>";
     print_r($config);
     echo "</pre>";
     return false;
 }
{
    if (!\file_exists($filename)) {
        return null;
    }
    $str = \file_get_contents($filename);
    return \unserialize($str);
}
function put($filename, $value)
{
    $data = \serialize($value);
    return \file_put_contents($filename, $data);
}
// ${access,request}_token
$tmpdir = \sys_get_temp_dir();
$access_token = get("{$tmpdir}/access_token.txt");
$request_token = get("{$tmpdir}/request_token.txt");
// $pin (oauth_verifier), $query (search.php), $status (update.php)
$opt = \getopt('', ['pin:', 'query:', 'status:']);
$pin = isset($opt['pin']) ? $opt['pin'] : null;
$query = isset($opt['query']) ? $opt['query'] : null;
$status = isset($opt['status']) ? $opt['status'] : null;
$config = \Zend\Config\Factory::fromFile(__DIR__ . '/config.yaml');
$config = new \Zend\Config\Config($config, true);
$processor = new \Zend\Config\Processor\Token();
$processor->addToken('$callback_url', \getenv('CALLBACK_URL') ?: 'oob');
$processor->addToken('$consumer_key', \getenv('CONSUMER_KEY'));
$processor->addToken('$consumer_secret', \getenv('CONSUMER_SECRET'));
$processor->process($config);
$config->accessToken = $access_token;
$twitter = new \ZendService\Twitter\Twitter($config);
return $twitter;