How to use checkOpenMode method of controller class

Best Atoum code snippet using controller.checkOpenMode

controller.php

Source:controller.php Github

copy

Full Screen

...80 $this->offset = null;81 $this->append = false;82 $isOpened = false;83 $reportErrors = ($options & STREAM_REPORT_ERRORS) == STREAM_REPORT_ERRORS;84 if (self::checkOpenMode($mode) === false)85 {86 if ($reportErrors === true)87 {88 trigger_error('Operation timed out', E_USER_WARNING);89 }90 }91 else92 {93 $this->setOpenMode($mode);94 switch (true)95 {96 case $this->read === true && $this->write === false:97 $isOpened = $this->checkIfReadable();98 break;99 case $this->read === false && $this->write === true:100 $isOpened = $this->checkIfWritable();101 break;102 default:103 $isOpened = $this->checkIfReadable() && $this->checkIfWritable();104 }105 if ($isOpened === false)106 {107 if ($reportErrors === true)108 {109 trigger_error('Permission denied', E_USER_WARNING);110 }111 }112 else113 {114 switch (self::getRawOpenMode($mode))115 {116 case 'w':117 $this->exists = true;118 $this->truncate(0);119 $this->seek(0);120 break;121 case 'r':122 $isOpened = $this->exists;123 if ($isOpened === true)124 {125 $this->seek(0);126 }127 else if ($reportErrors === true)128 {129 trigger_error('No such file or directory', E_USER_WARNING);130 }131 break;132 case 'c':133 $this->exists = true;134 $this->seek(0);135 break;136 case 'x':137 if ($this->exists === false)138 {139 $this->seek(0);140 }141 else142 {143 $isOpened = false;144 if ($reportErrors === true)145 {146 trigger_error('File exists', E_USER_WARNING);147 }148 }149 break;150 case 'a':151 $this->exists = true;152 if ($this->read === true)153 {154 $this->seek(0);155 }156 else157 {158 $this->seek(0, SEEK_END);159 $this->offset = $this->pointer;160 }161 $this->append = true;162 break;163 }164 }165 }166 $openedPath = null;167 if ($isOpened === true && ($options & STREAM_USE_PATH))168 {169 $openedPath = $this->getPath();170 }171 return $isOpened;172 }173 }174 public function stream_seek($offset, $whence = SEEK_SET)175 {176 if ($this->nextCallIsOverloaded(__FUNCTION__) === true)177 {178 return $this->invoke(__FUNCTION__, func_get_args());179 }180 else181 {182 $this->addCall(__FUNCTION__, func_get_args());183 return $this->seek($offset, $whence);184 }185 }186 public function stream_eof()187 {188 if ($this->nextCallIsOverloaded(__FUNCTION__) === true)189 {190 return $this->invoke(__FUNCTION__, func_get_args());191 }192 else193 {194 $this->addCall(__FUNCTION__, array());195 return $this->eof;196 }197 }198 public function stream_tell()199 {200 if ($this->nextCallIsOverloaded(__FUNCTION__) === true)201 {202 return $this->invoke(__FUNCTION__, array());203 }204 else205 {206 $this->addCall(__FUNCTION__, array());207 return ($this->offset === null ? $this->pointer : $this->pointer - $this->offset);208 }209 }210 public function stream_read($count)211 {212 if ($this->nextCallIsOverloaded(__FUNCTION__) === true)213 {214 return $this->invoke(__FUNCTION__, func_get_args());215 }216 else217 {218 $this->addCall(__FUNCTION__, func_get_args());219 $data = '';220 $this->eof = ($this->pointer < 0 || $this->pointer >= $this->stat['size']);221 if ($this->read === true && $this->pointer >= 0 && $this->eof === false)222 {223 $data = substr($this->contents, $this->pointer, $count) ?: '';224 $this->movePointer(strlen($data) ?: $count);225 }226 return $data;227 }228 }229 public function stream_write($data)230 {231 if ($this->nextCallIsOverloaded(__FUNCTION__) === true)232 {233 return $this->invoke(__FUNCTION__, func_get_args());234 }235 else236 {237 $this->addCall(__FUNCTION__, func_get_args());238 $bytesWrited = 0;239 if ($this->write === true)240 {241 $contents = $this->getContents();242 if ($this->append === true)243 {244 if ($contents !== '')245 {246 $contents .= PHP_EOL;247 $this->movePointer(1);248 }249 $this->append = false;250 }251 $this252 ->setContents($contents . $data)253 ->movePointer($bytesWrited = strlen($data))254 ;255 }256 return $bytesWrited;257 }258 }259 public function stream_flush()260 {261 return true;262 }263 public function stream_metadata($path, $option, $value)264 {265 if ($this->nextCallIsOverloaded(__FUNCTION__) === true)266 {267 return $this->invoke(__FUNCTION__, func_get_args());268 }269 else270 {271 $this->addCall(__FUNCTION__, func_get_args());272 switch ($option)273 {274 case STREAM_META_TOUCH:275 case STREAM_META_OWNER_NAME:276 case STREAM_META_OWNER:277 case STREAM_META_GROUP_NAME:278 case STREAM_META_GROUP:279 return true;280 case STREAM_META_ACCESS:281 $this->setPermissions($value);282 return true;283 default:284 return false;285 }286 }287 }288 public function stream_truncate($newSize)289 {290 if ($this->nextCallIsOverloaded(__FUNCTION__) === true)291 {292 return $this->invoke(__FUNCTION__, func_get_args());293 }294 else295 {296 $this->addCall(__FUNCTION__, func_get_args());297 return $this->truncate($newSize);298 }299 }300 public function stream_lock($mode)301 {302 if ($this->nextCallIsOverloaded(__FUNCTION__) === true)303 {304 return $this->invoke(__FUNCTION__, func_get_args());305 }306 else307 {308 $this->addCall(__FUNCTION__, func_get_args());309 return true;310 }311 }312 public function stream_close()313 {314 if ($this->nextCallIsOverloaded(__FUNCTION__) === true)315 {316 return $this->invoke(__FUNCTION__, array());317 }318 else319 {320 $this->addCall(__FUNCTION__, array());321 return true;322 }323 }324 public function unlink($path)325 {326 if ($this->nextCallIsOverloaded(__FUNCTION__) === true)327 {328 return $this->invoke(__FUNCTION__, func_get_args());329 }330 else331 {332 $this->addCall(__FUNCTION__, func_get_args());333 if ($this->exists === false || $this->checkIfWritable() === false)334 {335 return false;336 }337 else338 {339 $this->exists = false;340 return true;341 }342 }343 }344 public function rename($from, $to)345 {346 if ($this->nextCallIsOverloaded(__FUNCTION__) === true)347 {348 return $this->invoke(__FUNCTION__, func_get_args());349 }350 else351 {352 $this->addCall(__FUNCTION__, func_get_args());353 $this->setPath($to);354 return true;355 }356 }357 public function mkdir($path, $mode, $options)358 {359 return false;360 }361 public function dir_opendir($path, $options)362 {363 return false;364 }365 public function dir_readdir()366 {367 return false;368 }369 public function dir_rewinddir()370 {371 return false;372 }373 public function dir_closedir()374 {375 return false;376 }377 public function rmdir($path, $options)378 {379 return false;380 }381 protected function truncate($newSize)382 {383 $this->setContents(str_pad(substr($this->contents, 0, $newSize), $newSize, "\0"));384 return true;385 }386 protected function seek($offset, $whence = SEEK_SET)387 {388 switch ($whence)389 {390 case SEEK_CUR:391 $offset = $this->pointer + $offset;392 break;393 case SEEK_END:394 $offset = strlen($this->getContents()) + $offset;395 }396 if ($this->offset !== null && $offset < $this->offset)397 {398 $offset = $this->offset;399 }400 $this->setPointer($offset);401 return true;402 }403 protected function setOpenMode($mode)404 {405 $this->read = false;406 $this->write = false;407 switch (str_replace(array('b', 't'), '', $mode))408 {409 case 'r':410 case 'x':411 $this->read = true;412 break;413 case 'w':414 case 'a':415 case 'c':416 $this->write = true;417 break;418 case 'r+':419 case 'x+':420 case 'w+':421 case 'a+':422 case 'c+':423 $this->read = $this->write = true;424 }425 return $this;426 }427 protected function setPointer($pointer)428 {429 $this->pointer = $pointer;430 $this->eof = false;431 return $this;432 }433 protected function movePointer($offset)434 {435 return $this->setPointer($this->pointer + $offset);436 }437 protected static function getRawOpenMode($mode)438 {439 return str_replace(array('b', 't', '+'), '', $mode);440 }441 protected static function checkOpenMode($mode)442 {443 switch (self::getRawOpenMode($mode))444 {445 case 'r':446 case 'w':447 case 'a':448 case 'x':449 case 'c':450 return true;451 default:452 return false;453 }454 }455}...

Full Screen

Full Screen

checkOpenMode

Using AI Code Generation

copy

Full Screen

1$controller = new Controller();2$controller->checkOpenMode();3Your name to display (optional):4Your name to display (optional):5include 'controller.php';6Your name to display (optional):

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Atoum automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in controller

Trigger checkOpenMode code on LambdaTest Cloud Grid

Execute automation tests with checkOpenMode on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful