sentence1
stringlengths
52
3.87M
sentence2
stringlengths
1
47.2k
label
stringclasses
1 value
public function getClassMetadata($class) { return array_key_exists($class, $this->classMetadatas) ? $this->classMetadatas[$class] : $this->classMetadatas[$class] = $this->fetchClassMetadata($class); }
{@inheritdoc}
entailment
public function activate(Composer $composer, IOInterface $io) { $this->composer = $composer; $this->io = $io; $this->options = new Options($composer); // Set sane defaults for Drupal installer paths. $composer_installers_helper = new ComposerInstallersHelper($composer, $this->options); $composer_installers_helper->setInstallerPaths(); }
{@inheritdoc}
entailment
public static function getSubscribedEvents() { // Set the priorities so that cleanup actions are called at the end. return [ PackageEvents::POST_PACKAGE_INSTALL => ['cleanupVendorFiles', -100], PackageEvents::PRE_PACKAGE_INSTALL => ['cleanupVendorFiles', -100], ScriptEvents::POST_INSTALL_CMD => [ ['createDrupalFiles', -1], ['cleanupAdditionalFiles', -100], ], ScriptEvents::POST_UPDATE_CMD => [ ['createDrupalFiles', -1], ['cleanupAdditionalFiles', -100], ], DrupalScaffoldHandler::POST_DRUPAL_SCAFFOLD_CMD => 'createDrupalFiles', ]; }
{@inheritdoc}
entailment
public function serialize($data, $format, ContextInterface $context = null) { return $this->navigate($data, Direction::SERIALIZATION, $format, $context); }
{@inheritdoc}
entailment
public function deserialize($data, $type, $format, ContextInterface $context = null) { if (is_string($type)) { $type = $this->typeParser->parse($type); } if (!$type instanceof TypeMetadataInterface) { throw new \InvalidArgumentException(sprintf( 'The type must be a string or a "%s", got "%s".', TypeMetadataInterface::class, is_object($type) ? get_class($type) : gettype($type) )); } return $this->navigate($data, Direction::DESERIALIZATION, $format, $context, $type); }
{@inheritdoc}
entailment
private function navigate( $data, $direction, $format, ContextInterface $context = null, TypeMetadataInterface $type = null ) { $visitor = $this->visitorRegistry->getVisitor($direction, $format); $context = $context ?: new Context(); $context->initialize($this->navigator, $visitor, $direction, $format); $this->navigator->navigate($visitor->prepare($data, $context), $context, $type); return $visitor->getResult(); }
@param mixed $data @param int $direction @param string $format @param ContextInterface|null $context @param TypeMetadataInterface|null $type @return mixed
entailment
public function prepare($data, ContextInterface $context) { $this->stack = []; $this->result = null; return parent::prepare($data, $context); }
{@inheritdoc}
entailment
public function visitArray($data, TypeMetadataInterface $type, ContextInterface $context) { $result = []; if (!empty($data)) { $this->enterScope(); $result = parent::visitArray($data, $type, $context); $this->leaveScope(); } return $this->visitData($result, $type, $context); }
{@inheritdoc}
entailment
public function visitData($data, TypeMetadataInterface $type, ContextInterface $context) { if ($this->result === null) { $this->result = $data; } return $data; }
{@inheritdoc}
entailment
public function startVisitingObject($data, ClassMetadataInterface $class, ContextInterface $context) { if (!parent::startVisitingObject($data, $class, $context)) { return false; } $this->enterScope(); $this->result = $this->createResult($class->getName()); return true; }
{@inheritdoc}
entailment
public function finishVisitingObject($data, ClassMetadataInterface $class, ContextInterface $context) { parent::finishVisitingObject($data, $class, $context); return $this->leaveScope(); }
{@inheritdoc}
entailment
protected function doVisitArray($data, TypeMetadataInterface $type, ContextInterface $context) { $this->result = []; $keyType = $type->getOption('key'); $valueType = $type->getOption('value'); $ignoreNull = $context->isNullIgnored(); foreach ($data as $key => $value) { $value = $this->navigator->navigate($value, $context, $valueType); if ($value === null && $ignoreNull) { continue; } $key = $this->navigator->navigate($key, $context, $keyType); $this->result[$key] = $value; } return $this->result; }
{@inheritdoc}
entailment
public function useAppDataDriver(string $keyPrefix = '.temp/cache/'): self { $app = App::get(); $this->setDriver(new \BearFramework\App\DataCacheDriver($app->data, $keyPrefix)); return $this; }
Enables the app cache driver. The cached data will be stored in the app data repository. @param string $keyPrefix The key prefix for the cache items. @return self Returns a reference to itself.
entailment
public function setDriver(\BearFramework\App\ICacheDriver $driver): self { if ($this->driver !== null) { throw new \Exception('A cache driver is already set!'); } $this->driver = $driver; return $this; }
Sets a new cache driver. @param \BearFramework\App\ICacheDriver $driver The driver to use for cache storage. @return self Returns a reference to itself. @throws \Exception
entailment
private function getDriver(): \BearFramework\App\ICacheDriver { if ($this->driver !== null) { return $this->driver; } throw new \Exception('No cache driver specified! Use useAppDataDriver() or setDriver() to specify one.'); }
Returns the cache driver. @return \BearFramework\App\ICacheDriver @throws \Exception
entailment
public function make(string $key = null, $value = null): \BearFramework\App\CacheItem { if ($this->newCacheItemCache === null) { $this->newCacheItemCache = new CacheItem(); } $object = clone($this->newCacheItemCache); if ($key !== null) { $object->key = $key; } if ($value !== null) { $object->value = $value; } return $object; }
Constructs a new cache item and returns it. @param string|null $key The key of the cache item. @param string|null $value The value of the cache item. @return \BearFramework\App\CacheItem Returns a new cache item.
entailment
public function set(CacheItem $item): self { $driver = $this->getDriver(); $driver->set($item->key, $item->value, $item->ttl); if ($this->hasEventListeners('itemSet')) { $this->dispatchEvent('itemSet', new \BearFramework\App\Cache\ItemSetEventDetails(clone($item))); } if ($this->hasEventListeners('itemChange')) { $this->dispatchEvent('itemChange', new \BearFramework\App\Cache\ItemChangeEventDetails($item->key)); } return $this; }
Stores a cache item. @param \BearFramework\App\CacheItem $item The cache item to store. @return self Returns a reference to itself.
entailment
public function get(string $key): ?\BearFramework\App\CacheItem { $driver = $this->getDriver(); $item = null; $value = $driver->get($key); if ($value !== null) { $item = $this->make($key, $value); } if ($this->hasEventListeners('itemGet')) { $this->dispatchEvent('itemGet', new \BearFramework\App\Cache\ItemGetEventDetails($key, $item === null ? null : clone($item))); } if ($this->hasEventListeners('itemRequest')) { $this->dispatchEvent('itemRequest', new \BearFramework\App\Cache\ItemRequestEventDetails($key)); } return $item; }
Returns the cache item stored or null if not found. @param string $key The key of the cache item. @return \BearFramework\App\CacheItem|null The cache item stored or null if not found.
entailment
public function getValue(string $key) { $driver = $this->getDriver(); $value = $driver->get($key); if ($this->hasEventListeners('itemGetValue')) { $this->dispatchEvent('itemGetValue', new \BearFramework\App\Cache\ItemGetValueEventDetails($key, $value)); } if ($this->hasEventListeners('itemRequest')) { $this->dispatchEvent('itemRequest', new \BearFramework\App\Cache\ItemRequestEventDetails($key)); } return $value; }
Returns the value of the cache item specified. @param string $key The key of the cache item. @return mixed The value of the cache item or null if not found.
entailment
public function exists(string $key): bool { $driver = $this->getDriver(); $exists = $driver->get($key) !== null; if ($this->hasEventListeners('itemExists')) { $this->dispatchEvent('itemExists', new \BearFramework\App\Cache\ItemExistsEventDetails($key, $exists)); } if ($this->hasEventListeners('itemRequest')) { $this->dispatchEvent('itemRequest', new \BearFramework\App\Cache\ItemRequestEventDetails($key)); } return $exists; }
Returns information whether a key exists in the cache. @param string $key The key of the cache item. @return bool TRUE if the cache item exists in the cache, FALSE otherwise.
entailment
public function delete(string $key): self { $driver = $this->getDriver(); $driver->delete($key); if ($this->hasEventListeners('itemDelete')) { $this->dispatchEvent('itemDelete', new \BearFramework\App\Cache\ItemDeleteEventDetails($key)); } if ($this->hasEventListeners('itemChange')) { $this->dispatchEvent('itemChange', new \BearFramework\App\Cache\ItemChangeEventDetails($key)); } return $this; }
Deletes an item from the cache. @param string $key The key of the cache item. @return self Returns a reference to itself.
entailment
public function clear(): self { $driver = $this->getDriver(); $driver->clear(); if ($this->hasEventListeners('clear')) { $this->dispatchEvent('clear'); } return $this; }
Deletes all values from the cache. @return self Returns a reference to itself.
entailment
protected function loadFile($file) { try { return Yaml::parse(file_get_contents($file)); } catch (ParseException $e) { throw new \InvalidArgumentException($e->getMessage(), $e->getCode(), $e); } }
{@inheritdoc}
entailment
public function make(string $name = null, string $value = null): \BearFramework\App\Response\Header { if ($this->newHeaderCache === null) { $this->newHeaderCache = new \BearFramework\App\Response\Header(); } $object = clone($this->newHeaderCache); if ($name !== null) { $object->name = $name; } if ($value !== null) { $object->value = $value; } return $object; }
Constructs a new header and returns it. @param string|null $name The name of the header. @param string|null $value The value of the header. @return \BearFramework\App\Response\Header Returns a new header.
entailment
public function set(\BearFramework\App\Response\Header $header): self { $this->data[$header->name] = $header; return $this; }
Sets a header. @param \BearFramework\App\Response\Header $header The header to set. @return self Returns a reference to itself.
entailment
public function getValue(string $name): ?string { if (isset($this->data[$name])) { return $this->data[$name]->value; } return null; }
Returns the value of the header or null if not found. @param string $name The name of the header. @return string|null The value of the header requested of null if not found.
entailment
public function getList() { $list = new \BearFramework\DataList(); foreach ($this->data as $header) { $list[] = clone($header); } return $list; }
Returns a list of all headers. @return \BearFramework\DataList|\BearFramework\App\Response\Header[] An array containing all headers.
entailment
public function make(string $name = null, string $value = null): \BearFramework\App\Request\FormDataItem { if ($this->newFormDataItemCache === null) { $this->newFormDataItemCache = new \BearFramework\App\Request\FormDataItem(); } $object = clone($this->newFormDataItemCache); if ($name !== null) { $object->name = $name; } if ($value !== null) { $object->value = $value; } return $object; }
Constructs a new form data item and returns it. @param string|null $name The name of the form data item. @param string|null $value The value of the form data item. @return \BearFramework\App\Request\FormDataItem Returns a new form data item.
entailment
public function set(\BearFramework\App\Request\FormDataItem $dataItem): self { $this->data[$dataItem->name] = $dataItem; return $this; }
Sets a form data item. @param \BearFramework\App\Request\FormDataItem $form data item The form data item to set. @return self Returns a reference to itself.
entailment
public function getFile(string $name): ?\BearFramework\App\Request\FormDataFileItem { if (isset($this->data[$name]) && $this->data[$name] instanceof \BearFramework\App\Request\FormDataFileItem) { return $this->data[$name]; } return null; }
Returns a file data item or null if not found. @param string $name The name of the file data item. @return BearFramework\App\Request\FormDataFileItem|null The file data item requested of null if not found.
entailment
public function getList() { $list = new \BearFramework\DataList(); foreach ($this->data as $formDataItem) { $list[] = clone($formDataItem); } return $list; }
Returns a list of all form data items. @return \BearFramework\DataList|\BearFramework\App\Request\FormDataItem[] An array containing all form data items.
entailment
public function skipProperty(PropertyMetadataInterface $property, ContextInterface $context) { if (!$property->hasGroups()) { return !in_array(self::GROUP_DEFAULT, $this->groups, true); } foreach ($this->groups as $group) { if ($property->hasGroup($group)) { return false; } } return true; }
{@inheritdoc}
entailment
protected function decode($data) { $result = @json_decode($data, true, $this->maxDepth, $this->options); if (json_last_error() !== JSON_ERROR_NONE) { throw new \InvalidArgumentException(json_last_error_msg()); } return $result; }
{@inheritdoc}
entailment
protected function doConvert($name) { $name = str_replace(['--', '__', ' '], ' ', $name); $name = lcfirst(str_replace(['-', '_', ' '], $this->separator, $name)); return strtolower(preg_replace('/([A-Z])/', $this->separator.'$1', $name)); }
{@inheritdoc}
entailment
protected function loadProperty(\ReflectionProperty $property) { $result = []; $type = $this->loadPropertyType($property); if ($type !== null) { $result['type'] = $type; } return $result; }
{@inheritdoc}
entailment
private function loadPropertyType(\ReflectionProperty $property) { if ($this->extractor === null) { return; } $types = $this->extractor->getTypes($property->class, $property->name); if (empty($types)) { return; } $extractedType = current($types); $type = $extractedType->getBuiltinType(); if ($type === 'object') { $type = $extractedType->getClassName(); } return $type; }
@param \ReflectionProperty $property @return string|null
entailment
public function getMappedClasses() { if ($this->data === null) { $this->data = $this->loadFile($this->file); } return array_keys($this->data); }
{@inheritdoc}
entailment
protected function loadData($class) { if ($this->data === null) { $this->data = $this->loadFile($this->file); } if (isset($this->data[$class])) { return $this->data[$class]; } }
{@inheritdoc}
entailment
private function skip(ContextInterface $context) { $dataStack = $context->getDataStack(); $metadataStack = $context->getMetadataStack(); $references = []; $depth = 0; for ($index = count($metadataStack) - 1; $index >= 0; --$index) { $metadata = $metadataStack[$index]; $data = $dataStack[$index]; if ($metadata instanceof ClassMetadataInterface) { $hash = spl_object_hash($data); if (!isset($references[$hash])) { $references[$hash] = 0; } if (++$references[$hash] > $this->circularReferenceLimit) { return true; } } if ($metadata instanceof TypeMetadataInterface) { ++$depth; } if (!$metadata instanceof PropertyMetadataInterface) { continue; } ++$depth; if (!$metadata->hasMaxDepth()) { continue; } if ($depth > $metadata->getMaxDepth()) { return true; } } return false; }
@param ContextInterface $context @return bool
entailment
public function convert($data, TypeMetadataInterface $type, ContextInterface $context) { return $context->getVisitor()->visitString($data, $type, $context); }
{@inheritdoc}
entailment
public function skipProperty(PropertyMetadataInterface $property, ContextInterface $context) { if ($property->hasSinceVersion() && version_compare($property->getSinceVersion(), $this->version, '>')) { return true; } if ($property->hasUntilVersion() && version_compare($property->getUntilVersion(), $this->version, '<')) { return true; } return false; }
{@inheritdoc}
entailment
public function setValue($object, $property, $value) { if (property_exists($object, $property)) { $this->getReflectionProperty($object, $property)->setValue($object, $value); } else { $this->setMethodValue($object, $property, $value); } }
{@inheritdoc}
entailment
private function getReflectionProperty($object, $property) { if (isset($this->properties[$key = $this->getCacheKey($object, $property)])) { return $this->properties[$key]; } $reflection = new \ReflectionProperty($object, $property); $reflection->setAccessible(true); return $this->properties[$key] = $reflection; }
@param object $object @param string $property @return \ReflectionProperty
entailment
private function getReflectionMethod($object, $method) { if (isset($this->methods[$key = $this->getCacheKey($object, $method)])) { return $this->methods[$key]; } $reflection = new \ReflectionMethod($object, $method); $reflection->setAccessible(true); return $this->methods[$key] = $reflection; }
@param object $object @param string $method @return \ReflectionMethod
entailment
public function get(string $filename = null): \BearFramework\App\Context { if ($filename === null) { $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1); if (!isset($trace[0])) { throw new \Exception('Cannot detect context!'); } $filename = $trace[0]['file']; } $filename = \BearFramework\Internal\Utilities::normalizePath($filename); if (isset($this->objectsCache[$filename])) { return clone($this->objectsCache[$filename]); } $matchedDir = null; foreach ($this->dirs as $dir => $length) { if ($dir === $filename . '/' || substr($filename, 0, $length) === $dir) { $matchedDir = $dir; break; } } if ($matchedDir !== null) { if (isset($this->objectsCache[$matchedDir])) { return clone($this->objectsCache[$matchedDir]); } $this->objectsCache[$matchedDir] = new App\Context($this->app, substr($matchedDir, 0, -1)); $this->objectsCache[$filename] = clone($this->objectsCache[$matchedDir]); return clone($this->objectsCache[$matchedDir]); } throw new \Exception('Connot find context for ' . $filename); }
Returns a context object for the filename specified. @param string|null $filename The filename used to find the context. Will be automatically detected if not provided. @throws \Exception @return \BearFramework\App\Context The context object for the filename specified.
entailment
public function add(string $dir): self { $dir = rtrim(\BearFramework\Internal\Utilities::normalizePath($dir), '/') . '/'; if (!isset($this->dirs[$dir])) { $this->dirs[$dir] = strlen($dir); arsort($this->dirs); $indexFilename = $dir . 'index.php'; if (is_file($indexFilename)) { ob_start(); try { (static function($__filename) { include $__filename; })($indexFilename); ob_end_clean(); } catch (\Exception $e) { ob_end_clean(); throw $e; } } else { throw new \Exception('Cannot find index.php file in the dir specified (' . $dir . ')!'); } } return $this; }
Registers a new context. @param string $dir The context dir. @throws \Exception @return self Returns a reference to itself.
entailment
protected function decode($data) { try { return Yaml::parse($data, $this->options); } catch (\Exception $e) { throw new \InvalidArgumentException('Unable to deserialize data.', 0, $e); } }
{@inheritdoc}
entailment
public static function create(array $loaders = []) { if (empty($loaders)) { $extractor = null; if (class_exists(PropertyInfoExtractor::class)) { $extractors = $typeExtractors = [new ReflectionExtractor()]; if (class_exists(ClassReflector::class)) { array_unshift($typeExtractors, new PhpDocExtractor()); } $extractor = new PropertyInfoExtractor($extractors, $typeExtractors, [], $extractors); } $loaders = [new ReflectionClassMetadataLoader($extractor)]; if (class_exists(AnnotationReader::class)) { $loaders[] = new AnnotationClassMetadataLoader(new AnnotationReader()); } } return new static(count($loaders) > 1 ? new ChainClassMetadataLoader($loaders) : array_shift($loaders)); }
@param ClassMetadataLoaderInterface[] $loaders @return ClassMetadataFactoryInterface
entailment
protected function fetchClassMetadata($class) { $classMetadata = new ClassMetadata($class); $found = false; if (($parentMetadata = $this->getParentClassMetadata($class)) !== null) { $classMetadata->merge($parentMetadata); $found = true; } $found = $this->loader->loadClassMetadata($classMetadata) || $found; return $found ? $classMetadata : null; }
{@inheritdoc}
entailment
protected function encode($data) { try { return Yaml::dump($data, $this->inline, $this->indent, $this->options); } catch (\Exception $e) { throw new \InvalidArgumentException('Unable to serialize data.', 0, $e); } }
{@inheritdoc}
entailment
public function receiveAnEmail($params) { $message = $this->fetchLastMessage(); foreach ($params as $param => $value) { $this->assertEquals($value, $message->{$param}); } }
Check if the latest email received contains $params. @param $params @return mixed
entailment
public function fetchMessages() { $messages = $this->client->get("inboxes/{$this->config['inbox_id']}/messages")->getBody(); if ($messages instanceof Stream) { $messages = $messages->getContents(); } $messages = json_decode($messages, true); foreach ($messages as $key => $message) { $messages[$key] = new MailtrapMessage($message, $this->client); } return $messages; }
Get the most recent message of the default inbox. @return array
entailment
public function fetchLastMessages($number = 1) { $messages = $this->fetchMessages(); $firstIndex = count($messages) - $number; $messages = array_slice($messages, $firstIndex, $number); $this->assertCount($number, $messages); return $messages; }
Get the most recent messages of the default inbox. @param int $number @return array
entailment
public function fetchAttachmentsOfLastMessage() { $email = $this->fetchLastMessage(); $response = $this->client->get("inboxes/{$this->config['inbox_id']}/messages/{$email->id}/attachments")->getBody(); return json_decode($response, true); }
Gets the attachments on the last message. @return array
entailment
public function receiveAnEmailFromEmail($senderEmail) { $message = $this->fetchLastMessage(); $this->assertEquals($senderEmail, $message->from_email); }
Check if the latest email received is from $senderEmail. @param $senderEmail @return mixed
entailment
public function receiveAnEmailFromName($senderName) { $message = $this->fetchLastMessage(); $this->assertEquals($senderName, $message->from_name); }
Check if the latest email received is from $senderName. @param $senderName @return mixed
entailment
public function receiveAnEmailToEmail($recipientEmail) { $message = $this->fetchLastMessage(); $this->assertEquals($recipientEmail, $message->to_email); }
Check if the latest email was received by $recipientEmail. @param $recipientEmail @return mixed
entailment
public function receiveAnEmailToName($recipientName) { $message = $this->fetchLastMessage(); $this->assertEquals($recipientName, $message->to_name); }
Check if the latest email was received by $recipientName. @param $recipientName @return mixed
entailment
public function receiveAnEmailWithSubject($subject) { $message = $this->fetchLastMessage(); $this->assertEquals($subject, $message->subject); }
Check if the latest email received has the $subject. @param $subject @return mixed
entailment
public function receiveAnEmailWithTextBody($textBody) { $message = $this->fetchLastMessage(); $this->assertEquals($textBody, $message->text_body); }
Check if the latest email received has the $textBody. @param $textBody @return mixed
entailment
public function receiveAnEmailWithHtmlBody($htmlBody) { $message = $this->fetchLastMessage(); $this->assertEquals($htmlBody, $message->html_body); }
Check if the latest email received has the $htmlBody. @param $htmlBody @return mixed
entailment
public function seeInEmailTextBody($expected) { $email = $this->fetchLastMessage(); $this->assertContains($expected, $email->text_body, 'Email body contains text'); }
Look for a string in the most recent email (Text). @param $expected @return mixed
entailment
public function seeInEmailHtmlBody($expected) { $email = $this->fetchLastMessage(); $this->assertContains($expected, $email->html_body, 'Email body contains HTML'); }
Look for a string in the most recent email (HTML). @param $expected @return mixed
entailment
public function seeInEmailSubject($expected) { $email = $this->fetchLastMessage(); $this->assertContains($expected, $email->subject, 'Email subject contains text'); }
Look for a string in the most recent email subject. @param string $expected @return mixed
entailment
public function seeAttachments($count) { $attachments = $this->fetchAttachmentsOfLastMessage(); $this->assertEquals($count, count($attachments)); }
Look for an attachment on the most recent email. @param $count
entailment
public function seeAnAttachment($bool) { $attachments = $this->fetchAttachmentsOfLastMessage(); $this->assertEquals($bool, count($attachments) > 0); }
Look for an attachment on the most recent email. @param $bool
entailment
public function getBccEmailOfMessage($messageId) { $message = $this->client->get("inboxes/{$this->config['inbox_id']}/messages/$messageId/body.eml")->getBody(); if ($message instanceof Stream) { $message = $message->getContents(); } $matches = []; preg_match('/Bcc:\s[\w.-]+@[\w.-]+\.[a-z]{2,6}/', $message, $matches); $bcc = substr(array_shift($matches), 5); return $bcc; }
Get the bcc property of a message @param int $messageId @return string
entailment
public function waitForEmail($timeout = 5) { $condition = function () { return !empty($this->fetchLastMessage()); }; $message = sprintf('Waited for %d secs but no email has arrived', $timeout); $this->wait($timeout)->until($condition, $message); }
Wait until an email to be received. @param int $timeout @throws \Exception
entailment
public function waitForEmailWithSubject($subject, $timeout = 5) { $condition = function () use ($subject) { $emails = $this->fetchMessages(); foreach ($emails as $email) { $constraint = Assert::equalTo($subject); if ($constraint->evaluate($email->subject, '', true)) { return true; } } return false; }; $message = sprintf('Waited for %d secs but no email with the subject of %s has arrived', $timeout, $subject); $this->wait($timeout)->until($condition, $message); }
Wait until an email has been received with specific text in the text body. @param string $subject @param int $timeout @throws \Exception
entailment
public function waitForEmailWithTextInHTMLBody($text, $timeout = 5) { $condition = function () use ($text) { $emails = $this->fetchMessages(); foreach ($emails as $email) { $constraint = Assert::stringContains($text); if ($constraint->evaluate($email->html_body, '', true)) { return true; } } return false; }; $message = sprintf('Waited for %d secs but no email with the html body containing %s has arrived', $timeout, $text); $this->wait($timeout)->until($condition, $message); }
Wait until an email has been received with specific text in the text body. @param string $text @param int $timeout @throws \Exception
entailment
public function visitData($data, TypeMetadataInterface $type, ContextInterface $context) { if ($data === [] && class_exists($type->getName())) { $data = (object) $data; } return parent::visitData($data, $type, $context); }
{@inheritdoc}
entailment
public function finishVisitingObject($data, ClassMetadataInterface $class, ContextInterface $context) { if ($this->result === []) { $this->result = (object) $this->result; } return parent::finishVisitingObject($data, $class, $context); }
{@inheritdoc}
entailment
protected function encode($data) { $result = @json_encode($data, $this->options); if (json_last_error() !== JSON_ERROR_NONE) { throw new \InvalidArgumentException(json_last_error_msg()); } return $result; }
{@inheritdoc}
entailment
public function setConfig(array $configs = array() ) { foreach($configs as $config_key => $config) { switch($config_key) { case 'table-striped': $this->table_striped = $config; break; case 'table-bordered': $this->table_bordered = $config; break; case 'table-hover': $this->table_hover = $config; break; case 'table-condensed': $this->table_condensed = $config; break; case 'table-responsive': $this->table_responsive = $config; break; case 'id': $this->id = $config; break; default: throw new \InvalidArgumentException(); break; } } }
Set the configuration of the table @param array $config @throws InvalidArgumentException @return void
entailment
public function setHeader(array $header_cols){ $this->header = new TableHeader($header_cols); $this->updateMaxRowLength($this->header); }
Set the header of the table @param array $header_cols columns of the header @return void
entailment
public function addRows(array $rows, array $classes = array() ){ $table_row = new TableRow($rows, $classes); $this->rows[] = $table_row; $this->updateMaxRowLength($table_row); }
Add a row to the table @param array $row row with data columns @return void
entailment
protected function updateMaxRowLength($table_line) { $length = $table_line->getLength(); if($length > $this->max_length_rows) { $this->max_length_rows = $length; } return $this->max_length_rows; }
Update the max lenght of rows in the table @param $table_line @return $max_length_rows
entailment
protected function fillWithEmptyCells($table_row,$tag_row) { $html = ''; if( ! ($table_row instanceof TableLine) ) { throw new \InvalidArgumentException; } $length_row = $table_row->getLength(); $diff = $this->max_length_rows - $length_row; if( $diff > 0 ) { // add empty cells foreach( range(1,$diff) as $key) { $html.="\t\t\t<{$tag_row}></{$tag_row}>\n"; } } $html.="\t\t</tr>\n"; return $html; }
Fill the rest of the row with empty cells @throws InvalidArgumentException @return String $html
entailment
protected function getTableClasses() { $classes = ""; if($this->table_striped) { $classes.= "table-striped "; } if($this->table_bordered) { $classes.= "table-bordered "; } if($this->table_hover) { $classes.= "table-hover "; } if($this->table_condensed) { $classes.= "table-condensed "; } $classes.= $this->getTableExtraClassesString(); return $classes; }
Get the classes in string format separated by a space @return String $classes
entailment
protected function getTableExtraClassesString() { $classes_html = ''; if( ! empty($this->table_extra_classes) ) { foreach($this->table_extra_classes as $class) { $classes_html.= "{$class} "; } } return $classes_html; }
Return the extra classes as concatenated strings @return String $classes
entailment
public function setTableExtraClasses($classes = array()) { if( ! empty($classes) ) { // validate classes foreach($classes as $class) { if(str_word_count($class) > 1) { throw new \InvalidArgumentException; } } $this->table_extra_classes = $classes; } }
Add extra classes to the table @param array $classes @return void @throws \InvalidArgumentException
entailment
public function getHtml() { $html = ""; $table_classes = $this->getTableClasses(); if($this->table_responsive) { $html.= "<div class=\"table-responsive\">\n"; } $id_tag = $this->getTagId(); $html.= "<table {$id_tag} class=\"table {$table_classes}\">\n"; // table header if( isset($this->header) ) { $html.= "\t<thead>\n"; $html.= $this->header->getHtml(); $html.= $this->fillWithEmptyCells($this->header, $this->header->getTagRow() ); $html.= "\t</thead>\n"; } // table data if( isset($this->rows)) { $html.= "\t<tbody>\n"; foreach($this->rows as $row) { $html.= $row->getHtml(); $html.= $this->fillWithEmptyCells($row, $row->getTagRow() ); } $html.= "\t</tbody>\n"; } $html.= "</table>\n"; if($this->table_responsive) { $html.= "</div>\n"; } return $html; }
Return the table as Html @return String $html
entailment
public function scopeLive($query) { return $query->where($this->getTable().'.status', '=', Post::APPROVED) ->where($this->getTable().'.published_date', '<=', \Carbon\Carbon::now()); }
Query scope for "live" posts, adds conditions for status = APPROVED and published date is in the past @param $query @return mixed
entailment
public function scopeByYearMonth($query, $year, $month) { return $query->where(\DB::raw('DATE_FORMAT(published_date, "%Y%m")'), '=', $year.$month); }
Query scope for posts published within the given year and month number. @param $query @param $year @param $month @return mixed
entailment
public static function archives() { // Get the data $archives = self::live() ->select(\DB::raw(' YEAR(`published_date`) AS `year`, DATE_FORMAT(`published_date`, "%m") AS `month`, MONTHNAME(`published_date`) AS `monthname`, COUNT(*) AS `count` ')) ->groupBy(\DB::raw('DATE_FORMAT(`published_date`, "%Y%m")')) ->orderBy('published_date', 'desc') ->get(); // Convert it to a nicely formatted array so we can easily render the view $results = array(); foreach ($archives as $archive) { $results[$archive->year][$archive->month] = array( 'monthname' => $archive->monthname, 'count' => $archive->count, ); } return $results; }
Returns a formatted multi-dimensional array, indexed by year and month number, each with an array with keys for 'month name' and the count / number of items in that month. For example: array( 2014 => array( 01 => array( 'monthname' => 'January', 'count' => 4, ), 02 => array( 'monthname' => 'February', 'count' => 3, ), ) ) @return array
entailment
public function getImage($type, $size, array $attributes = array()) { if (empty($this->$type)) { return null; } $html = '<img src="' . $this->getImageSrc($type, $size) . '"'; $html .= ' alt="' . $this->{$type.'_alt'} . '"'; $html .= ' width="' . $this->getImageWidth($type, $size) . '"'; $html .= ' height="' . $this->getImageHeight($type, $size) . '"'; $html_attributes = ''; if (!empty($attributes)) { $html_attributes = join(' ', array_map(function($key) use ($attributes) { if(is_bool($attributes[$key])) { return $attributes[$key] ? $key : ''; } return "{$key}=\"{$attributes[$key]}\""; }, array_keys($attributes))); } return $html; }
Returns the HTML img tag for the requested image type and size for this item @param $type @param $size @return null|string
entailment
public function getImageSrc($type, $size) { if (empty($this->$type)) { return null; } return $this->getImageConfig($type, $size, 'dir') . $this->$type; }
Returns the value for use in the src attribute of an img tag for the given image type and size @param $type @param $size @return null|string
entailment
public function getImageWidth($type, $size) { if (empty($this->$type)) { return null; } $method = $this->getImageConfig($type, $size, 'method'); // Width varies for images that are 'portrait', 'auto', 'fit', 'crop' if (in_array($method, array('portrait', 'auto', 'fit', 'crop'))) { list($width) = $this->getImageDimensions($type, $size); return $width; } return $this->getImageConfig($type, $size, 'width'); }
Returns the value for use in the width attribute of an img tag for the given image type and size @param $type @param $size @return null|string
entailment
public function getImageHeight($type, $size) { if (empty($this->$type)) { return null; } $method = $this->getImageConfig($type, $size, 'method'); // Height varies for images that are 'landscape', 'auto', 'fit', 'crop' if (in_array($method, array('landscape', 'auto', 'fit', 'crop'))) { list($width, $height) = $this->getImageDimensions($type, $size); return $height; } return $this->getImageConfig($type, $size, 'height'); }
Returns the value for use in the height attribute of an img tag for the given image type and size @param $type @param $size @return null|string
entailment
protected function getImageDimensions($type, $size) { $pathToImage = public_path($this->getImageConfig($type, $size, 'dir') . $this->$type); if (is_file($pathToImage) && file_exists($pathToImage)) { list($width, $height) = getimagesize($pathToImage); } else { $width = $height = false; } return array($width, $height); }
Returns an array of the width and height of the current instance's image $type and $size @param $type @param $size @return array
entailment
public function getImageConfig($imageType, $size, $property) { $config = $this->getConfigPrefix().'images.' . $imageType . '.'; if ($size == 'original') { $config .= 'original.'; } elseif (!is_null($size)) { $config .= 'sizes.' . $size . '.'; } $config .= $property; return \Config::get($config); }
Returns the config setting for an image @param $imageType @param $size @param $property @internal param $type @return mixed
entailment
public function newer() { return $this->live() ->where('published_date', '>=', $this->published_date) ->where('id', '<>', $this->id) ->orderBy('published_date', 'asc') ->orderBy('id', 'asc') ->first(); }
Returns the next newer post, relative to the current one, if it exists @return mixed
entailment
public function older() { return $this->live() ->where('published_date', '<=', $this->published_date) ->where('id', '<>', $this->id) ->orderBy('published_date', 'desc') ->orderBy('id', 'desc') ->first(); }
Returns the next older post, relative to the current one, if it exists @return mixed
entailment
public function add(string $class, string $filename): self { if (substr($class, -2) === '\*') { // Is class in a namespace. Example: Namespace\* $this->patterns[] = [substr($class, 0, -1), $filename]; } else { $this->classes[$class] = $filename; } return $this; }
Registers a class for autoloading. @param string $class The class name or class name pattern (format: Namespace\*). @param string $filename The filename that contains the class or path pattern (format: path/to/file/*.php). @return self Returns a reference to itself.
entailment
public function load(string $class): self { $filename = $this->getFilename($class); if ($filename !== null) { (static function($__filename) { include_once $__filename; })($filename); } return $this; }
Loads a class if registered. @param string $class The class name. @return self Returns a reference to itself.
entailment
public function setValue($object, $property, $value) { $this->propertyAccessor->setValue($object, $property, $value); }
{@inheritdoc}
entailment
public function getList(\BearFramework\DataList\Context $context = null): \BearFramework\DataList { return new \BearFramework\DataList(); }
Returns a list of all items in the data storage. @param \BearFramework\DataList\Context|null $context @return \BearFramework\DataList|\BearFramework\App\DataItem[] A list of all items in the data storage. @throws \Exception @throws \BearFramework\App\Data\DataLockedException
entailment
public function loadClassMetadata(ClassMetadataInterface $classMetadata) { $class = $classMetadata->getName(); if (!array_key_exists($class, $this->data)) { $this->data[$class] = $this->loadData($class); } if (!is_array($data = $this->data[$class])) { return false; } if ($this->classResolver === null) { $this->configureClassOptions($this->classResolver = new OptionsResolver()); } try { $data = $this->classResolver->resolve($data); } catch (\InvalidArgumentException $e) { throw new \InvalidArgumentException(sprintf( 'The mapping for the class "%s" is not valid.', $class ), 0, $e); } $this->doLoadClassMetadata($classMetadata, $data); return true; }
{@inheritdoc}
entailment
private function sortProperties(array $properties, $order) { if (is_string($order)) { if ($order === 'ASC') { ksort($properties); } else { krsort($properties); } } elseif (is_array($order)) { $properties = array_merge(array_flip($order), $properties); } return $properties; }
@param PropertyMetadataInterface[] $properties @param string|string[] $order @return PropertyMetadataInterface[]
entailment
private function isPropertyExposed($property, $policy) { $expose = isset($property['expose']) && $property['expose']; $exclude = isset($property['exclude']) && $property['exclude']; return ($policy === ExclusionPolicy::ALL && $expose) || ($policy === ExclusionPolicy::NONE && !$exclude); }
@param mixed[] $property @param string $policy @return bool
entailment