Hoa central
Link.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\File\Link;
38 
39 use Hoa\Core;
40 use Hoa\File;
41 
50 class Link extends File
51 {
64  public function __construct(
65  $streamName,
66  $mode,
67  $context = null,
68  $wait = false
69  ) {
70  if (!is_link($streamName)) {
71  throw new File\Exception(
72  'File %s is not a link.',
73  0,
74  $streamName
75  );
76  }
77 
78  parent::__construct($streamName, $mode, $context, $wait);
79 
80  return;
81  }
82 
88  public function getStatistic()
89  {
90  return lstat($this->getStreamName());
91  }
92 
99  public function changeGroup($group)
100  {
101  return lchgrp($this->getStreamName(), $group);
102  }
103 
110  public function changeOwner($user)
111  {
112  return lchown($this->getStreamName(), $user);
113  }
114 
120  public function getPermissions()
121  {
122  return 41453; // i.e. lrwxr-xr-x
123  }
124 
131  public function getTarget()
132  {
133  $target = dirname($this->getStreamName()) . DS .
134  $this->getTargetName();
135  $context = null !== $this->getStreamContext()
136  ? $this->getStreamContext()->getCurrentId()
137  : null;
138 
139  if (true === is_link($target)) {
140  return new ReadWrite(
141  $target,
143  $context
144  );
145  } elseif (true === is_file($target)) {
146  return new File\ReadWrite(
147  $target,
149  $context
150  );
151  } elseif (true === is_dir($target)) {
152  return new File\Directory(
153  $target,
155  $context
156  );
157  }
158 
159  throw new File\Exception(
160  'Cannot find an appropriated object that matches with ' .
161  'path %s when defining it.',
162  1,
163  $target
164  );
165  }
166 
172  public function getTargetName()
173  {
174  return readlink($this->getStreamName());
175  }
176 
184  public static function create($name, $target)
185  {
186  if (false != linkinfo($name)) {
187  return true;
188  }
189 
190  return symlink($target, $name);
191  }
192 }
193 
197 Core\Consistency::flexEntity('Hoa\File\Link\Link');
const MODE_READ
Definition: File.php:62
changeGroup($group)
Definition: Link.php:99
static create($name, $target)
Definition: Link.php:184
const MODE_APPEND_READ_WRITE
Definition: File.php:104
__construct($streamName, $mode, $context=null, $wait=false)
Definition: Link.php:64
changeOwner($user)
Definition: Link.php:110