Overview

Namespaces

  • Charcoal
    • Loader
    • Model
      • Service
      • ServiceProvider
    • Source
      • Database
    • Validator

Classes

  • Charcoal\Loader\CollectionLoader
  • Charcoal\Loader\FileLoader
  • Charcoal\Model\AbstractMetadata
  • Charcoal\Model\AbstractModel
  • Charcoal\Model\Collection
  • Charcoal\Model\Model
  • Charcoal\Model\ModelMetadata
  • Charcoal\Model\ModelValidator
  • Charcoal\Model\Service\MetadataLoader
  • Charcoal\Model\Service\ModelBuilder
  • Charcoal\Model\Service\ModelLoader
  • Charcoal\Model\Service\ModelLoaderBuilder
  • Charcoal\Model\ServiceProvider\ModelServiceProvider
  • Charcoal\Source\AbstractSource
  • Charcoal\Source\Database\DatabaseFilter
  • Charcoal\Source\Database\DatabaseOrder
  • Charcoal\Source\Database\DatabasePagination
  • Charcoal\Source\DatabaseSource
  • Charcoal\Source\DatabaseSourceConfig
  • Charcoal\Source\Filter
  • Charcoal\Source\Order
  • Charcoal\Source\Pagination
  • Charcoal\Source\SourceConfig
  • Charcoal\Validator\AbstractValidator
  • Charcoal\Validator\ValidatorResult

Interfaces

  • Charcoal\Model\CollectionInterface
  • Charcoal\Model\DescribableInterface
  • Charcoal\Model\MetadataInterface
  • Charcoal\Model\ModelInterface
  • Charcoal\Source\DatabaseSourceInterface
  • Charcoal\Source\FilterInterface
  • Charcoal\Source\OrderInterface
  • Charcoal\Source\PaginationInterface
  • Charcoal\Source\SourceInterface
  • Charcoal\Source\StorableInterface
  • Charcoal\Validator\ValidatableInterface
  • Charcoal\Validator\ValidatorInterface

Traits

  • Charcoal\Model\DescribableTrait
  • Charcoal\Source\StorableTrait
  • Charcoal\Validator\ValidatableTrait
  • Overview
  • Namespace
  • Class
  1: <?php
  2: 
  3: namespace Charcoal\Model;
  4: 
  5: use \InvalidArgumentException;
  6: 
  7: // From 'charcoal-core'
  8: use \Charcoal\Model\AbstractMetadata;
  9: 
 10: /**
 11:  *
 12:  */
 13: class ModelMetadata extends AbstractMetadata
 14: {
 15:     /**
 16:      * The metadata identifier.
 17:      *
 18:      * @var string
 19:      */
 20:     private $ident;
 21: 
 22:     /**
 23:      * The model's sources.
 24:      *
 25:      * @var array
 26:      */
 27:     private $sources;
 28: 
 29:     /**
 30:      * The model's default source.
 31:      *
 32:      * @var string
 33:      */
 34:     private $defaultSource;
 35: 
 36:     /**
 37:      * Set the metadata identifier.
 38:      *
 39:      * @param  string $ident The metadata identifier.
 40:      * @throws InvalidArgumentException If identifier is not a string.
 41:      * @return StructureMetadata Chainable
 42:      */
 43:     public function setIdent($ident)
 44:     {
 45:         if (!is_string($ident)) {
 46:             throw new InvalidArgumentException(
 47:                 sprintf(
 48:                     '[%s] Identifier must be a string; received %s',
 49:                     get_called_class(),
 50:                     (is_object($ident) ? get_class($ident) : gettype($ident))
 51:                 )
 52:             );
 53:         }
 54: 
 55:         $this->ident = $ident;
 56: 
 57:         return $this;
 58:     }
 59: 
 60:     /**
 61:      * Retrieve the metadata identifier.
 62:      *
 63:      * @return string
 64:      */
 65:     public function ident()
 66:     {
 67:         return $this->ident;
 68:     }
 69: 
 70:     /**
 71:      * @param array $sources The available sources for this model.
 72:      * @return ModelMetadata Chainable
 73:      */
 74:     public function setSources(array $sources)
 75:     {
 76:         foreach ($sources as $sourceIdent => $source) {
 77:             $this->addSource($sourceIdent, $source);
 78:         }
 79:         return $this;
 80:     }
 81: 
 82:     /**
 83:      * @return array
 84:      */
 85:     public function sources()
 86:     {
 87:         return $this->sources;
 88:     }
 89: 
 90:     /**
 91:      * @param string $sourceIdent The source identifier.
 92:      * @param mixed  $source      The source data.
 93:      * @return ModelMetadata Chainable
 94:      */
 95:     public function addSource($sourceIdent, $source)
 96:     {
 97:         $this->sources[$sourceIdent] = $source;
 98:         return $this;
 99:     }
100: 
101:     /**
102:      * @param string $sourceIdent The source identifier to get.
103:      * @return mixed
104:      */
105:     public function source($sourceIdent)
106:     {
107:         return $this->sources[$sourceIdent];
108:     }
109: 
110:     /**
111:      * @param string $defaultSource The default source identifier.
112:      * @throws InvalidArgumentException If the argument is not a string.
113:      * @return ModelMetadata Chainable
114:      */
115:     public function setDefaultSource($defaultSource)
116:     {
117:         if (!is_string($defaultSource)) {
118:             throw new InvalidArgumentException(
119:                 'Default source needs to be a string.'
120:             );
121:         }
122:         $this->defaultSource = $defaultSource;
123:         return $this;
124:     }
125: 
126:     /**
127:      * @return string
128:      */
129:     public function defaultSource()
130:     {
131:         return $this->defaultSource;
132:     }
133: }
134: 
API documentation generated by ApiGen