repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
vimeo/laravel
src/VimeoFactory.php
VimeoFactory.make
public function make(array $config): Vimeo { $config = $this->getConfig($config); return $this->getClient($config); }
php
public function make(array $config): Vimeo { $config = $this->getConfig($config); return $this->getClient($config); }
[ "public", "function", "make", "(", "array", "$", "config", ")", ":", "Vimeo", "{", "$", "config", "=", "$", "this", "->", "getConfig", "(", "$", "config", ")", ";", "return", "$", "this", "->", "getClient", "(", "$", "config", ")", ";", "}" ]
Make a new Vimeo client. @param string[] $config @return \Vimeo\Vimeo
[ "Make", "a", "new", "Vimeo", "client", "." ]
b48690a2071d63db262c1fc090f8f7f2b8b04aac
https://github.com/vimeo/laravel/blob/b48690a2071d63db262c1fc090f8f7f2b8b04aac/src/VimeoFactory.php#L39-L44
train
EaDesgin/magento2-pdf-generator2
Model/Email/SenderBuilder.php
SenderBuilder.send
public function send() { $vars = $this->templateContainer->getTemplateVars(); $this->checkInvoice($vars); parent::send(); }
php
public function send() { $vars = $this->templateContainer->getTemplateVars(); $this->checkInvoice($vars); parent::send(); }
[ "public", "function", "send", "(", ")", "{", "$", "vars", "=", "$", "this", "->", "templateContainer", "->", "getTemplateVars", "(", ")", ";", "$", "this", "->", "checkInvoice", "(", "$", "vars", ")", ";", "parent", "::", "send", "(", ")", ";", "}" ]
Add attachment to the main mail
[ "Add", "attachment", "to", "the", "main", "mail" ]
87e4d346d1ad6afe25aa3812476e89320d95ffa2
https://github.com/EaDesgin/magento2-pdf-generator2/blob/87e4d346d1ad6afe25aa3812476e89320d95ffa2/Model/Email/SenderBuilder.php#L61-L67
train
EaDesgin/magento2-pdf-generator2
Model/Template/Processor.php
Processor.processTemplate
public function processTemplate() { // Support theme fallback for email templates $isDesignApplied = $this->applyDesignConfig(); $processor = $this->getTemplateFilter() ->setUseSessionInUrl(false) ->setPlainTemplateMode($this->isPlain()) ->setIsChildTemplate($this->isChildTemplate()) ->setTemplateProcessor([$this, 'getTemplateContent']); $processor->setVariables($this->getVariables()); $this->setUseAbsoluteLinks(true); $html = $this->html($processor); if ($isDesignApplied) { $this->cancelDesignConfig(); } return $html; }
php
public function processTemplate() { // Support theme fallback for email templates $isDesignApplied = $this->applyDesignConfig(); $processor = $this->getTemplateFilter() ->setUseSessionInUrl(false) ->setPlainTemplateMode($this->isPlain()) ->setIsChildTemplate($this->isChildTemplate()) ->setTemplateProcessor([$this, 'getTemplateContent']); $processor->setVariables($this->getVariables()); $this->setUseAbsoluteLinks(true); $html = $this->html($processor); if ($isDesignApplied) { $this->cancelDesignConfig(); } return $html; }
[ "public", "function", "processTemplate", "(", ")", "{", "// Support theme fallback for email templates", "$", "isDesignApplied", "=", "$", "this", "->", "applyDesignConfig", "(", ")", ";", "$", "processor", "=", "$", "this", "->", "getTemplateFilter", "(", ")", "-...
Get processed template @return string @throws \Magento\Framework\Exception\MailException
[ "Get", "processed", "template" ]
87e4d346d1ad6afe25aa3812476e89320d95ffa2
https://github.com/EaDesgin/magento2-pdf-generator2/blob/87e4d346d1ad6afe25aa3812476e89320d95ffa2/Model/Template/Processor.php#L71-L91
train
EaDesgin/magento2-pdf-generator2
Model/Template/Processor.php
Processor.getDesignConfig
public function getDesignConfig() { $templates = $this->getTemplate()->getData('store_id'); $this->storeId = $templates[0]; if ($this->designConfig === null) { //@codingStandardsIgnoreLine $this->designConfig = new DataObject( ['area' => Area::AREA_FRONTEND, 'store' => $this->storeId] ); } return $this->designConfig; }
php
public function getDesignConfig() { $templates = $this->getTemplate()->getData('store_id'); $this->storeId = $templates[0]; if ($this->designConfig === null) { //@codingStandardsIgnoreLine $this->designConfig = new DataObject( ['area' => Area::AREA_FRONTEND, 'store' => $this->storeId] ); } return $this->designConfig; }
[ "public", "function", "getDesignConfig", "(", ")", "{", "$", "templates", "=", "$", "this", "->", "getTemplate", "(", ")", "->", "getData", "(", "'store_id'", ")", ";", "$", "this", "->", "storeId", "=", "$", "templates", "[", "0", "]", ";", "if", "(...
Get design configuration data @return DataObject
[ "Get", "design", "configuration", "data" ]
87e4d346d1ad6afe25aa3812476e89320d95ffa2
https://github.com/EaDesgin/magento2-pdf-generator2/blob/87e4d346d1ad6afe25aa3812476e89320d95ffa2/Model/Template/Processor.php#L129-L142
train
EaDesgin/magento2-pdf-generator2
Controller/Adminhtml/Templates/Edit.php
Edit.execute
public function execute() { $id = $this->getRequest()->getParam('template_id'); if ($id) { $model = $this->templateRepository->getById($id); if (!$model->getId()) { $this->messageManager->addErrorMessage(__('This post no longer exists.')); /** \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); return $resultRedirect->setPath('*/*/'); } } else { $model = $this->pdfgeneratorFactory->create(); } /** @var Session $data */ $data = $this->session->getFormData(true); if (!empty($data)) { $model->setData($data); } $this->coreRegistry->register('pdfgenerator_template', $model); $resultPage = $this->_initAction(); $resultPage->addBreadcrumb( $id ? __('Edit Template') : __('New Template'), $id ? __('Edit Template') : __('New Template') ); $resultPage->getConfig()->getTitle()->prepend(__('Template')); $resultPage->getConfig()->getTitle() ->prepend( $model->getData('template_id') ? __('Template ') . $model->getTemplateName() : __('New Template') ); return $resultPage; }
php
public function execute() { $id = $this->getRequest()->getParam('template_id'); if ($id) { $model = $this->templateRepository->getById($id); if (!$model->getId()) { $this->messageManager->addErrorMessage(__('This post no longer exists.')); /** \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); return $resultRedirect->setPath('*/*/'); } } else { $model = $this->pdfgeneratorFactory->create(); } /** @var Session $data */ $data = $this->session->getFormData(true); if (!empty($data)) { $model->setData($data); } $this->coreRegistry->register('pdfgenerator_template', $model); $resultPage = $this->_initAction(); $resultPage->addBreadcrumb( $id ? __('Edit Template') : __('New Template'), $id ? __('Edit Template') : __('New Template') ); $resultPage->getConfig()->getTitle()->prepend(__('Template')); $resultPage->getConfig()->getTitle() ->prepend( $model->getData('template_id') ? __('Template ') . $model->getTemplateName() : __('New Template') ); return $resultPage; }
[ "public", "function", "execute", "(", ")", "{", "$", "id", "=", "$", "this", "->", "getRequest", "(", ")", "->", "getParam", "(", "'template_id'", ")", ";", "if", "(", "$", "id", ")", "{", "$", "model", "=", "$", "this", "->", "templateRepository", ...
Edit PDF Templates @return \Magento\Framework\Controller\Result\Redirect|object @SuppressWarnings(PHPMD.NPathComplexity)
[ "Edit", "PDF", "Templates" ]
87e4d346d1ad6afe25aa3812476e89320d95ffa2
https://github.com/EaDesgin/magento2-pdf-generator2/blob/87e4d346d1ad6afe25aa3812476e89320d95ffa2/Controller/Adminhtml/Templates/Edit.php#L103-L143
train
EaDesgin/magento2-pdf-generator2
Controller/Adminhtml/Variable/Template.php
Template.execute
public function execute() { $template = $this->_initTemplate(); try { $parts = $this->emailConfig->parseTemplateIdParts(self::INVOICE_TMEPLTE_ID); $templateId = $parts['templateId']; $theme = $parts['theme']; if ($theme) { $template->setForcedTheme($templateId, $theme); } $template->setForcedArea($templateId); $template->loadDefault($templateId); $template->setData('orig_template_code', $templateId); $template->setData( 'template_variables', Zend_Json::encode($template->getVariablesOptionArray(true)) ); $templateBlock = $this->_view->getLayout()->createBlock( \Magento\Email\Block\Adminhtml\Template\Edit::class ); $template->setData( 'orig_template_currently_used_for', $templateBlock->getCurrentlyUsedForPaths(false) ); $this->getResponse()->representJson( $this->jsonHelperData ->jsonEncode($template->getData()) ); } catch (Exception $e) { $this->messageManager->addErrorMessage($e, 'There was a problem:' . $e->getMessage()); } $customVariables = $this->variableModel ->getVariablesOptionArray(true); $storeContactVariables = $this->variablesFacrory->create()->toOptionArray(true); /** @var Json $resultJson */ $resultJson = $this->resultJsonFactory->create(); return $resultJson->setData([ $storeContactVariables, $customVariables, $template->getVariablesOptionArray(true) ]); }
php
public function execute() { $template = $this->_initTemplate(); try { $parts = $this->emailConfig->parseTemplateIdParts(self::INVOICE_TMEPLTE_ID); $templateId = $parts['templateId']; $theme = $parts['theme']; if ($theme) { $template->setForcedTheme($templateId, $theme); } $template->setForcedArea($templateId); $template->loadDefault($templateId); $template->setData('orig_template_code', $templateId); $template->setData( 'template_variables', Zend_Json::encode($template->getVariablesOptionArray(true)) ); $templateBlock = $this->_view->getLayout()->createBlock( \Magento\Email\Block\Adminhtml\Template\Edit::class ); $template->setData( 'orig_template_currently_used_for', $templateBlock->getCurrentlyUsedForPaths(false) ); $this->getResponse()->representJson( $this->jsonHelperData ->jsonEncode($template->getData()) ); } catch (Exception $e) { $this->messageManager->addErrorMessage($e, 'There was a problem:' . $e->getMessage()); } $customVariables = $this->variableModel ->getVariablesOptionArray(true); $storeContactVariables = $this->variablesFacrory->create()->toOptionArray(true); /** @var Json $resultJson */ $resultJson = $this->resultJsonFactory->create(); return $resultJson->setData([ $storeContactVariables, $customVariables, $template->getVariablesOptionArray(true) ]); }
[ "public", "function", "execute", "(", ")", "{", "$", "template", "=", "$", "this", "->", "_initTemplate", "(", ")", ";", "try", "{", "$", "parts", "=", "$", "this", "->", "emailConfig", "->", "parseTemplateIdParts", "(", "self", "::", "INVOICE_TMEPLTE_ID",...
WYSIWYG Plugin Action @return Json
[ "WYSIWYG", "Plugin", "Action" ]
87e4d346d1ad6afe25aa3812476e89320d95ffa2
https://github.com/EaDesgin/magento2-pdf-generator2/blob/87e4d346d1ad6afe25aa3812476e89320d95ffa2/Controller/Adminhtml/Variable/Template.php#L111-L160
train
EaDesgin/magento2-pdf-generator2
Model/ResourceModel/Pdfgenerator.php
Pdfgenerator.lookupStoreIds
public function lookupStoreIds($templateId) { $adapter = $this->getConnection(); $select = $adapter->select()->from( $this->getTable('eadesign_pdf_store'), 'store_id' )->where( 'template_id = ?', (int)$templateId ); return $adapter->fetchCol($select); }
php
public function lookupStoreIds($templateId) { $adapter = $this->getConnection(); $select = $adapter->select()->from( $this->getTable('eadesign_pdf_store'), 'store_id' )->where( 'template_id = ?', (int)$templateId ); return $adapter->fetchCol($select); }
[ "public", "function", "lookupStoreIds", "(", "$", "templateId", ")", "{", "$", "adapter", "=", "$", "this", "->", "getConnection", "(", ")", ";", "$", "select", "=", "$", "adapter", "->", "select", "(", ")", "->", "from", "(", "$", "this", "->", "get...
Get store ids to which specified item is assigned @param int $templateId @return array
[ "Get", "store", "ids", "to", "which", "specified", "item", "is", "assigned" ]
87e4d346d1ad6afe25aa3812476e89320d95ffa2
https://github.com/EaDesgin/magento2-pdf-generator2/blob/87e4d346d1ad6afe25aa3812476e89320d95ffa2/Model/ResourceModel/Pdfgenerator.php#L111-L123
train
EaDesgin/magento2-pdf-generator2
Model/ResourceModel/Pdfgenerator/AbstractCollection.php
AbstractCollection.addFieldToFilter
public function addFieldToFilter($field, $condition = null) { if ($field === 'store_id') { return $this->addStoreFilter($condition, false); } return parent::addFieldToFilter($field, $condition); }
php
public function addFieldToFilter($field, $condition = null) { if ($field === 'store_id') { return $this->addStoreFilter($condition, false); } return parent::addFieldToFilter($field, $condition); }
[ "public", "function", "addFieldToFilter", "(", "$", "field", ",", "$", "condition", "=", "null", ")", "{", "if", "(", "$", "field", "===", "'store_id'", ")", "{", "return", "$", "this", "->", "addStoreFilter", "(", "$", "condition", ",", "false", ")", ...
Add field filter to collection @param array|string $field @param string|int|array|null $condition @return \Magento\Framework\Data\Collection\AbstractDb
[ "Add", "field", "filter", "to", "collection" ]
87e4d346d1ad6afe25aa3812476e89320d95ffa2
https://github.com/EaDesgin/magento2-pdf-generator2/blob/87e4d346d1ad6afe25aa3812476e89320d95ffa2/Model/ResourceModel/Pdfgenerator/AbstractCollection.php#L123-L130
train
EaDesgin/magento2-pdf-generator2
Model/ResourceModel/Pdfgenerator/AbstractCollection.php
AbstractCollection.performAddStoreFilter
public function performAddStoreFilter($store, $withAdmin = true) { if ($store instanceof Store) { $store = [$store->getId()]; } if (!is_array($store)) { $store = [$store]; } if ($withAdmin) { $store[] = Store::DEFAULT_STORE_ID; } $this->addFilter('store', ['in' => $store], 'public'); }
php
public function performAddStoreFilter($store, $withAdmin = true) { if ($store instanceof Store) { $store = [$store->getId()]; } if (!is_array($store)) { $store = [$store]; } if ($withAdmin) { $store[] = Store::DEFAULT_STORE_ID; } $this->addFilter('store', ['in' => $store], 'public'); }
[ "public", "function", "performAddStoreFilter", "(", "$", "store", ",", "$", "withAdmin", "=", "true", ")", "{", "if", "(", "$", "store", "instanceof", "Store", ")", "{", "$", "store", "=", "[", "$", "store", "->", "getId", "(", ")", "]", ";", "}", ...
Perform adding filter by store @param int|array|Store $store @param bool $withAdmin @return void
[ "Perform", "adding", "filter", "by", "store" ]
87e4d346d1ad6afe25aa3812476e89320d95ffa2
https://github.com/EaDesgin/magento2-pdf-generator2/blob/87e4d346d1ad6afe25aa3812476e89320d95ffa2/Model/ResourceModel/Pdfgenerator/AbstractCollection.php#L148-L163
train
EaDesgin/magento2-pdf-generator2
Helper/Data.php
Data.isEnable
public function isEnable() { if (!$this->mPDFExists() || !$this->collection()->getSize()) { return false; } return $this->hasConfig(self::ENABLE); }
php
public function isEnable() { if (!$this->mPDFExists() || !$this->collection()->getSize()) { return false; } return $this->hasConfig(self::ENABLE); }
[ "public", "function", "isEnable", "(", ")", "{", "if", "(", "!", "$", "this", "->", "mPDFExists", "(", ")", "||", "!", "$", "this", "->", "collection", "(", ")", "->", "getSize", "(", ")", ")", "{", "return", "false", ";", "}", "return", "$", "th...
Check if module is enable @return boolean
[ "Check", "if", "module", "is", "enable" ]
87e4d346d1ad6afe25aa3812476e89320d95ffa2
https://github.com/EaDesgin/magento2-pdf-generator2/blob/87e4d346d1ad6afe25aa3812476e89320d95ffa2/Helper/Data.php#L74-L81
train
EaDesgin/magento2-pdf-generator2
Helper/Data.php
Data.getTemplateStatus
public function getTemplateStatus(Invoice $invoice) { $invoiceStore = $invoice->getOrder()->getStoreId(); $collection = $this->collection(); $collection->addStoreFilter($invoiceStore); $collection->addFieldToFilter('is_active', TemplateActive::STATUS_ENABLED); $collection->addFieldToFilter('template_default', AbstractSource::IS_DEFAULT); return $collection->getLastItem(); }
php
public function getTemplateStatus(Invoice $invoice) { $invoiceStore = $invoice->getOrder()->getStoreId(); $collection = $this->collection(); $collection->addStoreFilter($invoiceStore); $collection->addFieldToFilter('is_active', TemplateActive::STATUS_ENABLED); $collection->addFieldToFilter('template_default', AbstractSource::IS_DEFAULT); return $collection->getLastItem(); }
[ "public", "function", "getTemplateStatus", "(", "Invoice", "$", "invoice", ")", "{", "$", "invoiceStore", "=", "$", "invoice", "->", "getOrder", "(", ")", "->", "getStoreId", "(", ")", ";", "$", "collection", "=", "$", "this", "->", "collection", "(", ")...
Get the active template @param $invoice @return \Magento\Framework\DataObject
[ "Get", "the", "active", "template" ]
87e4d346d1ad6afe25aa3812476e89320d95ffa2
https://github.com/EaDesgin/magento2-pdf-generator2/blob/87e4d346d1ad6afe25aa3812476e89320d95ffa2/Helper/Data.php#L112-L121
train
EaDesgin/magento2-pdf-generator2
Model/Source/TemplatePaperForm.php
TemplatePaperForm.getAvailable
public function getAvailable() { return [ self::TEMAPLATE_PAPER_FORM_A4 => 'A4', self::TEMAPLATE_PAPER_FORMAT_A3 => 'A3', self::TEMAPLATE_PAPER_FORMAT_A5 => 'A5', self::TEMAPLATE_PAPER_FORMAT_A6 => 'A6', self::TEMAPLATE_PAPER_FORMAT_LETTER => 'Letter', self::TEMAPLATE_PAPER_FORMAT_LEGAL => 'Legal', ]; }
php
public function getAvailable() { return [ self::TEMAPLATE_PAPER_FORM_A4 => 'A4', self::TEMAPLATE_PAPER_FORMAT_A3 => 'A3', self::TEMAPLATE_PAPER_FORMAT_A5 => 'A5', self::TEMAPLATE_PAPER_FORMAT_A6 => 'A6', self::TEMAPLATE_PAPER_FORMAT_LETTER => 'Letter', self::TEMAPLATE_PAPER_FORMAT_LEGAL => 'Legal', ]; }
[ "public", "function", "getAvailable", "(", ")", "{", "return", "[", "self", "::", "TEMAPLATE_PAPER_FORM_A4", "=>", "'A4'", ",", "self", "::", "TEMAPLATE_PAPER_FORMAT_A3", "=>", "'A3'", ",", "self", "::", "TEMAPLATE_PAPER_FORMAT_A5", "=>", "'A5'", ",", "self", ":...
Prepare post's statuses. @return array
[ "Prepare", "post", "s", "statuses", "." ]
87e4d346d1ad6afe25aa3812476e89320d95ffa2
https://github.com/EaDesgin/magento2-pdf-generator2/blob/87e4d346d1ad6afe25aa3812476e89320d95ffa2/Model/Source/TemplatePaperForm.php#L46-L56
train
EaDesgin/magento2-pdf-generator2
Helper/Pdf.php
Pdf.template2Pdf
public function template2Pdf() { /**transport use to get the variables $order object, $invoice object and the template model object*/ $parts = $this->transport(); /** instantiate the mPDF class and add the processed html to get the pdf*/ $applySettings = $this->eaPDFSettings($parts); $fileParts = [ 'filestream' => $applySettings, 'filename' => filter_var($parts['filename'], FILTER_SANITIZE_URL) ]; return $fileParts; }
php
public function template2Pdf() { /**transport use to get the variables $order object, $invoice object and the template model object*/ $parts = $this->transport(); /** instantiate the mPDF class and add the processed html to get the pdf*/ $applySettings = $this->eaPDFSettings($parts); $fileParts = [ 'filestream' => $applySettings, 'filename' => filter_var($parts['filename'], FILTER_SANITIZE_URL) ]; return $fileParts; }
[ "public", "function", "template2Pdf", "(", ")", "{", "/**transport use to get the variables $order object, $invoice object and the template model object*/", "$", "parts", "=", "$", "this", "->", "transport", "(", ")", ";", "/** instantiate the mPDF class and add the processed html ...
Filename of the pdf and the stream to sent to the download @return array
[ "Filename", "of", "the", "pdf", "and", "the", "stream", "to", "sent", "to", "the", "download" ]
87e4d346d1ad6afe25aa3812476e89320d95ffa2
https://github.com/EaDesgin/magento2-pdf-generator2/blob/87e4d346d1ad6afe25aa3812476e89320d95ffa2/Helper/Pdf.php#L167-L181
train
segmentio/analytics-php
lib/Segment/QueueConsumer.php
Segment_QueueConsumer.flush
public function flush() { $count = count($this->queue); $success = true; while ($count > 0 && $success) { $batch = array_splice($this->queue, 0, min($this->batch_size, $count)); $success = $this->flushBatch($batch); $count = count($this->queue); } return $success; }
php
public function flush() { $count = count($this->queue); $success = true; while ($count > 0 && $success) { $batch = array_splice($this->queue, 0, min($this->batch_size, $count)); $success = $this->flushBatch($batch); $count = count($this->queue); } return $success; }
[ "public", "function", "flush", "(", ")", "{", "$", "count", "=", "count", "(", "$", "this", "->", "queue", ")", ";", "$", "success", "=", "true", ";", "while", "(", "$", "count", ">", "0", "&&", "$", "success", ")", "{", "$", "batch", "=", "arr...
Flushes our queue of messages by batching them to the server
[ "Flushes", "our", "queue", "of", "messages", "by", "batching", "them", "to", "the", "server" ]
9ee6e696ea12e2ac4145fdb9109a43b4cb556f1c
https://github.com/segmentio/analytics-php/blob/9ee6e696ea12e2ac4145fdb9109a43b4cb556f1c/lib/Segment/QueueConsumer.php#L108-L120
train
segmentio/analytics-php
lib/Segment/QueueConsumer.php
Segment_QueueConsumer.enqueue
protected function enqueue($item) { $count = count($this->queue); if ($count > $this->max_queue_size) { return false; } $count = array_push($this->queue, $item); if ($count >= $this->batch_size) { return $this->flush(); // return ->flush() result: true on success } return true; }
php
protected function enqueue($item) { $count = count($this->queue); if ($count > $this->max_queue_size) { return false; } $count = array_push($this->queue, $item); if ($count >= $this->batch_size) { return $this->flush(); // return ->flush() result: true on success } return true; }
[ "protected", "function", "enqueue", "(", "$", "item", ")", "{", "$", "count", "=", "count", "(", "$", "this", "->", "queue", ")", ";", "if", "(", "$", "count", ">", "$", "this", "->", "max_queue_size", ")", "{", "return", "false", ";", "}", "$", ...
Adds an item to our queue. @param mixed $item @return boolean whether call has succeeded
[ "Adds", "an", "item", "to", "our", "queue", "." ]
9ee6e696ea12e2ac4145fdb9109a43b4cb556f1c
https://github.com/segmentio/analytics-php/blob/9ee6e696ea12e2ac4145fdb9109a43b4cb556f1c/lib/Segment/QueueConsumer.php#L127-L141
train
segmentio/analytics-php
lib/Segment/Consumer/ForkCurl.php
Segment_Consumer_ForkCurl.flushBatch
public function flushBatch($messages) { $body = $this->payload($messages); $payload = json_encode($body); // Escape for shell usage. $payload = escapeshellarg($payload); $secret = $this->secret; $protocol = $this->ssl() ? "https://" : "http://"; if ($this->host) { $host = $this->host; } else { $host = "api.segment.io"; } $path = "/v1/import"; $url = $protocol . $host . $path; $cmd = "curl -u ${secret}: -X POST -H 'Content-Type: application/json'"; $tmpfname = ""; if ($this->compress_request) { // Compress request to file $tmpfname = tempnam("/tmp", "forkcurl_"); $cmd2 = "echo " . $payload . " | gzip > " . $tmpfname; exec($cmd2, $output, $exit); if (0 != $exit) { $this->handleError($exit, $output); return false; } $cmd.= " -H 'Content-Encoding: gzip'"; $cmd.= " --data-binary '@" . $tmpfname . "'"; } else { $cmd.= " -d " . $payload; } $cmd.= " '" . $url . "'"; // Verify message size is below than 32KB if (strlen($payload) >= 32 * 1024) { if ($this->debug()) { $msg = "Message size is larger than 32KB"; error_log("[Analytics][" . $this->type . "] " . $msg); } return false; } // Send user agent in the form of {library_name}/{library_version} as per RFC 7231. $library = $messages[0]['context']['library']; $libName = $library['name']; $libVersion = $library['version']; $cmd.= " -H 'User-Agent: ${libName}/${libVersion}'"; if (!$this->debug()) { $cmd .= " > /dev/null 2>&1 &"; } exec($cmd, $output, $exit); if (0 != $exit) { $this->handleError($exit, $output); } if ($tmpfname != "") { unlink($tmpfname); } return 0 == $exit; }
php
public function flushBatch($messages) { $body = $this->payload($messages); $payload = json_encode($body); // Escape for shell usage. $payload = escapeshellarg($payload); $secret = $this->secret; $protocol = $this->ssl() ? "https://" : "http://"; if ($this->host) { $host = $this->host; } else { $host = "api.segment.io"; } $path = "/v1/import"; $url = $protocol . $host . $path; $cmd = "curl -u ${secret}: -X POST -H 'Content-Type: application/json'"; $tmpfname = ""; if ($this->compress_request) { // Compress request to file $tmpfname = tempnam("/tmp", "forkcurl_"); $cmd2 = "echo " . $payload . " | gzip > " . $tmpfname; exec($cmd2, $output, $exit); if (0 != $exit) { $this->handleError($exit, $output); return false; } $cmd.= " -H 'Content-Encoding: gzip'"; $cmd.= " --data-binary '@" . $tmpfname . "'"; } else { $cmd.= " -d " . $payload; } $cmd.= " '" . $url . "'"; // Verify message size is below than 32KB if (strlen($payload) >= 32 * 1024) { if ($this->debug()) { $msg = "Message size is larger than 32KB"; error_log("[Analytics][" . $this->type . "] " . $msg); } return false; } // Send user agent in the form of {library_name}/{library_version} as per RFC 7231. $library = $messages[0]['context']['library']; $libName = $library['name']; $libVersion = $library['version']; $cmd.= " -H 'User-Agent: ${libName}/${libVersion}'"; if (!$this->debug()) { $cmd .= " > /dev/null 2>&1 &"; } exec($cmd, $output, $exit); if (0 != $exit) { $this->handleError($exit, $output); } if ($tmpfname != "") { unlink($tmpfname); } return 0 == $exit; }
[ "public", "function", "flushBatch", "(", "$", "messages", ")", "{", "$", "body", "=", "$", "this", "->", "payload", "(", "$", "messages", ")", ";", "$", "payload", "=", "json_encode", "(", "$", "body", ")", ";", "// Escape for shell usage.", "$", "payloa...
Make an async request to our API. Fork a curl process, immediately send to the API. If debug is enabled, we wait for the response. @param array $messages array of all the messages to send @return boolean whether the request succeeded
[ "Make", "an", "async", "request", "to", "our", "API", ".", "Fork", "a", "curl", "process", "immediately", "send", "to", "the", "API", ".", "If", "debug", "is", "enabled", "we", "wait", "for", "the", "response", "." ]
9ee6e696ea12e2ac4145fdb9109a43b4cb556f1c
https://github.com/segmentio/analytics-php/blob/9ee6e696ea12e2ac4145fdb9109a43b4cb556f1c/lib/Segment/Consumer/ForkCurl.php#L30-L101
train
segmentio/analytics-php
lib/Segment/Consumer/LibCurl.php
Segment_Consumer_LibCurl.flushBatch
public function flushBatch($messages) { $body = $this->payload($messages); $payload = json_encode($body); $secret = $this->secret; // Verify message size is below than 32KB if (strlen($payload) >= 32 * 1024) { if ($this->debug()) { $msg = "Message size is larger than 32KB"; error_log("[Analytics][" . $this->type . "] " . $msg); } return false; } if ($this->compress_request) { $payload = gzencode($payload); } $protocol = $this->ssl() ? "https://" : "http://"; if ($this->host) { $host = $this->host; } else { $host = "api.segment.io"; } $path = "/v1/import"; $url = $protocol . $host . $path; $backoff = 100; // Set initial waiting time to 100ms while ($backoff < $this->maximum_backoff_duration) { $start_time = microtime(true); // open connection $ch = curl_init(); // set the url, number of POST vars, POST data curl_setopt($ch, CURLOPT_USERPWD, $secret . ':'); curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); // set variables for headers $header = array(); $header[] = 'Content-Type: application/json'; if ($this->compress_request) { $header[] = 'Content-Encoding: gzip'; } // Send user agent in the form of {library_name}/{library_version} as per RFC 7231. $library = $messages[0]['context']['library']; $libName = $library['name']; $libVersion = $library['version']; $header[] = "User-Agent: ${libName}/${libVersion}"; curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // retry failed requests just once to diminish impact on performance $httpResponse = $this->executePost($ch); //close connection curl_close($ch); $elapsed_time = microtime(true) - $start_time; if (200 != $httpResponse) { // log error $this->handleError($ch, $httpResponse); if (($httpResponse >= 500 && $httpResponse <= 600) || 429 == $httpResponse) { // If status code is greater than 500 and less than 600, it indicates server error // Error code 429 indicates rate limited. // Retry uploading in these cases. usleep($backoff * 1000); $backoff *= 2; } elseif ($httpResponse >= 400) { break; } } else { break; // no error } } return $httpResponse; }
php
public function flushBatch($messages) { $body = $this->payload($messages); $payload = json_encode($body); $secret = $this->secret; // Verify message size is below than 32KB if (strlen($payload) >= 32 * 1024) { if ($this->debug()) { $msg = "Message size is larger than 32KB"; error_log("[Analytics][" . $this->type . "] " . $msg); } return false; } if ($this->compress_request) { $payload = gzencode($payload); } $protocol = $this->ssl() ? "https://" : "http://"; if ($this->host) { $host = $this->host; } else { $host = "api.segment.io"; } $path = "/v1/import"; $url = $protocol . $host . $path; $backoff = 100; // Set initial waiting time to 100ms while ($backoff < $this->maximum_backoff_duration) { $start_time = microtime(true); // open connection $ch = curl_init(); // set the url, number of POST vars, POST data curl_setopt($ch, CURLOPT_USERPWD, $secret . ':'); curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); // set variables for headers $header = array(); $header[] = 'Content-Type: application/json'; if ($this->compress_request) { $header[] = 'Content-Encoding: gzip'; } // Send user agent in the form of {library_name}/{library_version} as per RFC 7231. $library = $messages[0]['context']['library']; $libName = $library['name']; $libVersion = $library['version']; $header[] = "User-Agent: ${libName}/${libVersion}"; curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // retry failed requests just once to diminish impact on performance $httpResponse = $this->executePost($ch); //close connection curl_close($ch); $elapsed_time = microtime(true) - $start_time; if (200 != $httpResponse) { // log error $this->handleError($ch, $httpResponse); if (($httpResponse >= 500 && $httpResponse <= 600) || 429 == $httpResponse) { // If status code is greater than 500 and less than 600, it indicates server error // Error code 429 indicates rate limited. // Retry uploading in these cases. usleep($backoff * 1000); $backoff *= 2; } elseif ($httpResponse >= 400) { break; } } else { break; // no error } } return $httpResponse; }
[ "public", "function", "flushBatch", "(", "$", "messages", ")", "{", "$", "body", "=", "$", "this", "->", "payload", "(", "$", "messages", ")", ";", "$", "payload", "=", "json_encode", "(", "$", "body", ")", ";", "$", "secret", "=", "$", "this", "->...
Make a sync request to our API. If debug is enabled, we wait for the response and retry once to diminish impact on performance. @param array $messages array of all the messages to send @return boolean whether the request succeeded
[ "Make", "a", "sync", "request", "to", "our", "API", ".", "If", "debug", "is", "enabled", "we", "wait", "for", "the", "response", "and", "retry", "once", "to", "diminish", "impact", "on", "performance", "." ]
9ee6e696ea12e2ac4145fdb9109a43b4cb556f1c
https://github.com/segmentio/analytics-php/blob/9ee6e696ea12e2ac4145fdb9109a43b4cb556f1c/lib/Segment/Consumer/LibCurl.php#L30-L115
train
segmentio/analytics-php
lib/Segment/Client.php
Segment_Client.page
public function page(array $message) { $message = $this->message($message, "properties"); $message["type"] = "page"; return $this->consumer->page($message); }
php
public function page(array $message) { $message = $this->message($message, "properties"); $message["type"] = "page"; return $this->consumer->page($message); }
[ "public", "function", "page", "(", "array", "$", "message", ")", "{", "$", "message", "=", "$", "this", "->", "message", "(", "$", "message", ",", "\"properties\"", ")", ";", "$", "message", "[", "\"type\"", "]", "=", "\"page\"", ";", "return", "$", ...
Tracks a page view. @param [array] $message @return [boolean] whether the page call succeeded
[ "Tracks", "a", "page", "view", "." ]
9ee6e696ea12e2ac4145fdb9109a43b4cb556f1c
https://github.com/segmentio/analytics-php/blob/9ee6e696ea12e2ac4145fdb9109a43b4cb556f1c/lib/Segment/Client.php#L89-L94
train
segmentio/analytics-php
lib/Segment/Client.php
Segment_Client.screen
public function screen(array $message) { $message = $this->message($message, "properties"); $message["type"] = "screen"; return $this->consumer->screen($message); }
php
public function screen(array $message) { $message = $this->message($message, "properties"); $message["type"] = "screen"; return $this->consumer->screen($message); }
[ "public", "function", "screen", "(", "array", "$", "message", ")", "{", "$", "message", "=", "$", "this", "->", "message", "(", "$", "message", ",", "\"properties\"", ")", ";", "$", "message", "[", "\"type\"", "]", "=", "\"screen\"", ";", "return", "$"...
Tracks a screen view. @param [array] $message @return [boolean] whether the screen call succeeded
[ "Tracks", "a", "screen", "view", "." ]
9ee6e696ea12e2ac4145fdb9109a43b4cb556f1c
https://github.com/segmentio/analytics-php/blob/9ee6e696ea12e2ac4145fdb9109a43b4cb556f1c/lib/Segment/Client.php#L102-L107
train
segmentio/analytics-php
lib/Segment/Client.php
Segment_Client.alias
public function alias(array $message) { $message = $this->message($message); $message["type"] = "alias"; return $this->consumer->alias($message); }
php
public function alias(array $message) { $message = $this->message($message); $message["type"] = "alias"; return $this->consumer->alias($message); }
[ "public", "function", "alias", "(", "array", "$", "message", ")", "{", "$", "message", "=", "$", "this", "->", "message", "(", "$", "message", ")", ";", "$", "message", "[", "\"type\"", "]", "=", "\"alias\"", ";", "return", "$", "this", "->", "consum...
Aliases from one user id to another @param array $message @return boolean whether the alias call succeeded
[ "Aliases", "from", "one", "user", "id", "to", "another" ]
9ee6e696ea12e2ac4145fdb9109a43b4cb556f1c
https://github.com/segmentio/analytics-php/blob/9ee6e696ea12e2ac4145fdb9109a43b4cb556f1c/lib/Segment/Client.php#L115-L120
train
segmentio/analytics-php
lib/Segment/Client.php
Segment_Client.formatTime
private function formatTime($ts) { // time() if (null == $ts || !$ts) { $ts = time(); } if (false !== filter_var($ts, FILTER_VALIDATE_INT)) { return date("c", (int) $ts); } // anything else try to strtotime the date. if (false === filter_var($ts, FILTER_VALIDATE_FLOAT)) { if (is_string($ts)) { return date("c", strtotime($ts)); } return date("c"); } // fix for floatval casting in send.php $parts = explode(".", (string)$ts); if (!isset($parts[1])) { return date("c", (int)$parts[0]); } // microtime(true) $sec = (int)$parts[0]; $usec = (int)$parts[1]; $fmt = sprintf("Y-m-d\\TH:i:s%sP", $usec); return date($fmt, (int)$sec); }
php
private function formatTime($ts) { // time() if (null == $ts || !$ts) { $ts = time(); } if (false !== filter_var($ts, FILTER_VALIDATE_INT)) { return date("c", (int) $ts); } // anything else try to strtotime the date. if (false === filter_var($ts, FILTER_VALIDATE_FLOAT)) { if (is_string($ts)) { return date("c", strtotime($ts)); } return date("c"); } // fix for floatval casting in send.php $parts = explode(".", (string)$ts); if (!isset($parts[1])) { return date("c", (int)$parts[0]); } // microtime(true) $sec = (int)$parts[0]; $usec = (int)$parts[1]; $fmt = sprintf("Y-m-d\\TH:i:s%sP", $usec); return date($fmt, (int)$sec); }
[ "private", "function", "formatTime", "(", "$", "ts", ")", "{", "// time()", "if", "(", "null", "==", "$", "ts", "||", "!", "$", "ts", ")", "{", "$", "ts", "=", "time", "(", ")", ";", "}", "if", "(", "false", "!==", "filter_var", "(", "$", "ts",...
Formats a timestamp by making sure it is set and converting it to iso8601. The timestamp can be time in seconds `time()` or `microseconds(true)`. any other input is considered an error and the method will return a new date. Note: php's date() "u" format (for microseconds) has a bug in it it always shows `.000` for microseconds since `date()` only accepts ints, so we have to construct the date ourselves if microtime is passed. @param ts $timestamp - time in seconds (time())
[ "Formats", "a", "timestamp", "by", "making", "sure", "it", "is", "set", "and", "converting", "it", "to", "iso8601", "." ]
9ee6e696ea12e2ac4145fdb9109a43b4cb556f1c
https://github.com/segmentio/analytics-php/blob/9ee6e696ea12e2ac4145fdb9109a43b4cb556f1c/lib/Segment/Client.php#L147-L177
train
segmentio/analytics-php
lib/Segment/Client.php
Segment_Client.message
private function message($msg, $def = ""){ if ($def && !isset($msg[$def])) { $msg[$def] = array(); } if ($def && empty($msg[$def])) { $msg[$def] = (object)$msg[$def]; } if (!isset($msg["context"])) { $msg["context"] = array(); } $msg["context"] = array_merge($this->getDefaultContext(), $msg["context"]); if (!isset($msg["timestamp"])) { $msg["timestamp"] = null; } $msg["timestamp"] = $this->formatTime($msg["timestamp"]); $msg["messageId"] = self::messageId(); return $msg; }
php
private function message($msg, $def = ""){ if ($def && !isset($msg[$def])) { $msg[$def] = array(); } if ($def && empty($msg[$def])) { $msg[$def] = (object)$msg[$def]; } if (!isset($msg["context"])) { $msg["context"] = array(); } $msg["context"] = array_merge($this->getDefaultContext(), $msg["context"]); if (!isset($msg["timestamp"])) { $msg["timestamp"] = null; } $msg["timestamp"] = $this->formatTime($msg["timestamp"]); $msg["messageId"] = self::messageId(); return $msg; }
[ "private", "function", "message", "(", "$", "msg", ",", "$", "def", "=", "\"\"", ")", "{", "if", "(", "$", "def", "&&", "!", "isset", "(", "$", "msg", "[", "$", "def", "]", ")", ")", "{", "$", "msg", "[", "$", "def", "]", "=", "array", "(",...
Add common fields to the given `message` @param array $msg @param string $def @return array
[ "Add", "common", "fields", "to", "the", "given", "message" ]
9ee6e696ea12e2ac4145fdb9109a43b4cb556f1c
https://github.com/segmentio/analytics-php/blob/9ee6e696ea12e2ac4145fdb9109a43b4cb556f1c/lib/Segment/Client.php#L187-L207
train
segmentio/analytics-php
lib/Segment/Client.php
Segment_Client.messageId
private static function messageId(){ return sprintf("%04x%04x-%04x-%04x-%04x-%04x%04x%04x", mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0x0fff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000, mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) ); }
php
private static function messageId(){ return sprintf("%04x%04x-%04x-%04x-%04x-%04x%04x%04x", mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0x0fff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000, mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) ); }
[ "private", "static", "function", "messageId", "(", ")", "{", "return", "sprintf", "(", "\"%04x%04x-%04x-%04x-%04x-%04x%04x%04x\"", ",", "mt_rand", "(", "0", ",", "0xffff", ")", ",", "mt_rand", "(", "0", ",", "0xffff", ")", ",", "mt_rand", "(", "0", ",", "0...
Generate a random messageId. https://gist.github.com/dahnielson/508447#file-uuid-php-L74 @return string
[ "Generate", "a", "random", "messageId", "." ]
9ee6e696ea12e2ac4145fdb9109a43b4cb556f1c
https://github.com/segmentio/analytics-php/blob/9ee6e696ea12e2ac4145fdb9109a43b4cb556f1c/lib/Segment/Client.php#L217-L228
train
segmentio/analytics-php
lib/Segment/Consumer/File.php
Segment_Consumer_File.write
private function write($body) { if (!$this->file_handle) { return false; } $content = json_encode($body); $content.= "\n"; return fwrite($this->file_handle, $content) == strlen($content); }
php
private function write($body) { if (!$this->file_handle) { return false; } $content = json_encode($body); $content.= "\n"; return fwrite($this->file_handle, $content) == strlen($content); }
[ "private", "function", "write", "(", "$", "body", ")", "{", "if", "(", "!", "$", "this", "->", "file_handle", ")", "{", "return", "false", ";", "}", "$", "content", "=", "json_encode", "(", "$", "body", ")", ";", "$", "content", ".=", "\"\\n\"", ";...
Writes the API call to a file as line-delimited json @param [array] $body post body content. @return [boolean] whether the request succeeded
[ "Writes", "the", "API", "call", "to", "a", "file", "as", "line", "-", "delimited", "json" ]
9ee6e696ea12e2ac4145fdb9109a43b4cb556f1c
https://github.com/segmentio/analytics-php/blob/9ee6e696ea12e2ac4145fdb9109a43b4cb556f1c/lib/Segment/Consumer/File.php#L106-L115
train
segmentio/analytics-php
lib/Segment/Consumer.php
Segment_Consumer.handleError
protected function handleError($code, $msg) { if (isset($this->options['error_handler'])) { $handler = $this->options['error_handler']; $handler($code, $msg); } if ($this->debug()) { error_log("[Analytics][" . $this->type . "] " . $msg); } }
php
protected function handleError($code, $msg) { if (isset($this->options['error_handler'])) { $handler = $this->options['error_handler']; $handler($code, $msg); } if ($this->debug()) { error_log("[Analytics][" . $this->type . "] " . $msg); } }
[ "protected", "function", "handleError", "(", "$", "code", ",", "$", "msg", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "options", "[", "'error_handler'", "]", ")", ")", "{", "$", "handler", "=", "$", "this", "->", "options", "[", "'error_ha...
On an error, try and call the error handler, if debugging output to error_log as well. @param string $code @param string $msg
[ "On", "an", "error", "try", "and", "call", "the", "error", "handler", "if", "debugging", "output", "to", "error_log", "as", "well", "." ]
9ee6e696ea12e2ac4145fdb9109a43b4cb556f1c
https://github.com/segmentio/analytics-php/blob/9ee6e696ea12e2ac4145fdb9109a43b4cb556f1c/lib/Segment/Consumer.php#L90-L99
train
segmentio/analytics-php
lib/Segment.php
Segment.init
public static function init($secret, $options = array()) { self::assert($secret, "Segment::init() requires secret"); self::$client = new Segment_Client($secret, $options); }
php
public static function init($secret, $options = array()) { self::assert($secret, "Segment::init() requires secret"); self::$client = new Segment_Client($secret, $options); }
[ "public", "static", "function", "init", "(", "$", "secret", ",", "$", "options", "=", "array", "(", ")", ")", "{", "self", "::", "assert", "(", "$", "secret", ",", "\"Segment::init() requires secret\"", ")", ";", "self", "::", "$", "client", "=", "new", ...
Initializes the default client to use. Uses the libcurl consumer by default. @param string $secret your project's secret key @param array $options passed straight to the client
[ "Initializes", "the", "default", "client", "to", "use", ".", "Uses", "the", "libcurl", "consumer", "by", "default", "." ]
9ee6e696ea12e2ac4145fdb9109a43b4cb556f1c
https://github.com/segmentio/analytics-php/blob/9ee6e696ea12e2ac4145fdb9109a43b4cb556f1c/lib/Segment.php#L13-L16
train
segmentio/analytics-php
lib/Segment.php
Segment.screen
public static function screen(array $message) { self::checkClient(); self::validate($message, "screen"); return self::$client->screen($message); }
php
public static function screen(array $message) { self::checkClient(); self::validate($message, "screen"); return self::$client->screen($message); }
[ "public", "static", "function", "screen", "(", "array", "$", "message", ")", "{", "self", "::", "checkClient", "(", ")", ";", "self", "::", "validate", "(", "$", "message", ",", "\"screen\"", ")", ";", "return", "self", "::", "$", "client", "->", "scre...
Tracks a screen view @param array $message @return boolean whether the screen call succeeded
[ "Tracks", "a", "screen", "view" ]
9ee6e696ea12e2ac4145fdb9109a43b4cb556f1c
https://github.com/segmentio/analytics-php/blob/9ee6e696ea12e2ac4145fdb9109a43b4cb556f1c/lib/Segment.php#L81-L86
train
segmentio/analytics-php
lib/Segment.php
Segment.alias
public static function alias(array $message) { self::checkClient(); $userId = !empty($message["userId"]); $previousId = !empty($message["previousId"]); self::assert($userId && $previousId, "Segment::alias() requires both userId and previousId"); return self::$client->alias($message); }
php
public static function alias(array $message) { self::checkClient(); $userId = !empty($message["userId"]); $previousId = !empty($message["previousId"]); self::assert($userId && $previousId, "Segment::alias() requires both userId and previousId"); return self::$client->alias($message); }
[ "public", "static", "function", "alias", "(", "array", "$", "message", ")", "{", "self", "::", "checkClient", "(", ")", ";", "$", "userId", "=", "!", "empty", "(", "$", "message", "[", "\"userId\"", "]", ")", ";", "$", "previousId", "=", "!", "empty"...
Aliases the user id from a temporary id to a permanent one @param array $from user id to alias from @return boolean whether the alias call succeeded
[ "Aliases", "the", "user", "id", "from", "a", "temporary", "id", "to", "a", "permanent", "one" ]
9ee6e696ea12e2ac4145fdb9109a43b4cb556f1c
https://github.com/segmentio/analytics-php/blob/9ee6e696ea12e2ac4145fdb9109a43b4cb556f1c/lib/Segment.php#L94-L101
train
segmentio/analytics-php
lib/Segment.php
Segment.validate
public static function validate($msg, $type){ $userId = !empty($msg["userId"]); $anonId = !empty($msg["anonymousId"]); self::assert($userId || $anonId, "Segment::${type}() requires userId or anonymousId"); }
php
public static function validate($msg, $type){ $userId = !empty($msg["userId"]); $anonId = !empty($msg["anonymousId"]); self::assert($userId || $anonId, "Segment::${type}() requires userId or anonymousId"); }
[ "public", "static", "function", "validate", "(", "$", "msg", ",", "$", "type", ")", "{", "$", "userId", "=", "!", "empty", "(", "$", "msg", "[", "\"userId\"", "]", ")", ";", "$", "anonId", "=", "!", "empty", "(", "$", "msg", "[", "\"anonymousId\"",...
Validate common properties. @param array $msg @param string $type
[ "Validate", "common", "properties", "." ]
9ee6e696ea12e2ac4145fdb9109a43b4cb556f1c
https://github.com/segmentio/analytics-php/blob/9ee6e696ea12e2ac4145fdb9109a43b4cb556f1c/lib/Segment.php#L109-L113
train
segmentio/analytics-php
lib/Segment/Consumer/Socket.php
Segment_Consumer_Socket.makeRequest
private function makeRequest($socket, $req, $retry = true) { $bytes_written = 0; $bytes_total = strlen($req); $closed = false; // Retries with exponential backoff until success $backoff = 100; // Set initial waiting time to 100ms while (true) { // Send request to server while (!$closed && $bytes_written < $bytes_total) { try { // Since we're try catch'ing prevent PHP logs. $written = @fwrite($socket, substr($req, $bytes_written)); } catch (Exception $e) { $this->handleError($e->getCode(), $e->getMessage()); $closed = true; } if (!isset($written) || !$written) { $closed = true; } else { $bytes_written += $written; } } // Get response for request $statusCode = 0; $errorMessage = ""; if (!$closed) { $res = $this->parseResponse(fread($socket, 2048)); $statusCode = (int)$res["status"]; $errorMessage = $res["message"]; } fclose($socket); // If status code is 200, return true if (200 == $statusCode) { return true; } // If status code is greater than 500 and less than 600, it indicates server error // Error code 429 indicates rate limited. // Retry uploading in these cases. if (($statusCode >= 500 && $statusCode <= 600) || 429 == $statusCode || 0 == $statusCode) { if ($backoff >= $this->maximum_backoff_duration) { break; } usleep($backoff * 1000); } elseif ($statusCode >= 400) { if ($this->debug()) { $this->handleError($res["status"], $res["message"]); } break; } // Retry uploading... $backoff *= 2; $socket = $this->createSocket(); } return $success; }
php
private function makeRequest($socket, $req, $retry = true) { $bytes_written = 0; $bytes_total = strlen($req); $closed = false; // Retries with exponential backoff until success $backoff = 100; // Set initial waiting time to 100ms while (true) { // Send request to server while (!$closed && $bytes_written < $bytes_total) { try { // Since we're try catch'ing prevent PHP logs. $written = @fwrite($socket, substr($req, $bytes_written)); } catch (Exception $e) { $this->handleError($e->getCode(), $e->getMessage()); $closed = true; } if (!isset($written) || !$written) { $closed = true; } else { $bytes_written += $written; } } // Get response for request $statusCode = 0; $errorMessage = ""; if (!$closed) { $res = $this->parseResponse(fread($socket, 2048)); $statusCode = (int)$res["status"]; $errorMessage = $res["message"]; } fclose($socket); // If status code is 200, return true if (200 == $statusCode) { return true; } // If status code is greater than 500 and less than 600, it indicates server error // Error code 429 indicates rate limited. // Retry uploading in these cases. if (($statusCode >= 500 && $statusCode <= 600) || 429 == $statusCode || 0 == $statusCode) { if ($backoff >= $this->maximum_backoff_duration) { break; } usleep($backoff * 1000); } elseif ($statusCode >= 400) { if ($this->debug()) { $this->handleError($res["status"], $res["message"]); } break; } // Retry uploading... $backoff *= 2; $socket = $this->createSocket(); } return $success; }
[ "private", "function", "makeRequest", "(", "$", "socket", ",", "$", "req", ",", "$", "retry", "=", "true", ")", "{", "$", "bytes_written", "=", "0", ";", "$", "bytes_total", "=", "strlen", "(", "$", "req", ")", ";", "$", "closed", "=", "false", ";"...
Attempt to write the request to the socket, wait for response if debug mode is enabled. @param stream $socket the handle for the socket @param string $req request body @param boolean $retry @return boolean $success
[ "Attempt", "to", "write", "the", "request", "to", "the", "socket", "wait", "for", "response", "if", "debug", "mode", "is", "enabled", "." ]
9ee6e696ea12e2ac4145fdb9109a43b4cb556f1c
https://github.com/segmentio/analytics-php/blob/9ee6e696ea12e2ac4145fdb9109a43b4cb556f1c/lib/Segment/Consumer/Socket.php#L96-L160
train
segmentio/analytics-php
lib/Segment/Consumer/Socket.php
Segment_Consumer_Socket.createBody
private function createBody($host, $content) { $req = ""; $req.= "POST /v1/import HTTP/1.1\r\n"; $req.= "Host: " . $host . "\r\n"; $req.= "Content-Type: application/json\r\n"; $req.= "Authorization: Basic " . base64_encode($this->secret . ":") . "\r\n"; $req.= "Accept: application/json\r\n"; // Send user agent in the form of {library_name}/{library_version} as per RFC 7231. $content_json = json_decode($content, true); $library = $content_json['batch'][0]['context']['library']; $libName = $library['name']; $libVersion = $library['version']; $req.= "User-Agent: ${libName}/${libVersion}\r\n"; // Compress content if compress_request is true if ($this->compress_request) { $content = gzencode($content); $req.= "Content-Encoding: gzip\r\n"; } $req.= "Content-length: " . strlen($content) . "\r\n"; $req.= "\r\n"; $req.= $content; // Verify message size is below than 32KB if (strlen($req) >= 32 * 1024) { if ($this->debug()) { $msg = "Message size is larger than 32KB"; error_log("[Analytics][" . $this->type . "] " . $msg); } return false; } return $req; }
php
private function createBody($host, $content) { $req = ""; $req.= "POST /v1/import HTTP/1.1\r\n"; $req.= "Host: " . $host . "\r\n"; $req.= "Content-Type: application/json\r\n"; $req.= "Authorization: Basic " . base64_encode($this->secret . ":") . "\r\n"; $req.= "Accept: application/json\r\n"; // Send user agent in the form of {library_name}/{library_version} as per RFC 7231. $content_json = json_decode($content, true); $library = $content_json['batch'][0]['context']['library']; $libName = $library['name']; $libVersion = $library['version']; $req.= "User-Agent: ${libName}/${libVersion}\r\n"; // Compress content if compress_request is true if ($this->compress_request) { $content = gzencode($content); $req.= "Content-Encoding: gzip\r\n"; } $req.= "Content-length: " . strlen($content) . "\r\n"; $req.= "\r\n"; $req.= $content; // Verify message size is below than 32KB if (strlen($req) >= 32 * 1024) { if ($this->debug()) { $msg = "Message size is larger than 32KB"; error_log("[Analytics][" . $this->type . "] " . $msg); } return false; } return $req; }
[ "private", "function", "createBody", "(", "$", "host", ",", "$", "content", ")", "{", "$", "req", "=", "\"\"", ";", "$", "req", ".=", "\"POST /v1/import HTTP/1.1\\r\\n\"", ";", "$", "req", ".=", "\"Host: \"", ".", "$", "host", ".", "\"\\r\\n\"", ";", "$"...
Create the body to send as the post request. @param string $host @param string $content @return string body
[ "Create", "the", "body", "to", "send", "as", "the", "post", "request", "." ]
9ee6e696ea12e2ac4145fdb9109a43b4cb556f1c
https://github.com/segmentio/analytics-php/blob/9ee6e696ea12e2ac4145fdb9109a43b4cb556f1c/lib/Segment/Consumer/Socket.php#L168-L205
train
segmentio/analytics-php
lib/Segment/Consumer/Socket.php
Segment_Consumer_Socket.parseResponse
private function parseResponse($res) { $contents = explode("\n", $res); // Response comes back as HTTP/1.1 200 OK // Final line contains HTTP response. $status = explode(" ", $contents[0], 3); $result = $contents[count($contents) - 1]; return array( "status" => isset($status[1]) ? $status[1] : null, "message" => $result ); }
php
private function parseResponse($res) { $contents = explode("\n", $res); // Response comes back as HTTP/1.1 200 OK // Final line contains HTTP response. $status = explode(" ", $contents[0], 3); $result = $contents[count($contents) - 1]; return array( "status" => isset($status[1]) ? $status[1] : null, "message" => $result ); }
[ "private", "function", "parseResponse", "(", "$", "res", ")", "{", "$", "contents", "=", "explode", "(", "\"\\n\"", ",", "$", "res", ")", ";", "// Response comes back as HTTP/1.1 200 OK", "// Final line contains HTTP response.", "$", "status", "=", "explode", "(", ...
Parse our response from the server, check header and body. @param string $res @return array string $status HTTP code, e.g. "200" string $message JSON response from the api
[ "Parse", "our", "response", "from", "the", "server", "check", "header", "and", "body", "." ]
9ee6e696ea12e2ac4145fdb9109a43b4cb556f1c
https://github.com/segmentio/analytics-php/blob/9ee6e696ea12e2ac4145fdb9109a43b4cb556f1c/lib/Segment/Consumer/Socket.php#L214-L226
train
pel/pel
src/PelEntryVersion.php
PelEntryVersion.setValue
public function setValue($version = 0.0) { $this->version = $version; $major = floor($version); $minor = ($version - $major) * 100; $strValue = sprintf('%02.0f%02.0f', $major, $minor); $this->components = strlen($strValue); $this->bytes = $strValue; }
php
public function setValue($version = 0.0) { $this->version = $version; $major = floor($version); $minor = ($version - $major) * 100; $strValue = sprintf('%02.0f%02.0f', $major, $minor); $this->components = strlen($strValue); $this->bytes = $strValue; }
[ "public", "function", "setValue", "(", "$", "version", "=", "0.0", ")", "{", "$", "this", "->", "version", "=", "$", "version", ";", "$", "major", "=", "floor", "(", "$", "version", ")", ";", "$", "minor", "=", "(", "$", "version", "-", "$", "maj...
Set the version held by this entry. @param float $version The size of the entries leave room for exactly four digits: two digits on either side of the decimal point.
[ "Set", "the", "version", "held", "by", "this", "entry", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelEntryVersion.php#L106-L114
train
pel/pel
src/PelEntryVersion.php
PelEntryVersion.getText
public function getText($brief = false) { $v = $this->version; /* * Versions numbers like 2.0 would be output as just 2 if we don't * add the '.0' ourselves. */ if (floor($this->version) == $this->version) { $v .= '.0'; } switch ($this->tag) { case PelTag::EXIF_VERSION: if ($brief) { return Pel::fmt('Exif %s', $v); } else { return Pel::fmt('Exif Version %s', $v); } break; case PelTag::FLASH_PIX_VERSION: if ($brief) { return Pel::fmt('FlashPix %s', $v); } else { return Pel::fmt('FlashPix Version %s', $v); } break; case PelTag::INTEROPERABILITY_VERSION: if ($brief) { return Pel::fmt('Interoperability %s', $v); } else { return Pel::fmt('Interoperability Version %s', $v); } break; } if ($brief) { return $v; } else { return Pel::fmt('Version %s', $v); } }
php
public function getText($brief = false) { $v = $this->version; /* * Versions numbers like 2.0 would be output as just 2 if we don't * add the '.0' ourselves. */ if (floor($this->version) == $this->version) { $v .= '.0'; } switch ($this->tag) { case PelTag::EXIF_VERSION: if ($brief) { return Pel::fmt('Exif %s', $v); } else { return Pel::fmt('Exif Version %s', $v); } break; case PelTag::FLASH_PIX_VERSION: if ($brief) { return Pel::fmt('FlashPix %s', $v); } else { return Pel::fmt('FlashPix Version %s', $v); } break; case PelTag::INTEROPERABILITY_VERSION: if ($brief) { return Pel::fmt('Interoperability %s', $v); } else { return Pel::fmt('Interoperability Version %s', $v); } break; } if ($brief) { return $v; } else { return Pel::fmt('Version %s', $v); } }
[ "public", "function", "getText", "(", "$", "brief", "=", "false", ")", "{", "$", "v", "=", "$", "this", "->", "version", ";", "/*\n * Versions numbers like 2.0 would be output as just 2 if we don't\n * add the '.0' ourselves.\n */", "if", "(", "floor...
Return a text string with the version. @param boolean $brief controls if the output should be brief. Brief output omits the word 'Version' so the result is just 'Exif x.y' instead of 'Exif Version x.y' if the entry holds information about the Exif version --- the output for FlashPix is similar. @return string the version number with the type of the tag, either 'Exif' or 'FlashPix'.
[ "Return", "a", "text", "string", "with", "the", "version", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelEntryVersion.php#L140-L181
train
pel/pel
src/PelIfd.php
PelIfd.safeSetThumbnail
private function safeSetThumbnail(PelDataWindow $d, $offset, $length) { /* * Load the thumbnail if both the offset and the length is * available. */ if ($offset > 0 && $length > 0) { /* * Some images have a broken length, so we try to carefully * check the length before we store the thumbnail. */ if ($offset + $length > $d->getSize()) { Pel::maybeThrow( new PelIfdException( 'Thumbnail length %d bytes ' . 'adjusted to %d bytes.', $length, $d->getSize() - $offset ) ); $length = $d->getSize() - $offset; } /* Now set the thumbnail normally. */ try { $this->setThumbnail($d->getClone($offset, $length)); } catch (PelDataWindowWindowException $e) { Pel::maybeThrow(new PelIfdException($e->getMessage())); } } }
php
private function safeSetThumbnail(PelDataWindow $d, $offset, $length) { /* * Load the thumbnail if both the offset and the length is * available. */ if ($offset > 0 && $length > 0) { /* * Some images have a broken length, so we try to carefully * check the length before we store the thumbnail. */ if ($offset + $length > $d->getSize()) { Pel::maybeThrow( new PelIfdException( 'Thumbnail length %d bytes ' . 'adjusted to %d bytes.', $length, $d->getSize() - $offset ) ); $length = $d->getSize() - $offset; } /* Now set the thumbnail normally. */ try { $this->setThumbnail($d->getClone($offset, $length)); } catch (PelDataWindowWindowException $e) { Pel::maybeThrow(new PelIfdException($e->getMessage())); } } }
[ "private", "function", "safeSetThumbnail", "(", "PelDataWindow", "$", "d", ",", "$", "offset", ",", "$", "length", ")", "{", "/*\n * Load the thumbnail if both the offset and the length is\n * available.\n */", "if", "(", "$", "offset", ">", "0", "...
Extract thumbnail data safely. It is safe to call this method repeatedly with either the offset or the length set to zero, since it requires both of these arguments to be positive before the thumbnail is extracted. When both parameters are set it will check the length against the available data and adjust as necessary. Only then is the thumbnail data loaded. @param PelDataWindow $d the data from which the thumbnail will be extracted. @param int $offset the offset into the data. @param int $length the length of the thumbnail.
[ "Extract", "thumbnail", "data", "safely", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelIfd.php#L733-L762
train
pel/pel
src/PelIfd.php
PelIfd.setThumbnail
public function setThumbnail(PelDataWindow $d) { $size = $d->getSize(); /* Now move backwards until we find the EOI JPEG marker. */ while ($d->getByte($size - 2) != 0xFF || $d->getByte($size - 1) != PelJpegMarker::EOI) { $size --; } if ($size != $d->getSize()) { Pel::maybeThrow(new PelIfdException('Decrementing thumbnail size ' . 'to %d bytes', $size)); } $this->thumb_data = $d->getClone(0, $size); }
php
public function setThumbnail(PelDataWindow $d) { $size = $d->getSize(); /* Now move backwards until we find the EOI JPEG marker. */ while ($d->getByte($size - 2) != 0xFF || $d->getByte($size - 1) != PelJpegMarker::EOI) { $size --; } if ($size != $d->getSize()) { Pel::maybeThrow(new PelIfdException('Decrementing thumbnail size ' . 'to %d bytes', $size)); } $this->thumb_data = $d->getClone(0, $size); }
[ "public", "function", "setThumbnail", "(", "PelDataWindow", "$", "d", ")", "{", "$", "size", "=", "$", "d", "->", "getSize", "(", ")", ";", "/* Now move backwards until we find the EOI JPEG marker. */", "while", "(", "$", "d", "->", "getByte", "(", "$", "size"...
Set thumbnail data. Use this to embed an arbitrary JPEG image within this IFD. The data will be checked to ensure that it has a proper {@link PelJpegMarker::EOI} at the end. If not, then the length is adjusted until one if found. An {@link PelIfdException} might be thrown (depending on {@link Pel::$strict}) this case. @param PelDataWindow $d the thumbnail data.
[ "Set", "thumbnail", "data", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelIfd.php#L776-L788
train
pel/pel
src/PelIfd.php
PelIfd.getTypeName
public static function getTypeName($type) { switch ($type) { case self::IFD0: return '0'; case self::IFD1: return '1'; case self::EXIF: return 'Exif'; case self::GPS: return 'GPS'; case self::INTEROPERABILITY: return 'Interoperability'; case self::CANON_MAKER_NOTES: return 'Canon Maker Notes'; case self::CANON_CAMERA_SETTINGS: return 'Canon Camera Settings'; case self::CANON_SHOT_INFO: return 'Canon Shot Information'; case self::CANON_PANORAMA: return 'Canon Panorama Information'; case self::CANON_PICTURE_INFO: return 'Canon Picture Information'; case self::CANON_FILE_INFO: return 'Canon File Information'; case self::CANON_CUSTOM_FUNCTIONS: return 'Canon Custom Functions'; default: throw new PelIfdException('Unknown IFD type: %d', $type); } }
php
public static function getTypeName($type) { switch ($type) { case self::IFD0: return '0'; case self::IFD1: return '1'; case self::EXIF: return 'Exif'; case self::GPS: return 'GPS'; case self::INTEROPERABILITY: return 'Interoperability'; case self::CANON_MAKER_NOTES: return 'Canon Maker Notes'; case self::CANON_CAMERA_SETTINGS: return 'Canon Camera Settings'; case self::CANON_SHOT_INFO: return 'Canon Shot Information'; case self::CANON_PANORAMA: return 'Canon Panorama Information'; case self::CANON_PICTURE_INFO: return 'Canon Picture Information'; case self::CANON_FILE_INFO: return 'Canon File Information'; case self::CANON_CUSTOM_FUNCTIONS: return 'Canon Custom Functions'; default: throw new PelIfdException('Unknown IFD type: %d', $type); } }
[ "public", "static", "function", "getTypeName", "(", "$", "type", ")", "{", "switch", "(", "$", "type", ")", "{", "case", "self", "::", "IFD0", ":", "return", "'0'", ";", "case", "self", "::", "IFD1", ":", "return", "'1'", ";", "case", "self", "::", ...
Get the name of an IFD type. @param int $type one of {@link PelIfd::IFD0}, {@link PelIfd::IFD1}, {@link PelIfd::EXIF}, {@link PelIfd::GPS}, or {@link PelIfd::INTEROPERABILITY}. @return string the name of type.
[ "Get", "the", "name", "of", "an", "IFD", "type", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelIfd.php#L1139-L1169
train
pel/pel
src/PelIfd.php
PelIfd.addEntry
public function addEntry(PelEntry $e) { if ($this->isValidTag($e->getTag())) { $e->setIfdType($this->type); $this->entries[$e->getTag()] = $e; } else { throw new PelInvalidDataException("IFD %s cannot hold\n%s", $this->getName(), $e->__toString()); } }
php
public function addEntry(PelEntry $e) { if ($this->isValidTag($e->getTag())) { $e->setIfdType($this->type); $this->entries[$e->getTag()] = $e; } else { throw new PelInvalidDataException("IFD %s cannot hold\n%s", $this->getName(), $e->__toString()); } }
[ "public", "function", "addEntry", "(", "PelEntry", "$", "e", ")", "{", "if", "(", "$", "this", "->", "isValidTag", "(", "$", "e", "->", "getTag", "(", ")", ")", ")", "{", "$", "e", "->", "setIfdType", "(", "$", "this", "->", "type", ")", ";", "...
Adds an entry to the directory. @param PelEntry $e the entry that will be added. If the entry is not valid in this IFD (as per {@link isValidTag()}) an {@link PelInvalidDataException} is thrown. @todo The entry will be identified with its tag, so each directory can only contain one entry with each tag. Is this a bug?
[ "Adds", "an", "entry", "to", "the", "directory", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelIfd.php#L1193-L1201
train
pel/pel
src/PelIfd.php
PelIfd.offsetSet
public function offsetSet($tag, $e) { if ($e instanceof PelEntry) { $tag = $e->getTag(); $this->entries[$tag] = $e; } else { throw new PelInvalidArgumentException('Argument "%s" must be a PelEntry.', $e); } }
php
public function offsetSet($tag, $e) { if ($e instanceof PelEntry) { $tag = $e->getTag(); $this->entries[$tag] = $e; } else { throw new PelInvalidArgumentException('Argument "%s" must be a PelEntry.', $e); } }
[ "public", "function", "offsetSet", "(", "$", "tag", ",", "$", "e", ")", "{", "if", "(", "$", "e", "instanceof", "PelEntry", ")", "{", "$", "tag", "=", "$", "e", "->", "getTag", "(", ")", ";", "$", "this", "->", "entries", "[", "$", "tag", "]", ...
Set or update a given tag in this IFD. This methods is part of the ArrayAccess SPL interface for overriding array access of objects, it allows you to add new entries or replace esisting entries by doing: <code> $ifd[PelTag::EXPOSURE_BIAS_VALUE] = $entry; </code> Note that the actual array index passed is ignored! Instead the {@link PelTag} from the entry is used. @param int $tag unused. @param PelEntry $e the new value.
[ "Set", "or", "update", "a", "given", "tag", "in", "this", "IFD", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelIfd.php#L1268-L1276
train
pel/pel
src/PelIfd.php
PelIfd.getEntry
public function getEntry($tag) { if (isset($this->entries[$tag])) { return $this->entries[$tag]; } else { return null; } }
php
public function getEntry($tag) { if (isset($this->entries[$tag])) { return $this->entries[$tag]; } else { return null; } }
[ "public", "function", "getEntry", "(", "$", "tag", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "entries", "[", "$", "tag", "]", ")", ")", "{", "return", "$", "this", "->", "entries", "[", "$", "tag", "]", ";", "}", "else", "{", "retur...
Retrieve an entry. @param int $tag the tag identifying the entry. @return PelEntry the entry associated with the tag, or null if no such entry exists.
[ "Retrieve", "an", "entry", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelIfd.php#L1306-L1313
train
pel/pel
src/PelIfd.php
PelIfd.getSubIfd
public function getSubIfd($type) { if (isset($this->sub[$type])) { return $this->sub[$type]; } else { return null; } }
php
public function getSubIfd($type) { if (isset($this->sub[$type])) { return $this->sub[$type]; } else { return null; } }
[ "public", "function", "getSubIfd", "(", "$", "type", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "sub", "[", "$", "type", "]", ")", ")", "{", "return", "$", "this", "->", "sub", "[", "$", "type", "]", ";", "}", "else", "{", "return", ...
Return a sub IFD. @param int $type the type of the sub IFD. This must be one of {@link PelIfd::EXIF}, {@link PelIfd::GPS}, or {@link PelIfd::INTEROPERABILITY}. @return PelIfd the IFD associated with the type, or null if that sub IFD does not exist.
[ "Return", "a", "sub", "IFD", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelIfd.php#L1428-L1435
train
pel/pel
src/PelEntryTime.php
PelEntryTime.getValue
public function getValue($type = self::UNIX_TIMESTAMP) { switch ($type) { case self::UNIX_TIMESTAMP: $seconds = $this->convertJdToUnix($this->day_count); if ($seconds === false) { /* * We get false if the Julian Day Count is outside the range * of a UNIX timestamp. */ return false; } else { return $seconds + $this->seconds; } break; case self::EXIF_STRING: list ($year, $month, $day) = $this->convertJdToGregorian($this->day_count); $hours = (int) ($this->seconds / 3600); $minutes = (int) ($this->seconds % 3600 / 60); $seconds = $this->seconds % 60; return sprintf('%04d:%02d:%02d %02d:%02d:%02d', $year, $month, $day, $hours, $minutes, $seconds); case self::JULIAN_DAY_COUNT: return $this->day_count + $this->seconds / 86400; default: throw new PelInvalidArgumentException( 'Expected UNIX_TIMESTAMP (%d), ' . 'EXIF_STRING (%d), or ' . 'JULIAN_DAY_COUNT (%d) for $type, got %d.', self::UNIX_TIMESTAMP, self::EXIF_STRING, self::JULIAN_DAY_COUNT, $type ); } }
php
public function getValue($type = self::UNIX_TIMESTAMP) { switch ($type) { case self::UNIX_TIMESTAMP: $seconds = $this->convertJdToUnix($this->day_count); if ($seconds === false) { /* * We get false if the Julian Day Count is outside the range * of a UNIX timestamp. */ return false; } else { return $seconds + $this->seconds; } break; case self::EXIF_STRING: list ($year, $month, $day) = $this->convertJdToGregorian($this->day_count); $hours = (int) ($this->seconds / 3600); $minutes = (int) ($this->seconds % 3600 / 60); $seconds = $this->seconds % 60; return sprintf('%04d:%02d:%02d %02d:%02d:%02d', $year, $month, $day, $hours, $minutes, $seconds); case self::JULIAN_DAY_COUNT: return $this->day_count + $this->seconds / 86400; default: throw new PelInvalidArgumentException( 'Expected UNIX_TIMESTAMP (%d), ' . 'EXIF_STRING (%d), or ' . 'JULIAN_DAY_COUNT (%d) for $type, got %d.', self::UNIX_TIMESTAMP, self::EXIF_STRING, self::JULIAN_DAY_COUNT, $type ); } }
[ "public", "function", "getValue", "(", "$", "type", "=", "self", "::", "UNIX_TIMESTAMP", ")", "{", "switch", "(", "$", "type", ")", "{", "case", "self", "::", "UNIX_TIMESTAMP", ":", "$", "seconds", "=", "$", "this", "->", "convertJdToUnix", "(", "$", "...
Return the timestamp of the entry. The timestamp held by this entry is returned in one of three formats: as a standard UNIX timestamp (default), as a fractional Julian Day Count, or as a string. @param integer $type the type of the timestamp. This must be one of {@link UNIX_TIMESTAMP}, {@link EXIF_STRING}, or {@link JULIAN_DAY_COUNT}. @return integer the timestamp held by this entry in the correct form as indicated by the type argument. For {@link UNIX_TIMESTAMP} this is an integer counting the number of seconds since January 1st 1970, for {@link EXIF_STRING} this is a string of the form 'YYYY:MM:DD hh:mm:ss', and for {@link JULIAN_DAY_COUNT} this is a floating point number where the integer part denotes the day count and the fractional part denotes the time of day (0.25 means 6:00, 0.75 means 18:00).
[ "Return", "the", "timestamp", "of", "the", "entry", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelEntryTime.php#L161-L193
train
pel/pel
src/PelEntryTime.php
PelEntryTime.setValue
public function setValue($timestamp, $type = self::UNIX_TIMESTAMP) { switch ($type) { case self::UNIX_TIMESTAMP: $this->day_count = $this->convertUnixToJd($timestamp); $this->seconds = $timestamp % 86400; break; case self::EXIF_STRING: /* Clean the timestamp: some timestamps are broken other * separators than ':' and ' '. */ $d = preg_split('/[^0-9]+/', $timestamp); for ($i = 0; $i < 6; $i ++) { if (empty($d[$i])) { $d[$i] = 0; } } $this->day_count = $this->convertGregorianToJd($d[0], $d[1], $d[2]); $this->seconds = $d[3] * 3600 + $d[4] * 60 + $d[5]; break; case self::JULIAN_DAY_COUNT: $this->day_count = (int) floor($timestamp); $this->seconds = (int) (86400 * ($timestamp - floor($timestamp))); break; default: throw new PelInvalidArgumentException( 'Expected UNIX_TIMESTAMP (%d), ' . 'EXIF_STRING (%d), or ' . 'JULIAN_DAY_COUNT (%d) for $type, got %d.', self::UNIX_TIMESTAMP, self::EXIF_STRING, self::JULIAN_DAY_COUNT, $type ); } /* * Now finally update the string which will be used when this is * turned into bytes. */ parent::setValue($this->getValue(self::EXIF_STRING)); }
php
public function setValue($timestamp, $type = self::UNIX_TIMESTAMP) { switch ($type) { case self::UNIX_TIMESTAMP: $this->day_count = $this->convertUnixToJd($timestamp); $this->seconds = $timestamp % 86400; break; case self::EXIF_STRING: /* Clean the timestamp: some timestamps are broken other * separators than ':' and ' '. */ $d = preg_split('/[^0-9]+/', $timestamp); for ($i = 0; $i < 6; $i ++) { if (empty($d[$i])) { $d[$i] = 0; } } $this->day_count = $this->convertGregorianToJd($d[0], $d[1], $d[2]); $this->seconds = $d[3] * 3600 + $d[4] * 60 + $d[5]; break; case self::JULIAN_DAY_COUNT: $this->day_count = (int) floor($timestamp); $this->seconds = (int) (86400 * ($timestamp - floor($timestamp))); break; default: throw new PelInvalidArgumentException( 'Expected UNIX_TIMESTAMP (%d), ' . 'EXIF_STRING (%d), or ' . 'JULIAN_DAY_COUNT (%d) for $type, got %d.', self::UNIX_TIMESTAMP, self::EXIF_STRING, self::JULIAN_DAY_COUNT, $type ); } /* * Now finally update the string which will be used when this is * turned into bytes. */ parent::setValue($this->getValue(self::EXIF_STRING)); }
[ "public", "function", "setValue", "(", "$", "timestamp", ",", "$", "type", "=", "self", "::", "UNIX_TIMESTAMP", ")", "{", "switch", "(", "$", "type", ")", "{", "case", "self", "::", "UNIX_TIMESTAMP", ":", "$", "this", "->", "day_count", "=", "$", "this...
Update the timestamp held by this entry. @param integer $timestamp the timestamp held by this entry in the correct form as indicated by the third argument. For {@link UNIX_TIMESTAMP} this is an integer counting the number of seconds since January 1st 1970, for {@link EXIF_STRING} this is a string of the form 'YYYY:MM:DD hh:mm:ss', and for {@link JULIAN_DAY_COUNT} this is a floating point number where the integer part denotes the day count and the fractional part denotes the time of day (0.25 means 6:00, 0.75 means 18:00). @param integer $type the type of the timestamp. This must be one of {@link UNIX_TIMESTAMP}, {@link EXIF_STRING}, or {@link JULIAN_DAY_COUNT}.
[ "Update", "the", "timestamp", "held", "by", "this", "entry", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelEntryTime.php#L213-L254
train
pel/pel
src/PelConvert.php
PelConvert.shortToBytes
public static function shortToBytes($value, $endian) { if ($endian == self::LITTLE_ENDIAN) { return chr($value) . chr($value >> 8); } else { return chr($value >> 8) . chr($value); } }
php
public static function shortToBytes($value, $endian) { if ($endian == self::LITTLE_ENDIAN) { return chr($value) . chr($value >> 8); } else { return chr($value >> 8) . chr($value); } }
[ "public", "static", "function", "shortToBytes", "(", "$", "value", ",", "$", "endian", ")", "{", "if", "(", "$", "endian", "==", "self", "::", "LITTLE_ENDIAN", ")", "{", "return", "chr", "(", "$", "value", ")", ".", "chr", "(", "$", "value", ">>", ...
Convert an unsigned short into two bytes. @param integer $value the unsigned short that will be converted. The lower two bytes will be extracted regardless of the actual size passed. @param boolean $endian one of {@link LITTLE_ENDIAN} and {@link BIG_ENDIAN}. @return string the bytes representing the unsigned short.
[ "Convert", "an", "unsigned", "short", "into", "two", "bytes", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelConvert.php#L88-L95
train
pel/pel
src/PelConvert.php
PelConvert.longToBytes
public static function longToBytes($value, $endian) { /* * We cannot convert the number to bytes in the normal way (using * shifts and modulo calculations) because the PHP operator >> and * function chr() clip their arguments to 2^31-1, which is the * largest signed integer known to PHP. But luckily base_convert * handles such big numbers. */ $hex = str_pad(base_convert($value, 10, 16), 8, '0', STR_PAD_LEFT); if ($endian == self::LITTLE_ENDIAN) { return (chr(hexdec($hex{6} . $hex{7})) . chr(hexdec($hex{4} . $hex{5})) . chr(hexdec($hex{2} . $hex{3})) . chr(hexdec($hex{0} . $hex{1}))); } else { return (chr(hexdec($hex{0} . $hex{1})) . chr(hexdec($hex{2} . $hex{3})) . chr(hexdec($hex{4} . $hex{5})) . chr(hexdec($hex{6} . $hex{7}))); } }
php
public static function longToBytes($value, $endian) { /* * We cannot convert the number to bytes in the normal way (using * shifts and modulo calculations) because the PHP operator >> and * function chr() clip their arguments to 2^31-1, which is the * largest signed integer known to PHP. But luckily base_convert * handles such big numbers. */ $hex = str_pad(base_convert($value, 10, 16), 8, '0', STR_PAD_LEFT); if ($endian == self::LITTLE_ENDIAN) { return (chr(hexdec($hex{6} . $hex{7})) . chr(hexdec($hex{4} . $hex{5})) . chr(hexdec($hex{2} . $hex{3})) . chr(hexdec($hex{0} . $hex{1}))); } else { return (chr(hexdec($hex{0} . $hex{1})) . chr(hexdec($hex{2} . $hex{3})) . chr(hexdec($hex{4} . $hex{5})) . chr(hexdec($hex{6} . $hex{7}))); } }
[ "public", "static", "function", "longToBytes", "(", "$", "value", ",", "$", "endian", ")", "{", "/*\n * We cannot convert the number to bytes in the normal way (using\n * shifts and modulo calculations) because the PHP operator >> and\n * function chr() clip their arg...
Convert an unsigned long into four bytes. Because PHP limits the size of integers to 32 bit signed, one cannot really have an unsigned integer in PHP. But integers larger than 2^31-1 will be promoted to 64 bit signed floating point numbers, and so such large numbers can be handled too. @param integer $value the unsigned long that will be converted. The argument will be treated as an unsigned 32 bit integer and the lower four bytes will be extracted. Treating the argument as an unsigned integer means that the absolute value will be used. Use {@link sLongToBytes} to convert signed integers. @param boolean $endian one of {@link LITTLE_ENDIAN} and {@link BIG_ENDIAN}. @return string the bytes representing the unsigned long.
[ "Convert", "an", "unsigned", "long", "into", "four", "bytes", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelConvert.php#L140-L157
train
pel/pel
src/PelConvert.php
PelConvert.sLongToBytes
public static function sLongToBytes($value, $endian) { /* * We can convert the number into bytes in the normal way using * shifts and modulo calculations here (in contrast with * longToBytes) because PHP automatically handles 32 bit signed * integers for us. */ if ($endian == self::LITTLE_ENDIAN) { return (chr($value) . chr($value >> 8) . chr($value >> 16) . chr($value >> 24)); } else { return (chr($value >> 24) . chr($value >> 16) . chr($value >> 8) . chr($value)); } }
php
public static function sLongToBytes($value, $endian) { /* * We can convert the number into bytes in the normal way using * shifts and modulo calculations here (in contrast with * longToBytes) because PHP automatically handles 32 bit signed * integers for us. */ if ($endian == self::LITTLE_ENDIAN) { return (chr($value) . chr($value >> 8) . chr($value >> 16) . chr($value >> 24)); } else { return (chr($value >> 24) . chr($value >> 16) . chr($value >> 8) . chr($value)); } }
[ "public", "static", "function", "sLongToBytes", "(", "$", "value", ",", "$", "endian", ")", "{", "/*\n * We can convert the number into bytes in the normal way using\n * shifts and modulo calculations here (in contrast with\n * longToBytes) because PHP automatically h...
Convert a signed long into four bytes. @param integer $value the signed long that will be converted. The argument will be treated as a signed 32 bit integer, from which the lower four bytes will be extracted. @param boolean $endian one of {@link LITTLE_ENDIAN} and {@link BIG_ENDIAN}. @return string the bytes representing the signed long.
[ "Convert", "a", "signed", "long", "into", "four", "bytes", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelConvert.php#L173-L186
train
pel/pel
src/PelConvert.php
PelConvert.bytesToSByte
public static function bytesToSByte($bytes, $offset) { $n = self::bytesToByte($bytes, $offset); if ($n > 127) { return $n - 256; } else { return $n; } }
php
public static function bytesToSByte($bytes, $offset) { $n = self::bytesToByte($bytes, $offset); if ($n > 127) { return $n - 256; } else { return $n; } }
[ "public", "static", "function", "bytesToSByte", "(", "$", "bytes", ",", "$", "offset", ")", "{", "$", "n", "=", "self", "::", "bytesToByte", "(", "$", "bytes", ",", "$", "offset", ")", ";", "if", "(", "$", "n", ">", "127", ")", "{", "return", "$"...
Extract a signed byte from bytes. @param string $bytes the bytes. @param integer $offset the offset. The byte found at the offset will be returned as an integer. The must be at least one byte available at offset. @return integer the signed byte found at offset, e.g., an integer in the range -128 to 127.
[ "Extract", "a", "signed", "byte", "from", "bytes", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelConvert.php#L221-L229
train
pel/pel
src/PelConvert.php
PelConvert.bytesToShort
public static function bytesToShort($bytes, $offset, $endian) { if ($endian == self::LITTLE_ENDIAN) { return (ord($bytes{$offset + 1}) * 256 + ord($bytes{$offset})); } else { return (ord($bytes{$offset}) * 256 + ord($bytes{$offset + 1})); } }
php
public static function bytesToShort($bytes, $offset, $endian) { if ($endian == self::LITTLE_ENDIAN) { return (ord($bytes{$offset + 1}) * 256 + ord($bytes{$offset})); } else { return (ord($bytes{$offset}) * 256 + ord($bytes{$offset + 1})); } }
[ "public", "static", "function", "bytesToShort", "(", "$", "bytes", ",", "$", "offset", ",", "$", "endian", ")", "{", "if", "(", "$", "endian", "==", "self", "::", "LITTLE_ENDIAN", ")", "{", "return", "(", "ord", "(", "$", "bytes", "{", "$", "offset",...
Extract an unsigned short from bytes. @param string $bytes the bytes. @param integer $offset the offset. The short found at the offset will be returned as an integer. There must be at least two bytes available beginning at the offset given. @param boolean $endian one of {@link LITTLE_ENDIAN} and {@link BIG_ENDIAN}. @return integer the unsigned short found at offset, e.g., an integer in the range 0 to 65535.
[ "Extract", "an", "unsigned", "short", "from", "bytes", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelConvert.php#L248-L255
train
pel/pel
src/PelConvert.php
PelConvert.bytesToSShort
public static function bytesToSShort($bytes, $offset, $endian) { $n = self::bytesToShort($bytes, $offset, $endian); if ($n > 32767) { return $n - 65536; } else { return $n; } }
php
public static function bytesToSShort($bytes, $offset, $endian) { $n = self::bytesToShort($bytes, $offset, $endian); if ($n > 32767) { return $n - 65536; } else { return $n; } }
[ "public", "static", "function", "bytesToSShort", "(", "$", "bytes", ",", "$", "offset", ",", "$", "endian", ")", "{", "$", "n", "=", "self", "::", "bytesToShort", "(", "$", "bytes", ",", "$", "offset", ",", "$", "endian", ")", ";", "if", "(", "$", ...
Extract a signed short from bytes. @param string $bytes @param integer $offset The short found at offset will be returned as an integer. There must be at least two bytes available beginning at the offset given. @param boolean $endian one of {@link LITTLE_ENDIAN} and {@link BIG_ENDIAN}. @return integer the signed byte found at offset, e.g., an integer in the range -32768 to 32767.
[ "Extract", "a", "signed", "short", "from", "bytes", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelConvert.php#L273-L281
train
pel/pel
src/PelConvert.php
PelConvert.bytesToLong
public static function bytesToLong($bytes, $offset, $endian) { if ($endian == self::LITTLE_ENDIAN) { return (ord($bytes{$offset + 3}) * 16777216 + ord($bytes{$offset + 2}) * 65536 + ord($bytes{$offset + 1}) * 256 + ord($bytes{$offset})); } else { return (ord($bytes{$offset}) * 16777216 + ord($bytes{$offset + 1}) * 65536 + ord($bytes{$offset + 2}) * 256 + ord($bytes{$offset + 3})); } }
php
public static function bytesToLong($bytes, $offset, $endian) { if ($endian == self::LITTLE_ENDIAN) { return (ord($bytes{$offset + 3}) * 16777216 + ord($bytes{$offset + 2}) * 65536 + ord($bytes{$offset + 1}) * 256 + ord($bytes{$offset})); } else { return (ord($bytes{$offset}) * 16777216 + ord($bytes{$offset + 1}) * 65536 + ord($bytes{$offset + 2}) * 256 + ord($bytes{$offset + 3})); } }
[ "public", "static", "function", "bytesToLong", "(", "$", "bytes", ",", "$", "offset", ",", "$", "endian", ")", "{", "if", "(", "$", "endian", "==", "self", "::", "LITTLE_ENDIAN", ")", "{", "return", "(", "ord", "(", "$", "bytes", "{", "$", "offset", ...
Extract an unsigned long from bytes. @param string $bytes @param integer $offset The long found at offset will be returned as an integer. There must be at least four bytes available beginning at the offset given. @param boolean $endian one of {@link LITTLE_ENDIAN} and {@link BIG_ENDIAN}. @return integer the unsigned long found at offset, e.g., an integer in the range 0 to 4294967295.
[ "Extract", "an", "unsigned", "long", "from", "bytes", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelConvert.php#L299-L308
train
pel/pel
src/PelConvert.php
PelConvert.bytesToSLong
public static function bytesToSLong($bytes, $offset, $endian) { $n = self::bytesToLong($bytes, $offset, $endian); if ($n > 2147483647) { return $n - 4294967296; } else { return $n; } }
php
public static function bytesToSLong($bytes, $offset, $endian) { $n = self::bytesToLong($bytes, $offset, $endian); if ($n > 2147483647) { return $n - 4294967296; } else { return $n; } }
[ "public", "static", "function", "bytesToSLong", "(", "$", "bytes", ",", "$", "offset", ",", "$", "endian", ")", "{", "$", "n", "=", "self", "::", "bytesToLong", "(", "$", "bytes", ",", "$", "offset", ",", "$", "endian", ")", ";", "if", "(", "$", ...
Extract a signed long from bytes. @param string $bytes @param integer $offset The long found at offset will be returned as an integer. There must be at least four bytes available beginning at the offset given. @param boolean $endian one of {@link LITTLE_ENDIAN} and {@link BIG_ENDIAN}. * @return integer the signed long found at offset, e.g., an integer in the range -2147483648 to 2147483647.
[ "Extract", "a", "signed", "long", "from", "bytes", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelConvert.php#L326-L334
train
pel/pel
src/PelConvert.php
PelConvert.bytesToRational
public static function bytesToRational($bytes, $offset, $endian) { return [ self::bytesToLong($bytes, $offset, $endian), self::bytesToLong($bytes, $offset + 4, $endian) ]; }
php
public static function bytesToRational($bytes, $offset, $endian) { return [ self::bytesToLong($bytes, $offset, $endian), self::bytesToLong($bytes, $offset + 4, $endian) ]; }
[ "public", "static", "function", "bytesToRational", "(", "$", "bytes", ",", "$", "offset", ",", "$", "endian", ")", "{", "return", "[", "self", "::", "bytesToLong", "(", "$", "bytes", ",", "$", "offset", ",", "$", "endian", ")", ",", "self", "::", "by...
Extract an unsigned rational from bytes. @param string $bytes @param integer $offset The rational found at offset will be returned as an array. There must be at least eight bytes available beginning at the offset given. @param boolean $endian one of {@link LITTLE_ENDIAN} and {@link BIG_ENDIAN}. * @return array the unsigned rational found at offset, e.g., an array with two integers in the range 0 to 4294967295.
[ "Extract", "an", "unsigned", "rational", "from", "bytes", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelConvert.php#L352-L358
train
pel/pel
src/PelConvert.php
PelConvert.bytesToSRational
public static function bytesToSRational($bytes, $offset, $endian) { return [ self::bytesToSLong($bytes, $offset, $endian), self::bytesToSLong($bytes, $offset + 4, $endian) ]; }
php
public static function bytesToSRational($bytes, $offset, $endian) { return [ self::bytesToSLong($bytes, $offset, $endian), self::bytesToSLong($bytes, $offset + 4, $endian) ]; }
[ "public", "static", "function", "bytesToSRational", "(", "$", "bytes", ",", "$", "offset", ",", "$", "endian", ")", "{", "return", "[", "self", "::", "bytesToSLong", "(", "$", "bytes", ",", "$", "offset", ",", "$", "endian", ")", ",", "self", "::", "...
Extract a signed rational from bytes. @param string $bytes @param integer $offset The rational found at offset will be returned as an array. There must be at least eight bytes available beginning at the offset given. @param boolean $endian one of {@link LITTLE_ENDIAN} and {@link BIG_ENDIAN}. @return array the signed rational found at offset, e.g., an array with two integers in the range -2147483648 to 2147483647.
[ "Extract", "a", "signed", "rational", "from", "bytes", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelConvert.php#L376-L382
train
pel/pel
src/PelConvert.php
PelConvert.bytesToDump
public static function bytesToDump($bytes, $max = 0) { $s = strlen($bytes); if ($max > 0) { $s = min($max, $s); } $line = 24; for ($i = 0; $i < $s; $i ++) { printf('%02X ', ord($bytes{$i})); if (($i + 1) % $line == 0) { print("\n"); } } print("\n"); }
php
public static function bytesToDump($bytes, $max = 0) { $s = strlen($bytes); if ($max > 0) { $s = min($max, $s); } $line = 24; for ($i = 0; $i < $s; $i ++) { printf('%02X ', ord($bytes{$i})); if (($i + 1) % $line == 0) { print("\n"); } } print("\n"); }
[ "public", "static", "function", "bytesToDump", "(", "$", "bytes", ",", "$", "max", "=", "0", ")", "{", "$", "s", "=", "strlen", "(", "$", "bytes", ")", ";", "if", "(", "$", "max", ">", "0", ")", "{", "$", "s", "=", "min", "(", "$", "max", "...
Format bytes for dumping. This method is for debug output, it will format a string as a hexadecimal dump suitable for display on a terminal. The output is printed directly to standard out. @param string $bytes the bytes that will be dumped. @param integer $max the maximum number of bytes to dump. If this is left out (or left to the default of 0), then the entire string will be dumped. @return void
[ "Format", "bytes", "for", "dumping", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelConvert.php#L400-L417
train
pel/pel
src/PelJpeg.php
PelJpeg.setExif
public function setExif(PelExif $exif) { $app0_offset = 1; $app1_offset = - 1; /* Search through all sections looking for APP0 or APP1. */ $sections_count = count($this->sections); for ($i = 0; $i < $sections_count; $i ++) { if (! empty($this->sections[$i][0])) { $section = $this->sections[$i]; if ($section[0] == PelJpegMarker::APP0) { $app0_offset = $i; } elseif (($section[0] == PelJpegMarker::APP1) && ($section[1] instanceof PelExif)) { $app1_offset = $i; break; } } } /* * Store the Exif data at the appropriate place, either where the * old Exif data was stored ($app1_offset) or right after APP0 * ($app0_offset+1). */ if ($app1_offset > 0) { $this->sections[$app1_offset][1] = $exif; } else { $this->insertSection(PelJpegMarker::APP1, $exif, $app0_offset + 1); } }
php
public function setExif(PelExif $exif) { $app0_offset = 1; $app1_offset = - 1; /* Search through all sections looking for APP0 or APP1. */ $sections_count = count($this->sections); for ($i = 0; $i < $sections_count; $i ++) { if (! empty($this->sections[$i][0])) { $section = $this->sections[$i]; if ($section[0] == PelJpegMarker::APP0) { $app0_offset = $i; } elseif (($section[0] == PelJpegMarker::APP1) && ($section[1] instanceof PelExif)) { $app1_offset = $i; break; } } } /* * Store the Exif data at the appropriate place, either where the * old Exif data was stored ($app1_offset) or right after APP0 * ($app0_offset+1). */ if ($app1_offset > 0) { $this->sections[$app1_offset][1] = $exif; } else { $this->insertSection(PelJpegMarker::APP1, $exif, $app0_offset + 1); } }
[ "public", "function", "setExif", "(", "PelExif", "$", "exif", ")", "{", "$", "app0_offset", "=", "1", ";", "$", "app1_offset", "=", "-", "1", ";", "/* Search through all sections looking for APP0 or APP1. */", "$", "sections_count", "=", "count", "(", "$", "this...
Set Exif data. Use this to set the Exif data in the image. This will overwrite any old Exif information in the image. @param PelExif the Exif data.
[ "Set", "Exif", "data", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelJpeg.php#L298-L327
train
pel/pel
src/PelJpeg.php
PelJpeg.setICC
public function setICC(PelJpegContent $icc) { $app1_offset = 1; $app2_offset = - 1; /* Search through all sections looking for APP0 or APP1. */ $count_sections = count($this->sections); for ($i = 0; $i < $count_sections; $i ++) { if (! empty($this->sections[$i][0])) { if ($this->sections[$i][0] == PelJpegMarker::APP1) { $app1_offset = $i; } elseif ($this->sections[$i][0] == PelJpegMarker::APP2) { $app2_offset = $i; break; } } } /* * Store the Exif data at the appropriate place, either where the * old Exif data was stored ($app1_offset) or right after APP0 * ($app0_offset+1). */ if ($app2_offset > 0) { $this->sections[$app1_offset][1] = $icc; } else { $this->insertSection(PelJpegMarker::APP2, $icc, $app1_offset + 1); } }
php
public function setICC(PelJpegContent $icc) { $app1_offset = 1; $app2_offset = - 1; /* Search through all sections looking for APP0 or APP1. */ $count_sections = count($this->sections); for ($i = 0; $i < $count_sections; $i ++) { if (! empty($this->sections[$i][0])) { if ($this->sections[$i][0] == PelJpegMarker::APP1) { $app1_offset = $i; } elseif ($this->sections[$i][0] == PelJpegMarker::APP2) { $app2_offset = $i; break; } } } /* * Store the Exif data at the appropriate place, either where the * old Exif data was stored ($app1_offset) or right after APP0 * ($app0_offset+1). */ if ($app2_offset > 0) { $this->sections[$app1_offset][1] = $icc; } else { $this->insertSection(PelJpegMarker::APP2, $icc, $app1_offset + 1); } }
[ "public", "function", "setICC", "(", "PelJpegContent", "$", "icc", ")", "{", "$", "app1_offset", "=", "1", ";", "$", "app2_offset", "=", "-", "1", ";", "/* Search through all sections looking for APP0 or APP1. */", "$", "count_sections", "=", "count", "(", "$", ...
Set ICC data. Use this to set the ICC data in the image. This will overwrite any old ICC information in the image. @param PelJpegContent the ICC data.
[ "Set", "ICC", "data", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelJpeg.php#L338-L366
train
pel/pel
src/PelJpeg.php
PelJpeg.getExif
public function getExif() { $sections_count = count($this->sections); for ($i = 0; $i < $sections_count; $i ++) { $section = $this->getSection(PelJpegMarker::APP1, $i); if ($section instanceof PelExif) { return $section; } } return null; }
php
public function getExif() { $sections_count = count($this->sections); for ($i = 0; $i < $sections_count; $i ++) { $section = $this->getSection(PelJpegMarker::APP1, $i); if ($section instanceof PelExif) { return $section; } } return null; }
[ "public", "function", "getExif", "(", ")", "{", "$", "sections_count", "=", "count", "(", "$", "this", "->", "sections", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "sections_count", ";", "$", "i", "++", ")", "{", "$", "s...
Get first valid APP1 Exif section data. Use this to get the @{link PelExif Exif data} stored. @return PelExif the Exif data found or null if the image has no Exif data.
[ "Get", "first", "valid", "APP1", "Exif", "section", "data", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelJpeg.php#L376-L386
train
pel/pel
src/PelJpeg.php
PelJpeg.getICC
public function getICC() { $icc = $this->getSection(PelJpegMarker::APP2); if ($icc instanceof PelJpegContent) { return $icc; } return null; }
php
public function getICC() { $icc = $this->getSection(PelJpegMarker::APP2); if ($icc instanceof PelJpegContent) { return $icc; } return null; }
[ "public", "function", "getICC", "(", ")", "{", "$", "icc", "=", "$", "this", "->", "getSection", "(", "PelJpegMarker", "::", "APP2", ")", ";", "if", "(", "$", "icc", "instanceof", "PelJpegContent", ")", "{", "return", "$", "icc", ";", "}", "return", ...
Get ICC data. Use this to get the @{link PelJpegContent ICC data} stored. @return PelJpegContent the ICC data found or null if the image has no ICC data.
[ "Get", "ICC", "data", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelJpeg.php#L396-L403
train
pel/pel
src/PelJpeg.php
PelJpeg.clearExif
public function clearExif() { $idx = 0; while ($idx < count($this->sections)) { $s = $this->sections[$idx]; if (($s[0] == PelJpegMarker::APP1) && ($s[1] instanceof PelExif)) { array_splice($this->sections, $idx, 1); $idx--; } else { ++ $idx; } } }
php
public function clearExif() { $idx = 0; while ($idx < count($this->sections)) { $s = $this->sections[$idx]; if (($s[0] == PelJpegMarker::APP1) && ($s[1] instanceof PelExif)) { array_splice($this->sections, $idx, 1); $idx--; } else { ++ $idx; } } }
[ "public", "function", "clearExif", "(", ")", "{", "$", "idx", "=", "0", ";", "while", "(", "$", "idx", "<", "count", "(", "$", "this", "->", "sections", ")", ")", "{", "$", "s", "=", "$", "this", "->", "sections", "[", "$", "idx", "]", ";", "...
Clear any Exif data. This method will only clear @{link PelJpegMarker::APP1} EXIF sections found.
[ "Clear", "any", "Exif", "data", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelJpeg.php#L410-L422
train
pel/pel
src/PelJpeg.php
PelJpeg.insertSection
public function insertSection($marker, PelJpegContent $content, $offset) { array_splice($this->sections, $offset, 0, [ [ $marker, $content ] ]); }
php
public function insertSection($marker, PelJpegContent $content, $offset) { array_splice($this->sections, $offset, 0, [ [ $marker, $content ] ]); }
[ "public", "function", "insertSection", "(", "$", "marker", ",", "PelJpegContent", "$", "content", ",", "$", "offset", ")", "{", "array_splice", "(", "$", "this", "->", "sections", ",", "$", "offset", ",", "0", ",", "[", "[", "$", "marker", ",", "$", ...
Insert a new section. Please use @{link setExif()} instead if you intend to add Exif information to an image as that function will know the right place to insert the data. @param PelJpegMarker the marker for the new section. @param PelJpegContent the content of the new section. @param int the offset where the new section will be inserted --- use 0 to insert it at the very beginning, use 1 to insert it between sections 1 and 2, etc.
[ "Insert", "a", "new", "section", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelJpeg.php#L467-L475
train
pel/pel
src/PelJpeg.php
PelJpeg.getSection
public function getSection($marker, $skip = 0) { foreach ($this->sections as $s) { if ($s[0] == $marker) { if ($skip > 0) { $skip --; } else { return $s[1]; } } } return null; }
php
public function getSection($marker, $skip = 0) { foreach ($this->sections as $s) { if ($s[0] == $marker) { if ($skip > 0) { $skip --; } else { return $s[1]; } } } return null; }
[ "public", "function", "getSection", "(", "$", "marker", ",", "$", "skip", "=", "0", ")", "{", "foreach", "(", "$", "this", "->", "sections", "as", "$", "s", ")", "{", "if", "(", "$", "s", "[", "0", "]", "==", "$", "marker", ")", "{", "if", "(...
Get a section corresponding to a particular marker. Please use the {@link getExif()} if you just need the Exif data. This will search through the sections of this JPEG object, looking for a section identified with the specified {@link PelJpegMarker marker}. The {@link PelJpegContent content} will then be returned. The optional argument can be used to skip over some of the sections. So if one is looking for the, say, third {@link PelJpegMarker::DHT DHT} section one would do: <code> $dht3 = $jpeg->getSection(PelJpegMarker::DHT, 2); </code> @param PelJpegMarker the marker identifying the section. @param int the number of sections to be skipped. This must be a non-negative integer. @return PelJpegContent the content found, or null if there is no content available.
[ "Get", "a", "section", "corresponding", "to", "a", "particular", "marker", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelJpeg.php#L503-L516
train
pel/pel
src/PelJpeg.php
PelJpeg.getBytes
public function getBytes() { $bytes = ''; foreach ($this->sections as $section) { $m = $section[0]; $c = $section[1]; /* Write the marker */ $bytes .= "\xFF" . PelJpegMarker::getBytes($m); /* Skip over empty markers. */ if ($m == PelJpegMarker::SOI || $m == PelJpegMarker::EOI) { continue; } $data = $c->getBytes(); $size = strlen($data) + 2; $bytes .= PelConvert::shortToBytes($size, PelConvert::BIG_ENDIAN); $bytes .= $data; /* In case of SOS, we need to write the JPEG data. */ if ($m == PelJpegMarker::SOS) { $bytes .= $this->jpeg_data->getBytes(); } } return $bytes; }
php
public function getBytes() { $bytes = ''; foreach ($this->sections as $section) { $m = $section[0]; $c = $section[1]; /* Write the marker */ $bytes .= "\xFF" . PelJpegMarker::getBytes($m); /* Skip over empty markers. */ if ($m == PelJpegMarker::SOI || $m == PelJpegMarker::EOI) { continue; } $data = $c->getBytes(); $size = strlen($data) + 2; $bytes .= PelConvert::shortToBytes($size, PelConvert::BIG_ENDIAN); $bytes .= $data; /* In case of SOS, we need to write the JPEG data. */ if ($m == PelJpegMarker::SOS) { $bytes .= $this->jpeg_data->getBytes(); } } return $bytes; }
[ "public", "function", "getBytes", "(", ")", "{", "$", "bytes", "=", "''", ";", "foreach", "(", "$", "this", "->", "sections", "as", "$", "section", ")", "{", "$", "m", "=", "$", "section", "[", "0", "]", ";", "$", "c", "=", "$", "section", "[",...
Turn this JPEG object into bytes. The bytes returned by this method is ready to be stored in a file as a valid JPEG image. Use the {@link saveFile()} convenience method to do this. @return string bytes representing this JPEG object, including all its sections and their associated data.
[ "Turn", "this", "JPEG", "object", "into", "bytes", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelJpeg.php#L564-L592
train
pel/pel
src/PelJpeg.php
PelJpeg.isValid
public static function isValid(PelDataWindow $d) { /* JPEG data is stored in big-endian format. */ $d->setByteOrder(PelConvert::BIG_ENDIAN); $i = self::getJpgSectionStart($d); return $d->getByte($i) == PelJpegMarker::SOI; }
php
public static function isValid(PelDataWindow $d) { /* JPEG data is stored in big-endian format. */ $d->setByteOrder(PelConvert::BIG_ENDIAN); $i = self::getJpgSectionStart($d); return $d->getByte($i) == PelJpegMarker::SOI; }
[ "public", "static", "function", "isValid", "(", "PelDataWindow", "$", "d", ")", "{", "/* JPEG data is stored in big-endian format. */", "$", "d", "->", "setByteOrder", "(", "PelConvert", "::", "BIG_ENDIAN", ")", ";", "$", "i", "=", "self", "::", "getJpgSectionStar...
Test data to see if it could be a valid JPEG image. The function will only look at the first few bytes of the data, and try to determine if it could be a valid JPEG image based on those bytes. This means that the check is more like a heuristic than a rigorous check. @param PelDataWindow the bytes that will be checked. @return boolean true if the bytes look like the beginning of a JPEG image, false otherwise. @see PelTiff::isValid()
[ "Test", "data", "to", "see", "if", "it", "could", "be", "a", "valid", "JPEG", "image", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelJpeg.php#L660-L668
train
pel/pel
src/PelFormat.php
PelFormat.getSize
public static function getSize($type) { if (array_key_exists($type, self::$formatLength)) { return self::$formatLength[$type]; } else { return Pel::fmt('Unknown format: 0x%X', $type); } }
php
public static function getSize($type) { if (array_key_exists($type, self::$formatLength)) { return self::$formatLength[$type]; } else { return Pel::fmt('Unknown format: 0x%X', $type); } }
[ "public", "static", "function", "getSize", "(", "$", "type", ")", "{", "if", "(", "array_key_exists", "(", "$", "type", ",", "self", "::", "$", "formatLength", ")", ")", "{", "return", "self", "::", "$", "formatLength", "[", "$", "type", "]", ";", "}...
Return the size of components in a given format in bytes needed to store one component with the given format. @param integer $type as defined in {@link PelFormat} @return integer|string
[ "Return", "the", "size", "of", "components", "in", "a", "given", "format", "in", "bytes", "needed", "to", "store", "one", "component", "with", "the", "given", "format", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelFormat.php#L219-L226
train
pel/pel
src/PelTag.php
PelTag.getTagByName
public static function getTagByName($name) { $k = array_search($name, self::$exifTagsShort); if ($k !== false) { return $k; } $k = array_search($name, static::$gpsTagsShort); if ($k !== false) { return $k; } return array_search($name, self::$canonTagsShort); }
php
public static function getTagByName($name) { $k = array_search($name, self::$exifTagsShort); if ($k !== false) { return $k; } $k = array_search($name, static::$gpsTagsShort); if ($k !== false) { return $k; } return array_search($name, self::$canonTagsShort); }
[ "public", "static", "function", "getTagByName", "(", "$", "name", ")", "{", "$", "k", "=", "array_search", "(", "$", "name", ",", "self", "::", "$", "exifTagsShort", ")", ";", "if", "(", "$", "k", "!==", "false", ")", "{", "return", "$", "k", ";", ...
Reverse lookup of a tag id by its short name. Return false for the unknown tag name. @deprecated Use getExifTagByName() and getGpsTagByName() to distinct the type of tag. @param string $name tag short name. @return mixed (bool|int) the tag.
[ "Reverse", "lookup", "of", "a", "tag", "id", "by", "its", "short", "name", ".", "Return", "false", "for", "the", "unknown", "tag", "name", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelTag.php#L2338-L2351
train
pel/pel
src/PelTag.php
PelTag.getName
public static function getName($type, $tag) { switch ($type) { case PelIfd::IFD0: case PelIfd::IFD1: case PelIfd::EXIF: case PelIfd::INTEROPERABILITY: return self::getValue(self::$exifTagsShort, $tag); case PelIfd::GPS: return self::getValue(self::$gpsTagsShort, $tag); case PelIfd::CANON_MAKER_NOTES: return self::getValue(self::$canonTagsShort, $tag); case PelIfd::CANON_CAMERA_SETTINGS: return self::getValue(self::$canonCsTagsShort, $tag); case PelIfd::CANON_SHOT_INFO: return self::getValue(self::$canonSiTagsShort, $tag); case PelIfd::CANON_PANORAMA: return self::getValue(self::$canonPaTagsShort, $tag); case PelIfd::CANON_PICTURE_INFO: return self::getValue(self::$canonPiTagsShort, $tag); case PelIfd::CANON_FILE_INFO: return self::getValue(self::$canonFiTagsShort, $tag); } return self::unknownTag($tag); }
php
public static function getName($type, $tag) { switch ($type) { case PelIfd::IFD0: case PelIfd::IFD1: case PelIfd::EXIF: case PelIfd::INTEROPERABILITY: return self::getValue(self::$exifTagsShort, $tag); case PelIfd::GPS: return self::getValue(self::$gpsTagsShort, $tag); case PelIfd::CANON_MAKER_NOTES: return self::getValue(self::$canonTagsShort, $tag); case PelIfd::CANON_CAMERA_SETTINGS: return self::getValue(self::$canonCsTagsShort, $tag); case PelIfd::CANON_SHOT_INFO: return self::getValue(self::$canonSiTagsShort, $tag); case PelIfd::CANON_PANORAMA: return self::getValue(self::$canonPaTagsShort, $tag); case PelIfd::CANON_PICTURE_INFO: return self::getValue(self::$canonPiTagsShort, $tag); case PelIfd::CANON_FILE_INFO: return self::getValue(self::$canonFiTagsShort, $tag); } return self::unknownTag($tag); }
[ "public", "static", "function", "getName", "(", "$", "type", ",", "$", "tag", ")", "{", "switch", "(", "$", "type", ")", "{", "case", "PelIfd", "::", "IFD0", ":", "case", "PelIfd", "::", "IFD1", ":", "case", "PelIfd", "::", "EXIF", ":", "case", "Pe...
Returns a short name for an Exif tag. @param int $type the IFD type of the tag, one of {@link PelIfd::IFD0}, {@link PelIfd::IFD1}, {@link PelIfd::EXIF}, {@link PelIfd::GPS}, or {@link PelIfd::INTEROPERABILITY}. @param int $tag the tag. @return string the short name of the tag, e.g., 'ImageWidth' for the {@link IMAGE_WIDTH} tag. If the tag is not known, the string 'Unknown:0xTTTT' will be returned where 'TTTT' is the hexadecimal representation of the tag.
[ "Returns", "a", "short", "name", "for", "an", "Exif", "tag", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelTag.php#L2411-L2436
train
pel/pel
src/PelTag.php
PelTag.getTitle
public function getTitle($type, $tag) { switch ($type) { case PelIfd::IFD0: case PelIfd::IFD1: case PelIfd::EXIF: case PelIfd::INTEROPERABILITY: return Pel::tra(self::getValue(self::$exifTagsTitle, $tag)); case PelIfd::GPS: return Pel::tra(self::getValue(self::$gpsTagsShort, $tag)); case PelIfd::CANON_MAKER_NOTES: return Pel::tra(self::getValue(self::$canonTagsTitle, $tag)); case PelIfd::CANON_CAMERA_SETTINGS: return self::getValue(self::$canonCsTagsTitle, $tag); case PelIfd::CANON_SHOT_INFO: return self::getValue(self::$canonSiTagsTitle, $tag); case PelIfd::CANON_PANORAMA: return self::getValue(self::$canonPaTagsTitle, $tag); case PelIfd::CANON_PICTURE_INFO: return self::getValue(self::$canonPiTagsTitle, $tag); case PelIfd::CANON_FILE_INFO: return self::getValue(self::$canonFiTagsTitle, $tag); } return self::unknownTag($tag); }
php
public function getTitle($type, $tag) { switch ($type) { case PelIfd::IFD0: case PelIfd::IFD1: case PelIfd::EXIF: case PelIfd::INTEROPERABILITY: return Pel::tra(self::getValue(self::$exifTagsTitle, $tag)); case PelIfd::GPS: return Pel::tra(self::getValue(self::$gpsTagsShort, $tag)); case PelIfd::CANON_MAKER_NOTES: return Pel::tra(self::getValue(self::$canonTagsTitle, $tag)); case PelIfd::CANON_CAMERA_SETTINGS: return self::getValue(self::$canonCsTagsTitle, $tag); case PelIfd::CANON_SHOT_INFO: return self::getValue(self::$canonSiTagsTitle, $tag); case PelIfd::CANON_PANORAMA: return self::getValue(self::$canonPaTagsTitle, $tag); case PelIfd::CANON_PICTURE_INFO: return self::getValue(self::$canonPiTagsTitle, $tag); case PelIfd::CANON_FILE_INFO: return self::getValue(self::$canonFiTagsTitle, $tag); } return self::unknownTag($tag); }
[ "public", "function", "getTitle", "(", "$", "type", ",", "$", "tag", ")", "{", "switch", "(", "$", "type", ")", "{", "case", "PelIfd", "::", "IFD0", ":", "case", "PelIfd", "::", "IFD1", ":", "case", "PelIfd", "::", "EXIF", ":", "case", "PelIfd", ":...
Returns a title for an Exif tag. @param int $type the IFD type of the tag, one of {@link PelIfd::IFD0}, {@link PelIfd::IFD1}, {@link PelIfd::EXIF}, {@link PelIfd::GPS}, or {@link PelIfd::INTEROPERABILITY}. @param int $tag the tag. @return string the title of the tag, e.g., 'Image Width' for the {@link IMAGE_WIDTH} tag. If the tag isn't known, the string 'Unknown Tag: 0xTT' will be returned where 'TT' is the hexadecimal representation of the tag.
[ "Returns", "a", "title", "for", "an", "Exif", "tag", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelTag.php#L2454-L2479
train
pel/pel
src/PelEntryUndefined.php
PelEntryUndefined.getText
public function getText($brief = false) { switch ($this->tag) { case PelTag::FILE_SOURCE: // CC (e->components, 1, v); switch (ord($this->bytes{0})) { case 0x03: return 'DSC'; default: return sprintf('0x%02X', ord($this->bytes{0})); } break; case PelTag::SCENE_TYPE: // CC (e->components, 1, v); switch (ord($this->bytes{0})) { case 0x01: return 'Directly photographed'; default: return sprintf('0x%02X', ord($this->bytes{0})); } break; case PelTag::COMPONENTS_CONFIGURATION: // CC (e->components, 4, v); $v = ''; for ($i = 0; $i < 4; $i ++) { switch (ord($this->bytes{$i})) { case 0: $v .= '-'; break; case 1: $v .= 'Y'; break; case 2: $v .= 'Cb'; break; case 3: $v .= 'Cr'; break; case 4: $v .= 'R'; break; case 5: $v .= 'G'; break; case 6: $v .= 'B'; break; default: $v .= 'reserved'; break; } if ($i < 3) { $v .= ' '; } } return $v; break; case PelTag::MAKER_NOTE: // TODO: handle maker notes. return $this->components . ' bytes unknown MakerNote data'; break; default: return '(undefined)'; } }
php
public function getText($brief = false) { switch ($this->tag) { case PelTag::FILE_SOURCE: // CC (e->components, 1, v); switch (ord($this->bytes{0})) { case 0x03: return 'DSC'; default: return sprintf('0x%02X', ord($this->bytes{0})); } break; case PelTag::SCENE_TYPE: // CC (e->components, 1, v); switch (ord($this->bytes{0})) { case 0x01: return 'Directly photographed'; default: return sprintf('0x%02X', ord($this->bytes{0})); } break; case PelTag::COMPONENTS_CONFIGURATION: // CC (e->components, 4, v); $v = ''; for ($i = 0; $i < 4; $i ++) { switch (ord($this->bytes{$i})) { case 0: $v .= '-'; break; case 1: $v .= 'Y'; break; case 2: $v .= 'Cb'; break; case 3: $v .= 'Cr'; break; case 4: $v .= 'R'; break; case 5: $v .= 'G'; break; case 6: $v .= 'B'; break; default: $v .= 'reserved'; break; } if ($i < 3) { $v .= ' '; } } return $v; break; case PelTag::MAKER_NOTE: // TODO: handle maker notes. return $this->components . ' bytes unknown MakerNote data'; break; default: return '(undefined)'; } }
[ "public", "function", "getText", "(", "$", "brief", "=", "false", ")", "{", "switch", "(", "$", "this", "->", "tag", ")", "{", "case", "PelTag", "::", "FILE_SOURCE", ":", "// CC (e->components, 1, v);", "switch", "(", "ord", "(", "$", "this", "->", "byte...
Get the value of this entry as text. The value will be returned in a format suitable for presentation. @param boolean some values can be returned in a long or more brief form, and this parameter controls that. @return string the value as text.
[ "Get", "the", "value", "of", "this", "entry", "as", "text", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelEntryUndefined.php#L108-L172
train
pel/pel
src/PelTiff.php
PelTiff.load
public function load(PelDataWindow $d) { Pel::debug('Parsing %d bytes of TIFF data...', $d->getSize()); /* * There must be at least 8 bytes available: 2 bytes for the byte * order, 2 bytes for the TIFF header, and 4 bytes for the offset * to the first IFD. */ if ($d->getSize() < 8) { throw new PelInvalidDataException('Expected at least 8 bytes of TIFF ' . 'data, found just %d bytes.', $d->getSize()); } /* Byte order */ if ($d->strcmp(0, 'II')) { Pel::debug('Found Intel byte order'); $d->setByteOrder(PelConvert::LITTLE_ENDIAN); } elseif ($d->strcmp(0, 'MM')) { Pel::debug('Found Motorola byte order'); $d->setByteOrder(PelConvert::BIG_ENDIAN); } else { throw new PelInvalidDataException('Unknown byte order found in TIFF ' . 'data: 0x%2X%2X', $d->getByte(0), $d->getByte(1)); } /* Verify the TIFF header */ if ($d->getShort(2) != self::TIFF_HEADER) { throw new PelInvalidDataException('Missing TIFF magic value.'); } /* IFD 0 offset */ $offset = $d->getLong(4); Pel::debug('First IFD at offset %d.', $offset); if ($offset > 0) { /* * Parse the first IFD, this will automatically parse the * following IFDs and any sub IFDs. */ $this->ifd = new PelIfd(PelIfd::IFD0); $this->ifd->load($d, $offset); } }
php
public function load(PelDataWindow $d) { Pel::debug('Parsing %d bytes of TIFF data...', $d->getSize()); /* * There must be at least 8 bytes available: 2 bytes for the byte * order, 2 bytes for the TIFF header, and 4 bytes for the offset * to the first IFD. */ if ($d->getSize() < 8) { throw new PelInvalidDataException('Expected at least 8 bytes of TIFF ' . 'data, found just %d bytes.', $d->getSize()); } /* Byte order */ if ($d->strcmp(0, 'II')) { Pel::debug('Found Intel byte order'); $d->setByteOrder(PelConvert::LITTLE_ENDIAN); } elseif ($d->strcmp(0, 'MM')) { Pel::debug('Found Motorola byte order'); $d->setByteOrder(PelConvert::BIG_ENDIAN); } else { throw new PelInvalidDataException('Unknown byte order found in TIFF ' . 'data: 0x%2X%2X', $d->getByte(0), $d->getByte(1)); } /* Verify the TIFF header */ if ($d->getShort(2) != self::TIFF_HEADER) { throw new PelInvalidDataException('Missing TIFF magic value.'); } /* IFD 0 offset */ $offset = $d->getLong(4); Pel::debug('First IFD at offset %d.', $offset); if ($offset > 0) { /* * Parse the first IFD, this will automatically parse the * following IFDs and any sub IFDs. */ $this->ifd = new PelIfd(PelIfd::IFD0); $this->ifd->load($d, $offset); } }
[ "public", "function", "load", "(", "PelDataWindow", "$", "d", ")", "{", "Pel", "::", "debug", "(", "'Parsing %d bytes of TIFF data...'", ",", "$", "d", "->", "getSize", "(", ")", ")", ";", "/*\n * There must be at least 8 bytes available: 2 bytes for the byte\n ...
Load TIFF data. The data given will be parsed and an internal tree representation will be built. If the data cannot be parsed correctly, a {@link PelInvalidDataException} is thrown, explaining the problem. @param d PelDataWindow the data from which the object will be constructed. This should be valid TIFF data, coming either directly from a TIFF image or from the Exif data in a JPEG image.
[ "Load", "TIFF", "data", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelTiff.php#L122-L161
train
pel/pel
src/PelTiff.php
PelTiff.setIfd
public function setIfd(PelIfd $ifd) { if ($ifd->getType() != PelIfd::IFD0) { throw new PelInvalidDataException('Invalid type of IFD: %d, expected %d.', $ifd->getType(), PelIfd::IFD0); } $this->ifd = $ifd; }
php
public function setIfd(PelIfd $ifd) { if ($ifd->getType() != PelIfd::IFD0) { throw new PelInvalidDataException('Invalid type of IFD: %d, expected %d.', $ifd->getType(), PelIfd::IFD0); } $this->ifd = $ifd; }
[ "public", "function", "setIfd", "(", "PelIfd", "$", "ifd", ")", "{", "if", "(", "$", "ifd", "->", "getType", "(", ")", "!=", "PelIfd", "::", "IFD0", ")", "{", "throw", "new", "PelInvalidDataException", "(", "'Invalid type of IFD: %d, expected %d.'", ",", "$"...
Set the first IFD. @param PelIfd $ifd the new first IFD, which must be of type {@link PelIfd::IFD0}.
[ "Set", "the", "first", "IFD", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelTiff.php#L181-L187
train
pel/pel
src/PelTiff.php
PelTiff.getBytes
public function getBytes($order = PelConvert::LITTLE_ENDIAN) { if ($order == PelConvert::LITTLE_ENDIAN) { $bytes = 'II'; } else { $bytes = 'MM'; } /* TIFF magic number --- fixed value. */ $bytes .= PelConvert::shortToBytes(self::TIFF_HEADER, $order); if ($this->ifd !== null) { /* * IFD 0 offset. We will always start IDF 0 at an offset of 8 * bytes (2 bytes for byte order, another 2 bytes for the TIFF * header, and 4 bytes for the IFD 0 offset make 8 bytes * together). */ $bytes .= PelConvert::longToBytes(8, $order); /* * The argument specifies the offset of this IFD. The IFD will * use this to calculate offsets from the entries to their data, * all those offsets are absolute offsets counted from the * beginning of the data. */ $bytes .= $this->ifd->getBytes(8, $order); } else { $bytes .= PelConvert::longToBytes(0, $order); } return $bytes; }
php
public function getBytes($order = PelConvert::LITTLE_ENDIAN) { if ($order == PelConvert::LITTLE_ENDIAN) { $bytes = 'II'; } else { $bytes = 'MM'; } /* TIFF magic number --- fixed value. */ $bytes .= PelConvert::shortToBytes(self::TIFF_HEADER, $order); if ($this->ifd !== null) { /* * IFD 0 offset. We will always start IDF 0 at an offset of 8 * bytes (2 bytes for byte order, another 2 bytes for the TIFF * header, and 4 bytes for the IFD 0 offset make 8 bytes * together). */ $bytes .= PelConvert::longToBytes(8, $order); /* * The argument specifies the offset of this IFD. The IFD will * use this to calculate offsets from the entries to their data, * all those offsets are absolute offsets counted from the * beginning of the data. */ $bytes .= $this->ifd->getBytes(8, $order); } else { $bytes .= PelConvert::longToBytes(0, $order); } return $bytes; }
[ "public", "function", "getBytes", "(", "$", "order", "=", "PelConvert", "::", "LITTLE_ENDIAN", ")", "{", "if", "(", "$", "order", "==", "PelConvert", "::", "LITTLE_ENDIAN", ")", "{", "$", "bytes", "=", "'II'", ";", "}", "else", "{", "$", "bytes", "=", ...
Turn this object into bytes. TIFF images can have {@link PelConvert::LITTLE_ENDIAN little-endian} or {@link PelConvert::BIG_ENDIAN big-endian} byte order, and so this method takes an argument specifying that. @param boolean $order the desired byte order of the TIFF data. This should be one of {@link PelConvert::LITTLE_ENDIAN} or {@link PelConvert::BIG_ENDIAN}. @return string the bytes representing this object.
[ "Turn", "this", "object", "into", "bytes", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelTiff.php#L214-L246
train
pel/pel
src/PelTiff.php
PelTiff.isValid
public static function isValid(PelDataWindow $d) { /* First check that we have enough data. */ if ($d->getSize() < 8) { return false; } /* Byte order */ if ($d->strcmp(0, 'II')) { $d->setByteOrder(PelConvert::LITTLE_ENDIAN); } elseif ($d->strcmp(0, 'MM')) { Pel::debug('Found Motorola byte order'); $d->setByteOrder(PelConvert::BIG_ENDIAN); } else { return false; } /* Verify the TIFF header */ return $d->getShort(2) == self::TIFF_HEADER; }
php
public static function isValid(PelDataWindow $d) { /* First check that we have enough data. */ if ($d->getSize() < 8) { return false; } /* Byte order */ if ($d->strcmp(0, 'II')) { $d->setByteOrder(PelConvert::LITTLE_ENDIAN); } elseif ($d->strcmp(0, 'MM')) { Pel::debug('Found Motorola byte order'); $d->setByteOrder(PelConvert::BIG_ENDIAN); } else { return false; } /* Verify the TIFF header */ return $d->getShort(2) == self::TIFF_HEADER; }
[ "public", "static", "function", "isValid", "(", "PelDataWindow", "$", "d", ")", "{", "/* First check that we have enough data. */", "if", "(", "$", "d", "->", "getSize", "(", ")", "<", "8", ")", "{", "return", "false", ";", "}", "/* Byte order */", "if", "("...
Check if data is valid TIFF data. This will read just enough data from the data window to determine if the data could be a valid TIFF data. This means that the check is more like a heuristic than a rigorous check. @param PelDataWindow $d the bytes that will be examined. @return boolean true if the data looks like valid TIFF data, false otherwise. @see PelJpeg::isValid()
[ "Check", "if", "data", "is", "valid", "TIFF", "data", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelTiff.php#L294-L313
train
pel/pel
src/PelEntryWindowsString.php
PelEntryWindowsString.setValue
public function setValue($str, $from_exif = false) { $zlen = strlen(static::ZEROES); if (false !== $from_exif) { $s = $str; if (substr($str, -$zlen, $zlen) == static::ZEROES) { $str = substr($str, 0, -$zlen); } $str = mb_convert_encoding($str, 'UTF-8', 'UCS-2LE'); } else { $s = mb_convert_encoding($str, 'UCS-2LE', 'auto'); } if (substr($s, -$zlen, $zlen) != static::ZEROES) { $s .= static::ZEROES; } $l = strlen($s); $this->components = $l; $this->str = $str; $this->bytes = $s; }
php
public function setValue($str, $from_exif = false) { $zlen = strlen(static::ZEROES); if (false !== $from_exif) { $s = $str; if (substr($str, -$zlen, $zlen) == static::ZEROES) { $str = substr($str, 0, -$zlen); } $str = mb_convert_encoding($str, 'UTF-8', 'UCS-2LE'); } else { $s = mb_convert_encoding($str, 'UCS-2LE', 'auto'); } if (substr($s, -$zlen, $zlen) != static::ZEROES) { $s .= static::ZEROES; } $l = strlen($s); $this->components = $l; $this->str = $str; $this->bytes = $s; }
[ "public", "function", "setValue", "(", "$", "str", ",", "$", "from_exif", "=", "false", ")", "{", "$", "zlen", "=", "strlen", "(", "static", "::", "ZEROES", ")", ";", "if", "(", "false", "!==", "$", "from_exif", ")", "{", "$", "s", "=", "$", "str...
Give the entry a new value. This will overwrite the previous value. The value can be retrieved later with the {@link getValue} method. @param string $str the new value of the entry. @param bool $from_exif internal use only, tells that string is UCS-2LE encoded, as PHP fails to detect this encoding
[ "Give", "the", "entry", "a", "new", "value", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelEntryWindowsString.php#L122-L143
train
pel/pel
src/PelEntryCopyright.php
PelEntryCopyright.setValue
public function setValue($photographer = '', $editor = '') { $this->photographer = $photographer; $this->editor = $editor; if ($photographer == '' && $editor != '') { $photographer = ' '; } if ($editor == '') { parent::setValue($photographer); } else { parent::setValue($photographer . chr(0x00) . $editor); } }
php
public function setValue($photographer = '', $editor = '') { $this->photographer = $photographer; $this->editor = $editor; if ($photographer == '' && $editor != '') { $photographer = ' '; } if ($editor == '') { parent::setValue($photographer); } else { parent::setValue($photographer . chr(0x00) . $editor); } }
[ "public", "function", "setValue", "(", "$", "photographer", "=", "''", ",", "$", "editor", "=", "''", ")", "{", "$", "this", "->", "photographer", "=", "$", "photographer", ";", "$", "this", "->", "editor", "=", "$", "editor", ";", "if", "(", "$", ...
Update the copyright information. @param string the photographer copyright. Use the empty string if there is no photographer copyright. @param string the editor copyright. Use the empty string if there is no editor copyright.
[ "Update", "the", "copyright", "information", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelEntryCopyright.php#L116-L130
train
pel/pel
src/PelEntryCopyright.php
PelEntryCopyright.getText
public function getText($brief = false) { if ($brief) { $p = ''; $e = ''; } else { $p = ' ' . Pel::tra('(Photographer)'); $e = ' ' . Pel::tra('(Editor)'); } if ($this->photographer != '' && $this->editor != '') { return $this->photographer . $p . ' - ' . $this->editor . $e; } if ($this->photographer != '') { return $this->photographer . $p; } if ($this->editor != '') { return $this->editor . $e; } return ''; }
php
public function getText($brief = false) { if ($brief) { $p = ''; $e = ''; } else { $p = ' ' . Pel::tra('(Photographer)'); $e = ' ' . Pel::tra('(Editor)'); } if ($this->photographer != '' && $this->editor != '') { return $this->photographer . $p . ' - ' . $this->editor . $e; } if ($this->photographer != '') { return $this->photographer . $p; } if ($this->editor != '') { return $this->editor . $e; } return ''; }
[ "public", "function", "getText", "(", "$", "brief", "=", "false", ")", "{", "if", "(", "$", "brief", ")", "{", "$", "p", "=", "''", ";", "$", "e", "=", "''", ";", "}", "else", "{", "$", "p", "=", "' '", ".", "Pel", "::", "tra", "(", "'(Phot...
Return a text string with the copyright information. The photographer and editor copyright fields will be returned with a '-' in between if both copyright fields are present, otherwise only one of them will be returned. @param boolean if false, then the strings '(Photographer)' and '(Editor)' will be appended to the photographer and editor copyright fields (if present), otherwise the fields will be returned as is. @return string the copyright information in a string.
[ "Return", "a", "text", "string", "with", "the", "copyright", "information", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelEntryCopyright.php#L167-L190
train
pel/pel
src/PelJpegMarker.php
PelJpegMarker.getDescription
public static function getDescription($marker) { if (array_key_exists($marker, self::$jpegMarkerShort)) { if (array_key_exists($marker, self::$jpegMarkerDescriptions)) { return self::$jpegMarkerDescriptions[$marker]; } else { $splitted = preg_split( "/(\d+)/", self::$jpegMarkerShort[$marker], - 1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE ); if ((count($splitted) == 2) && array_key_exists($splitted[0], self::$jpegMarkerDescriptions)) { return Pel::fmt(self::$jpegMarkerDescriptions[$splitted[0]], $splitted[1]); } } } return Pel::fmt('Unknown marker: 0x%02X', $marker); }
php
public static function getDescription($marker) { if (array_key_exists($marker, self::$jpegMarkerShort)) { if (array_key_exists($marker, self::$jpegMarkerDescriptions)) { return self::$jpegMarkerDescriptions[$marker]; } else { $splitted = preg_split( "/(\d+)/", self::$jpegMarkerShort[$marker], - 1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE ); if ((count($splitted) == 2) && array_key_exists($splitted[0], self::$jpegMarkerDescriptions)) { return Pel::fmt(self::$jpegMarkerDescriptions[$splitted[0]], $splitted[1]); } } } return Pel::fmt('Unknown marker: 0x%02X', $marker); }
[ "public", "static", "function", "getDescription", "(", "$", "marker", ")", "{", "if", "(", "array_key_exists", "(", "$", "marker", ",", "self", "::", "$", "jpegMarkerShort", ")", ")", "{", "if", "(", "array_key_exists", "(", "$", "marker", ",", "self", "...
Returns a description of a JPEG marker. @param integer $marker the marker as defined in {@link PelJpegMarker} @return string
[ "Returns", "a", "description", "of", "a", "JPEG", "marker", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelJpegMarker.php#L524-L542
train
pel/pel
src/PelEntryNumber.php
PelEntryNumber.setValueArray
public function setValueArray($value) { foreach ($value as $v) { $this->validateNumber($v); } $this->components = count($value); $this->value = $value; }
php
public function setValueArray($value) { foreach ($value as $v) { $this->validateNumber($v); } $this->components = count($value); $this->value = $value; }
[ "public", "function", "setValueArray", "(", "$", "value", ")", "{", "foreach", "(", "$", "value", "as", "$", "v", ")", "{", "$", "this", "->", "validateNumber", "(", "$", "v", ")", ";", "}", "$", "this", "->", "components", "=", "count", "(", "$", ...
Change the value. This method can change both the number of components and the value of the components. Range checks will be made on the new value, and a {@link PelOverflowException} will be thrown if the value is found to be outside the legal range. @param array the new values. The array must contain the new numbers. @see getValue
[ "Change", "the", "value", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelEntryNumber.php#L124-L132
train
pel/pel
src/PelEntryNumber.php
PelEntryNumber.addNumber
public function addNumber($n) { $this->validateNumber($n); $this->value[] = $n; $this->components ++; }
php
public function addNumber($n) { $this->validateNumber($n); $this->value[] = $n; $this->components ++; }
[ "public", "function", "addNumber", "(", "$", "n", ")", "{", "$", "this", "->", "validateNumber", "(", "$", "n", ")", ";", "$", "this", "->", "value", "[", "]", "=", "$", "n", ";", "$", "this", "->", "components", "++", ";", "}" ]
Add a number. This appends a number to the numbers already held by this entry, thereby increasing the number of components by one. @param int|array the number to be added.
[ "Add", "a", "number", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelEntryNumber.php#L187-L192
train
pel/pel
src/PelEntryNumber.php
PelEntryNumber.getBytes
public function getBytes($o) { $bytes = ''; for ($i = 0; $i < $this->components; $i ++) { if ($this->dimension == 1) { $bytes .= $this->numberToBytes($this->value[$i], $o); } else { for ($j = 0; $j < $this->dimension; $j ++) { $bytes .= $this->numberToBytes($this->value[$i][$j], $o); } } } return $bytes; }
php
public function getBytes($o) { $bytes = ''; for ($i = 0; $i < $this->components; $i ++) { if ($this->dimension == 1) { $bytes .= $this->numberToBytes($this->value[$i], $o); } else { for ($j = 0; $j < $this->dimension; $j ++) { $bytes .= $this->numberToBytes($this->value[$i][$j], $o); } } } return $bytes; }
[ "public", "function", "getBytes", "(", "$", "o", ")", "{", "$", "bytes", "=", "''", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "this", "->", "components", ";", "$", "i", "++", ")", "{", "if", "(", "$", "this", "->", "dime...
Turn this entry into bytes. @param PelByteOrder the desired byte order, which must be either {@link PelConvert::LITTLE_ENDIAN} or {@link PelConvert::BIG_ENDIAN}. @return string bytes representing this entry.
[ "Turn", "this", "entry", "into", "bytes", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelEntryNumber.php#L223-L236
train
pel/pel
src/PelEntryNumber.php
PelEntryNumber.getText
public function getText($brief = false) { if ($this->components == 0) { return ''; } $str = $this->formatNumber($this->value[0]); for ($i = 1; $i < $this->components; $i ++) { $str .= ($brief ? ' ' : ', '); $str .= $this->formatNumber($this->value[$i]); } return $str; }
php
public function getText($brief = false) { if ($this->components == 0) { return ''; } $str = $this->formatNumber($this->value[0]); for ($i = 1; $i < $this->components; $i ++) { $str .= ($brief ? ' ' : ', '); $str .= $this->formatNumber($this->value[$i]); } return $str; }
[ "public", "function", "getText", "(", "$", "brief", "=", "false", ")", "{", "if", "(", "$", "this", "->", "components", "==", "0", ")", "{", "return", "''", ";", "}", "$", "str", "=", "$", "this", "->", "formatNumber", "(", "$", "this", "->", "va...
Get the numeric value of this entry as text. @param boolean use brief output? The numbers will be separated by a single space if brief output is requested, otherwise a space and a comma will be used. @return string the numbers(s) held by this entry.
[ "Get", "the", "numeric", "value", "of", "this", "entry", "as", "text", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelEntryNumber.php#L271-L284
train
pel/pel
src/PelEntryUserComment.php
PelEntryUserComment.setValue
public function setValue($comment = '', $encoding = 'ASCII') { $this->comment = $comment; $this->encoding = $encoding; parent::setValue(str_pad($encoding, 8, chr(0)) . $comment); }
php
public function setValue($comment = '', $encoding = 'ASCII') { $this->comment = $comment; $this->encoding = $encoding; parent::setValue(str_pad($encoding, 8, chr(0)) . $comment); }
[ "public", "function", "setValue", "(", "$", "comment", "=", "''", ",", "$", "encoding", "=", "'ASCII'", ")", "{", "$", "this", "->", "comment", "=", "$", "comment", ";", "$", "this", "->", "encoding", "=", "$", "encoding", ";", "parent", "::", "setVa...
Set the user comment. @param string the new user comment. @param string the encoding of the comment. This should be either 'ASCII', 'JIS', 'Unicode', or the empty string specifying an unknown encoding.
[ "Set", "the", "user", "comment", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelEntryUserComment.php#L116-L121
train
pel/pel
src/PelDataWindow.php
PelDataWindow.setWindowStart
public function setWindowStart($start) { if ($start < 0 || $start > $this->size) { throw new PelDataWindowWindowException( 'Window [%d, %d] does ' . 'not fit in window [0, %d]', $start, $this->size, $this->size ); } $this->start += $start; $this->size -= $start; }
php
public function setWindowStart($start) { if ($start < 0 || $start > $this->size) { throw new PelDataWindowWindowException( 'Window [%d, %d] does ' . 'not fit in window [0, %d]', $start, $this->size, $this->size ); } $this->start += $start; $this->size -= $start; }
[ "public", "function", "setWindowStart", "(", "$", "start", ")", "{", "if", "(", "$", "start", "<", "0", "||", "$", "start", ">", "$", "this", "->", "size", ")", "{", "throw", "new", "PelDataWindowWindowException", "(", "'Window [%d, %d] does '", ".", "'not...
Move the start of the window forward. @param integer $start the new start of the window. All new offsets will be calculated from this new start offset, and the size of the window will shrink to keep the end of the window in place.
[ "Move", "the", "start", "of", "the", "window", "forward", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelDataWindow.php#L162-L174
train
pel/pel
src/PelDataWindow.php
PelDataWindow.setWindowSize
public function setWindowSize($size) { if ($size < 0) { $size += $this->size; } if ($size < 0 || $size > $this->size) { throw new PelDataWindowWindowException( 'Window [0, %d] ' . 'does not fit in window [0, %d]', $size, $this->size ); } $this->size = $size; }
php
public function setWindowSize($size) { if ($size < 0) { $size += $this->size; } if ($size < 0 || $size > $this->size) { throw new PelDataWindowWindowException( 'Window [0, %d] ' . 'does not fit in window [0, %d]', $size, $this->size ); } $this->size = $size; }
[ "public", "function", "setWindowSize", "(", "$", "size", ")", "{", "if", "(", "$", "size", "<", "0", ")", "{", "$", "size", "+=", "$", "this", "->", "size", ";", "}", "if", "(", "$", "size", "<", "0", "||", "$", "size", ">", "$", "this", "->"...
Adjust the size of the window. The size can only be made smaller. @param integer $size the desired size of the window. If the argument is negative, the window will be shrunk by the argument.
[ "Adjust", "the", "size", "of", "the", "window", ".", "The", "size", "can", "only", "be", "made", "smaller", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelDataWindow.php#L184-L197
train
pel/pel
src/PelDataWindow.php
PelDataWindow.getClone
public function getClone($start = null, $size = null) { $c = clone $this; if (is_int($start)) { $c->setWindowStart($start); } if (is_int($size)) { $c->setWindowSize($size); } return $c; }
php
public function getClone($start = null, $size = null) { $c = clone $this; if (is_int($start)) { $c->setWindowStart($start); } if (is_int($size)) { $c->setWindowSize($size); } return $c; }
[ "public", "function", "getClone", "(", "$", "start", "=", "null", ",", "$", "size", "=", "null", ")", "{", "$", "c", "=", "clone", "$", "this", ";", "if", "(", "is_int", "(", "$", "start", ")", ")", "{", "$", "c", "->", "setWindowStart", "(", "...
Make a new data window with the same data as the this window. @param integer|NULL $start if an integer is supplied, then it will be the start of the window in the clone. If left unspecified, then the clone will inherit the start from this object. @param integer|NULL $size if an integer is supplied, then it will be the size of the window in the clone. If left unspecified, then the clone will inherit the size from this object. @return PelDataWindow a new window that operates on the same data as this window, but (optionally) with a smaller window size.
[ "Make", "a", "new", "data", "window", "with", "the", "same", "data", "as", "the", "this", "window", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelDataWindow.php#L215-L226
train
pel/pel
src/PelDataWindow.php
PelDataWindow.validateOffset
private function validateOffset($offset) { if ($offset < 0 || $offset >= $this->size) { throw new PelDataWindowOffsetException('Offset %d not within [%d, %d]', $offset, 0, $this->size - 1); } }
php
private function validateOffset($offset) { if ($offset < 0 || $offset >= $this->size) { throw new PelDataWindowOffsetException('Offset %d not within [%d, %d]', $offset, 0, $this->size - 1); } }
[ "private", "function", "validateOffset", "(", "$", "offset", ")", "{", "if", "(", "$", "offset", "<", "0", "||", "$", "offset", ">=", "$", "this", "->", "size", ")", "{", "throw", "new", "PelDataWindowOffsetException", "(", "'Offset %d not within [%d, %d]'", ...
Validate an offset against the current window. @param integer $offset the offset to be validated. If the offset is negative or if it is greater than or equal to the current window size, then a {@link PelDataWindowOffsetException} is thrown. @return void if the offset is valid nothing is returned, if it is invalid a new {@link PelDataWindowOffsetException} is thrown. @throws PelDataWindowOffsetException
[ "Validate", "an", "offset", "against", "the", "current", "window", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelDataWindow.php#L240-L245
train
pel/pel
src/PelDataWindow.php
PelDataWindow.getBytes
public function getBytes($start = null, $size = null) { if (is_int($start)) { if ($start < 0) { $start += $this->size; } $this->validateOffset($start); } else { $start = 0; } if (is_int($size)) { if ($size <= 0) { $size += $this->size - $start; } $this->validateOffset($start + $size); } else { $size = $this->size - $start; } return substr($this->data, $this->start + $start, $size); }
php
public function getBytes($start = null, $size = null) { if (is_int($start)) { if ($start < 0) { $start += $this->size; } $this->validateOffset($start); } else { $start = 0; } if (is_int($size)) { if ($size <= 0) { $size += $this->size - $start; } $this->validateOffset($start + $size); } else { $size = $this->size - $start; } return substr($this->data, $this->start + $start, $size); }
[ "public", "function", "getBytes", "(", "$", "start", "=", "null", ",", "$", "size", "=", "null", ")", "{", "if", "(", "is_int", "(", "$", "start", ")", ")", "{", "if", "(", "$", "start", "<", "0", ")", "{", "$", "start", "+=", "$", "this", "-...
Return some or all bytes visible in the window. This method works just like the standard {@link substr()} function in PHP with the exception that it works within the window of accessible bytes and does strict range checking. @param integer|NULL $start the offset to the first byte returned. If a negative number is given, then the counting will be from the end of the window. Invalid offsets will result in a {@link PelDataWindowOffsetException} being thrown. @param integer|NUL $size the size of the sub-window. If a negative number is given, then that many bytes will be omitted from the result. @return string a subset of the bytes in the window. This will always return no more than {@link getSize()} bytes. @throws PelDataWindowOffsetException
[ "Return", "some", "or", "all", "bytes", "visible", "in", "the", "window", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelDataWindow.php#L268-L291
train
pel/pel
src/PelDataWindow.php
PelDataWindow.getByte
public function getByte($offset = 0) { /* * Validate the offset --- this throws an exception if offset is * out of range. */ $this->validateOffset($offset); /* Translate the offset into an offset into the data. */ $offset += $this->start; /* Return an unsigned byte. */ return PelConvert::bytesToByte($this->data, $offset); }
php
public function getByte($offset = 0) { /* * Validate the offset --- this throws an exception if offset is * out of range. */ $this->validateOffset($offset); /* Translate the offset into an offset into the data. */ $offset += $this->start; /* Return an unsigned byte. */ return PelConvert::bytesToByte($this->data, $offset); }
[ "public", "function", "getByte", "(", "$", "offset", "=", "0", ")", "{", "/*\n * Validate the offset --- this throws an exception if offset is\n * out of range.\n */", "$", "this", "->", "validateOffset", "(", "$", "offset", ")", ";", "/* Translate the...
Return an unsigned byte from the data. @param integer $offset the offset into the data. An offset of zero will return the first byte in the current allowed window. The last valid offset is equal to {@link getSize()}-1. Invalid offsets will result in a {@link PelDataWindowOffsetException} being thrown. @return integer the unsigned byte found at offset. @throws PelDataWindowOffsetException
[ "Return", "an", "unsigned", "byte", "from", "the", "data", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelDataWindow.php#L306-L319
train
pel/pel
src/PelDataWindow.php
PelDataWindow.getSByte
public function getSByte($offset = 0) { /* * Validate the offset --- this throws an exception if offset is * out of range. */ $this->validateOffset($offset); /* Translate the offset into an offset into the data. */ $offset += $this->start; /* Return a signed byte. */ return PelConvert::bytesToSByte($this->data, $offset); }
php
public function getSByte($offset = 0) { /* * Validate the offset --- this throws an exception if offset is * out of range. */ $this->validateOffset($offset); /* Translate the offset into an offset into the data. */ $offset += $this->start; /* Return a signed byte. */ return PelConvert::bytesToSByte($this->data, $offset); }
[ "public", "function", "getSByte", "(", "$", "offset", "=", "0", ")", "{", "/*\n * Validate the offset --- this throws an exception if offset is\n * out of range.\n */", "$", "this", "->", "validateOffset", "(", "$", "offset", ")", ";", "/* Translate th...
Return a signed byte from the data. @param integer $offset the offset into the data. An offset of zero will return the first byte in the current allowed window. The last valid offset is equal to {@link getSize()}-1. Invalid offsets will result in a {@link PelDataWindowOffsetException} being thrown. @return integer the signed byte found at offset. @throws PelDataWindowOffsetException
[ "Return", "a", "signed", "byte", "from", "the", "data", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelDataWindow.php#L334-L347
train
pel/pel
src/PelDataWindow.php
PelDataWindow.getShort
public function getShort($offset = 0) { /* * Validate the offset+1 to see if we can safely get two bytes --- * this throws an exception if offset is out of range. */ $this->validateOffset($offset); $this->validateOffset($offset + 1); /* Translate the offset into an offset into the data. */ $offset += $this->start; /* Return an unsigned short. */ return PelConvert::bytesToShort($this->data, $offset, $this->order); }
php
public function getShort($offset = 0) { /* * Validate the offset+1 to see if we can safely get two bytes --- * this throws an exception if offset is out of range. */ $this->validateOffset($offset); $this->validateOffset($offset + 1); /* Translate the offset into an offset into the data. */ $offset += $this->start; /* Return an unsigned short. */ return PelConvert::bytesToShort($this->data, $offset, $this->order); }
[ "public", "function", "getShort", "(", "$", "offset", "=", "0", ")", "{", "/*\n * Validate the offset+1 to see if we can safely get two bytes ---\n * this throws an exception if offset is out of range.\n */", "$", "this", "->", "validateOffset", "(", "$", "o...
Return an unsigned short read from the data. @param integer $offset the offset into the data. An offset of zero will return the first short available in the current allowed window. The last valid offset is equal to {@link getSize()}-2. Invalid offsets will result in a {@link PelDataWindowOffsetException} being thrown. @return integer the unsigned short found at offset. @throws PelDataWindowOffsetException
[ "Return", "an", "unsigned", "short", "read", "from", "the", "data", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelDataWindow.php#L362-L376
train
pel/pel
src/PelDataWindow.php
PelDataWindow.getSShort
public function getSShort($offset = 0) { /* * Validate the offset+1 to see if we can safely get two bytes --- * this throws an exception if offset is out of range. */ $this->validateOffset($offset); $this->validateOffset($offset + 1); /* Translate the offset into an offset into the data. */ $offset += $this->start; /* Return a signed short. */ return PelConvert::bytesToSShort($this->data, $offset, $this->order); }
php
public function getSShort($offset = 0) { /* * Validate the offset+1 to see if we can safely get two bytes --- * this throws an exception if offset is out of range. */ $this->validateOffset($offset); $this->validateOffset($offset + 1); /* Translate the offset into an offset into the data. */ $offset += $this->start; /* Return a signed short. */ return PelConvert::bytesToSShort($this->data, $offset, $this->order); }
[ "public", "function", "getSShort", "(", "$", "offset", "=", "0", ")", "{", "/*\n * Validate the offset+1 to see if we can safely get two bytes ---\n * this throws an exception if offset is out of range.\n */", "$", "this", "->", "validateOffset", "(", "$", "...
Return a signed short read from the data. @param integer $offset the offset into the data. An offset of zero will return the first short available in the current allowed window. The last valid offset is equal to {@link getSize()}-2. Invalid offsets will result in a {@link PelDataWindowOffsetException} being thrown. @return integer the signed short found at offset. @throws PelDataWindowOffsetException
[ "Return", "a", "signed", "short", "read", "from", "the", "data", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelDataWindow.php#L391-L405
train
pel/pel
src/PelDataWindow.php
PelDataWindow.getLong
public function getLong($offset = 0) { /* * Validate the offset+3 to see if we can safely get four bytes * --- this throws an exception if offset is out of range. */ $this->validateOffset($offset); $this->validateOffset($offset + 3); /* Translate the offset into an offset into the data. */ $offset += $this->start; /* Return an unsigned long. */ return PelConvert::bytesToLong($this->data, $offset, $this->order); }
php
public function getLong($offset = 0) { /* * Validate the offset+3 to see if we can safely get four bytes * --- this throws an exception if offset is out of range. */ $this->validateOffset($offset); $this->validateOffset($offset + 3); /* Translate the offset into an offset into the data. */ $offset += $this->start; /* Return an unsigned long. */ return PelConvert::bytesToLong($this->data, $offset, $this->order); }
[ "public", "function", "getLong", "(", "$", "offset", "=", "0", ")", "{", "/*\n * Validate the offset+3 to see if we can safely get four bytes\n * --- this throws an exception if offset is out of range.\n */", "$", "this", "->", "validateOffset", "(", "$", "o...
Return an unsigned long read from the data. @param integer $offset the offset into the data. An offset of zero will return the first long available in the current allowed window. The last valid offset is equal to {@link getSize()}-4. Invalid offsets will result in a {@link PelDataWindowOffsetException} being thrown. @return integer the unsigned long found at offset. @throws PelDataWindowOffsetException
[ "Return", "an", "unsigned", "long", "read", "from", "the", "data", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelDataWindow.php#L420-L434
train
pel/pel
src/PelDataWindow.php
PelDataWindow.getSLong
public function getSLong($offset = 0) { /* * Validate the offset+3 to see if we can safely get four bytes * --- this throws an exception if offset is out of range. */ $this->validateOffset($offset); $this->validateOffset($offset + 3); /* Translate the offset into an offset into the data. */ $offset += $this->start; /* Return a signed long. */ return PelConvert::bytesToSLong($this->data, $offset, $this->order); }
php
public function getSLong($offset = 0) { /* * Validate the offset+3 to see if we can safely get four bytes * --- this throws an exception if offset is out of range. */ $this->validateOffset($offset); $this->validateOffset($offset + 3); /* Translate the offset into an offset into the data. */ $offset += $this->start; /* Return a signed long. */ return PelConvert::bytesToSLong($this->data, $offset, $this->order); }
[ "public", "function", "getSLong", "(", "$", "offset", "=", "0", ")", "{", "/*\n * Validate the offset+3 to see if we can safely get four bytes\n * --- this throws an exception if offset is out of range.\n */", "$", "this", "->", "validateOffset", "(", "$", "...
Return a signed long read from the data. @param integer $offset the offset into the data. An offset of zero will return the first long available in the current allowed window. The last valid offset is equal to {@link getSize()}-4. Invalid offsets will result in a {@link PelDataWindowOffsetException} being thrown. @return integer the signed long found at offset. @throws PelDataWindowOffsetException
[ "Return", "a", "signed", "long", "read", "from", "the", "data", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelDataWindow.php#L449-L463
train
pel/pel
src/PelDataWindow.php
PelDataWindow.strcmp
public function strcmp($offset, $str) { /* * Validate the offset of the final character we might have to * check. */ $s = strlen($str); $this->validateOffset($offset); $this->validateOffset($offset + $s - 1); /* Translate the offset into an offset into the data. */ $offset += $this->start; /* Check each character, return as soon as the answer is known. */ for ($i = 0; $i < $s; $i ++) { if ($this->data{$offset + $i} != $str{$i}) { return false; } } /* All characters matches each other, return true. */ return true; }
php
public function strcmp($offset, $str) { /* * Validate the offset of the final character we might have to * check. */ $s = strlen($str); $this->validateOffset($offset); $this->validateOffset($offset + $s - 1); /* Translate the offset into an offset into the data. */ $offset += $this->start; /* Check each character, return as soon as the answer is known. */ for ($i = 0; $i < $s; $i ++) { if ($this->data{$offset + $i} != $str{$i}) { return false; } } /* All characters matches each other, return true. */ return true; }
[ "public", "function", "strcmp", "(", "$", "offset", ",", "$", "str", ")", "{", "/*\n * Validate the offset of the final character we might have to\n * check.\n */", "$", "s", "=", "strlen", "(", "$", "str", ")", ";", "$", "this", "->", "validat...
String comparison on substrings. @param integer $offset the offset into the data. An offset of zero will make the comparison start with the very first byte available in the window. The last valid offset is equal to {@link getSize()} minus the length of the string. If the string is too long, then a {@link PelDataWindowOffsetException} will be thrown. @param string $str the string to compare with. @return boolean true if the string given matches the data in the window, at the specified offset, false otherwise. The comparison will stop as soon as a mismatch if found. @throws PelDataWindowOffsetException
[ "String", "comparison", "on", "substrings", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelDataWindow.php#L529-L551
train
pel/pel
src/PelEntryAscii.php
PelEntryAscii.setValue
public function setValue($str) { $this->components = strlen($str) + 1; $this->str = $str; $this->bytes = $str . chr(0x00); }
php
public function setValue($str) { $this->components = strlen($str) + 1; $this->str = $str; $this->bytes = $str . chr(0x00); }
[ "public", "function", "setValue", "(", "$", "str", ")", "{", "$", "this", "->", "components", "=", "strlen", "(", "$", "str", ")", "+", "1", ";", "$", "this", "->", "str", "=", "$", "str", ";", "$", "this", "->", "bytes", "=", "$", "str", ".", ...
Give the entry a new ASCII value. This will overwrite the previous value. The value can be retrieved later with the {@link getValue} method. @param string the new value of the entry. This should be given without any trailing NULL character. The string must be plain 7-bit ASCII, the string should contain no high bytes. @todo Implement check for high bytes?
[ "Give", "the", "entry", "a", "new", "ASCII", "value", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelEntryAscii.php#L107-L112
train
pel/pel
src/Pel.php
Pel.maybeThrow
public static function maybeThrow(PelException $e) { if (self::$strict) { throw $e; } else { self::$exceptions[] = $e; self::warning('%s (%s:%s)', $e->getMessage(), basename($e->getFile()), $e->getLine()); } }
php
public static function maybeThrow(PelException $e) { if (self::$strict) { throw $e; } else { self::$exceptions[] = $e; self::warning('%s (%s:%s)', $e->getMessage(), basename($e->getFile()), $e->getLine()); } }
[ "public", "static", "function", "maybeThrow", "(", "PelException", "$", "e", ")", "{", "if", "(", "self", "::", "$", "strict", ")", "{", "throw", "$", "e", ";", "}", "else", "{", "self", "::", "$", "exceptions", "[", "]", "=", "$", "e", ";", "sel...
Conditionally throw an exception. This method will throw the passed exception when strict parsing in effect (see {@link setStrictParsing()}). Otherwise the exception is stored (it can be accessed with {@link getExceptions()}) and a warning is issued (with {@link Pel::warning}). @param PelException $e the exceptions.
[ "Conditionally", "throw", "an", "exception", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/Pel.php#L181-L189
train
pel/pel
src/Pel.php
Pel.debug
public static function debug($format) { if (self::$debug) { $args = func_get_args(); $str = array_shift($args); vprintf($str . "\n", $args); } }
php
public static function debug($format) { if (self::$debug) { $args = func_get_args(); $str = array_shift($args); vprintf($str . "\n", $args); } }
[ "public", "static", "function", "debug", "(", "$", "format", ")", "{", "if", "(", "self", "::", "$", "debug", ")", "{", "$", "args", "=", "func_get_args", "(", ")", ";", "$", "str", "=", "array_shift", "(", "$", "args", ")", ";", "vprintf", "(", ...
Conditionally output debug information. This method works just like printf() except that it always terminates the output with a newline, and that it only outputs something if the {@link Pel::$debug} is true. @param string $format the format string. @param mixed ...$args any number of arguments can be given. The arguments will be available for the format string as usual with sprintf().
[ "Conditionally", "output", "debug", "information", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/Pel.php#L261-L268
train
pel/pel
src/Pel.php
Pel.fmt
public static function fmt($format) { $args = func_get_args(); $str = array_shift($args); return vsprintf(self::dgettextWrapper('pel', $str), $args); }
php
public static function fmt($format) { $args = func_get_args(); $str = array_shift($args); return vsprintf(self::dgettextWrapper('pel', $str), $args); }
[ "public", "static", "function", "fmt", "(", "$", "format", ")", "{", "$", "args", "=", "func_get_args", "(", ")", ";", "$", "str", "=", "array_shift", "(", "$", "args", ")", ";", "return", "vsprintf", "(", "self", "::", "dgettextWrapper", "(", "'pel'",...
Translate and format a string. This static function will first use Gettext to translate a format string, which will then have access to any extra arguments. By always using this function for dynamic string one is assured that the translation will be taken from the correct text domain. If the string is static, use {@link tra} instead as it will be faster. @param string $format the format string. This will be translated before being used as a format string. @param mixed ...$args any number of arguments can be given. The arguments will be available for the format string as usual with sprintf(). @return string the translated string, or the original string if no translation could be found.
[ "Translate", "and", "format", "a", "string", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/Pel.php#L336-L341
train
pel/pel
src/Pel.php
Pel.dgettextWrapper
private static function dgettextWrapper($domain, $str) { if (self::$hasdgetext === null) { self::$hasdgetext = function_exists('dgettext'); if (self::$hasdgetext === true) { bindtextdomain('pel', __DIR__ . '/locale'); } } if (self::$hasdgetext) { return dgettext($domain, $str); } else { return $str; } }
php
private static function dgettextWrapper($domain, $str) { if (self::$hasdgetext === null) { self::$hasdgetext = function_exists('dgettext'); if (self::$hasdgetext === true) { bindtextdomain('pel', __DIR__ . '/locale'); } } if (self::$hasdgetext) { return dgettext($domain, $str); } else { return $str; } }
[ "private", "static", "function", "dgettextWrapper", "(", "$", "domain", ",", "$", "str", ")", "{", "if", "(", "self", "::", "$", "hasdgetext", "===", "null", ")", "{", "self", "::", "$", "hasdgetext", "=", "function_exists", "(", "'dgettext'", ")", ";", ...
Warapper for dgettext. The untranslated stub will be return in the case that dgettext is not available. @param string $domain @param string $str @return string
[ "Warapper", "for", "dgettext", ".", "The", "untranslated", "stub", "will", "be", "return", "in", "the", "case", "that", "dgettext", "is", "not", "available", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/Pel.php#L351-L364
train
pel/pel
src/PelExif.php
PelExif.load
public function load(PelDataWindow $d) { Pel::debug('Parsing %d bytes of Exif data...', $d->getSize()); /* There must be at least 6 bytes for the Exif header. */ if ($d->getSize() < 6) { throw new PelInvalidDataException('Expected at least 6 bytes of Exif ' . 'data, found just %d bytes.', $d->getSize()); } /* Verify the Exif header */ if ($d->strcmp(0, self::EXIF_HEADER)) { $d->setWindowStart(strlen(self::EXIF_HEADER)); } else { throw new PelInvalidDataException('Exif header not found.'); } /* The rest of the data is TIFF data. */ $this->tiff = new PelTiff(); $this->tiff->load($d); }
php
public function load(PelDataWindow $d) { Pel::debug('Parsing %d bytes of Exif data...', $d->getSize()); /* There must be at least 6 bytes for the Exif header. */ if ($d->getSize() < 6) { throw new PelInvalidDataException('Expected at least 6 bytes of Exif ' . 'data, found just %d bytes.', $d->getSize()); } /* Verify the Exif header */ if ($d->strcmp(0, self::EXIF_HEADER)) { $d->setWindowStart(strlen(self::EXIF_HEADER)); } else { throw new PelInvalidDataException('Exif header not found.'); } /* The rest of the data is TIFF data. */ $this->tiff = new PelTiff(); $this->tiff->load($d); }
[ "public", "function", "load", "(", "PelDataWindow", "$", "d", ")", "{", "Pel", "::", "debug", "(", "'Parsing %d bytes of Exif data...'", ",", "$", "d", "->", "getSize", "(", ")", ")", ";", "/* There must be at least 6 bytes for the Exif header. */", "if", "(", "$"...
Load and parse Exif data. This will populate the object with Exif data, contained as a {@link PelTiff} object. This TIFF object can be accessed with the {@link getTiff()} method. @param PelDataWindow $d
[ "Load", "and", "parse", "Exif", "data", "." ]
d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e
https://github.com/pel/pel/blob/d4ca1d5d3599a5a3be9eccdf8a54d83ca78b734e/src/PelExif.php#L91-L109
train
chrislim2888/IP2Location-PHP-Module
IP2Location.php
Database.findFile
private static function findFile($file = null) { if (null !== $file) { // Get actual file path $rfile = realpath($file); // If the file cannot be found, except away if (false === $rfile) { throw new \Exception(__CLASS__ . ": Database file '{$file}' does not seem to exist.", self::EXCEPTION_DBFILE_NOT_FOUND); } return $rfile; } else { // Try to get current path $current = realpath(dirname(__FILE__)); if (false === $current) { throw new \Exception(__CLASS__ . ": Cannot determine current path.", self::EXCEPTION_NO_PATH); } // Try each database in turn foreach (self::$databases as $database) { $rfile = realpath("{$current}/{$database}.BIN"); if (false !== $rfile) { return $rfile; } } // No candidates found throw new \Exception(__CLASS__ . ": No candidate database files found.", self::EXCEPTION_NO_CANDIDATES); } }
php
private static function findFile($file = null) { if (null !== $file) { // Get actual file path $rfile = realpath($file); // If the file cannot be found, except away if (false === $rfile) { throw new \Exception(__CLASS__ . ": Database file '{$file}' does not seem to exist.", self::EXCEPTION_DBFILE_NOT_FOUND); } return $rfile; } else { // Try to get current path $current = realpath(dirname(__FILE__)); if (false === $current) { throw new \Exception(__CLASS__ . ": Cannot determine current path.", self::EXCEPTION_NO_PATH); } // Try each database in turn foreach (self::$databases as $database) { $rfile = realpath("{$current}/{$database}.BIN"); if (false !== $rfile) { return $rfile; } } // No candidates found throw new \Exception(__CLASS__ . ": No candidate database files found.", self::EXCEPTION_NO_CANDIDATES); } }
[ "private", "static", "function", "findFile", "(", "$", "file", "=", "null", ")", "{", "if", "(", "null", "!==", "$", "file", ")", "{", "// Get actual file path", "$", "rfile", "=", "realpath", "(", "$", "file", ")", ";", "// If the file cannot be found, exce...
Return the realpath of the given file or look for the first matching database option @param string $file File to try to find, or null to try the databases in turn on the current file's path @return string @throws \Exception
[ "Return", "the", "realpath", "of", "the", "given", "file", "or", "look", "for", "the", "first", "matching", "database", "option" ]
178e115645407284dc377a7b017a0cbb3681298f
https://github.com/chrislim2888/IP2Location-PHP-Module/blob/178e115645407284dc377a7b017a0cbb3681298f/IP2Location.php#L863-L891
train