### Starting the Test Parse Server Source: https://github.com/parse-community/parse-php-sdk/blob/master/CONTRIBUTING.md This command initiates the test Parse Server instance, which is pre-configured with the necessary settings and handles MongoDB setup, allowing the PHP SDK test suite to run against it. ```Shell npm start ``` -------------------------------- ### Starting Parse Server Without MongoDB Setup Source: https://github.com/parse-community/parse-php-sdk/blob/master/CONTRIBUTING.md This command starts the test Parse Server without attempting to set up a MongoDB instance, which is useful if a MongoDB instance is already running independently and you only need the server. ```Shell npm run server-only ``` -------------------------------- ### Installing PHP Dependencies with Composer Source: https://github.com/parse-community/parse-php-sdk/blob/master/CONTRIBUTING.md This command uses Composer, the PHP package manager, to download and install all required PHP dependencies for the Parse PHP SDK project, ensuring the development environment is ready. ```Shell composer install ``` -------------------------------- ### Installing Node.js Dependencies for Test Server Source: https://github.com/parse-community/parse-php-sdk/blob/master/CONTRIBUTING.md This command uses npm, the Node.js package manager, to install the Parse Server and its related dependencies from the project root, which is essential for setting up the local test environment. ```Shell npm install ``` -------------------------------- ### Running Tests via npm Script Source: https://github.com/parse-community/parse-php-sdk/blob/master/CONTRIBUTING.md This command executes the test suite defined in the project's 'package.json' file, typically configured to run PHPUnit tests, providing a convenient alternative way to initiate testing. ```Shell npm test ``` -------------------------------- ### Configuring Mock Android Push Notifications for Parse Server Source: https://github.com/parse-community/parse-php-sdk/blob/master/CONTRIBUTING.md This JSON snippet provides an example configuration for a mock Android push notification setup within Parse Server, requiring a sender ID and an API key for testing purposes without real credentials. ```JSON { "android": { "senderId": "blank-sender-id", "apiKey": "not-a-real-api-key" } } ``` -------------------------------- ### Verifying PHP Documentation with npm Script Source: https://github.com/parse-community/parse-php-sdk/blob/master/CONTRIBUTING.md This command executes a check to ensure that the PHP documentation (phpdoc) is acceptable and correctly formatted, verifying adherence to documentation standards and completeness. ```Shell npm run document-check ``` -------------------------------- ### Executing PHPUnit Tests from Vendor Bin Source: https://github.com/parse-community/parse-php-sdk/blob/master/CONTRIBUTING.md This command directly invokes the PHPUnit test runner located in the Composer vendor binaries directory, allowing developers to execute the Parse PHP SDK's test suite. ```Shell ./vendor/bin/phpunit ``` -------------------------------- ### Example Setting Parse Server URL and Mount Point - PHP Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md Provides a concrete example of setting the Parse Server URL and mount point, demonstrating the use of a specific domain, port (1337), and the default 'parse' route prefix. ```php ParseClient::setServerURL('https://example.com:1337','parse'); ``` -------------------------------- ### Configuring Mock Email Adapter for Parse Server Source: https://github.com/parse-community/parse-php-sdk/blob/master/CONTRIBUTING.md This JSON snippet demonstrates how to configure a mock email adapter, specifically 'parse-server-simple-mailgun-adapter', for Parse Server, including placeholder API key, domain, and sender address options for testing. ```JSON { "module": "parse-server-simple-mailgun-adapter", "options": { "apiKey": "not-a-real-api-key", "domain": "example.com", "fromAddress": "example@example.com" } } ``` -------------------------------- ### Requiring Parse SDK Autoloader for Git Installation Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md This PHP snippet includes the `autoload.php` file directly from the Parse PHP SDK directory. This is used when the SDK is installed via Git, making its classes available without Composer's autoloader. ```PHP require 'autoload.php'; ``` -------------------------------- ### Debugging with Helper::print() in PHP Source: https://github.com/parse-community/parse-php-sdk/blob/master/CONTRIBUTING.md This PHP function call, 'Helper::print()', is provided for debugging purposes within the Parse PHP SDK test environment, likely offering formatted output of variables or states to aid in troubleshooting. ```PHP Helper::print() ``` -------------------------------- ### Linting PHP Code with npm Script Source: https://github.com/parse-community/parse-php-sdk/blob/master/CONTRIBUTING.md This command runs the PHP Code Sniffer (phpcs) via an npm script to check the PHP code against the PSR-2 coding style guidelines, ensuring code quality and consistency across the project. ```Shell npm run lint ``` -------------------------------- ### Example of Failed Server Health Response (Bad Mount Path) - JSON Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md Demonstrates a health check response indicating a 404 Not Found error, typically occurring when the specified mount path for the Parse Server is incorrect. ```json // ParseClient::setServerURL('http://localhost:1337', 'not-good'); { "status": 404, "response": "...Cannot GET \/not-good\/health..." } ``` -------------------------------- ### Getting Specific Parse Server Features (PHP) Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md This snippet demonstrates how to retrieve specific feature configurations from the Parse Server, such as hooks, cloud code, logs, push, and schemas, using dedicated methods of `ParseServerInfo`. It also shows how to get additional features manually by name. ```php ParseServerInfo::getHooksFeatures(); ParseServerInfo::getCloudCodeFeatures(); ParseServerInfo::getLogsFeatures(); ParseServerInfo::getPushFeatures(); ParseServerInfo::getSchemasFeatures(); // additional features can be obtained manually using 'get' $feature = ParseServerInfo::get('new-feature'); ``` -------------------------------- ### Getting Parse Server Global Config Features (PHP) Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md This code shows how to query the Parse Server for its global configuration features, such as create, read, update, and delete permissions, using `ParseServerInfo::getGlobalConfigFeatures()`. It also mentions how to get all feature data. ```php // get the current version of the server you are connected to (2.6.5, 2.5.4, etc.) $version = ParseServerInfo::getVersion(); // get various features $globalConfigFeatures = ParseServerInfo::getGlobalConfigFeatures(); /** * Returns json of the related features * { * "create" : true, * "read" : true, * "update" : true, * "delete" : true * } */ // you can always get all feature data $data = ParseServerInfo::getFeatures(); ``` -------------------------------- ### Managing Cloud Jobs with Parse PHP SDK Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md This code illustrates how to start asynchronous server-side cloud jobs using `ParseCloud::startJob` and then track their progress. The `startJob` method returns a job status ID, which can be used with `ParseCloud::getJobStatus` to retrieve the current state of the job, such as 'failed' or 'succeeded'. ```PHP // start job $jobStatusId = ParseCloud::startJob('MyCloudJob', array("startedBy" => "me!")); // get job status, a ParseObject! $jobStatus = ParseCloud::getJobStatus($jobStatusId); $status = $jobStatus->get('status'); // failed / succeeded when done ``` -------------------------------- ### Performing Data Queries (PHP) Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md This code demonstrates various ways to query Parse Objects, including retrieving a specific object by ID, limiting results, finding all matching objects, getting only the first result, and iterating through all results using the `each` method. It also shows how to use the master key to override ACLs during queries. ```PHP $query = new ParseQuery("TestObject"); // Get a specific object: $object = $query->get("anObjectId"); $query->limit(10); // default 100, max 1000 // All results, normally: $results = $query->find(); // Or pass true to use the master key to override ACLs when querying: $results = $query->find(true); // 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(); }); ``` -------------------------------- ### Sending Push Notifications with a Query (PHP) Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md This example illustrates how to send push notifications to devices that match a specific query on the `ParseInstallation` class. It shows how to build a query using `equalTo` and then pass it as the 'where' parameter to `ParsePush::send`. ```php // Push to Query $query = ParseInstallation::query(); $query->equalTo("design", "rad"); ParsePush::send(array( "where" => $query, "data" => $data ), true); ``` -------------------------------- ### Automatically Fixing PHP Lint Errors with npm Script Source: https://github.com/parse-community/parse-php-sdk/blob/master/CONTRIBUTING.md This command uses PHP Code Beautifier and Fixer (phpcbf) via an npm script to automatically correct common linting errors in the PHP codebase, helping maintain adherence to PSR-2 coding standards efficiently. ```Shell npm run lint:fix ``` -------------------------------- ### Defining Parse PHP SDK Dependency in Composer Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md This JSON snippet defines the Parse PHP SDK as a required dependency in a `composer.json` file, specifying version `1.5.*`. This allows Composer to manage the SDK's installation and autoloading. ```JSON { "require": { "parse/php-sdk" : "1.5.*" } } ``` -------------------------------- ### Example of Successful Server Health Response - JSON Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md Illustrates the structure of a successful health check response from the Parse Server, indicating an HTTP status of 200 and an 'ok' status from the server itself. ```json { "status" : 200, "response" : { "status" : "ok" } } ``` -------------------------------- ### Getting Parse Server Version (PHP) Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md This snippet demonstrates how to retrieve the current version of the Parse Server that the SDK is connected to, using the `ParseServerInfo::getVersion()` method. ```php // get the current version of the server you are connected to (2.6.5, 2.5.4, etc.) $version = ParseServerInfo::getVersion(); ``` -------------------------------- ### Requiring Composer Autoloader in PHP Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md This PHP snippet includes Composer's autoloader file, `vendor/autoload.php`, which is generated after running `composer install`. This makes all classes from installed dependencies, including the Parse PHP SDK, available in the script without manual `require` statements. ```PHP require 'vendor/autoload.php'; ``` -------------------------------- ### Accessing Parse Server Config with PHP Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md This snippet demonstrates how to interact with the global ParseConfig object to access and modify server-side configuration values. You can retrieve existing settings using `get`, update them with `set`, and persist changes using `save`, allowing for dynamic global settings across your Parse applications. ```PHP $config = new ParseConfig(); // check a config value of yours $allowed = $config->get('feature_allowed'); // add a simple config value $config->set('feature_allowed', true); // save this global config $config->save(); ``` -------------------------------- ### Example of Failed Server Health Response (Unresolved Host) - JSON Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md Shows a health check response indicating an error (status 0, error 6) when the ParseClient cannot resolve the specified host, often due to an invalid domain name. ```json // ParseClient::setServerURL('http://__uh__oh__.com', 'parse'); { "status": 0, "error": 6, "error_message": "Couldn't resolve host '__uh__oh__.com'" } ``` -------------------------------- ### Tracking Analytics Events with Parse PHP SDK Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md This example shows how to use `ParseAnalytics::track` to send custom analytics events to your Parse Server. You can specify an event name and include additional data as an associative array, enabling detailed tracking of user interactions and application behavior. ```PHP ParseAnalytics::track("logoReaction", array( "saw" => "elephant", "said" => "cute" )); ``` -------------------------------- ### Checking Push Notification Status (PHP) Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md This code shows how to retrieve and monitor the status of a sent push notification if the server supports it. It demonstrates using `ParsePush::hasStatus` and `ParsePush::getStatus` to check various states (pending, running, succeeded, failed) and get counts of sent/failed pushes. ```php // Get Push Status $response = ParsePush::send(array( "channels" => ["StatusFans"], "data" => $data ), true); if(ParsePush::hasStatus($response)) { // Retrieve PushStatus object $pushStatus = ParsePush::getStatus($response); // check push status if($pushStatus->isPending()) { // handle a pending push request } else if($pushStatus->isRunning()) { // handle a running push request } else if($pushStatus->hasSucceeded()) { // handle a successful push request } else if($pushStatus->hasFailed()) { // handle a failed request } // ...or get the push status string to check yourself $status = $pushStatus->getPushStatus(); // get # pushes sent $sent = $pushStatus->getPushesSent(); // get # pushes failed $failed = $pushStatus->getPushesFailed(); } ``` -------------------------------- ### Requesting User Verification Email (PHP) Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md This code demonstrates how to manually request a verification email for a user's account. This function is useful when email verification is enabled on your Parse Server setup and you need to trigger the email sending process for a specific email address, provided the account is not already verified. ```PHP ParseUser::requestVerificationEmail('email@example.com'); ``` -------------------------------- ### Initializing ParseClient with All Keys - PHP Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md Initializes the ParseClient with the application ID, REST API key, and master key. This is the standard way to set up the client for communication with Parse Server. ```php ParseClient::initialize( $app_id, $rest_key, $master_key ); ``` -------------------------------- ### User Authentication and Session Management (PHP) Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md This snippet covers essential user operations including signing up a new user, logging in an existing user, and retrieving the currently logged-in user. It includes basic error handling for signup and login operations using ParseException. ```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(); ``` -------------------------------- ### Cloning Parse PHP SDK Repository with Git Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md This Bash command clones the official Parse PHP SDK repository from GitHub into the current directory. This method allows developers to obtain the SDK source code directly for manual integration or development. ```Bash git clone https://github.com/parse-community/parse-php-sdk.git ``` -------------------------------- ### Managing Files with Parse PHP SDK Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md This snippet demonstrates how to interact with files stored on Parse Server, including retrieving file details like name, URL, and contents from a Parse Object. It also shows how to upload new files from a local path using `ParseFile::createFromFile` or directly from variable contents using `ParseFile::createFromData`. ```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 variable contents (string, binary) $file = ParseFile::createFromData($contents, "Parse.txt", "text/plain"); ``` -------------------------------- ### Initializing ParseClient Omitting REST Key - PHP Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md Initializes the ParseClient when the Parse Server does not require or use a REST API key. The REST key parameter is safely omitted by passing `null`. ```php ParseClient::initialize( $app_id, null, $master_key ); ``` -------------------------------- ### Setting Parse Server URL and Mount Point - PHP Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md Configures the ParseClient to point to a specific Parse Server URL and its mount point. This is crucial for directing API requests to the correct server instance. ```php // Users of Parse Server will need to point ParseClient at their remote URL and Mount Point: ParseClient::setServerURL('https://my-parse-server.com:port','parse'); ``` -------------------------------- ### Importing Parse Classes (PHP) Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md This snippet demonstrates the necessary 'use' declarations for various Parse PHP SDK classes. These declarations allow you to refer to the classes by their short names without specifying their full namespaces, simplifying code readability and usage throughout your Parse application. ```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; use Parse\ParseClient; use Parse\ParsePushStatus; use Parse\ParseServerInfo; use Parse\ParseLogs; use Parse\ParseAudience; ``` -------------------------------- ### Managing Parse Objects (PHP) Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md This code illustrates how to create, manipulate, save, encode, and decode Parse Objects. Parse Objects are fundamental for persisting data without direct database interaction. It shows setting various data types, including arrays and associative arrays, and demonstrates saving with and without the master key. ```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") ); // Save normally: $object->save(); // Or pass true to use the master key to override ACLs when saving: $object->save(true); // encode an object for later use $encoded = $object->encode(); // decode an object $decodedObject = ParseObject::decode($encoded); ``` -------------------------------- ### Calling Cloud Functions with Parse PHP SDK Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md This snippet shows how to directly invoke server-side cloud functions using `ParseCloud::run`. It demonstrates passing parameters to the cloud function and receiving the results, enabling server-side logic execution from your PHP application. ```PHP $results = ParseCloud::run("aCloudFunction", array("from" => "php")); ``` -------------------------------- ### Managing Parse Schema: Adding and Deleting Indexes (PHP) Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md This snippet covers the creation and deletion of database indexes on a Parse class. It shows how to add a new index to an existing field using `addIndex()` and remove an index using `deleteIndex()`, both requiring `save()` to persist. It also demonstrates how to retrieve existing indexes. MasterKey is required for these operations. ```php // To add an index, the field must exist before you create an index $schema->addString('field'); $index = [ 'field' => 1 ]; $schema->addIndex('index_name', $index); $schema->save(); // Delete an index $schema->deleteIndex('index_name'); $schema->save(); // If indexes exist, you can retrieve them $result = $schema->get(); $indexes = $result['indexes']; ``` -------------------------------- ### Managing Parse Schema: Creating Classes and Adding Fields (PHP) Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md This snippet demonstrates how to initialize a `ParseSchema` instance for a specific class and perform various schema modifications. It shows how to retrieve current schema data, add different types of fields (string, number, boolean, date, file, geopoint, polygon, array, object, pointer, relation), and persist these changes using `save()` or `update()`. ```php // create an instance to manage your class $mySchema = new ParseSchema("MyClass"); // gets the current schema data as an associative array, for inspection $data = $mySchema->get(); // add any # of fields, without having to create any objects $mySchema->addString('string_field'); $mySchema->addNumber('num_field'); $mySchema->addBoolean('bool_field'); $mySchema->addDate('date_field'); $mySchema->addFile('file_field'); $mySchema->addGeoPoint('geopoint_field'); $mySchema->addPolygon('polygon_field'); $mySchema->addArray('array_field'); $mySchema->addObject('obj_field'); $mySchema->addPointer('pointer_field'); // you can even setup pointer/relation fields this way $mySchema->addPointer('pointer_field', 'TargetClass'); $mySchema->addRelation('relation_field', 'TargetClass'); // new types can be added as they are available $mySchema->addField('new_field', 'ANewDataType'); // save/update this schema to persist your field changes $mySchema->save(); // or $mySchema->update(); ``` -------------------------------- ### Retrieving Parse Server Logs (PHP) Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md This snippet shows how to retrieve info and error logs from the Parse server using `ParseLogs`. It illustrates fetching the last 100 logs and also retrieving logs with more specific parameters like count, date ranges, and order, similar to the Parse Dashboard functionality. A correct MasterKey is required for access. ```php // get last 100 info logs, sorted in descending order $logs = ParseLogs::getInfoLogs(); // get last 100 info logs, sorted in descending order $logs = ParseLogs::getErrorLogs(); // logs can be retrieved with further specificity // get 10 logs from a date up to a date in ascending order $logs = ParseLogs::getInfoLogs(10, $fromDate, $untilDate, 'asc'); // above can be done for 'getErrorLogs' as well ``` -------------------------------- ### Setting HTTP Client to Stream - PHP Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md Configures the ParseClient to use the stream HTTP client. This client requires the `allow_url_fopen` setting to be enabled in `php.ini` for proper functionality. ```php // set stream http client // ** requires 'allow_url_fopen' to be enabled in php.ini ** ParseClient::setHttpClient(new ParseStreamHttpClient()); ``` -------------------------------- ### Aggregate Queries with Parse PHP SDK Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md This snippet demonstrates how to perform aggregate queries using different pipelines like 'group' for accumulation, 'project' for field selection, and 'match' for filtering. It's important to use 'objectId' instead of '_id' and note that the MasterKey is required for these operations. ```PHP // group pipeline is similar to distinct, can apply $sum, $avg, $max, $min // accumulate sum and store in total field $pipeline = [ 'group' => [ 'objectId' => null, 'total' => [ '$sum' => '$score'] ] ]; $results = $query->aggregate($pipeline); // project pipeline is similar to keys, add or remove existing fields // includes name key $pipeline = [ 'project' => [ 'name' => 1 ] ]; $results = $query->aggregate($pipeline); // match pipeline is similar to equalTo // filter out objects with score greater than 15 $pipeline = [ 'match' => [ 'score' => [ '$gt' => 15 ] ] ]; $results = $query->aggregate($pipeline); ``` -------------------------------- ### Sending Push Notifications to Channels (PHP) Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md This snippet demonstrates how to send a basic push notification to a specific channel using the Parse PHP SDK. It highlights the requirement of the master key for sending pushes and specifies recipients via the 'channels' parameter. ```php $data = array("alert" => "Hi!"); // Parse Server has a few requirements: // - The master key is required for sending pushes, pass true as the second parameter // - You must set your recipients by using 'channels' or 'where', but you must not pass both // Push to Channels ParsePush::send(array( "channels" => ["PHPFans"], "data" => $data ), true); ``` -------------------------------- ### Distinct Queries with Parse PHP SDK Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md This code illustrates how to use the 'distinct' method to find unique values for a specified field in Parse queries. It also shows how 'distinct' can be combined with other query constraints like 'equalTo' to refine the results. A MasterKey is required for distinct queries. ```PHP // finds score that are unique $results = $query->distinct('score'); // can be used with equalTo $query = new ParseQuery('TestObject'); $query->equalTo('name', 'foo'); $results = $query->distinct('score'); ``` -------------------------------- ### Configuring Access Control Lists (ACLs) (PHP) Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md This snippet illustrates how to create and configure Access Control Lists (ACLs) for Parse Objects. ACLs provide granular control over read and write access for the public, specific users, and roles, allowing you to define permissions for individual objects. ```PHP // Access only by the ParseUser in $user $userACL = ParseACL::createACLWithUser($user); // 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); ``` -------------------------------- ### Setting HTTP Client to cURL - PHP Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md Configures the ParseClient to use the cURL HTTP client, which is the default if no client is explicitly set. This client is generally robust for network requests. ```php // set curl http client (default if none set) ParseClient::setHttpClient(new ParseCurlHttpClient()); ``` -------------------------------- ### Sending Push Notifications with an Audience (PHP) Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md This snippet demonstrates how to use the `ParseAudience` class to manage and track push notifications sent via queries. It covers creating and saving an audience with a name and query, and how using 'audience_id' updates 'lastUsed' and 'timesUsed' for tracking. ```php $iosQuery = ParseInstallation::getQuery(); $iosQuery->equalTo("deviceType", "ios"); // create & save your audience $audience = ParseAudience::createAudience( 'MyiOSAudience', $iosQuery ); $audience->save(true); // send a push using the query in this audience and it's id // The 'audience_id' is what allows parse to update 'lastUsed' and 'timesUsed' // You could use any audience_id with any query and it will still update that audience ParsePush::send([ 'data' => [ 'alert' => 'hello ios users!' ], 'where' => $audience->getQuery(), 'audience_id' => $audience->getObjectId() ], true); // fetch changes to this audience $audience->fetch(true); // get last & times used for tracking $timesUsed = $audience->getTimesUsed(); $lastUsed = $audience->getLastUsed(); ``` -------------------------------- ### Setting Custom CA Certificate File - PHP Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md Specifies an absolute path to a Certificate Authority (CA) bundle file. This is necessary for SSL/TLS peer verification in environments where the default CA store is insufficient or unavailable, such as shared hosting. ```php // ** Use an Absolute path for your file! ** // holds one or more certificates to verify the peer with ParseClient::setCAFile(__DIR__ . '/certs/cacert.pem'); ``` -------------------------------- ### Managing Parse Schema: Deleting a Class (PHP) Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md This snippet demonstrates how to delete an entire class schema from the Parse server. It highlights the prerequisite that the class must be empty before it can be deleted using the `delete()` method. ```php $mySchema->delete(); ``` -------------------------------- ### Managing Parse Schema: Purging All Objects from a Class (PHP) Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md This snippet demonstrates how to delete all objects within a specific Parse class using the `purge()` method. It emphasizes that this is an irreversible action and should be used with extreme caution, typically only when preparing to delete the class itself. ```php // delete all objects in the schema $mySchema->purge(); ``` -------------------------------- ### Performing Server Health Check - PHP Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md Executes a health check on the configured Parse Server to verify its availability and the correctness of the server URL and mount path. The response includes an HTTP status code and server-specific status. ```php $health = ParseClient::getServerHealth(); if($health['status'] === 200) { // everything looks good! } ``` -------------------------------- ### Managing Parse Schema: Deleting Fields (PHP) Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md This snippet illustrates how to remove an existing field from a Parse class schema. It shows the use of `deleteField()` followed by `save()` or `update()` to apply the changes to the server. ```php $mySchema->deleteField('string_field'); $mySchema->save(): // or for an existing schema... $mySchema->update(): ``` -------------------------------- ### Relative Time Queries with Parse PHP SDK Source: https://github.com/parse-community/parse-php-sdk/blob/master/README.md This section demonstrates how to perform queries based on relative time using methods like 'greaterThanRelativeTime', 'lessThanRelativeTime', and 'greaterThanOrEqualToRelativeTime'. These queries are executed using the server's time and timezone, allowing for flexible date-based filtering with natural language expressions. ```PHP // greater than 2 weeks ago $query->greaterThanRelativeTime('createdAt', '2 weeks ago'); // less than 1 day in the future $query->lessThanRelativeTime('updatedAt', 'in 1 day'); // can make queries to very specific points in time $query->greaterThanOrEqualToRelativeTime('createdAt', '1 year 2 weeks 30 days 2 hours 5 minutes 10 seconds ago'); // can make queries based on right now // gets everything updated up to this point in time $query->lessThanOrEqualToRelativeTime('updatedAt', 'now'); // shorthand keywords work as well $query->greaterThanRelativeTime('date', '1 yr 2 wks 30 d 2 hrs 5 mins 10 secs ago'); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.