Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'dev'

  • Loading branch information...
commit 7a9faef1247e28849586a79c7fa186495f1a1ab1 2 parents 505c158 + 05abf7b
@nateabele nateabele authored
Showing with 4,135 additions and 860 deletions.
  1. +6 −2 .travis.yml
  2. +1 −1  LICENSE.txt
  3. +1 −1  action/Controller.php
  4. +9 −8 action/Request.php
  5. +3 −3 analysis/Debugger.php
  6. +30 −12 analysis/Inspector.php
  7. +11 −0 analysis/Logger.php
  8. +3 −5 analysis/Parser.php
  9. +2 −2 console/Command.php
  10. +1 −1  console/Dispatcher.php
  11. +1 −1  console/Request.php
  12. +1 −1  console/Router.php
  13. +2 −2 console/command/Create.php
  14. +1 −1  console/command/G11n.php
  15. +1 −1  console/command/Help.php
  16. +11 −10 console/command/Library.php
  17. +1 −1  console/command/Route.php
  18. +5 −5 console/command/Test.php
  19. +1 −1  console/command/create/View.php
  20. +1 −1  console/command/g11n/Extract.php
  21. +1 −1  console/li3.bat
  22. +1 −1  console/lithium.php
  23. +1 −1  core/Adaptable.php
  24. +1 −1  core/ClassNotFoundException.php
  25. +1 −1  core/ConfigException.php
  26. +4 −4 core/ErrorHandler.php
  27. +7 −7 core/Libraries.php
  28. +26 −5 core/Object.php
  29. +26 −5 core/StaticObject.php
  30. +1 −1  data/Collection.php
  31. +1 −1  data/Connections.php
  32. +3 −3 data/DocumentSchema.php
  33. +35 −9 data/Entity.php
  34. +24 −7 data/Model.php
  35. +4 −4 data/Schema.php
  36. +1 −1  data/Source.php
  37. +1 −1  data/collection/DocumentSet.php
  38. +1 −1  data/collection/MultiKeyRecordSet.php
  39. +20 −8 data/collection/RecordSet.php
  40. +1 −1  data/entity/Document.php
  41. +2 −1  data/entity/Record.php
  42. +12 −1 data/model/Query.php
  43. +1 −1  data/model/QueryException.php
  44. +15 −4 data/model/Relationship.php
  45. +24 −18 data/source/Database.php
  46. +15 −4 data/source/Http.php
  47. +1 −1  data/source/Mock.php
  48. +24 −10 data/source/MongoDb.php
  49. +2 −2 data/source/Result.php
  50. +7 −7 data/source/database/adapter/MySql.php
  51. +30 −2 data/source/database/adapter/PostgreSql.php
  52. +5 −5 data/source/database/adapter/Sqlite3.php
  53. +1 −1  data/source/database/adapter/pdo/Result.php
  54. +19 −9 data/source/http/adapter/CouchDb.php
  55. +4 −4 data/source/mongo_db/Exporter.php
  56. +1 −1  data/source/mongo_db/Result.php
  57. +1 −1  data/source/mongo_db/Schema.php
  58. +1 −1  g11n/Catalog.php
  59. +14 −3 g11n/Locale.php
  60. +2 −2 g11n/Message.php
  61. +1 −1  g11n/Multibyte.php
  62. +1 −1  g11n/catalog/Adapter.php
  63. +3 −3 g11n/catalog/adapter/Code.php
  64. +3 −3 g11n/catalog/adapter/Gettext.php
  65. +1 −1  g11n/catalog/adapter/Memory.php
  66. +1 −1  g11n/catalog/adapter/Php.php
  67. +1 −1  g11n/multibyte/adapter/Iconv.php
  68. +1 −1  g11n/multibyte/adapter/Intl.php
  69. +1 −1  g11n/multibyte/adapter/Mbstring.php
  70. +1 −1  g11n/resources/php/da_DK/validation/default.php
  71. +1 −1  g11n/resources/php/de/message/default.php
  72. +1 −1  g11n/resources/php/de_BE/validation/default.php
  73. +1 −1  g11n/resources/php/de_DE/validation/default.php
  74. +1 −1  g11n/resources/php/en/message/default.php
  75. +1 −1  g11n/resources/php/en_CA/validation/default.php
  76. +1 −1  g11n/resources/php/en_GB/validation/default.php
  77. +1 −1  g11n/resources/php/en_US/validation/default.php
  78. +1 −1  g11n/resources/php/fr/message/default.php
  79. +1 −1  g11n/resources/php/fr_BE/validation/default.php
  80. +1 −1  g11n/resources/php/fr_CA/validation/default.php
  81. +1 −1  g11n/resources/php/it_IT/validation/default.php
  82. +1 −1  g11n/resources/php/nl_BE/validation/default.php
  83. +1 −1  g11n/resources/php/nl_NL/validation/default.php
  84. +1 −1  net/Message.php
  85. +1 −1  net/Socket.php
  86. +1 −1  net/http/Auth.php
  87. +1 −1  net/http/ClientMediaException.php
  88. +4 −4 net/http/Media.php
  89. +1 −1  net/http/MediaException.php
  90. +1 −1  net/http/Message.php
  91. +1 −1  net/http/Request.php
  92. +3 −3 net/http/Response.php
  93. +1 −1  net/http/Route.php
  94. +1 −1  net/http/Router.php
  95. +1 −1  net/http/RoutingException.php
  96. +12 −1 net/http/Service.php
  97. +6 −3 net/socket/Context.php
  98. +8 −5 net/socket/Curl.php
  99. +1 −1  net/socket/Stream.php
  100. +6 −2 readme.md
  101. +1 −1  security/Auth.php
  102. +1 −1  security/Password.php
  103. +1 −1  security/auth/adapter/Form.php
  104. +1 −1  security/auth/adapter/Http.php
  105. +1 −1  security/validation/RequestToken.php
  106. +1 −1  storage/Cache.php
  107. +1 −1  storage/Session.php
  108. +1 −1  storage/cache/adapter/Apc.php
  109. +3 −3 storage/cache/adapter/File.php
  110. +1 −1  storage/cache/adapter/Memcache.php
  111. +1 −1  storage/cache/adapter/Memory.php
  112. +13 −1 storage/cache/adapter/Redis.php
  113. +3 −5 storage/cache/adapter/XCache.php
  114. +1 −1  storage/cache/strategy/Base64.php
  115. +1 −1  storage/cache/strategy/Json.php
  116. +1 −1  storage/cache/strategy/Serializer.php
  117. +2 −2 storage/session/adapter/Cookie.php
  118. +1 −1  storage/session/adapter/Memory.php
  119. +1 −1  storage/session/adapter/Php.php
  120. +1 −1  storage/session/strategy/Encrypt.php
  121. +1 −1  storage/session/strategy/Hmac.php
  122. +1 −1  storage/session/strategy/MissingSignatureException.php
  123. +1 −1  template/Helper.php
  124. +1 −1  template/TemplateException.php
  125. +10 −6 template/View.php
  126. +25 −14 template/helper/Form.php
  127. +6 −6 template/helper/Html.php
  128. +1 −1  template/helper/Security.php
  129. +1 −1  template/view/Compiler.php
  130. +21 −5 template/view/Renderer.php
  131. +2 −1  template/view/adapter/File.php
  132. +1 −1  template/view/adapter/Simple.php
  133. +1 −1  test/Controller.php
  134. +1 −1  test/Dispatcher.php
  135. +1 −1  test/Filter.php
  136. +1 −1  test/Group.php
  137. +2 −2 test/Integration.php
  138. +94 −23 test/Mocker.php
  139. +208 −0 test/MockerChain.php
  140. +3 −3 test/Report.php
  141. +968 −10 test/Unit.php
  142. +1 −1  test/filter/Affected.php
  143. +1 −1  test/filter/Complexity.php
  144. +5 −3 test/filter/Coverage.php
  145. +2 −2 test/filter/Profiler.php
  146. +1 −1  test/templates/layout.html.php
  147. +1 −1  tests/cases/action/DispatcherTest.php
  148. +75 −75 tests/cases/action/RequestTest.php
  149. +1 −1  tests/cases/action/ResponseTest.php
  150. +1 −1  tests/cases/analysis/DebuggerTest.php
  151. +1 −1  tests/cases/analysis/DocblockTest.php
  152. +39 −3 tests/cases/analysis/InspectorTest.php
  153. +19 −3 tests/cases/analysis/LoggerTest.php
  154. +12 −1 tests/cases/analysis/ParserTest.php
  155. +1 −1  tests/cases/analysis/logger/adapter/CacheTest.php
  156. +1 −1  tests/cases/analysis/logger/adapter/FileTest.php
  157. +1 −1  tests/cases/analysis/logger/adapter/FirePhpTest.php
  158. +1 −1  tests/cases/analysis/logger/adapter/GrowlTest.php
  159. +1 −1  tests/cases/analysis/logger/adapter/SyslogTest.php
  160. +1 −1  tests/cases/console/CommandTest.php
  161. +1 −1  tests/cases/console/DispatcherTest.php
  162. +1 −1  tests/cases/console/RequestTest.php
  163. +1 −1  tests/cases/console/ResponseTest.php
  164. +1 −1  tests/cases/console/RouterTest.php
  165. +1 −1  tests/cases/console/command/CreateTest.php
  166. +12 −14 tests/cases/console/command/LibraryTest.php
  167. +1 −1  tests/cases/console/command/RouteTest.php
  168. +1 −1  tests/cases/console/command/TestTest.php
  169. +1 −1  tests/cases/console/command/create/ControllerTest.php
  170. +1 −1  tests/cases/console/command/create/MockTest.php
  171. +1 −1  tests/cases/console/command/create/ModelTest.php
  172. +1 −1  tests/cases/console/command/create/TestTest.php
  173. +1 −1  tests/cases/console/command/create/ViewTest.php
  174. +1 −1  tests/cases/console/command/g11n/ExtractTest.php
  175. +1 −1  tests/cases/core/AdaptableTest.php
  176. +3 −3 tests/cases/core/EnvironmentTest.php
  177. +19 −2 tests/cases/core/LibrariesTest.php
  178. +62 −3 tests/cases/core/ObjectTest.php
  179. +58 −1 tests/cases/core/StaticObjectTest.php
  180. +1 −1  tests/cases/data/CollectionTest.php
  181. +2 −2 tests/cases/data/ConnectionsTest.php
  182. +53 −1 tests/cases/data/EntityTest.php
  183. +35 −8 tests/cases/data/ModelTest.php
  184. +1 −1  tests/cases/data/SchemaTest.php
  185. +1 −1  tests/cases/data/SourceTest.php
  186. +4 −4 tests/cases/data/collection/DocumentSetTest.php
  187. +33 −15 tests/cases/data/collection/MultiKeyRecordSetTest.php
  188. +20 −10 tests/cases/data/collection/RecordSetTest.php
  189. +2 −2 tests/cases/data/entity/DocumentTest.php
  190. +1 −1  tests/cases/data/entity/RecordTest.php
  191. +19 −7 tests/cases/data/model/QueryTest.php
  192. +23 −0 tests/cases/data/model/RelationshipTest.php
  193. +20 −14 tests/cases/data/source/DatabaseTest.php
  194. +15 −1 tests/cases/data/source/HttpTest.php
  195. +122 −8 tests/cases/data/source/MongoDbTest.php
  196. +2 −2 tests/cases/data/source/database/adapter/MySqlTest.php
  197. +19 −5 tests/cases/data/source/database/adapter/PostgreSqlTest.php
  198. +2 −2 tests/cases/data/source/database/adapter/Sqlite3Test.php
  199. +7 −7 tests/cases/data/source/database/adapter/pdo/ResultTest.php
  200. +9 −2 tests/cases/data/source/http/adapter/CouchDbTest.php
  201. +1 −1  tests/cases/data/source/mongo_db/ExporterTest.php
  202. +1 −1  tests/cases/data/source/mongo_db/SchemaTest.php
  203. +3 −3 tests/cases/g11n/CatalogTest.php
  204. +13 −1 tests/cases/g11n/LocaleTest.php
  205. +3 −3 tests/cases/g11n/MessageTest.php
  206. +1 −1  tests/cases/g11n/MultibyteTest.php
  207. +1 −1  tests/cases/g11n/catalog/AdapterTest.php
  208. +6 −9 tests/cases/g11n/catalog/adapter/CodeTest.php
  209. +1 −1  tests/cases/g11n/catalog/adapter/GettextTest.php
  210. +1 −1  tests/cases/g11n/catalog/adapter/MemoryTest.php
  211. +1 −1  tests/cases/g11n/catalog/adapter/PhpTest.php
  212. +1 −1  tests/cases/g11n/multibyte/adapter/IconvTest.php
  213. +1 −1  tests/cases/g11n/multibyte/adapter/IntlTest.php
  214. +1 −1  tests/cases/g11n/multibyte/adapter/MbstringTest.php
  215. +1 −1  tests/cases/net/MessageTest.php
  216. +1 −1  tests/cases/net/SocketTest.php
  217. +6 −6 tests/cases/net/http/AuthTest.php
  218. +1 −1  tests/cases/net/http/MediaTest.php
  219. +1 −1  tests/cases/net/http/MessageTest.php
  220. +1 −1  tests/cases/net/http/RequestTest.php
  221. +3 −3 tests/cases/net/http/ResponseTest.php
  222. +1 −1  tests/cases/net/http/RouteTest.php
  223. +1 −1  tests/cases/net/http/RouterTest.php
  224. +8 −1 tests/cases/net/http/ServiceTest.php
  225. +1 −1  tests/cases/net/socket/ContextTest.php
  226. +1 −1  tests/cases/net/socket/CurlTest.php
  227. +1 −1  tests/cases/net/socket/StreamTest.php
  228. +1 −1  tests/cases/security/PasswordTest.php
  229. +1 −1  tests/cases/security/auth/adapter/FormTest.php
  230. +7 −10 tests/cases/security/auth/adapter/HttpTest.php
  231. +1 −1  tests/cases/security/validation/RequestTokenTest.php
  232. +1 −1  tests/cases/storage/CacheTest.php
  233. +1 −1  tests/cases/storage/SessionTest.php
  234. +1 −1  tests/cases/storage/cache/adapter/ApcTest.php
  235. +1 −1  tests/cases/storage/cache/adapter/FileTest.php
  236. +1 −1  tests/cases/storage/cache/adapter/MemcacheTest.php
  237. +1 −1  tests/cases/storage/cache/adapter/MemoryTest.php
  238. +13 −1 tests/cases/storage/cache/adapter/RedisTest.php
  239. +1 −1  tests/cases/storage/cache/adapter/XCacheTest.php
  240. +1 −1  tests/cases/storage/cache/strategy/Base64Test.php
  241. +1 −1  tests/cases/storage/cache/strategy/JsonTest.php
  242. +1 −1  tests/cases/storage/cache/strategy/SerializerTest.php
  243. +1 −1  tests/cases/storage/session/adapter/CookieTest.php
  244. +1 −1  tests/cases/storage/session/adapter/MemoryTest.php
  245. +1 −1  tests/cases/storage/session/adapter/PhpTest.php
  246. +1 −1  tests/cases/storage/session/strategy/EncryptTest.php
  247. +1 −1  tests/cases/storage/session/strategy/HmacTest.php
  248. +1 −1  tests/cases/template/HelperTest.php
  249. +47 −3 tests/cases/template/ViewTest.php
  250. +63 −9 tests/cases/template/helper/FormTest.php
  251. +2 −58 tests/cases/template/helper/HtmlTest.php
  252. +1 −1  tests/cases/template/helper/SecurityTest.php
  253. +1 −1  tests/cases/template/view/CompilerTest.php
  254. +7 −1 tests/cases/template/view/RendererTest.php
  255. +1 −1  tests/cases/template/view/adapter/FileTest.php
  256. +1 −1  tests/cases/template/view/adapter/SimpleTest.php
  257. +1 −1  tests/cases/test/ControllerTest.php
  258. +1 −1  tests/cases/test/DispatcherTest.php
  259. +1 −1  tests/cases/test/GroupTest.php
  260. +1 −1  tests/cases/test/IntegrationTest.php
  261. +140 −0 tests/cases/test/MockerChainTest.php
  262. +72 −9 tests/cases/test/MockerTest.php
  263. +1 −1  tests/cases/test/ReportTest.php
  264. +936 −2 tests/cases/test/UnitTest.php
  265. +1 −1  tests/cases/test/filter/AffectedTest.php
  266. +7 −5 tests/cases/test/filter/ComplexityTest.php
  267. +28 −6 tests/cases/util/CollectionTest.php
  268. +1 −1  tests/cases/util/InflectorTest.php
  269. +12 −6 tests/cases/util/SetTest.php
  270. +1 −1  tests/cases/util/StringTest.php
  271. +21 −7 tests/cases/util/ValidatorTest.php
  272. +1 −1  tests/cases/util/collection/FiltersTest.php
  273. +1 −1  tests/ci_depends.php
  274. +2 −2 tests/integration/analysis/LoggerTest.php
  275. +7 −6 tests/integration/data/CrudTest.php
  276. +5 −7 tests/integration/data/DatabaseTest.php
  277. +5 −5 tests/integration/data/DocumentTest.php
  278. +6 −9 tests/integration/data/FieldsTest.php
  279. +6 −6 tests/integration/data/SourceTest.php
  280. +1 −1  tests/integration/g11n/CatalogInflectorTest.php
  281. +2 −2 tests/integration/g11n/CatalogValidatorTest.php
  282. +1 −1  tests/integration/g11n/ResourcesMessageTest.php
  283. +1 −1  tests/integration/g11n/ResourcesValidatorTest.php
  284. +1 −1  tests/integration/net/SocketTest.php
  285. +1 −1  tests/integration/net/http/MediaTest.php
  286. +1 −1  tests/integration/net/http/ServiceTest.php
  287. +2 −2 tests/integration/storage/SessionTest.php
  288. +11 −9 tests/integration/test/FilterTest.php
  289. +1 −1  tests/mocks/action/MockCgiRequest.php
  290. +1 −1  tests/mocks/action/MockControllerRequest.php
  291. +1 −1  tests/mocks/action/MockControllerResponse.php
  292. +1 −1  tests/mocks/action/MockIisRequest.php
  293. +1 −1  tests/mocks/action/MockMediaClass.php
  294. +1 −1  tests/mocks/action/MockNginxRequest.php
  295. +1 −4 tests/mocks/action/MockPostsController.php
  296. +1 −1  tests/mocks/action/MockRequestType.php
  297. +1 −1  tests/mocks/action/MockResponse.php
  298. +1 −1  tests/mocks/analysis/MockEmptyClass.php
  299. +1 −1  tests/mocks/analysis/MockLoggerAdapter.php
  300. +1 −1  tests/mocks/console/MockCommand.php
Sorry, we could not display the entire diff because too many files (398) changed.
View
8 .travis.yml
@@ -8,9 +8,13 @@ php:
- 5.3
- 5.4
-before_script: php tests/ci_depends.php $OPCODE_CACHE
+before_script:
+ - php tests/ci_depends.php $OPCODE_CACHE
+# - cd ../ && git clone git://github.com/UnionOfRAD/li3_quality.git && cd lithium
-script: console/li3 test --filters=Profiler tests/cases
+script:
+ - console/li3 test --filters=Profiler tests/cases
+# - console/li3 test --filters=Profiler tests/cases && cd ../li3_quality && for FILE in $(cd ../lithium/ && git diff-index --name-only --diff-filter=AM HEAD~1); do ../lithium/console/li3 quality syntax ../lithium/${FILE} --silent; done
notifications:
irc: "irc.freenode.org#li3-core"
View
2  LICENSE.txt
@@ -1,4 +1,4 @@
-Copyright (c) 2012, Union of RAD http://union-of-rad.org
+Copyright (c) 2013, Union of RAD http://union-of-rad.org
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
View
2  action/Controller.php
@@ -174,7 +174,7 @@ public function __invoke($request, $dispatchParams, array $options = array()) {
$args = isset($dispatchParams['args']) ? $dispatchParams['args'] : array();
$result = null;
- if (substr($action, 0, 1) == '_' || method_exists(__CLASS__, $action)) {
+ if (substr($action, 0, 1) === '_' || method_exists(__CLASS__, $action)) {
throw new DispatchException('Attempted to invoke a private method.');
}
if (!method_exists($self, $action)) {
View
17 action/Request.php
@@ -231,12 +231,12 @@ public function __isset($name) {
* @todo Refactor to lazy-load environment settings
*/
public function env($key) {
- if (strtolower($key) == 'base') {
+ if (strtolower($key) === 'base') {
return $this->_base;
}
- if ($key == 'SCRIPT_NAME' && !isset($this->_env['SCRIPT_NAME'])) {
- if ($this->_env['PLATFORM'] == 'CGI' || isset($this->_env['SCRIPT_URL'])) {
+ if ($key === 'SCRIPT_NAME' && !isset($this->_env['SCRIPT_NAME'])) {
+ if ($this->_env['PLATFORM'] === 'CGI' || isset($this->_env['SCRIPT_URL'])) {
$key = 'SCRIPT_URL';
}
}
@@ -245,7 +245,8 @@ public function env($key) {
$this->_env[$key] = $val;
if ($key == 'REMOTE_ADDR') {
- foreach (array('HTTP_X_FORWARDED_FOR', 'HTTP_PC_REMOTE_ADDR', 'HTTP_X_REAL_IP') as $altKey) {
+ $https = array('HTTP_X_FORWARDED_FOR', 'HTTP_PC_REMOTE_ADDR', 'HTTP_X_REAL_IP');
+ foreach ($https as $altKey) {
if ($addr = $this->env($altKey)) {
$val = $addr;
break;
@@ -287,7 +288,7 @@ public function env($key) {
));
case 'CGI':
case 'CGI_MODE':
- return ($this->_env['PLATFORM'] == 'CGI');
+ return ($this->_env['PLATFORM'] === 'CGI');
case 'HTTP_BASE':
return preg_replace('/^([^.])*/i', null, $this->_env['HTTP_HOST']);
}
@@ -327,7 +328,7 @@ protected function _parseAccept() {
foreach (array_reverse($accept) as $i => $type) {
unset($accept[$i]);
list($type, $q) = (explode(';q=', $type, 2) + array($type, 1.0 + $i / 100));
- $accept[$type] = ($type == '*/*') ? 0.1 : floatval($q);
+ $accept[$type] = ($type === '*/*') ? 0.1 : floatval($q);
}
arsort($accept, SORT_NUMERIC);
@@ -513,7 +514,7 @@ public function referer($default = null, $local = false) {
if (!$local) {
return $ref;
}
- if (strpos($ref, '://') == false) {
+ if (strpos($ref, '://') === false) {
return $ref;
}
}
@@ -581,7 +582,7 @@ protected function _url() {
if (isset($this->_config['url'])) {
return rtrim($this->_config['url'], '/');
}
- if (!empty($_GET['url']) ) {
+ if (!empty($_GET['url'])) {
return rtrim($_GET['url'], '/');
}
if ($uri = $this->env('REQUEST_URI')) {
View
6 analysis/Debugger.php
@@ -16,7 +16,7 @@
* The `Debugger` class provides basic facilities for generating and rendering meta-data about the
* state of an application in its current context.
*/
-class Debugger extends \lithium\core\Object {
+class Debugger extends \lithium\core\StaticObject {
/**
* Used for temporary closure caching.
@@ -87,7 +87,7 @@ public static function trace(array $options = array()) {
}
$trace['functionRef'] = $function;
- if ($options['format'] == 'points' && $trace['file'] != '[internal]') {
+ if ($options['format'] === 'points' && $trace['file'] !== '[internal]') {
$back[] = array('file' => $trace['file'], 'line' => $trace['line']);
} elseif (is_string($options['format']) && $options['format'] != 'array') {
$back[] = String::insert($options['format'], array_map(
@@ -108,7 +108,7 @@ function($data) { return is_object($data) ? get_class($data) : $data; },
}
}
- if ($options['format'] == 'array' || $options['format'] == 'points') {
+ if ($options['format'] === 'array' || $options['format'] === 'points') {
return $back;
}
return join("\n", $back);
View
42 analysis/Inspector.php
@@ -49,6 +49,22 @@ class Inspector extends \lithium\core\StaticObject {
);
/**
+ * Will determine if a method can be called.
+ *
+ * @param string|object $class Class to inspect.
+ * @param string $method Method name.
+ * @param bool $internal Interal call or not.
+ * @return bool
+ */
+ public static function isCallable($object, $method, $internal = false) {
+ $methodExists = method_exists($object, $method);
+ $callable = function($object, $method) {
+ return is_callable(array($object, $method));
+ };
+ return $internal ? $methodExists : $methodExists && $callable($object, $method);
+ }
+
+ /**
* Determines if a given $identifier is a class property, a class method, a class itself,
* or a namespace identifier.
*
@@ -88,7 +104,7 @@ public static function info($identifier, $info = array()) {
$result = array();
$class = null;
- if ($type == 'method' || $type == 'property') {
+ if ($type === 'method' || $type === 'property') {
list($class, $identifier) = explode('::', $identifier);
try {
@@ -97,7 +113,7 @@ public static function info($identifier, $info = array()) {
return null;
}
- if ($type == 'property') {
+ if ($type === 'property') {
$identifier = substr($identifier, 1);
$accessor = 'getProperty';
} else {
@@ -111,7 +127,7 @@ public static function info($identifier, $info = array()) {
return null;
}
$result['modifiers'] = static::_modifiers($inspector);
- } elseif ($type == 'class') {
+ } elseif ($type === 'class') {
$inspector = new ReflectionClass($identifier);
} else {
return null;
@@ -123,7 +139,7 @@ public static function info($identifier, $info = array()) {
}
if (method_exists($inspector, static::$_methodMap[$key])) {
$setAccess = (
- ($type == 'method' || $type == 'property') &&
+ ($type === 'method' || $type === 'property') &&
array_intersect($result['modifiers'], array('private', 'protected')) != array()
&& method_exists($inspector, 'setAccessible')
);
@@ -140,7 +156,7 @@ public static function info($identifier, $info = array()) {
}
}
- if ($type == 'property' && !$classInspector->isAbstract()) {
+ if ($type === 'property' && !$classInspector->isAbstract()) {
$inspector->setAccessible(true);
try {
@@ -231,7 +247,7 @@ function($ln) use ($start) { return $ln + $start - 1; },
$result = array_keys(array_filter($lines, function($line) use ($options) {
$line = trim($line);
$empty = preg_match($options['pattern'], $line);
- return $empty ? false : (str_replace($options['empty'], '', $line) != '');
+ return $empty ? false : (str_replace($options['empty'], '', $line) !== '');
}));
}
return $result;
@@ -373,7 +389,7 @@ public static function lines($data, $lines) {
$file = new SplFileObject($data);
foreach ($file as $current) {
- $c[$file->key()+1] = rtrim($file->current());
+ $c[$file->key() + 1] = rtrim($file->current());
}
}
@@ -434,17 +450,19 @@ function($class) { return new ReflectionClass($class); }, $list
include $file;
$list = array_diff(get_declared_classes(), $list);
} else {
- $filter = function($class) use ($file) { return $class->getFileName() == $file; };
- $list = $loaded->find($filter)->getName();
+ $filter = function($class) use ($file) { return $class->getFileName() === $file; };
+ $list = $loaded->find($filter)->map(function ($class) {
+ return $class->getName() ?: $class->name;
+ }, array('collect' => false));
}
}
foreach ($list as $class) {
$inspector = new ReflectionClass($class);
- if ($options['group'] == 'classes') {
+ if ($options['group'] === 'classes') {
$inspector->getFileName() ? $classes[$class] = $inspector->getFileName() : null;
- } elseif ($options['group'] == 'files') {
+ } elseif ($options['group'] === 'files') {
$classes[$inspector->getFileName()][] = $inspector;
}
}
@@ -543,7 +561,7 @@ protected static function _items($class, $method, $options) {
if ($options['self']) {
$data = array_filter($data, function($item) use ($class) {
- return ($item->getDeclaringClass()->getName() == $class->getName());
+ return ($item->getDeclaringClass()->getName() === $class->getName());
});
}
View
11 analysis/Logger.php
@@ -140,6 +140,17 @@ public static function __callStatic($priority, $params) {
}
/**
+ * Custom check to determine if our given magic methods can be responded to.
+ *
+ * @param string $method Method name.
+ * @param bool $internal Interal call or not.
+ * @return bool
+ */
+ public static function respondsTo($method, $internal = false) {
+ return isset(static::$_priorities[$method]) || parent::respondsTo($method, $internal);
+ }
+
+ /**
* This method is called automatically to initialize the default configuration of a log adapter,
* such that the adapter defaults to accepting log messages of any priority (i.e. the
* `'priority'` key is set to `true`).
View
8 analysis/Parser.php
@@ -75,9 +75,7 @@ public static function tokenize($code, array $options = array()) {
}
$tokens[] = array('id' => $id, 'name' => $name, 'content' => $content, 'line' => $line);
- if ($id === T_WHITESPACE) {
- $line += count(preg_split('/\r\n|\r|\n/', $content)) - 1;
- }
+ $line += count(preg_split('/\r\n|\r|\n/', $content)) - 1;
}
if ($options['wrap'] && empty($options['include'])) {
@@ -272,13 +270,13 @@ public static function matchToken($pattern, $token) {
$match = $pattern['content'];
$content = $token['content'];
- if ($pattern['name'] == 'T_VARIABLE') {
+ if ($pattern['name'] === 'T_VARIABLE') {
$match = substr($match, 1);
$content = substr($content, 1);
}
switch (true) {
- case ($match == '_' || $match == $content):
+ case ($match === '_' || $match == $content):
return true;
}
return false;
View
4 console/Command.php
@@ -2,7 +2,7 @@
/**
* Lithium: the most rad php framework
*
- * @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
+ * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/
@@ -224,7 +224,7 @@ public function in($prompt = null, array $options = array()) {
} while (
!empty($options['choices']) && !in_array($result, $options['choices'], true)
&& (empty($options['quit']) || $result !== $options['quit'])
- && ($options['default'] == null || $result !== '')
+ && (!$options['default'] || $result !== '')
);
if ($result == $options['quit']) {
View
2  console/Dispatcher.php
@@ -2,7 +2,7 @@
/**
* Lithium: the most rad php framework
*
- * @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
+ * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/
View
2  console/Request.php
@@ -2,7 +2,7 @@
/**
* Lithium: the most rad php framework
*
- * @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
+ * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/
View
2  console/Router.php
@@ -2,7 +2,7 @@
/**
* Lithium: the most rad php framework
*
- * @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
+ * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/
View
4 console/command/Create.php
@@ -209,7 +209,7 @@ protected function _instance($name, array $config = array()) {
return new $class(array(
'request' => $this->request,
- 'classes'=> $this->_classes
+ 'classes' => $this->_classes
));
}
return parent::_instance($name, $config);
@@ -245,7 +245,7 @@ protected function _save(array $params = array()) {
if (file_exists($file)) {
$prompt = "{$relative} already exists. Overwrite?";
$choices = array('y', 'n');
- if ($this->in($prompt, compact('choices')) != 'y') {
+ if ($this->in($prompt, compact('choices')) !== 'y') {
return "{$params['class']} skipped.";
}
}
View
2  console/command/G11n.php
@@ -2,7 +2,7 @@
/**
* Lithium: the most rad php framework
*
- * @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
+ * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/
View
2  console/command/Help.php
@@ -2,7 +2,7 @@
/**
* Lithium: the most rad php framework
*
- * @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
+ * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/
View
21 console/command/Library.php
@@ -2,7 +2,7 @@
/**
* Lithium: the most rad php framework
*
- * @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
+ * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/
@@ -321,7 +321,7 @@ protected function _replaceAfterExtract($extracted, $options = array()) {
if (dirname(LITHIUM_APP_PATH) . '/libraries' !== $this->lithiumLibraryPath) {
$pathinfo = pathinfo($this->lithiumLibraryPath);
- if ($pathinfo['dirname'] != '.') {
+ if ($pathinfo['dirname'] !== '.') {
$this->lithiumLibraryPath = "'" . $this->lithiumLibraryPath . "'";
}
@@ -379,7 +379,7 @@ protected function _replaceAfterExtract($extracted, $options = array()) {
*/
protected function _wildcardPaths($path, $base = '') {
if (strpos($path, '*') === false) {
- return array($base . '/' . $path);
+ return array($base . '/' . $path);
}
if ($path[0] === '*') {
$paths = array();
@@ -395,7 +395,7 @@ protected function _wildcardPaths($path, $base = '') {
);
}
} else {
- $paths = array_filter(glob($base . '/' . $path), function($path) {
+ $paths = array_filter(glob($base . '/' . $path), function($path) {
$basename = basename($path);
return $basename !== '.' && $basename !== '..';
});
@@ -418,7 +418,7 @@ protected function _wildcardPaths($path, $base = '') {
* @return boolean
*/
public function archive($name = null, $result = null) {
- if (ini_get('phar.readonly') == '1') {
+ if (ini_get('phar.readonly') === '1') {
throw new RuntimeException('Set `phar.readonly` to `0` in `php.ini`.');
}
$from = $name;
@@ -438,7 +438,7 @@ public function archive($name = null, $result = null) {
Phar::unlinkArchive("{$path}.phar");
}
try {
- $archive = new Phar("{$path}.phar");
+ $archive = new Phar("{$path}.phar");
} catch (Exception $e) {
$this->error($e->getMessage());
return false;
@@ -470,13 +470,14 @@ public function archive($name = null, $result = null) {
* List all the plugins and extensions available on the server.
*
* @param string $type plugins|extensions
- * @return void
*/
public function find($type = 'plugins') {
$results = array();
foreach ($this->_settings['servers'] as $server => $enabled) {
- if (!$enabled) { continue; }
+ if (!$enabled) {
+ continue;
+ }
$service = $this->_instance('service', array(
'host' => $server, 'port' => $this->port
));
@@ -552,7 +553,7 @@ public function install($name = null) {
}
$url = parse_url($source);
- if (!empty($url['scheme']) && $url['scheme'] == 'git' && $hasGit()) {
+ if (!empty($url['scheme']) && $url['scheme'] === 'git' && $hasGit()) {
$cmd = "cd {$this->path} && git clone --quiet {$source} {$plugin->name}";
$result = shell_exec($cmd);
@@ -710,7 +711,7 @@ public function update() {
*/
protected function _toPath($name = null) {
$pathinfo = pathinfo($name);
- if ($name && $pathinfo['dirname'] != '.') {
+ if ($name && $pathinfo['dirname'] !== '.') {
return $name;
}
View
2  console/command/Route.php
@@ -2,7 +2,7 @@
/**
* Lithium: the most rad php framework
*
- * @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
+ * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/
namespace lithium\console\command;
View
10 console/command/Test.php
@@ -2,7 +2,7 @@
/**
* Lithium: the most rad php framework
*
- * @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
+ * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/
@@ -127,7 +127,7 @@ protected function _init() {
$reporter = function($result) use ($command, &$i, $columns, $colorize) {
$shorten = array('fail', 'skip', 'exception');
- if ($result['result'] == 'pass') {
+ if ($result['result'] === 'pass') {
$symbol = '.';
} elseif (in_array($result['result'], $shorten)) {
$symbol = strtoupper($result['result'][0]);
@@ -281,10 +281,10 @@ protected function _path($path) {
$this->error('Please provide a path to tests.');
return false;
}
- if ($path[0] == '/') {
+ if ($path[0] === '/') {
$library = $this->_library($path);
}
- if ($path[0] != '/') {
+ if ($path[0] !== '/') {
$libraries = array_reduce(Libraries::get(), function($v, $w) {
$v[] = basename($w['path']);
return $v;
@@ -294,7 +294,7 @@ protected function _path($path) {
$parts = explode('/', str_replace("../", "", $path));
$plugin = array_shift($parts);
- if ($plugin == 'libraries') {
+ if ($plugin === 'libraries') {
$plugin = array_shift($parts);
}
if (in_array($plugin, $libraries)) {
View
2  console/command/create/View.php
@@ -77,7 +77,7 @@ protected function _save(array $params = array()) {
if (file_exists($file)) {
$prompt = "{$file} already exists. Overwrite?";
$choices = array('y', 'n');
- if ($this->in($prompt, compact('choices')) != 'y') {
+ if ($this->in($prompt, compact('choices')) !== 'y') {
return "{$params['file']} skipped.";
}
}
View
2  console/command/g11n/Extract.php
@@ -23,7 +23,7 @@ class Extract extends \lithium\console\Command {
public $scope;
- public function _init() {
+ protected function _init() {
parent::_init();
$this->source = $this->source ?: LITHIUM_APP_PATH;
$this->destination = $this->destination ?: Libraries::get(true, 'resources') . '/g11n';
View
2  console/li3.bat
@@ -2,7 +2,7 @@
rem
rem Lithium: the most rad php framework
rem
-rem @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
+rem @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
rem @license http://opensource.org/licenses/bsd-license.php The BSD License
rem
php -f "%~dp0lithium.php" %*
View
2  console/lithium.php
@@ -2,7 +2,7 @@
/**
* Lithium: the most rad php framework
*
- * @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
+ * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/
View
2  core/Adaptable.php
@@ -2,7 +2,7 @@
/**
* Lithium: the most rad php framework
*
- * @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
+ * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/
View
2  core/ClassNotFoundException.php
@@ -2,7 +2,7 @@
/**
* Lithium: the most rad php framework
*
- * @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
+ * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/
View
2  core/ConfigException.php
@@ -2,7 +2,7 @@
/**
* Lithium: the most rad php framework
*
- * @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
+ * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/
View
8 core/ErrorHandler.php
@@ -68,7 +68,7 @@ public static function __init() {
static::$_checks = array(
'type' => function($config, $info) {
return (boolean) array_filter((array) $config['type'], function($type) use ($info) {
- return $type == $info['type'] || is_subclass_of($info['type'], $type);
+ return $type === $info['type'] || is_subclass_of($info['type'], $type);
});
},
'code' => function($config, $info) {
@@ -216,10 +216,10 @@ public static function handle($info, $scope = array()) {
foreach ($rules as $config) {
foreach (array_keys($config) as $key) {
- if ($key == 'conditions' || $key == 'scope' || $key == 'handler') {
+ if ($key === 'conditions' || $key === 'scope' || $key === 'handler') {
continue;
}
- if (!isset($info[$key]) || !isset($checks[$key])) {
+ if (!isset($info[$key]) || !isset($checks[$key])) {
continue 2;
}
if (($check = $checks[$key]) && !$check($config, $info)) {
@@ -285,7 +285,7 @@ public static function matches($info, $conditions) {
$info = is_object($info) ? $handler($info, true) : $info;
foreach (array_keys($conditions) as $key) {
- if ($key == 'conditions' || $key == 'scope' || $key == 'handler') {
+ if ($key === 'conditions' || $key === 'scope' || $key === 'handler') {
continue;
}
if (!isset($info[$key]) || !isset($checks[$key])) {
View
14 core/Libraries.php
@@ -2,7 +2,7 @@
/**
* Lithium: the most rad php framework
*
- * @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
+ * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/
@@ -456,7 +456,7 @@ public static function find($library, array $options = array()) {
$options += $defaults;
$libs = array();
- if ($options['namespaces'] && $options['filter'] == $defaults['filter']) {
+ if ($options['namespaces'] && $options['filter'] === $defaults['filter']) {
$options['format'] = function($class, $config) use ($format, $defaults) {
if (is_dir($class)) {
return $format($class, $config);
@@ -616,9 +616,9 @@ public static function realPath($path) {
list(, $relativePath, $pharPath) = $pathComponents;
$pharPath = implode('/', array_reduce(explode('/', $pharPath), function ($parts, $value) {
- if ($value == '..') {
+ if ($value === '..') {
array_pop($parts);
- } elseif ($value != '.') {
+ } elseif ($value !== '.') {
$parts[] = $value;
}
return $parts;
@@ -979,8 +979,8 @@ protected static function _search($config, $options, $name = null) {
$suffix = $options['namespaces'] ? '' : $config['suffix'];
$suffix = ($options['suffix'] === null) ? $suffix : $options['suffix'];
- $dFlags = GLOB_ONLYDIR;
- $libs = (array) glob($path . $suffix, $options['namespaces'] ? $dFlags : 0);
+ $dFlags = GLOB_ONLYDIR & GLOB_BRACE;
+ $libs = (array) glob($path . $suffix, $options['namespaces'] ? $dFlags : GLOB_BRACE);
if ($options['recursive']) {
list($current, $match) = explode('/*', $path, 2);
@@ -1076,4 +1076,4 @@ protected static function _params($type, $name = "*") {
}
}
-?>
+?>
View
31 core/Object.php
@@ -2,7 +2,7 @@
/**
* Lithium: the most rad php framework
*
- * @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
+ * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/
@@ -10,6 +10,7 @@
use lithium\core\Libraries;
use lithium\util\collection\Filters;
+use lithium\analysis\Inspector;
/**
* Base class in Lithium's hierarchy, from which all concrete classes inherit. This class defines
@@ -137,16 +138,24 @@ protected function _init() {
* @see lithium\core\Object::_filter()
* @see lithium\util\collection\Filters
* @param mixed $method The name of the method to apply the closure to. Can either be a single
- * method name as a string, or an array of method names.
- * @param closure $filter The closure that is used to filter the method(s).
+ * method name as a string, or an array of method names. Can also be false to remove
+ * all filters on the current object.
+ * @param closure $filter The closure that is used to filter the method(s), can also be false
+ * to remove all the current filters for the given method.
* @return void
*/
public function applyFilter($method, $filter = null) {
+ if ($method === false) {
+ $this->_methodFilters = array();
+ return;
+ }
foreach ((array) $method as $m) {
- if (!isset($this->_methodFilters[$m])) {
+ if (!isset($this->_methodFilters[$m]) || $filter === false) {
$this->_methodFilters[$m] = array();
}
- $this->_methodFilters[$m][] = $filter;
+ if ($filter !== false) {
+ $this->_methodFilters[$m][] = $filter;
+ }
}
}
@@ -198,6 +207,17 @@ public static function __set_state($data) {
}
/**
+ * Will determine if a method can be called.
+ *
+ * @param string $method Method name.
+ * @param bool $internal Interal call or not.
+ * @return bool
+ */
+ public function respondsTo($method, $internal = false) {
+ return Inspector::isCallable($this, $method, $internal);
+ }
+
+ /**
* Returns an instance of a class with given `config`. The `name` could be a key from the
* `classes` array, a fully-namespaced class name, or an object. Typically this method is used
* in `_init` to create the dependencies used in the current class.
@@ -266,6 +286,7 @@ protected static function _parents() {
protected function _stop($status = 0) {
exit($status);
}
+
}
?>
View
31 core/StaticObject.php
@@ -2,7 +2,7 @@
/**
* Lithium: the most rad php framework
*
- * @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
+ * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/
@@ -10,6 +10,7 @@
use lithium\core\Libraries;
use lithium\util\collection\Filters;
+use lithium\analysis\Inspector;
/**
* Provides a base class for all static classes in the Lithium framework. Similar to its
@@ -40,17 +41,25 @@ class StaticObject {
* @see lithium\core\StaticObject::_filter()
* @see lithium\util\collection\Filters
* @param mixed $method The name of the method to apply the closure to. Can either be a single
- * method name as a string, or an array of method names.
- * @param closure $filter The closure that is used to filter the method.
+ * method name as a string, or an array of method names. Can also be false to remove
+ * all filters on the current object.
+ * @param closure $filter The closure that is used to filter the method(s), can also be false
+ * to remove all the current filters for the given method.
* @return void
*/
public static function applyFilter($method, $filter = null) {
$class = get_called_class();
+ if ($method === false) {
+ static::$_methodFilters[$class] = array();
+ return;
+ }
foreach ((array) $method as $m) {
- if (!isset(static::$_methodFilters[$class][$m])) {
+ if (!isset(static::$_methodFilters[$class][$m]) || $filter === false) {
static::$_methodFilters[$class][$m] = array();
}
- static::$_methodFilters[$class][$m][] = $filter;
+ if ($filter !== false) {
+ static::$_methodFilters[$class][$m][] = $filter;
+ }
}
}
@@ -83,6 +92,17 @@ public static function invokeMethod($method, $params = array()) {
}
/**
+ * Will determine if a method can be called.
+ *
+ * @param string $method Method name.
+ * @param bool $internal Interal call or not.
+ * @return bool
+ */
+ public static function respondsTo($method, $internal = false) {
+ return Inspector::isCallable(get_called_class(), $method, $internal);
+ }
+
+ /**
* Returns an instance of a class with given `config`. The `name` could be a key from the
* `classes` array, a fully namespaced class name, or an object. Typically this method is used
* in `_init` to create the dependencies used in the current class.
@@ -149,6 +169,7 @@ protected static function _parents() {
protected static function _stop($status = 0) {
exit($status);
}
+
}
?>
View
2  data/Collection.php
@@ -2,7 +2,7 @@
/**
* Lithium: the most rad php framework
*
- * @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
+ * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/
View
2  data/Connections.php
@@ -2,7 +2,7 @@
/**
* Lithium: the most rad php framework
*
- * @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
+ * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/
View
6 data/DocumentSchema.php
@@ -2,7 +2,7 @@
/**
* Lithium: the most rad php framework
*
- * @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
+ * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/
@@ -54,7 +54,7 @@ public function cast($object, $key, $data, array $options = array()) {
protected function _castArray($object, $val, $pathKey, $options, $defaults) {
$isArray = $this->is('array', $pathKey) && (!$object instanceof $this->_classes['set']);
- $isObject = ($this->type($pathKey) == 'object');
+ $isObject = ($this->type($pathKey) === 'object');
$valIsArray = is_array($val);
$numericArray = false;
$class = 'entity';
@@ -81,7 +81,7 @@ protected function _castArray($object, $val, $pathKey, $options, $defaults) {
);
$config += compact('pathKey') + array_diff_key($options, $defaults);
$val = $this->_instance($class, $config);
- } elseif ($class == 'set') {
+ } elseif ($class === 'set') {
$val = $val ?: array();
foreach ($val as &$value) {
$value = $this->_castType($value, $pathKey);
View
44 data/Entity.php
@@ -2,7 +2,7 @@
/**
* Lithium: the most rad php framework
*
- * @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
+ * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/
@@ -11,6 +11,7 @@
use BadMethodCallException;
use UnexpectedValueException;
use lithium\data\Collection;
+use lithium\analysis\Inspector;
/**
* `Entity` is a smart data object which represents data such as a row or document in a
@@ -187,7 +188,7 @@ public function __isset($name) {
* @return mixed
*/
public function __call($method, $params) {
- if ($model = $this->_model) {
+ if (($model = $this->_model) && method_exists($model, '_object')) {
array_unshift($params, $this);
$class = $model::invokeMethod('_object');
return call_user_func_array(array(&$class, $method), $params);
@@ -197,6 +198,27 @@ public function __call($method, $params) {
}
/**
+ * Custom check to determine if our given magic methods can be responded to.
+ *
+ * @param string $method Method name.
+ * @param bool $internal Interal call or not.
+ * @return bool
+ */
+ public function respondsTo($method, $internal = false) {
+ $class = $this->_model;
+ $modelRespondsTo = false;
+ $parentRespondsTo = parent::respondsTo($method, $internal);
+ $staticRespondsTo = $class::respondsTo($method, $internal);
+ if (method_exists($class, '_object')) {
+ $model = $class::invokeMethod('_object');
+ $modelRespondsTo = $model->respondsTo($method);
+ } else {
+ $modelRespondsTo = Inspector::isCallable($class, $method, $internal);
+ }
+ return $parentRespondsTo || $staticRespondsTo || $modelRespondsTo;
+ }
+
+ /**
* Allows several properties to be assigned at once, i.e.:
* {{{
* $record->set(array('title' => 'Lorem Ipsum', 'value' => 42));
@@ -365,7 +387,8 @@ public function decrement($field, $value = 1) {
* @param string The field name to check its state.
* @return mixed Returns `true` if a field is given and was updated, `false` otherwise and
* `null` if the field was not set at all. If no field is given returns an arra
- * where the keys are entity field names, and the values are `true` for changed fields.
+ * where the keys are entity field names, and the values are `true` for changed
+ * fields.
*/
public function modified($field = null) {
if ($field) {
@@ -373,14 +396,18 @@ public function modified($field = null) {
return null;
}
- $value = !($value = isset($this->_updated[$field])) ?: $this->_updated[$field];
- if (!$value) {
+ if (!array_key_exists($field, $this->_updated)) {
return false;
- } elseif (is_object($value) && method_exists($value, 'modified')) {
+ }
+
+ $value = $this->_updated[$field];
+ if (is_object($value) && method_exists($value, 'modified')) {
$modified = $value->modified();
return $modified === true || is_array($modified) && in_array(true, $modified, true);
}
- return !isset($this->_data[$field]) || $this->_data[$field] !== $this->_updated[$field];
+
+ $isSet = isset($this->_data[$field]);
+ return !$isSet || ($this->_data[$field] !== $this->_updated[$field]);
}
$fields = array_fill_keys(array_keys($this->_data), false);
@@ -398,8 +425,7 @@ public function modified($field = null) {
);
} else {
$fields[$field] = (
- !isset($fields[$field]) ||
- $this->_data[$field] !== $this->_updated[$field]
+ !isset($fields[$field]) || $this->_data[$field] !== $this->_updated[$field]
);
}
}
View
31 data/Model.php
@@ -2,7 +2,7 @@
/**
* Lithium: the most rad php framework
*
- * @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
+ * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/
@@ -401,7 +401,7 @@ protected static function _initialize($class) {
${$key} = is_array($val) ? ${$key} + $val : $val;
}
}
- if ($parent == __CLASS__) {
+ if ($parent === __CLASS__) {
break;
}
}
@@ -483,7 +483,7 @@ public static function __callStatic($method, $params) {
$params = array($params[1] + array($method => $params[0]));
}
- if ($method == 'all' || $isFinder) {
+ if ($method === 'all' || $isFinder) {
if ($params && !is_array($params[0])) {
$params[0] = array('conditions' => static::key($params[0]));
}
@@ -501,7 +501,7 @@ public static function __callStatic($method, $params) {
$type[0] = strtolower($type[0]);
$conditions = array($field => array_shift($params));
- $params = (isset($params[0]) && count($params) == 1) ? $params[0] : $params;
+ $params = (isset($params[0]) && count($params) === 1) ? $params[0] : $params;
return $self::find($type, compact('conditions') + $params);
}
@@ -524,6 +524,23 @@ public function __call($method, $params) {
}
/**
+ * Custom check to determine if our given magic methods can be responded to.
+ *
+ * @param string $method Method name.
+ * @param bool $internal Interal call or not.
+ * @return bool
+ */
+ public static function respondsTo($method, $internal = false) {
+ $self = static::_object();
+ $methods = static::instanceMethods();
+ $isFinder = isset($self->_finders[$method]);
+ preg_match('/^findBy(?P<field>\w+)$|^find(?P<type>\w+)By(?P<fields>\w+)$/', $method, $args);
+ $staticRepondsTo = $isFinder || $method === 'all' || !!$args;
+ $instanceRespondsTo = isset($methods[$method]);
+ return $instanceRespondsTo || $staticRepondsTo || parent::respondsTo($method, $internal);
+ }
+
+ /**
* The `find` method allows you to retrieve data from the connected data source.
*
* Examples:
@@ -560,7 +577,7 @@ public static function find($type, array $options = array()) {
}
$isFinder = is_string($type) && isset($self->_finders[$type]);
- if ($type != 'all' && !is_array($type) && !$isFinder) {
+ if ($type !== 'all' && !is_array($type) && !$isFinder) {
$options['conditions'] = static::key($type);
$type = 'first';
}
@@ -798,13 +815,13 @@ protected static function _relations($type = null, $name = null) {
return $self->_relations;
}
foreach ($self->_relationsToLoad as $name => $t) {
- if ($type == $t) {
+ if ($type === $t) {
static::bind($t, $name, (array) $self->{$t}[$name]);
unset($self->_relationsToLoad[$name]);
}
}
return array_filter($self->_relations, function($i) use ($type) {
- return $i->data('type') == $type;
+ return $i->data('type') === $type;
});
}
View
8 data/Schema.php
@@ -2,7 +2,7 @@
/**
* Lithium: the most rad php framework
*
- * @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
+ * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/
@@ -142,9 +142,9 @@ public function append(array $fields) {
/**
* Merges another `Schema` object into the current one.
*
- * @param object $schema Another `Schema` class object to be merged into the current one. If this schema
- * contains field names that conflict with existing field names, the existing fields will not
- * be overwritten.
+ * @param object $schema Another `Schema` class object to be merged into the current one.
+ * If this schema contains field names that conflict with existing field names,
+ * the existing fields will not be overwritten.
* @return void
*/
public function merge($schema) {
View
2  data/Source.php
@@ -2,7 +2,7 @@
/**
* Lithium: the most rad php framework
*
- * @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
+ * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/
View
2  data/collection/DocumentSet.php
@@ -2,7 +2,7 @@
/**
* Lithium: the most rad php framework
*
- * @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
+ * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/
View
2  data/collection/MultiKeyRecordSet.php
@@ -2,7 +2,7 @@
/**
* Lithium: the most rad php framework
*
- * @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
+ * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/
View
28 data/collection/RecordSet.php
@@ -2,7 +2,7 @@
/**
* Lithium: the most rad php framework
*
- * @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
+ * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/
@@ -120,14 +120,18 @@ protected function _mapRecord($data) {
}
foreach ($this->_columns as $name => $fields) {
$fieldCount = count($fields);
- $record[$i][$name] = array_combine($fields, array_slice($data, $offset, $fieldCount));
+ $record[$i][$name] = array_combine(
+ $fields, array_slice($data, $offset, $fieldCount)
+ );
$offset += $fieldCount;
}
$i++;
} while ($main && $data = $this->_result->next());
$relMap = $this->_query->relationships();
- return $this->_hydrateRecord($this->_dependencies, $primary, $record, 0, $i, '', $relMap, $conn);
+ return $this->_hydrateRecord(
+ $this->_dependencies, $primary, $record, 0, $i, '', $relMap, $conn
+ );
}
/**
@@ -161,23 +165,31 @@ protected function _hydrateRecord($relations, $primary, $record, $min, $max, $na
while ($j < $max) {
$keys = $relModel::key($record[$j][$relName]);
if ($main != $keys) {
- $rel[] = $this->_hydrateRecord($subrelations, $relModel, $record, $i, $j, $relName, $relMap, $conn);
+ $rel[] = $this->_hydrateRecord(
+ $subrelations, $relModel, $record, $i, $j, $relName, $relMap, $conn
+ );
$main = $keys;
$i = $j;
}
$j++;
}
if (array_filter($record[$i][$relName])) {
- $rel[] = $this->_hydrateRecord($subrelations, $relModel, $record, $i, $j, $relName, $relMap, $conn);
+ $rel[] = $this->_hydrateRecord(
+ $subrelations, $relModel, $record, $i, $j, $relName, $relMap, $conn
+ );
}
$opts = array('class' => 'set') + $options;
$record[$min][$name][$field] = $conn->item($primary, $rel, $opts);
} else {
- $record[$min][$name][$field] = $this->_hydrateRecord($subrelations, $relModel, $record, $min, $max, $relName, $relMap, $conn);
+ $record[$min][$name][$field] = $this->_hydrateRecord(
+ $subrelations, $relModel, $record, $min, $max, $relName, $relMap, $conn
+ );
}
}
}
- return $conn->item($primary, isset($record[$min][$name]) ? $record[$min][$name] : array(), $options);
+ return $conn->item(
+ $primary, isset($record[$min][$name]) ? $record[$min][$name] : array(), $options
+ );
}
protected function _columnMap() {
@@ -212,7 +224,7 @@ protected function _keyIndex($name) {
}
$index = 0;
foreach ($this->_columns as $key => $value) {
- if ($key == $name) {
+ if ($key === $name) {
$flip = array_flip($value);
$keys = $model::meta('key');
if (!is_array($keys)) {
View
2  data/entity/Document.php
@@ -2,7 +2,7 @@
/**
* Lithium: the most rad php framework
*
- * @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
+ * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/
View
3  data/entity/Record.php
@@ -2,7 +2,7 @@
/**
* Lithium: the most rad php framework
*
- * @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
+ * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/
@@ -29,4 +29,5 @@ public function to($format, array $options = array()) {
return parent::to($format, $options);
}
}
+
?>
View
13 data/model/Query.php
@@ -2,7 +2,7 @@
/**
* Lithium: the most rad php framework
*
- * @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
+ * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/
@@ -766,6 +766,17 @@ public function __call($method, array $params = array()) {
}
/**
+ * Custom check to determine if our given magic methods can be responded to.
+ *
+ * @param string $method Method name.
+ * @param bool $internal Interal call or not.
+ * @return bool
+ */
+ public function respondsTo($method, $internal = false) {
+ return isset($this->_config[$method]) || parent::respondsTo($method, $internal);
+ }
+
+ /**
* Will return a find first condition on the associated model if a record is connected.
* Called by conditions when it is called as a get and no condition is set.
*
View
2  data/model/QueryException.php
@@ -2,7 +2,7 @@
/**
* Lithium: the most rad php framework
*
- * @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
+ * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/
View
19 data/model/Relationship.php
@@ -2,7 +2,7 @@
/**
* Lithium: the most rad php framework
*
- * @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
+ * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/
@@ -112,7 +112,7 @@ protected function _init() {
$config =& $this->_config;
$type = $config['type'];
- $name = ($type == 'hasOne') ? Inflector::pluralize($config['name']) : $config['name'];
+ $name = ($type === 'hasOne') ? Inflector::pluralize($config['name']) : $config['name'];
$config['fieldName'] = $config['fieldName'] ?: lcfirst($name);
if (!$config['to']) {
@@ -135,9 +135,20 @@ public function __call($name, $args = array()) {
return $this->data($name);
}
+ /**
+ * Custom check to determine if our given magic methods can be responded to.
+ *
+ * @param string $method Method name.
+ * @param bool $internal Interal call or not.
+ * @return bool
+ */
+ public function respondsTo($method, $internal = false) {
+ return is_callable(array($this, $method), true);
+ }
+
protected function _keys($keys) {
$config = $this->_config;
- $hasRel = ($related = ($config['type'] == 'belongsTo') ? $config['to'] : $config['from']);
+ $hasRel = ($related = ($config['type'] === 'belongsTo') ? $config['to'] : $config['from']);
if (!$hasRel || !$keys) {
return array();
@@ -151,7 +162,7 @@ protected function _keys($keys) {
$keys = (array) $keys;
$related = (array) $related::key();
- if (count($keys) != count($related)) {
+ if (count($keys) !== count($related)) {
$msg = "Unmatched keys in relationship `{$config['name']}` between models ";
$msg .= "`{$config['from']}` and `{$config['to']}`.";
throw new ConfigException($msg);
View
42 data/source/Database.php
@@ -2,7 +2,7 @@
/**
* Lithium: the most rad php framework
*
- * @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
+ * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/
@@ -231,6 +231,9 @@ public function __construct(array $config = array()) {
$models = $context->models();
foreach ($context->fields() as $field) {
+ if (!is_string($field)) {
+ continue;
+ }
list($alias, $field) = $self->invokeMethod('_splitFieldname', array($field));
$alias = $alias ?: $field;
if ($alias && isset($models[$alias])) {
@@ -271,7 +274,7 @@ public function connect() {
preg_match('/SQLSTATE\[(.+?)\]/', $e->getMessage(), $code);
$code = $code[1] ?: 0;
switch (true) {
- case $code == 'HY000' || substr($code, 0, 2) == '08':
+ case $code === 'HY000' || substr($code, 0, 2) === '08':
$msg = "Unable to connect to host `{$config['host']}`.";
throw new NetworkException($msg, null, $e);
case in_array($code, array('28000', '42000')):
@@ -284,7 +287,7 @@ public function connect() {
if ($this->_config['encoding']) {
$this->encoding($this->_config['encoding']);
- }
+ }
return $this->_isConnected;
}
@@ -510,7 +513,7 @@ public function read($query, array $options = array()) {
*/
protected function &_queryExport($query) {
$data = $query->export($this);
- if ($query->limit() && ($model = $query-> model())) {
+ if ($query->limit() && ($model = $query->model())) {
foreach ($query->relationships() as $relation) {
if ($relation['type'] === 'hasMany') {
$name = $model::meta('name');
@@ -626,14 +629,14 @@ public function calculation($type, $query, array $options = array()) {
* @return array Returns an array containing the configuration for a model relationship.
*/
public function relationship($class, $type, $name, array $config = array()) {
- $field = Inflector::underscore(Inflector::singularize($name));//($type == 'hasMany') ? : ;
+ $field = Inflector::underscore(Inflector::singularize($name));
$key = "{$field}_id";
$primary = $class::meta('key');