Example #1
0
 /**
  * @param Client  $client
  * @param Project $project
  * @param array   $data
  * @return Event
  */
 public static function fromArray(Client $client, Project $project, array $data)
 {
     $event = new static($project, $client);
     if (isset($data['author_id'])) {
         $data['author'] = new User($data['author_id'], $client);
     }
     return $event->hydrate($data);
 }
Example #2
0
 /**
  * @param Client  $client
  * @param Project $project
  * @param array   $data
  * @return Snippet
  */
 public static function fromArray(Client $client, Project $project, array $data)
 {
     $snippet = new static($project, $data['id'], $client);
     if (isset($data['author'])) {
         $data['author'] = User::fromArray($client, $data['author']);
     }
     return $snippet->hydrate($data);
 }
Example #3
0
 /**
  * @param Client $client
  * @param Noteable $type
  * @param array $data
  * @return mixed
  */
 public static function fromArray(Client $client, Noteable $type, array $data)
 {
     $comment = new static($type, $client);
     if (isset($data['author'])) {
         $data['author'] = User::fromArray($client, $data['author']);
     }
     return $comment->hydrate($data);
 }
Example #4
0
 /**
  * @param Client  $client
  * @param Project $project
  * @param array   $data
  * @return Branch
  */
 public static function fromArray(Client $client, Project $project, array $data)
 {
     $branch = new static($project, $data['name'], $client);
     if (isset($data['commit'])) {
         $data['commit'] = Commit::fromArray($client, $project, $data['commit']);
     }
     return $branch->hydrate($data);
 }
 /**
  * @param \GitlabCI\Client $oClient
  * @param array $aData
  * @return \GitlabCI\Model\Project
  * @throws \GitlabCI\Exception\InvalidArgumentException
  */
 public static function fromArray(\GitlabCI\Client $oClient, array $aData)
 {
     if (empty($aData['id'])) {
         throw new \GitlabCI\Exception\InvalidArgumentException('Data "id" is empty');
     }
     $oProject = new static($aData['id']);
     $oProject->setClient($oClient);
     return $oProject->hydrate($aData);
 }
Example #6
0
 /**
  * @param Client $client
  * @param array $data
  * @return Project
  */
 public static function fromArray(Client $client, array $data)
 {
     $project = new static($data['id']);
     $project->setClient($client);
     if (isset($data['owner'])) {
         $data['owner'] = User::fromArray($client, $data['owner']);
     }
     if (isset($data['namespace']) && is_array($data['namespace'])) {
         $data['namespace'] = ProjectNamespace::fromArray($client, $data['namespace']);
     }
     return $project->hydrate($data);
 }
Example #7
0
 /**
  * @param Client $client
  * @param array  $data
  * @return Group
  */
 public static function fromArray(Client $client, array $data)
 {
     $group = new static($data['id'], $client);
     if (isset($data['projects'])) {
         $projects = array();
         foreach ($data['projects'] as $project) {
             $projects[] = Project::fromArray($client, $project);
         }
         $data['projects'] = $projects;
     }
     return $group->hydrate($data);
 }
 public static function hasCustomFields($postType = null, callable $addMeta = null, callable $save = null)
 {
     $addMeta = $addMeta ?: function ($type, $wpPost) use($postType) {
         $post = new static($wpPost->ID);
         $post->hydrate();
         $post->registerFields($postType);
     };
     $save = $save ?: function ($id, $wpPost, $update) {
         $post = new static($id);
         $saved = $post->save();
     };
     // TODO use post-specific action, e.g. add_meta_boxes_post...
     add_action('add_meta_boxes', $addMeta, Plugin::ACTION_PRIORITY, $numArgs = 2);
     add_action('save_post', $save, Plugin::ACTION_PRIORITY, $numArgs = 3);
 }
Example #9
0
 /**
  * @param Client  $client
  * @param Project $project
  * @param array   $data
  * @return Commit
  */
 public static function fromArray(Client $client, Project $project, array $data)
 {
     $commit = new static($project, $data['id'], $client);
     if (isset($data['parents'])) {
         $parents = array();
         foreach ($data['parents'] as $parent) {
             $parents[] = static::fromArray($client, $project, $parent);
         }
         $data['parents'] = $parents;
     }
     if (isset($data['author'])) {
         $data['author'] = User::fromArray($client, $data['author']);
     }
     if (isset($data['committer'])) {
         $data['committer'] = User::fromArray($client, $data['committer']);
     }
     return $commit->hydrate($data);
 }
Example #10
0
 /**
  * @param Client  $client
  * @param Project $project
  * @param array   $data
  * @return MergeRequest
  */
 public static function fromArray(Client $client, Project $project, array $data)
 {
     $mr = new static($project, $data['id'], $client);
     if (isset($data['author'])) {
         $data['author'] = User::fromArray($client, $data['author']);
     }
     if (isset($data['assignee'])) {
         $data['assignee'] = User::fromArray($client, $data['assignee']);
     }
     if (isset($data['milestone'])) {
         $data['milestone'] = Milestone::fromArray($client, $project, $data['milestone']);
     }
     if (isset($data['files'])) {
         $files = array();
         foreach ($data['files'] as $file) {
             $files[] = File::fromArray($client, $project, $file);
         }
         $data['files'] = $files;
     }
     return $mr->hydrate($data);
 }
Example #11
0
 /**
  * @param Client $client
  * @param Project $project
  * @param array $data
  * @return Comparison
  */
 public static function fromArray(Client $client, Project $project, array $data)
 {
     $file = new static($project, $client);
     if (isset($data['commit'])) {
         $data['commit'] = Commit::fromArray($client, $project, $data['commit']);
     }
     if (isset($data['commits'])) {
         $commits = array();
         foreach ($data['commits'] as $commit) {
             $commits[] = Commit::fromArray($client, $project, $commit);
         }
         $data['commits'] = $commits;
     }
     if (isset($data['diffs'])) {
         $diffs = array();
         foreach ($data['diffs'] as $diff) {
             $diffs[] = Diff::fromArray($client, $project, $diff);
         }
         $data['diffs'] = $diffs;
     }
     return $file->hydrate($data);
 }
Example #12
0
 /**
  * Find one model from criteria
  *
  * @param array $where - associative array ex:
  *                     simple criteria        array('idMarque' => 1)
  *                     custom operator        array('idMarque' => array('operator' => '<=','value' => ''))
  *                     raw SQL                array('idMarque' => array('IN (5,6,4)'))
  * @param array $order - associative array ex:array('libMarque'=>'ASC')
  *
  * @return static
  */
 public static function findOne($where = array(), $order = array())
 {
     // try to fetch a model from database
     if ($dataModel = self::select(array('*'), $where, $order, 1)) {
         // hydrate new model instance with fetched data
         $model = new static();
         $model->hydrate($dataModel);
         return $model;
     } else {
         return null;
     }
 }
Example #13
0
 /**
  * @param $newKey
  *
  * @return static
  */
 public function saveAsNew($newKey = null)
 {
     $new = new static();
     // hydrate new mapper with existing values
     $new->hydrate(call_user_func('get_object_vars', $this));
     // hydrate new mapper with specified keys
     $new->setId($newKey);
     // unset autoTimestamps
     if (static::useAutoTimestamp()) {
         $new->updatedAt = null;
         $new->createdAt = null;
     }
     $new->save();
     return $new;
 }
Example #14
0
 /**
  * @param Client $client
  * @param array  $data
  * @return User
  */
 public static function fromArray(Client $client, array $data)
 {
     $id = isset($data['id']) ? $data['id'] : 0;
     $user = new static($id, $client);
     return $user->hydrate($data);
 }
 /**
  * @param ConfigItemResponse $item
  *
  * @return static
  */
 public static function createFromResponse(ConfigItemResponse $item)
 {
     $config = new static();
     $config->hydrate($item);
     return $config;
 }
Example #16
0
 /**
  * @param Client  $client
  * @param Project $project
  * @param array   $data
  * @return Node
  */
 public static function fromArray(Client $client, Project $project, array $data)
 {
     $node = new static($project, $data['id'], $client);
     return $node->hydrate($data);
 }
Example #17
0
 public static function make($data)
 {
     $object = new static();
     $object->hydrate($data);
     return $object;
 }
Example #18
0
 /**
  * Create a new response object and hydrate with data
  *
  * @param $data
  *
  * @return static
  */
 public static function make($data)
 {
     $response = new static();
     $response->hydrate($data);
     return $response;
 }
 public static function fromArray(Client $client, array $data)
 {
     $item = new static($data['id']);
     $item->setClient($client);
     return $item->hydrate($data);
 }
Example #20
0
 /**
  * @param Client $client
  * @param Project $project
  * @param array $data
  * @return Diff
  */
 public static function fromArray(Client $client, Project $project, array $data)
 {
     $diff = new static($project, $client);
     return $diff->hydrate($data);
 }
 /**
  * @param array $data
  * @return GenericEntity
  */
 public static function create(array $data = array())
 {
     $entity = new static();
     $entity->hydrate($data);
     return $entity;
 }
Example #22
0
 public function saveAsNew($newKey = null)
 {
     $new = new static();
     $new->hydrate(call_user_func('get_object_vars', $this));
     $new->setId($newKey);
     $new->save();
     return $new;
 }
Example #23
0
 /**
  * @param Client $client
  * @param Project $project
  * @param array $data
  * @return Contributor
  */
 public static function fromArray(Client $client, Project $project, array $data)
 {
     $contributor = new static($project, $client);
     return $contributor->hydrate($data);
 }
Example #24
0
 /**
  * Find a single object within this Collection meeting the specified criteria.
  *
  * @param array|\Closure $criteria The criteria for selecting the object from the Collection.
  * @param array          $fields An array of fields to be returned from the object.
  * All fields are returned if not provided.
  * @param Repository     $repository A specific Repository to find the object in.
  *
  * @return Persistent|null The Persistent object meeting the criteria or null.
  */
 public static function findOne($criteria, array $fields = array(), Repository $repository = null)
 {
     $instance = null;
     if ($model = static::collection($repository)->findOne($criteria, $fields)) {
         /** @var Persistent $instance */
         $instance = new static($repository);
         $instance->hydrate($model);
     }
     return $instance;
 }
Example #25
0
 /**
  * @param Client $client
  * @param array  $data
  * @return Session
  */
 public static function fromArray(Client $client, array $data)
 {
     $session = new static($client);
     return $session->hydrate($data);
 }
Example #26
0
 /**
  * @param Client $client
  * @param array  $data
  * @return Hook
  */
 public static function fromArray(Client $client, array $data)
 {
     $hook = new static($data['id'], $client);
     return $hook->hydrate($data);
 }
Example #27
0
 /**
  * @param Client $client
  * @param Project $project
  * @param array $data
  * @return File
  */
 public static function fromArray(Client $client, Project $project, array $data)
 {
     $file = new static($project, $data['file_path'], $client);
     return $file->hydrate($data);
 }