Skip to content

Actually Move To PSR-2 #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from Mar 31, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.idea
vendor/
composer.lock
vendor
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ For us to accept contributions you will have to first have signed the
[Contributor License Agreement].

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

Installation
------------

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

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

[Get Composer]: https://getcomposer.org/download/
[Contributor License Agreement]: https://developers.facebook.com/opensource/cla
[Create Parse App]: https://parse.com/apps/new
[Create Parse App]: https://parse.com/apps/new
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ from your PHP app or script.
Installation
------------

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

```json
{
"require": {
"parse/php-sdk" : "1.1.*"
}
"require": {
"parse/php-sdk" : "1.1.*"
}
}
```

Expand Down Expand Up @@ -51,7 +51,7 @@ Usage

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

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

```php
Expand Down Expand Up @@ -80,7 +80,7 @@ $object->set("elephant", "php");
$object->set("today", new DateTime());
$object->setArray("mylist", [1, 2, 3]);
$object->setAssociativeArray(
"languageTypes", array("php" => "awesome", "ruby" => "wtf")
"languageTypes", array("php" => "awesome", "ruby" => "wtf")
);

// Save:
Expand All @@ -95,16 +95,16 @@ $user = new ParseUser();
$user->setUsername("foo");
$user->setPassword("Q2w#4!o)df");
try {
$user->signUp();
$user->signUp();
} catch (ParseException $ex) {
// error in $ex->getMessage();
// error in $ex->getMessage();
}

// Login
try {
$user = ParseUser::logIn("foo", "Q2w#4!o)df");
$user = ParseUser::logIn("foo", "Q2w#4!o)df");
} catch(ParseException $ex) {
// error in $ex->getMessage();
// error in $ex->getMessage();
}

// Current user
Expand Down Expand Up @@ -147,7 +147,7 @@ $first = $query->first();
// Process ALL (without limit) results with "each".
// Will throw if sort, skip, or limit is used.
$query->each(function($obj) {
echo $obj->getObjectId();
echo $obj->getObjectId();
});
```

Expand All @@ -161,8 +161,8 @@ Analytics:

```php
ParseAnalytics::track("logoReaction", array(
"saw" => "elephant",
"said" => "cute"
"saw" => "elephant",
"said" => "cute"
));
```

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

// Upload from a local file:
$file = ParseFile::createFromFile(
"/tmp/foo.bar", "Parse.txt", "text/plain"
"/tmp/foo.bar", "Parse.txt", "text/plain"
);

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

// Push to Channels
ParsePush::send(array(
"channels" => ["PHPFans"],
"data" => $data
"channels" => ["PHPFans"],
"data" => $data
));

// Push to Query
$query = ParseInstallation::query();
$query->equalTo("design", "rad");
ParsePush::send(array(
"where" => $query,
"data" => $data
"where" => $query,
"data" => $data
));
```

Contributing / Testing
----------------------

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

[Get Composer]: https://getcomposer.org/download/
[Parse PHP Guide]: https://www.parse.com/docs/php_guide
62 changes: 30 additions & 32 deletions autoload.php
Original file line number Diff line number Diff line change
@@ -1,46 +1,44 @@
<?php

/**
/*
* You only need this file if you are not using composer.
*/

if (version_compare(PHP_VERSION, '5.4.0', '<')) {
throw new Exception('The Parse SDK requires PHP version 5.4 or higher.');
}

/*
* Register the autoloader for the Parse SDK
* Register the autoloader for the Parse SDK.
*
* Based off the official PSR-4 autoloader example found here:
* https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md
*
* @param string $class The fully-qualified class name.
* @return void
*/
spl_autoload_register(function ($class) {
// Parse class prefix
$prefix = 'Parse\\';

// base directory for the namespace prefix
$base_dir = defined('PARSE_SDK_DIR') ? PARSE_SDK_DIR : __DIR__.'/src/Parse/';

// does the class use the namespace prefix?
$len = strlen($prefix);
if (strncmp($prefix, $class, $len) !== 0) {
// no, move to the next registered autoloader
return;
}

// get the relative class name
$relative_class = substr($class, $len);

// replace the namespace prefix with the base directory, replace namespace
// separators with directory separators in the relative class name, append
// with .php
$file = $base_dir.str_replace('\\', '/', $relative_class).'.php';

// echo $relative_class . '<br/>';

// if the file exists, require it
if (file_exists($file)) {
require $file;
}
spl_autoload_register(function ($class) {
// Parse class prefix
$prefix = 'Parse\\';

// base directory for the namespace prefix
$base_dir = defined('PARSE_SDK_DIR') ? PARSE_SDK_DIR : __DIR__.'/src/Parse/';

// does the class use the namespace prefix?
$len = strlen($prefix);
if (strncmp($prefix, $class, $len) !== 0) {
// no, move to the next registered autoloader
return;
}

// get the relative class name
$relative_class = substr($class, $len);

// replace the namespace prefix with the base directory, replace namespace
// separators with directory separators in the relative class name, append
// with .php
$file = $base_dir.str_replace('\\', '/', $relative_class).'.php';

// if the file exists, require it
if (file_exists($file)) {
require $file;
}
});
Loading