-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from RobertGrubb/updates
Structural Updates
- Loading branch information
Showing
11 changed files
with
293 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
"id": "5ed1b2957c6d9" | ||
}, | ||
{ | ||
"username": "etari3", | ||
"username": "test234", | ||
"email": "[email protected]", | ||
"location": { | ||
"country": "US", | ||
|
@@ -25,5 +25,13 @@ | |
"state": "KY" | ||
}, | ||
"id": "5ed1b2957c6d93" | ||
}, | ||
{ | ||
"id": "5ed1b2957c6d92", | ||
"username": "test234" | ||
}, | ||
{ | ||
"id": "5ed1b2957c6d92", | ||
"username": "test234" | ||
} | ||
] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace FilerDB\Core\Helpers; | ||
|
||
use FilerDB\Core\Exceptions\FilerDBException; | ||
|
||
class Document { | ||
|
||
/** | ||
* Check documents to see if the id exists. | ||
* @param array | ||
* @param string | ||
* @return boolean | ||
*/ | ||
public static function exists ($documents, $id) { | ||
if (self::byId($documents, $id) === false) return false; | ||
return true; | ||
} | ||
|
||
/** | ||
* Iterates through an array of documents, and finds | ||
* the object that has a specific id. It will then | ||
* return an object with the index, and the data | ||
* of that document. | ||
* @param array $documents | ||
* @param string $id | ||
* @return mixed | ||
*/ | ||
public static function byId ($documents, $id = null) { | ||
if (is_null($id)) return false; | ||
|
||
// Set the index to false by default | ||
$index = false; | ||
|
||
// Set the doc to false by default. | ||
$doc = false; | ||
|
||
// Iterate through documents, continue if no match. | ||
foreach ($documents as $i => $document) { | ||
|
||
if ($document->id === $id) { | ||
$index = $i; | ||
$doc = $document; | ||
} else { | ||
continue; | ||
} | ||
} | ||
|
||
// If no index was set, return false. | ||
if (!$index) return false; | ||
|
||
// Return object with data. | ||
return (object) [ | ||
'index' => $index, | ||
'document' => $doc | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.