与costum bundle symfony2中的命名空间的Typo错误(Typo error with namespace in costum bundle symfony2)
我正在按照教程“简单的方法将Twitter OAuth库转换为Symfony 2 Bundle” tuto
但不适合我,总是我得到这个错误:
“自动加载器预期类”FEB \ TwitterBundle \ Api \ TwitterOAuth“将在文件”D:\ xampp \ htdocs \ FEB / src \ FEB \ TwitterBundle \ Api \ TwitterOAuth.php“中定义。文件被找到但是课程是不在其中,类名或命名空间可能有拼写错误。“
我花了很多天才发现发生了什么。 我敢肯定这是命名空间问题,但我疯了。
我的twitterapi.php
namespace FEB\TwitterBundle\Api; use FEB\TwitterBundle\Api\TwitterOAuth; class TwitterApi { protected $apiKey; protected $apiKeySecret; protected $apiToken; protected $apiTokenSecret; public function __construct($apiKey, $apiKeySecret, $apiToken, $apiTokenSecret){ $this->apiKey = $apiKey; $this->apiKeySecret = $apiKeySecret; $this->apiToken = $apiToken; $this->apiTokenSecret = $apiTokenSecret; } public function getapiKey(){ return $this->apiKey; } public function getUsers($users, $url = 'users/lookup') { $connection = new TwitterOAuth($this->apiKey, $this->apiKeySecret, $this->apiToken, $this->apiTokenSecret); $users = $connection->get($url, array('screen_name' => $users)); return $users; } }
有什么帮助吗?
编辑:我的TwitterOAuth.php
<?php /* * Abraham Williams (abraham@abrah.am) http://abrah.am * * The first PHP Library to support OAuth for Twitter's REST API. */ /* Load OAuth lib. You can find it at http://oauth.net */ namespace FEB\TwitterBundle\Api\Meta; /** * Twitter OAuth class */ class TwitterOAuth { /* Contains the last HTTP status code returned. */ public $http_code; /* Contains the last API call. */ public $url; /* Set up the API root URL. */ public $host = "https://api.twitter.com/1.1/"; /* Set timeout default. */ public $timeout = 30; /* Set connect timeout. */ public $connecttimeout = 30; /* Verify SSL Cert. */ public $ssl_verifypeer = FALSE; /* Respons format. */ public $format = 'json'; /* Decode returned json data. */ public $decode_json = TRUE; /* Contains the last HTTP headers returned. */ public $http_info; /* Set the useragnet. */ public $useragent = 'TwitterOAuth v0.2.0-beta2'; /* Immediately retry the API call if the response was not successful. */ //public $retry = TRUE; /** * Set API URLS */ function accessTokenURL() { return 'https://api.twitter.com/oauth/access_token'; } function authenticateURL() { return 'https://api.twitter.com/oauth/authenticate'; } function authorizeURL() { return 'https://api.twitter.com/oauth/authorize'; } function requestTokenURL() { return 'https://api.twitter.com/oauth/request_token'; } /** * Debug helpers */ function lastStatusCode() { return $this->http_status; } function lastAPICall() { return $this->last_api_call; } /** * construct TwitterOAuth object */ function __construct($consumer_key, $consumer_secret, $oauth_token = NULL, $oauth_token_secret = NULL) { $this->sha1_method = new OAuthSignatureMethod_HMAC_SHA1(); $this->consumer = new OAuthConsumer($consumer_key, $consumer_secret); if (!empty($oauth_token) && !empty($oauth_token_secret)) { $this->token = new OAuthConsumer($oauth_token, $oauth_token_secret); } else { $this->token = NULL; } } /** * Get a request_token from Twitter * * @returns a key/value array containing oauth_token and oauth_token_secret */ function getRequestToken($oauth_callback) { $parameters = array(); $parameters['oauth_callback'] = $oauth_callback; $request = $this->oAuthRequest($this->requestTokenURL(), 'GET', $parameters); $token = OAuthUtil::parse_parameters($request); $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']); return $token; } /** * Get the authorize URL * * @returns a string */ function getAuthorizeURL($token, $sign_in_with_twitter = TRUE) { if (is_array($token)) { $token = $token['oauth_token']; } if (empty($sign_in_with_twitter)) { return $this->authorizeURL() . "?oauth_token={$token}"; } else { return $this->authenticateURL() . "?oauth_token={$token}"; } } /** * Exchange request token and secret for an access token and * secret, to sign API calls. * * @returns array("oauth_token" => "the-access-token", * "oauth_token_secret" => "the-access-secret", * "user_id" => "9436992", * "screen_name" => "abraham") */ function getAccessToken($oauth_verifier) { $parameters = array(); $parameters['oauth_verifier'] = $oauth_verifier; $request = $this->oAuthRequest($this->accessTokenURL(), 'GET', $parameters); $token = OAuthUtil::parse_parameters($request); $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']); return $token; } /** * One time exchange of username and password for access token and secret. * * @returns array("oauth_token" => "the-access-token", * "oauth_token_secret" => "the-access-secret", * "user_id" => "9436992", * "screen_name" => "abraham", * "x_auth_expires" => "0") */ function getXAuthToken($username, $password) { $parameters = array(); $parameters['x_auth_username'] = $username; $parameters['x_auth_password'] = $password; $parameters['x_auth_mode'] = 'client_auth'; $request = $this->oAuthRequest($this->accessTokenURL(), 'POST', $parameters); $token = OAuthUtil::parse_parameters($request); $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']); return $token; } /** * GET wrapper for oAuthRequest. */ function get($url, $parameters = array()) { $response = $this->oAuthRequest($url, 'GET', $parameters); if ($this->format === 'json' && $this->decode_json) { return json_decode($response); } return $response; } /** * POST wrapper for oAuthRequest. */ function post($url, $parameters = array()) { $response = $this->oAuthRequest($url, 'POST', $parameters); if ($this->format === 'json' && $this->decode_json) { return json_decode($response); } return $response; } /** * DELETE wrapper for oAuthReqeust. */ function delete($url, $parameters = array()) { $response = $this->oAuthRequest($url, 'DELETE', $parameters); if ($this->format === 'json' && $this->decode_json) { return json_decode($response); } return $response; } /** * Format and sign an OAuth / API request */ function oAuthRequest($url, $method, $parameters) { if (strrpos($url, 'https://') !== 0 && strrpos($url, 'http://') !== 0) { $url = "{$this->host}{$url}.{$this->format}"; } $request = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, $method, $url, $parameters); $request->sign_request($this->sha1_method, $this->consumer, $this->token); switch ($method) { case 'GET': return $this->http($request->to_url(), 'GET'); default: return $this->http($request->get_normalized_http_url(), $method, $request->to_postdata()); } } /** * Make an HTTP request * * @return API results */ function http($url, $method, $postfields = NULL) { $this->http_info = array(); $ci = curl_init(); /* Curl settings */ curl_setopt($ci, CURLOPT_USERAGENT, $this->useragent); curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, $this->connecttimeout); curl_setopt($ci, CURLOPT_TIMEOUT, $this->timeout); curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ci, CURLOPT_HTTPHEADER, array('Expect:')); curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this->ssl_verifypeer); curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader')); curl_setopt($ci, CURLOPT_HEADER, FALSE); switch ($method) { case 'POST': curl_setopt($ci, CURLOPT_POST, TRUE); if (!empty($postfields)) { curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields); } break; case 'DELETE': curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE'); if (!empty($postfields)) { $url = "{$url}?{$postfields}"; } } curl_setopt($ci, CURLOPT_URL, $url); $response = curl_exec($ci); $this->http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE); $this->http_info = array_merge($this->http_info, curl_getinfo($ci)); $this->url = $url; curl_close ($ci); return $response; } /** * Get the header info to store. */ function getHeader($ch, $header) { $i = strpos($header, ':'); if (!empty($i)) { $key = str_replace('-', '_', strtolower(substr($header, 0, $i))); $value = trim(substr($header, $i + 2)); $this->http_header[$key] = $value; } return strlen($header); } }
Edit2: 这是文件夹结构
I'm following the tutorial "Easy Way to Transform a Twitter OAuth Library into a Symfony 2 Bundle" tuto
But not working for me, Always I got this error:
"The autoloader expected class "FEB\TwitterBundle\Api\TwitterOAuth" to be defined in file "D:\xampp\htdocs\FEB/src\FEB\TwitterBundle\Api\TwitterOAuth.php". The file was found but the class was not in it, the class name or namespace probably has a typo."
I've spent many days and I can´t find out what happen. I'm sure that is a namespace issue but i'm getting crazy.
My twitterapi.php
namespace FEB\TwitterBundle\Api; use FEB\TwitterBundle\Api\TwitterOAuth; class TwitterApi { protected $apiKey; protected $apiKeySecret; protected $apiToken; protected $apiTokenSecret; public function __construct($apiKey, $apiKeySecret, $apiToken, $apiTokenSecret){ $this->apiKey = $apiKey; $this->apiKeySecret = $apiKeySecret; $this->apiToken = $apiToken; $this->apiTokenSecret = $apiTokenSecret; } public function getapiKey(){ return $this->apiKey; } public function getUsers($users, $url = 'users/lookup') { $connection = new TwitterOAuth($this->apiKey, $this->apiKeySecret, $this->apiToken, $this->apiTokenSecret); $users = $connection->get($url, array('screen_name' => $users)); return $users; } }
Any help, please?
Edit: My TwitterOAuth.php
<?php /* * Abraham Williams (abraham@abrah.am) http://abrah.am * * The first PHP Library to support OAuth for Twitter's REST API. */ /* Load OAuth lib. You can find it at http://oauth.net */ namespace FEB\TwitterBundle\Api\Meta; /** * Twitter OAuth class */ class TwitterOAuth { /* Contains the last HTTP status code returned. */ public $http_code; /* Contains the last API call. */ public $url; /* Set up the API root URL. */ public $host = "https://api.twitter.com/1.1/"; /* Set timeout default. */ public $timeout = 30; /* Set connect timeout. */ public $connecttimeout = 30; /* Verify SSL Cert. */ public $ssl_verifypeer = FALSE; /* Respons format. */ public $format = 'json'; /* Decode returned json data. */ public $decode_json = TRUE; /* Contains the last HTTP headers returned. */ public $http_info; /* Set the useragnet. */ public $useragent = 'TwitterOAuth v0.2.0-beta2'; /* Immediately retry the API call if the response was not successful. */ //public $retry = TRUE; /** * Set API URLS */ function accessTokenURL() { return 'https://api.twitter.com/oauth/access_token'; } function authenticateURL() { return 'https://api.twitter.com/oauth/authenticate'; } function authorizeURL() { return 'https://api.twitter.com/oauth/authorize'; } function requestTokenURL() { return 'https://api.twitter.com/oauth/request_token'; } /** * Debug helpers */ function lastStatusCode() { return $this->http_status; } function lastAPICall() { return $this->last_api_call; } /** * construct TwitterOAuth object */ function __construct($consumer_key, $consumer_secret, $oauth_token = NULL, $oauth_token_secret = NULL) { $this->sha1_method = new OAuthSignatureMethod_HMAC_SHA1(); $this->consumer = new OAuthConsumer($consumer_key, $consumer_secret); if (!empty($oauth_token) && !empty($oauth_token_secret)) { $this->token = new OAuthConsumer($oauth_token, $oauth_token_secret); } else { $this->token = NULL; } } /** * Get a request_token from Twitter * * @returns a key/value array containing oauth_token and oauth_token_secret */ function getRequestToken($oauth_callback) { $parameters = array(); $parameters['oauth_callback'] = $oauth_callback; $request = $this->oAuthRequest($this->requestTokenURL(), 'GET', $parameters); $token = OAuthUtil::parse_parameters($request); $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']); return $token; } /** * Get the authorize URL * * @returns a string */ function getAuthorizeURL($token, $sign_in_with_twitter = TRUE) { if (is_array($token)) { $token = $token['oauth_token']; } if (empty($sign_in_with_twitter)) { return $this->authorizeURL() . "?oauth_token={$token}"; } else { return $this->authenticateURL() . "?oauth_token={$token}"; } } /** * Exchange request token and secret for an access token and * secret, to sign API calls. * * @returns array("oauth_token" => "the-access-token", * "oauth_token_secret" => "the-access-secret", * "user_id" => "9436992", * "screen_name" => "abraham") */ function getAccessToken($oauth_verifier) { $parameters = array(); $parameters['oauth_verifier'] = $oauth_verifier; $request = $this->oAuthRequest($this->accessTokenURL(), 'GET', $parameters); $token = OAuthUtil::parse_parameters($request); $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']); return $token; } /** * One time exchange of username and password for access token and secret. * * @returns array("oauth_token" => "the-access-token", * "oauth_token_secret" => "the-access-secret", * "user_id" => "9436992", * "screen_name" => "abraham", * "x_auth_expires" => "0") */ function getXAuthToken($username, $password) { $parameters = array(); $parameters['x_auth_username'] = $username; $parameters['x_auth_password'] = $password; $parameters['x_auth_mode'] = 'client_auth'; $request = $this->oAuthRequest($this->accessTokenURL(), 'POST', $parameters); $token = OAuthUtil::parse_parameters($request); $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']); return $token; } /** * GET wrapper for oAuthRequest. */ function get($url, $parameters = array()) { $response = $this->oAuthRequest($url, 'GET', $parameters); if ($this->format === 'json' && $this->decode_json) { return json_decode($response); } return $response; } /** * POST wrapper for oAuthRequest. */ function post($url, $parameters = array()) { $response = $this->oAuthRequest($url, 'POST', $parameters); if ($this->format === 'json' && $this->decode_json) { return json_decode($response); } return $response; } /** * DELETE wrapper for oAuthReqeust. */ function delete($url, $parameters = array()) { $response = $this->oAuthRequest($url, 'DELETE', $parameters); if ($this->format === 'json' && $this->decode_json) { return json_decode($response); } return $response; } /** * Format and sign an OAuth / API request */ function oAuthRequest($url, $method, $parameters) { if (strrpos($url, 'https://') !== 0 && strrpos($url, 'http://') !== 0) { $url = "{$this->host}{$url}.{$this->format}"; } $request = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, $method, $url, $parameters); $request->sign_request($this->sha1_method, $this->consumer, $this->token); switch ($method) { case 'GET': return $this->http($request->to_url(), 'GET'); default: return $this->http($request->get_normalized_http_url(), $method, $request->to_postdata()); } } /** * Make an HTTP request * * @return API results */ function http($url, $method, $postfields = NULL) { $this->http_info = array(); $ci = curl_init(); /* Curl settings */ curl_setopt($ci, CURLOPT_USERAGENT, $this->useragent); curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, $this->connecttimeout); curl_setopt($ci, CURLOPT_TIMEOUT, $this->timeout); curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ci, CURLOPT_HTTPHEADER, array('Expect:')); curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this->ssl_verifypeer); curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader')); curl_setopt($ci, CURLOPT_HEADER, FALSE); switch ($method) { case 'POST': curl_setopt($ci, CURLOPT_POST, TRUE); if (!empty($postfields)) { curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields); } break; case 'DELETE': curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE'); if (!empty($postfields)) { $url = "{$url}?{$postfields}"; } } curl_setopt($ci, CURLOPT_URL, $url); $response = curl_exec($ci); $this->http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE); $this->http_info = array_merge($this->http_info, curl_getinfo($ci)); $this->url = $url; curl_close ($ci); return $response; } /** * Get the header info to store. */ function getHeader($ch, $header) { $i = strpos($header, ':'); if (!empty($i)) { $key = str_replace('-', '_', strtolower(substr($header, 0, $i))); $value = trim(substr($header, $i + 2)); $this->http_header[$key] = $value; } return strlen($header); } }
Edit2: This is the folder structure
原文:https://stackoverflow.com/questions/17826705
最满意答案
正确的选项是
--max_old_space_size
。 请注意下划线而不是破折号。 如果运行节点6,则执行node --v8-options
以获取所有节点V8选项的列表。The correct option is
--max_old_space_size
. Note the underscore instead of the dash. If running Node 6, executenode --v8-options
to get a list of all node V8 options.
相关问答
更多-
软件包节点与node.js.无关。 nodejs是你想要的,但是,与使用#!/usr/bin/env node脚本兼容,将命令称为节点可以说更好。 您可以在路径中创建一个符号链接: sudo ln -s `which nodejs` /usr/local/bin/node 或者您可以安装nvm ,然后使用它来安装最新版本的node.js: nvm install stable 我喜欢nvm方法,因为它允许你sudo apt-get remove nodejs ,然后管理你自己使用的那个版本的节点。 您还 ...
-
需要帮助来理解 - XPath / XSLT中的上下文节点和当前节点(Need help to understand - context node and current node in XPath/XSLT)[2023-07-15]
只有当您在XSLT范围内时,当前节点才有意义; 它指的是当前模板应用于的节点,可以使用current()进行访问。 对于普通XPath(没有XSLT),此功能不可用,并且当前既不可访问也不相关。 有关XSLT中当前节点的更多详细信息,我指的是Paul A Jungwirth关于另一个问题的答案 。 The current node is only relevant if you are in an XSLT-scope; it refers to the node the current template ... -
是的 - 这正是它的本质。 这是一个包含结构构造函数示例的页面。 http://www.yolinux.com/TUTORIALS/LinuxTutorialC++Structures.html Yes - that's exactly what it is. Here's a page with an example of a struct constructor. http://www.yolinux.com/TUTORIALS/LinuxTutorialC++Structures.html
-
堆差异节点4和节点6(Heap differences Node 4 and Node 6)[2023-05-20]
正确的选项是--max_old_space_size 。 请注意下划线而不是破折号。 如果运行节点6,则执行node --v8-options以获取所有节点V8选项的列表。 The correct option is --max_old_space_size. Note the underscore instead of the dash. If running Node 6, execute node --v8-options to get a list of all node V8 options. -
从堆中删除第i个节点(Delete ith node from a Heap)[2023-10-29]
从堆中删除任意节点的昂贵部分不在于删除,而在于查找要删除的节点。 实际上删除节点是O(log n)。 但首先,您必须对底层数据存储执行顺序扫描才能找到节点。 这是O(n)部分。 加快这一速度的唯一方法是保留第二个数据结构,如字典或哈希映射或类似,可以快速告诉您项目在后备存储中的位置。 然后在字典中进行O(1)查找,从字典中删除O(1),从堆中删除O(log n)。 The expensive part of deleting an arbitrary node from a heap isn't in th ... -
可以在具有O(1)查找复杂性(平均)的哈希表中分别维护索引(id,节点)。 总的复杂性保持为O(log n)。 The index (id, node) can be maintained separately in a hashtable which has O(1) lookup complexity (on average). The overall complexity then remains O(log n).
-
只是快速查看,它使用线程,是的。 另一方面,节点使用进程,因为它的设计是单线程的,但是在内部它创建线程池,因此在回调创建期间创建线程。 进程的节点实现使用套接字进行通信,这在延迟方面非常慢。 因此,您的任务应该是可分的,因此您不需要进行太多沟通。 线程就像进程一样,但是与它们的调用进程共享内存,因此通信更快,但更危险。 所以,问题是目标是线程比并发流程更好吗? 它取决于...但在Node上下文中使用集群和进程。 你引用的图书馆很老了吧? 最好不要使用它。 人们放弃这样的东西是有原因的。 Just havin ...
-
libsodium实现PHP和Node.js之间的差异(libsodium implementation differences between PHP and Node.js)[2022-02-01]
你实际上在使用Node-Sodium而不是secretbox吗? secretbox需要额外的字节来预先secretbox /剥离。 它仅用于向后兼容,除了在C中使用它之外没有任何意义,但由于某种原因,Node-Sodium提供它。 PHP绑定不需要这些额外的字节。 像大多数其他绑定一样, secretbox实际上是secretbox_easy 。 好消息是Node-Sodium还提供了secretbox_easy 。 你只需要明确地称之为secretbox_easy 。 不再需要填充。 Are you a ... -
不完全是O(1),但是O(loglogn)(对于所有实际目的O(1))解决方案将存储某种级别的stat。 例如。 您可以存储每个级别的最大值并进行二分查找。 According to Inserting a new element into a heap [Doberkat, 1981] binary heaps with a uniform key distribution see an average of 1.6 UpHeap operations per insertion. The equival ...
-
Node * node [100]和Node node [100]之间有什么区别(What is the differences between Node *node[100] and Node node[100])[2022-04-15]
No a[100]定义100对象的数组,而No* a[100]定义100指针的数组。 在定义对象数组时,可以使用默认构造函数或具有默认参数的其他构造函数来定义每个对象,以使其像默认构造函数一样运行。 由于您尚未定义适当的构造函数,因此编译器无法找到初始化数组中对象的方法。 指针数组没有这样的问题。 您可以通过提供默认构造函数或使用参数的默认值更改当前构造函数来修复它。 No a[100] defines an array of 100 objects while No* a[100] defines an ...