Skip to content

Adding syntax highlighting to README #1

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 1 commit into from
Aug 5, 2014
Merged
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
225 changes: 123 additions & 102 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@ Installation
[Get Composer], the PHP package manager. Then create a composer.json file in
your projects root folder, containing:

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

Run "composer install" to download the SDK and set up the autoloader,
and then require it from your PHP script:

require 'vendor/autoload.php';
```php
require 'vendor/autoload.php';
```

Usage
-----
Expand All @@ -29,138 +33,155 @@ 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
sample code in this file:

use Parse\ParseObject;
use Parse\ParseQuery;
use Parse\ParseACL;
use Parse\ParsePush;
use Parse\ParseUser;
use Parse\ParseInstallation;
use Parse\ParseException;
use Parse\ParseAnalytics;
use Parse\ParseFile;
use Parse\ParseCloud;

```php
use Parse\ParseObject;
use Parse\ParseQuery;
use Parse\ParseACL;
use Parse\ParsePush;
use Parse\ParseUser;
use Parse\ParseInstallation;
use Parse\ParseException;
use Parse\ParseAnalytics;
use Parse\ParseFile;
use Parse\ParseCloud;
```

Objects:

$object = ParseObject::create("TestObject");
$objectId = $object->getObjectId();
$php = $object->get("elephant");
```php
$object = ParseObject::create("TestObject");
$objectId = $object->getObjectId();
$php = $object->get("elephant");

// Set values:
$object->set("elephant", "php");
$object->set("today", new DateTime());
$object->setArray("mylist", [1, 2, 3]);
$object->setAssociativeArray(
"languageTypes", array("php" => "awesome", "ruby" => "wtf")
);
// Set values:
$object->set("elephant", "php");
$object->set("today", new DateTime());
$object->setArray("mylist", [1, 2, 3]);
$object->setAssociativeArray(
"languageTypes", array("php" => "awesome", "ruby" => "wtf")
);

// Save:
$object->save();
// Save:
$object->save();
```

Users:

// Signup
$user = new ParseUser();
$user->setUsername("foo");
$user->setPassword("Q2w#4!o)df");
try {
$user->signUp();
} catch (ParseException $ex) {
// error in $ex->getMessage();
}

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

// Current user
$user = ParseUser::getCurrentUser();
```php
// Signup
$user = new ParseUser();
$user->setUsername("foo");
$user->setPassword("Q2w#4!o)df");
try {
$user->signUp();
} catch (ParseException $ex) {
// error in $ex->getMessage();
}

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

// Current user
$user = ParseUser::getCurrentUser();
```

Security:

// Access only by the ParseUser in $user
$userACL = ParseACL::createACLWithUser($user);
```php
// Access only by the ParseUser in $user
$userACL = ParseACL::createACLWithUser($user);

// Access only by master key
$restrictedACL = new ParseACL();
// Access only by master key
$restrictedACL = new ParseACL();

// Set individual access rights
$acl = new ParseACL();
$acl->setPublicReadAccess(true);
$acl->setPublicWriteAccess(false);
$acl->setUserWriteAccess($user, true);
$acl->setRoleWriteAccessWithName("PHPFans", true);
// Set individual access rights
$acl = new ParseACL();
$acl->setPublicReadAccess(true);
$acl->setPublicWriteAccess(false);
$acl->setUserWriteAccess($user, true);
$acl->setRoleWriteAccessWithName("PHPFans", true);
```

Queries:

$query = new ParseQuery("TestObject");
```php
$query = new ParseQuery("TestObject");

// Get a specific object:
$object = $query->get("anObjectId");
// Get a specific object:
$object = $query->get("anObjectId");

$query->limit(10); // default 100, max 1000
$query->limit(10); // default 100, max 1000

// All results:
$results = $query->find();
// All results:
$results = $query->find();

// Just the first result:
$first = $query->first();
// Just the first result:
$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();
});
// Process ALL (without limit) results with "each".
// Will throw if sort, skip, or limit is used.
$query->each(function($obj) {
echo $obj->getObjectId();
});
```

Cloud Functions:

$results = ParseCloud::run("aCloudFunction", array("from" => "php"));
```php
$results = ParseCloud::run("aCloudFunction", array("from" => "php"));
```

Analytics:

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

Files:

// Get from a Parse Object:
$file = $aParseObject->get("aFileColumn");
$name = $file->getName();
$url = $file->getURL();
// Download the contents:
$contents = $file->getData();
```php
// Get from a Parse Object:
$file = $aParseObject->get("aFileColumn");
$name = $file->getName();
$url = $file->getURL();
// Download the contents:
$contents = $file->getData();

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

// Upload from variable contents (string, binary)
$file = ParseFile::createFromData($contents, "Parse.txt", "text/plain");
// Upload from variable contents (string, binary)
$file = ParseFile::createFromData($contents, "Parse.txt", "text/plain");
```

Push:

$data = array("alert" => "Hi!");
```php
$data = array("alert" => "Hi!");

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

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

Contributing / Testing
----------------------
Expand All @@ -169,4 +190,4 @@ See the CONTRIBUTORS.md file for information on testing and contributing to
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
[Parse PHP Guide]: https://www.parse.com/docs/php_guide