Skip to content

Commit 975cf33

Browse files
committed
Merge pull request #87 from GrahamForks/cs
Actually Move To PSR-2
2 parents b738bc4 + 87e9d1c commit 975cf33

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+5637
-5642
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
.idea
2-
vendor/
32
composer.lock
3+
vendor

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ For us to accept contributions you will have to first have signed the
55
[Contributor License Agreement].
66

77
When committing, keep all lines to less than 80 characters, and try to
8-
follow the existing style. Before creating a pull request, squash your commits
8+
follow the existing style. Before creating a pull request, squash your commits
99
into a single commit. Please provide ample explanation in the commit message.
1010

1111
Installation
1212
------------
1313

14-
Testing the Parse PHP SDK involves some set-up. You'll need to create a Parse
14+
Testing the Parse PHP SDK involves some set-up. You'll need to create a Parse
1515
App just for testing, and deploy some cloud code to it.
1616

1717
* [Get Composer], the PHP package manager.
@@ -31,4 +31,4 @@ At present the full suite of tests takes around 20 minutes.
3131

3232
[Get Composer]: https://getcomposer.org/download/
3333
[Contributor License Agreement]: https://developers.facebook.com/opensource/cla
34-
[Create Parse App]: https://parse.com/apps/new
34+
[Create Parse App]: https://parse.com/apps/new

README.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ from your PHP app or script.
77
Installation
88
------------
99

10-
[Get Composer], the PHP package manager. Then create a composer.json file in
10+
[Get Composer], the PHP package manager. Then create a composer.json file in
1111
your projects root folder, containing:
1212

1313
```json
1414
{
15-
"require": {
16-
"parse/php-sdk" : "1.1.*"
17-
}
15+
"require": {
16+
"parse/php-sdk" : "1.1.*"
17+
}
1818
}
1919
```
2020

@@ -51,7 +51,7 @@ Usage
5151

5252
Check out the [Parse PHP Guide] for the full documentation.
5353

54-
Add the "use" declarations where you'll be using the classes. For all of the
54+
Add the "use" declarations where you'll be using the classes. For all of the
5555
sample code in this file:
5656

5757
```php
@@ -80,7 +80,7 @@ $object->set("elephant", "php");
8080
$object->set("today", new DateTime());
8181
$object->setArray("mylist", [1, 2, 3]);
8282
$object->setAssociativeArray(
83-
"languageTypes", array("php" => "awesome", "ruby" => "wtf")
83+
"languageTypes", array("php" => "awesome", "ruby" => "wtf")
8484
);
8585

8686
// Save:
@@ -95,16 +95,16 @@ $user = new ParseUser();
9595
$user->setUsername("foo");
9696
$user->setPassword("Q2w#4!o)df");
9797
try {
98-
$user->signUp();
98+
$user->signUp();
9999
} catch (ParseException $ex) {
100-
// error in $ex->getMessage();
100+
// error in $ex->getMessage();
101101
}
102102

103103
// Login
104104
try {
105-
$user = ParseUser::logIn("foo", "Q2w#4!o)df");
105+
$user = ParseUser::logIn("foo", "Q2w#4!o)df");
106106
} catch(ParseException $ex) {
107-
// error in $ex->getMessage();
107+
// error in $ex->getMessage();
108108
}
109109

110110
// Current user
@@ -147,7 +147,7 @@ $first = $query->first();
147147
// Process ALL (without limit) results with "each".
148148
// Will throw if sort, skip, or limit is used.
149149
$query->each(function($obj) {
150-
echo $obj->getObjectId();
150+
echo $obj->getObjectId();
151151
});
152152
```
153153

@@ -161,8 +161,8 @@ Analytics:
161161

162162
```php
163163
ParseAnalytics::track("logoReaction", array(
164-
"saw" => "elephant",
165-
"said" => "cute"
164+
"saw" => "elephant",
165+
"said" => "cute"
166166
));
167167
```
168168

@@ -178,7 +178,7 @@ $contents = $file->getData();
178178

179179
// Upload from a local file:
180180
$file = ParseFile::createFromFile(
181-
"/tmp/foo.bar", "Parse.txt", "text/plain"
181+
"/tmp/foo.bar", "Parse.txt", "text/plain"
182182
);
183183

184184
// Upload from variable contents (string, binary)
@@ -192,24 +192,24 @@ $data = array("alert" => "Hi!");
192192

193193
// Push to Channels
194194
ParsePush::send(array(
195-
"channels" => ["PHPFans"],
196-
"data" => $data
195+
"channels" => ["PHPFans"],
196+
"data" => $data
197197
));
198198

199199
// Push to Query
200200
$query = ParseInstallation::query();
201201
$query->equalTo("design", "rad");
202202
ParsePush::send(array(
203-
"where" => $query,
204-
"data" => $data
203+
"where" => $query,
204+
"data" => $data
205205
));
206206
```
207207

208208
Contributing / Testing
209209
----------------------
210210

211211
See the CONTRIBUTORS.md file for information on testing and contributing to
212-
the Parse PHP SDK. We welcome fixes and enhancements.
212+
the Parse PHP SDK. We welcome fixes and enhancements.
213213

214214
[Get Composer]: https://getcomposer.org/download/
215215
[Parse PHP Guide]: https://www.parse.com/docs/php_guide

autoload.php

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,44 @@
11
<?php
22

3-
/**
3+
/*
44
* You only need this file if you are not using composer.
55
*/
6+
67
if (version_compare(PHP_VERSION, '5.4.0', '<')) {
78
throw new Exception('The Parse SDK requires PHP version 5.4 or higher.');
89
}
910

1011
/*
11-
* Register the autoloader for the Parse SDK
12+
* Register the autoloader for the Parse SDK.
13+
*
1214
* Based off the official PSR-4 autoloader example found here:
1315
* https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md
14-
*
15-
* @param string $class The fully-qualified class name.
16-
* @return void
1716
*/
18-
spl_autoload_register(function ($class) {
19-
// Parse class prefix
20-
$prefix = 'Parse\\';
21-
22-
// base directory for the namespace prefix
23-
$base_dir = defined('PARSE_SDK_DIR') ? PARSE_SDK_DIR : __DIR__.'/src/Parse/';
2417

25-
// does the class use the namespace prefix?
26-
$len = strlen($prefix);
27-
if (strncmp($prefix, $class, $len) !== 0) {
28-
// no, move to the next registered autoloader
29-
return;
30-
}
31-
32-
// get the relative class name
33-
$relative_class = substr($class, $len);
34-
35-
// replace the namespace prefix with the base directory, replace namespace
36-
// separators with directory separators in the relative class name, append
37-
// with .php
38-
$file = $base_dir.str_replace('\\', '/', $relative_class).'.php';
39-
40-
// echo $relative_class . '<br/>';
41-
42-
// if the file exists, require it
43-
if (file_exists($file)) {
44-
require $file;
45-
}
18+
spl_autoload_register(function ($class) {
19+
// Parse class prefix
20+
$prefix = 'Parse\\';
21+
22+
// base directory for the namespace prefix
23+
$base_dir = defined('PARSE_SDK_DIR') ? PARSE_SDK_DIR : __DIR__.'/src/Parse/';
24+
25+
// does the class use the namespace prefix?
26+
$len = strlen($prefix);
27+
if (strncmp($prefix, $class, $len) !== 0) {
28+
// no, move to the next registered autoloader
29+
return;
30+
}
31+
32+
// get the relative class name
33+
$relative_class = substr($class, $len);
34+
35+
// replace the namespace prefix with the base directory, replace namespace
36+
// separators with directory separators in the relative class name, append
37+
// with .php
38+
$file = $base_dir.str_replace('\\', '/', $relative_class).'.php';
39+
40+
// if the file exists, require it
41+
if (file_exists($file)) {
42+
require $file;
43+
}
4644
});

0 commit comments

Comments
 (0)