Overview

Namespaces

  • NGS
    • Client
      • Exception
    • Converter
    • Patterns
  • PHP

Classes

  • AggregateDomainEvent
  • AggregateRoot
  • CubeBuilder
  • DomainEvent
  • GenericSearch
  • Identifiable
  • OlapCube
  • Repository
  • Search
  • Searchable
  • SearchBuilder
  • Snapshot
  • Specification
  • Templater

Interfaces

  • IDomainObject
  • IIdentifiable
  • Overview
  • Namespace
  • Class
  • Tree
 1: <?php
 2: namespace NGS\Patterns;
 3: 
 4: require_once(__DIR__.'/Searchable.php');
 5: require_once(__DIR__.'/IIdentifiable.php');
 6: require_once(__DIR__.'/../Client/DomainProxy.php');
 7: require_once(__DIR__.'/../Client/CrudProxy.php');
 8: require_once(__DIR__.'/../Converter/PrimitiveConverter.php');
 9: 
10: use NGS\Converter\PrimitiveConverter;
11: use NGS\Client\DomainProxy;
12: use NGS\Client\CrudProxy;
13: 
14: /**
15:  * Domain object uniquely represented by its URI.
16:  * Entity and snowflake are example of domain objects which are
17:  * identified by it's identity, instead of values.
18:  * While entity does not implement Identifiable, aggregate root does.
19:  */
20: abstract class Identifiable extends Searchable implements IIdentifiable
21: {
22:     /**
23:      * Finds one or more objects by one or more URIs.
24:      * @param string|array Single string or array of strings representing URIs
25:      * @return Object if single string is given, or array of objects
26:      * @throws NotFoundException When argument is a single string URI and object
27:      * is not found.
28:      */
29:     public static function find($uri)
30:     {
31:         if(is_array($uri)) {
32:             $uri = PrimitiveConverter::toStringArray($uri);
33:             return DomainProxy::instance()->find(get_called_class(), $uri);
34:         }
35:         $uri = PrimitiveConverter::toString($uri);
36:         return CrudProxy::instance()->read(get_called_class(), $uri);
37:     }
38: 
39:     /**
40:      * Checks if object with given URI exists. It won't throw an exception if
41:      * object is not found (as Identifiable::find would).
42:      * @param string $uri Object URI
43:      * @return bool True if object was found, false otherwise.
44:      */
45:     public static function exists($uri)
46:     {
47:         $uri = PrimitiveConverter::toString($uri);
48:         $res = self::find(array($uri));
49:         return !empty($res);
50:     }
51: }
52: 
API documentation generated by ApiGen 2.8.0