Exemple #1
0
 /**
  * @param array $tags
  * @return null
  */
 public function getFlushTags(array &$tags)
 {
     $unique = $this->Model->getUnique();
     if (in_array($unique, $tags)) {
         return null;
     }
     $tags[] = $unique;
     foreach ($this->Model->getDefinition()->getRelations() as $relation) {
         $relation->Model->cache()->getFlushTags($tags);
     }
 }
Exemple #2
0
 /**
  * Defines: Model, key, prefix, as, asProp, skip, attributes, where, required, children.
  * @param Model $Model
  * @param array $params
  * @param null|stdClass $parent
  * @return stdClass
  */
 private function createNode(Model $Model, array $params = [], stdClass $parent = null)
 {
     $node = new stdClass();
     $node->Model = $Model;
     $node->key = $Model->getUnique();
     $node->prefix = null;
     $node->asProp = null;
     # Handle `as`:
     $node->as = null;
     if (isset($params['as'])) {
         $node->as = $params['as'];
         $node->key .= Extras::GLUE_CHAR . $params['as'];
     }
     # Handle `attributes`:
     $node->skip = [];
     $attrs = array_keys($Model->getDefinition()->getAttributes());
     # Handle timestamps:
     if ($Model->isTimestamps()) {
         $attrs[] = $Model->getCreatedAtAttr();
         $attrs[] = $Model->getUpdatedAtAttr();
     }
     # Handle attributes in options:
     if (isset($params['attributes']) && $params['attributes']) {
         $attrs = array_intersect($attrs, $params['attributes']);
     }
     if (!in_array('id', $attrs)) {
         array_unshift($attrs, 'id');
         $node->skip[] = 'id';
     }
     $node->attributes = $attrs;
     # Handle `where`:
     $node->where = isset($params['where']) ? $params['where'] : [];
     # Handle `required`:
     $node->required = isset($params['required']) ? (bool) $params['required'] : null;
     # Handle `include`:
     !$parent ?: $this->handleRelation($parent, $node);
     $this->handleChildren($node, $params);
     return $node;
 }
Exemple #3
0
 /**
  * @param string $type
  * @param Model $Model
  * @param array $options
  * @return stdClass
  */
 private static function performRelation($type, $Model, array $options = [])
 {
     $as = isset($options['as']) ? $options['as'] : null;
     if (array_key_exists('foreignKey', $options)) {
         $foreignKey = $options['foreignKey'];
     } else {
         $className = get_class($Model->getDefinition());
         if ($pos = strrpos($className, '\\')) {
             $className = substr($className, $pos + 1);
         }
         $foreignKey = Inflector::tableize($className) . '_id';
     }
     $relatedKey = $Model->getUnique();
     !$as ?: ($relatedKey .= Extras::GLUE_CHAR . $as);
     $relation = new stdClass();
     $relation->Model = $Model;
     // required for cache
     $relation->type = $type;
     $relation->as = $as;
     $relation->foreignKey = $foreignKey;
     $relation->relatedKey = $relatedKey;
     return $relation;
 }