-
Notifications
You must be signed in to change notification settings - Fork 17
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 #37 from whikloj/updates-thinCollection
Updates for thin collection controller
- Loading branch information
Showing
2 changed files
with
116 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of Islandora. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* PHP Version 5.5.9 | ||
* | ||
* @category Islandora | ||
* @package Islandora | ||
* @author Daniel Lamb <daniel@discoverygarden.ca> | ||
* @license http://www.gnu.org/licenses/gpl-3.0.en.html GPL | ||
* @link http://www.islandora.ca | ||
*/ | ||
|
||
namespace Islandora\Chullo\Uuid; | ||
|
||
/** | ||
* Interface for generating UUIDs. | ||
* | ||
* @category Islandora | ||
* @package Islandora | ||
* @author Daniel Lamb <daniel@discoverygarden.ca> | ||
* @license http://www.gnu.org/licenses/gpl-3.0.en.html GPL | ||
* @link http://www.islandora.ca | ||
*/ | ||
interface IUuidGenerator { | ||
|
||
/** | ||
* Generates a v4 UUID. | ||
* | ||
* @return String Valid v4 UUID. | ||
*/ | ||
public function generateV4(); | ||
|
||
/** | ||
* Generates a v5 UUID. | ||
* | ||
* @return String Valid v5 UUID. | ||
*/ | ||
public function generateV5($name, $namespace = NULL); | ||
} |
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,72 @@ | ||
<?php | ||
|
||
namespace Islandora\Chullo\Uuid; | ||
|
||
use Ramsey\Uuid\Uuid; | ||
|
||
/** | ||
* Generator for v4 & v5 UUIDs. | ||
*/ | ||
class UuidGenerator implements IUuidGenerator | ||
{ | ||
/** | ||
* @var string $namespace | ||
* The UUID for this namespace. | ||
*/ | ||
protected $namespace; | ||
|
||
/** | ||
* @param string $namespace | ||
* The initial namespace for the Uuid Generator. | ||
*/ | ||
public function __construct($namespace = NULL) { | ||
// Give sensible default namespace if none is provided. | ||
if (empty($namespace)) { | ||
$namespace = "islandora.ca"; | ||
} | ||
|
||
// If we are passed a namespace UUID don't generate it. | ||
if (Uuid::isValid($namespace)) { | ||
$this->namespace = $namespace; | ||
} | ||
// Otherwise generate a namespace UUID from the passed in namespace. | ||
else { | ||
$this->namespace = Uuid::uuid5(Uuid::NAMESPACE_DNS, $namespace); | ||
} | ||
} | ||
|
||
/** | ||
* Generates a v4 UUID. | ||
* | ||
* @return String Valid v4 UUID. | ||
*/ | ||
public function generateV4() { | ||
return Uuid::uuid4()->toString(); | ||
} | ||
|
||
/** | ||
* Generates a v5 UUID. | ||
* | ||
* @param string $str | ||
* The word to generate the UUID with. | ||
* @param string $namespace | ||
* A namespace | ||
* @return String Valid v5 UUID. | ||
*/ | ||
public function generateV5($str, $namespace = NULL) { | ||
// Use default namespace if none is provided. | ||
if (!empty($namespace)) { | ||
// Is this a UUID already? | ||
if (Uuid::isValid($namespace)) { | ||
return Uuid::uuid5($namespace, $str)->toString(); | ||
} | ||
else { | ||
return Uuid::uuid5(Uuid::uuid5(Uuid::NAMESPACE_DNS, $namespace), $str)->toString(); | ||
} | ||
} | ||
else { | ||
return Uuid::uuid5($this->namespace, $str)->toString(); | ||
} | ||
} | ||
|
||
} |