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
concrete5/concrete5
concrete/src/Cookie/ResponseCookieJar.php
ResponseCookieJar.addCookieObject
public function addCookieObject(Cookie $cookie) { $name = $cookie->getName(); $isNew = true; foreach ($this->cookies as $index => $value) { if ($value->getName() === $name) { $this->cookies[$index] = $cookie; $isNew = false; } } if ($isNew) { $index = array_search($name, $this->clearedCookies, true); if ($index !== false) { unset($this->clearedCookies[$index]); $this->clearedCookies = array_values($this->clearedCookies); } $this->cookies[] = $cookie; } return $this; }
php
public function addCookieObject(Cookie $cookie) { $name = $cookie->getName(); $isNew = true; foreach ($this->cookies as $index => $value) { if ($value->getName() === $name) { $this->cookies[$index] = $cookie; $isNew = false; } } if ($isNew) { $index = array_search($name, $this->clearedCookies, true); if ($index !== false) { unset($this->clearedCookies[$index]); $this->clearedCookies = array_values($this->clearedCookies); } $this->cookies[] = $cookie; } return $this; }
[ "public", "function", "addCookieObject", "(", "Cookie", "$", "cookie", ")", "{", "$", "name", "=", "$", "cookie", "->", "getName", "(", ")", ";", "$", "isNew", "=", "true", ";", "foreach", "(", "$", "this", "->", "cookies", "as", "$", "index", "=>", "$", "value", ")", "{", "if", "(", "$", "value", "->", "getName", "(", ")", "===", "$", "name", ")", "{", "$", "this", "->", "cookies", "[", "$", "index", "]", "=", "$", "cookie", ";", "$", "isNew", "=", "false", ";", "}", "}", "if", "(", "$", "isNew", ")", "{", "$", "index", "=", "array_search", "(", "$", "name", ",", "$", "this", "->", "clearedCookies", ",", "true", ")", ";", "if", "(", "$", "index", "!==", "false", ")", "{", "unset", "(", "$", "this", "->", "clearedCookies", "[", "$", "index", "]", ")", ";", "$", "this", "->", "clearedCookies", "=", "array_values", "(", "$", "this", "->", "clearedCookies", ")", ";", "}", "$", "this", "->", "cookies", "[", "]", "=", "$", "cookie", ";", "}", "return", "$", "this", ";", "}" ]
Adds a Cookie object to the array of cookies for the object. @param \Symfony\Component\HttpFoundation\Cookie $cookie @return $this
[ "Adds", "a", "Cookie", "object", "to", "the", "array", "of", "cookies", "for", "the", "object", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Cookie/ResponseCookieJar.php#L51-L71
train
concrete5/concrete5
concrete/src/Cookie/ResponseCookieJar.php
ResponseCookieJar.getCookieByName
public function getCookieByName($name) { foreach ($this->cookies as $cookie) { if ($cookie->getName() === $name) { return $cookie; } } return null; }
php
public function getCookieByName($name) { foreach ($this->cookies as $cookie) { if ($cookie->getName() === $name) { return $cookie; } } return null; }
[ "public", "function", "getCookieByName", "(", "$", "name", ")", "{", "foreach", "(", "$", "this", "->", "cookies", "as", "$", "cookie", ")", "{", "if", "(", "$", "cookie", "->", "getName", "(", ")", "===", "$", "name", ")", "{", "return", "$", "cookie", ";", "}", "}", "return", "null", ";", "}" ]
Get the response cookie given its name. @param string $name The key the cookie is stored under @return \Symfony\Component\HttpFoundation\Cookie|null
[ "Get", "the", "response", "cookie", "given", "its", "name", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Cookie/ResponseCookieJar.php#L90-L99
train
concrete5/concrete5
concrete/src/Cookie/ResponseCookieJar.php
ResponseCookieJar.clear
public function clear($name) { if (!in_array($name, $this->clearedCookies, true)) { $this->clearedCookies[] = $name; foreach ($this->cookies as $index => $value) { if ($value->getName() === $name) { unset($this->cookies[$index]); } } $this->cookies = array_values($this->cookies); } }
php
public function clear($name) { if (!in_array($name, $this->clearedCookies, true)) { $this->clearedCookies[] = $name; foreach ($this->cookies as $index => $value) { if ($value->getName() === $name) { unset($this->cookies[$index]); } } $this->cookies = array_values($this->cookies); } }
[ "public", "function", "clear", "(", "$", "name", ")", "{", "if", "(", "!", "in_array", "(", "$", "name", ",", "$", "this", "->", "clearedCookies", ",", "true", ")", ")", "{", "$", "this", "->", "clearedCookies", "[", "]", "=", "$", "name", ";", "foreach", "(", "$", "this", "->", "cookies", "as", "$", "index", "=>", "$", "value", ")", "{", "if", "(", "$", "value", "->", "getName", "(", ")", "===", "$", "name", ")", "{", "unset", "(", "$", "this", "->", "cookies", "[", "$", "index", "]", ")", ";", "}", "}", "$", "this", "->", "cookies", "=", "array_values", "(", "$", "this", "->", "cookies", ")", ";", "}", "}" ]
Clear a cookie. @param string $name @return $this
[ "Clear", "a", "cookie", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Cookie/ResponseCookieJar.php#L130-L141
train
concrete5/concrete5
concrete/src/Geolocator/GeolocatorService.php
GeolocatorService.getByID
public function getByID($id) { $id = (int) $id; return $id > 0 ? $this->em->find(Geolocator::class, $id) : null; }
php
public function getByID($id) { $id = (int) $id; return $id > 0 ? $this->em->find(Geolocator::class, $id) : null; }
[ "public", "function", "getByID", "(", "$", "id", ")", "{", "$", "id", "=", "(", "int", ")", "$", "id", ";", "return", "$", "id", ">", "0", "?", "$", "this", "->", "em", "->", "find", "(", "Geolocator", "::", "class", ",", "$", "id", ")", ":", "null", ";", "}" ]
Get a geolocator library given its ID. @param int $id @return Geolocator|null
[ "Get", "a", "geolocator", "library", "given", "its", "ID", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Geolocator/GeolocatorService.php#L46-L51
train
concrete5/concrete5
concrete/src/Geolocator/GeolocatorService.php
GeolocatorService.getByHandle
public function getByHandle($handle) { $handle = (string) $handle; return $handle === '' ? null : $this->repo->findOneBy(['glHandle' => $handle]); }
php
public function getByHandle($handle) { $handle = (string) $handle; return $handle === '' ? null : $this->repo->findOneBy(['glHandle' => $handle]); }
[ "public", "function", "getByHandle", "(", "$", "handle", ")", "{", "$", "handle", "=", "(", "string", ")", "$", "handle", ";", "return", "$", "handle", "===", "''", "?", "null", ":", "$", "this", "->", "repo", "->", "findOneBy", "(", "[", "'glHandle'", "=>", "$", "handle", "]", ")", ";", "}" ]
Get a geolocator library given its handle. @param string $handle @return Geolocator|null
[ "Get", "a", "geolocator", "library", "given", "its", "handle", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Geolocator/GeolocatorService.php#L60-L65
train
concrete5/concrete5
concrete/src/Geolocator/GeolocatorService.php
GeolocatorService.setCurrent
public function setCurrent(Geolocator $geolocator = null) { $currentGeolocator = $this->getCurrent(); if ($currentGeolocator !== $geolocator) { if ($currentGeolocator !== null) { $currentGeolocator->setIsActive(false); if ($currentGeolocator->getGeolocatorID() !== null) { $this->em->flush($currentGeolocator); } } if ($geolocator !== null) { $geolocator->setIsActive(true); if ($geolocator->getGeolocatorID() !== null) { $this->em->flush($geolocator); } } } }
php
public function setCurrent(Geolocator $geolocator = null) { $currentGeolocator = $this->getCurrent(); if ($currentGeolocator !== $geolocator) { if ($currentGeolocator !== null) { $currentGeolocator->setIsActive(false); if ($currentGeolocator->getGeolocatorID() !== null) { $this->em->flush($currentGeolocator); } } if ($geolocator !== null) { $geolocator->setIsActive(true); if ($geolocator->getGeolocatorID() !== null) { $this->em->flush($geolocator); } } } }
[ "public", "function", "setCurrent", "(", "Geolocator", "$", "geolocator", "=", "null", ")", "{", "$", "currentGeolocator", "=", "$", "this", "->", "getCurrent", "(", ")", ";", "if", "(", "$", "currentGeolocator", "!==", "$", "geolocator", ")", "{", "if", "(", "$", "currentGeolocator", "!==", "null", ")", "{", "$", "currentGeolocator", "->", "setIsActive", "(", "false", ")", ";", "if", "(", "$", "currentGeolocator", "->", "getGeolocatorID", "(", ")", "!==", "null", ")", "{", "$", "this", "->", "em", "->", "flush", "(", "$", "currentGeolocator", ")", ";", "}", "}", "if", "(", "$", "geolocator", "!==", "null", ")", "{", "$", "geolocator", "->", "setIsActive", "(", "true", ")", ";", "if", "(", "$", "geolocator", "->", "getGeolocatorID", "(", ")", "!==", "null", ")", "{", "$", "this", "->", "em", "->", "flush", "(", "$", "geolocator", ")", ";", "}", "}", "}", "}" ]
Set the currently active geolocator library. @return Geolocator|null
[ "Set", "the", "currently", "active", "geolocator", "library", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Geolocator/GeolocatorService.php#L82-L99
train
concrete5/concrete5
concrete/src/Geolocator/GeolocatorService.php
GeolocatorService.getList
public function getList() { $result = $this->repo->findAll(); $comparer = new Comparer(); usort($result, function (Geolocator $a, Geolocator $b) use ($comparer) { return $comparer->compare($a->getGeolocatorDisplayName('text'), $b->getGeolocatorDisplayName('text')); }); return $result; }
php
public function getList() { $result = $this->repo->findAll(); $comparer = new Comparer(); usort($result, function (Geolocator $a, Geolocator $b) use ($comparer) { return $comparer->compare($a->getGeolocatorDisplayName('text'), $b->getGeolocatorDisplayName('text')); }); return $result; }
[ "public", "function", "getList", "(", ")", "{", "$", "result", "=", "$", "this", "->", "repo", "->", "findAll", "(", ")", ";", "$", "comparer", "=", "new", "Comparer", "(", ")", ";", "usort", "(", "$", "result", ",", "function", "(", "Geolocator", "$", "a", ",", "Geolocator", "$", "b", ")", "use", "(", "$", "comparer", ")", "{", "return", "$", "comparer", "->", "compare", "(", "$", "a", "->", "getGeolocatorDisplayName", "(", "'text'", ")", ",", "$", "b", "->", "getGeolocatorDisplayName", "(", "'text'", ")", ")", ";", "}", ")", ";", "return", "$", "result", ";", "}" ]
Get all the installed geolocator libraries. @return Geolocator[]
[ "Get", "all", "the", "installed", "geolocator", "libraries", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Geolocator/GeolocatorService.php#L106-L115
train
concrete5/concrete5
concrete/src/Error/Handler/ErrorHandler.php
ErrorHandler.addDetails
protected function addDetails() { /* * General */ $this->addDataTable( 'Concrete5', [ 'Version' => Config::get('concrete.version'), 'Installed Version' => Config::get('concrete.version_installed'), ] ); /* * Config */ $this->addDataTable('Concrete Configuration', $this->flatConfig(Config::get('concrete'), 'concrete')); }
php
protected function addDetails() { /* * General */ $this->addDataTable( 'Concrete5', [ 'Version' => Config::get('concrete.version'), 'Installed Version' => Config::get('concrete.version_installed'), ] ); /* * Config */ $this->addDataTable('Concrete Configuration', $this->flatConfig(Config::get('concrete'), 'concrete')); }
[ "protected", "function", "addDetails", "(", ")", "{", "/*\n * General\n */", "$", "this", "->", "addDataTable", "(", "'Concrete5'", ",", "[", "'Version'", "=>", "Config", "::", "get", "(", "'concrete.version'", ")", ",", "'Installed Version'", "=>", "Config", "::", "get", "(", "'concrete.version_installed'", ")", ",", "]", ")", ";", "/*\n * Config\n */", "$", "this", "->", "addDataTable", "(", "'Concrete Configuration'", ",", "$", "this", "->", "flatConfig", "(", "Config", "::", "get", "(", "'concrete'", ")", ",", "'concrete'", ")", ")", ";", "}" ]
Add the c5 specific debug stuff.
[ "Add", "the", "c5", "specific", "debug", "stuff", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Error/Handler/ErrorHandler.php#L82-L99
train
concrete5/concrete5
concrete/src/Marketplace/Marketplace.php
Marketplace.get
private function get($url) { try { $result = $this->fileHelper->getContents( $url, $this->config->get('concrete.marektplace.request_timeout')); } catch (TimeoutException $e) { // Catch a timeout $this->connectionError = self::E_CONNECTION_TIMEOUT; return null; } catch (Exception $e) { $this->connectionError = self::E_GENERAL_CONNECTION_ERROR; return null; } return $result ?: null; }
php
private function get($url) { try { $result = $this->fileHelper->getContents( $url, $this->config->get('concrete.marektplace.request_timeout')); } catch (TimeoutException $e) { // Catch a timeout $this->connectionError = self::E_CONNECTION_TIMEOUT; return null; } catch (Exception $e) { $this->connectionError = self::E_GENERAL_CONNECTION_ERROR; return null; } return $result ?: null; }
[ "private", "function", "get", "(", "$", "url", ")", "{", "try", "{", "$", "result", "=", "$", "this", "->", "fileHelper", "->", "getContents", "(", "$", "url", ",", "$", "this", "->", "config", "->", "get", "(", "'concrete.marektplace.request_timeout'", ")", ")", ";", "}", "catch", "(", "TimeoutException", "$", "e", ")", "{", "// Catch a timeout", "$", "this", "->", "connectionError", "=", "self", "::", "E_CONNECTION_TIMEOUT", ";", "return", "null", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "$", "this", "->", "connectionError", "=", "self", "::", "E_GENERAL_CONNECTION_ERROR", ";", "return", "null", ";", "}", "return", "$", "result", "?", ":", "null", ";", "}" ]
Get the contents of a URL @param $url @return string|null
[ "Get", "the", "contents", "of", "a", "URL" ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Marketplace/Marketplace.php#L112-L130
train
concrete5/concrete5
concrete/src/Marketplace/Marketplace.php
Marketplace.checkPackageUpdates
public static function checkPackageUpdates() { $em = \ORM::entityManager(); $items = self::getAvailableMarketplaceItems(false); foreach ($items as $i) { $p = Package::getByHandle($i->getHandle()); if (is_object($p)) { /** * @var $p \Concrete\Core\Entity\Package */ $p->setPackageAvailableVersion($i->getVersion()); $em->persist($p); } } $em->flush(); }
php
public static function checkPackageUpdates() { $em = \ORM::entityManager(); $items = self::getAvailableMarketplaceItems(false); foreach ($items as $i) { $p = Package::getByHandle($i->getHandle()); if (is_object($p)) { /** * @var $p \Concrete\Core\Entity\Package */ $p->setPackageAvailableVersion($i->getVersion()); $em->persist($p); } } $em->flush(); }
[ "public", "static", "function", "checkPackageUpdates", "(", ")", "{", "$", "em", "=", "\\", "ORM", "::", "entityManager", "(", ")", ";", "$", "items", "=", "self", "::", "getAvailableMarketplaceItems", "(", "false", ")", ";", "foreach", "(", "$", "items", "as", "$", "i", ")", "{", "$", "p", "=", "Package", "::", "getByHandle", "(", "$", "i", "->", "getHandle", "(", ")", ")", ";", "if", "(", "is_object", "(", "$", "p", ")", ")", "{", "/**\n * @var $p \\Concrete\\Core\\Entity\\Package\n */", "$", "p", "->", "setPackageAvailableVersion", "(", "$", "i", "->", "getVersion", "(", ")", ")", ";", "$", "em", "->", "persist", "(", "$", "p", ")", ";", "}", "}", "$", "em", "->", "flush", "(", ")", ";", "}" ]
Runs through all packages on the marketplace, sees if they're installed here, and updates the available version number for them.
[ "Runs", "through", "all", "packages", "on", "the", "marketplace", "sees", "if", "they", "re", "installed", "here", "and", "updates", "the", "available", "version", "number", "for", "them", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Marketplace/Marketplace.php#L187-L202
train
concrete5/concrete5
concrete/src/Csv/WriterFactory.php
WriterFactory.createFromPath
public function createFromPath($path, $open_mode = 'r+') { $class = $this->writerClass; return $this->prepare($class::createFromPath($path, $open_mode)); }
php
public function createFromPath($path, $open_mode = 'r+') { $class = $this->writerClass; return $this->prepare($class::createFromPath($path, $open_mode)); }
[ "public", "function", "createFromPath", "(", "$", "path", ",", "$", "open_mode", "=", "'r+'", ")", "{", "$", "class", "=", "$", "this", "->", "writerClass", ";", "return", "$", "this", "->", "prepare", "(", "$", "class", "::", "createFromPath", "(", "$", "path", ",", "$", "open_mode", ")", ")", ";", "}" ]
Create a CSV writer from a string. @param string $path @param string $open_mode @return \League\Csv\Writer @see \League\Csv\AbstractCsv::createFromPath()
[ "Create", "a", "CSV", "writer", "from", "a", "string", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Csv/WriterFactory.php#L91-L96
train
concrete5/concrete5
concrete/src/File/File.php
File.getByID
public static function getByID($fID) { return $fID ? Application::getFacadeApplication()->make(EntityManagerInterface::class)->find(FileEntity::class, $fID) : null; }
php
public static function getByID($fID) { return $fID ? Application::getFacadeApplication()->make(EntityManagerInterface::class)->find(FileEntity::class, $fID) : null; }
[ "public", "static", "function", "getByID", "(", "$", "fID", ")", "{", "return", "$", "fID", "?", "Application", "::", "getFacadeApplication", "(", ")", "->", "make", "(", "EntityManagerInterface", "::", "class", ")", "->", "find", "(", "FileEntity", "::", "class", ",", "$", "fID", ")", ":", "null", ";", "}" ]
Return a file object for the given file ID. @param int $fID The file identifier @return FileEntity|null
[ "Return", "a", "file", "object", "for", "the", "given", "file", "ID", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/File.php#L30-L33
train
concrete5/concrete5
concrete/src/Entity/File/Version.php
Version.add
public static function add(File $file, $filename, $prefix, $data = []) { $data += [ 'uID' => 0, 'fvTitle' => '', 'fvDescription' => '', 'fvTags' => '', 'fvIsApproved' => true, ]; $app = Application::getFacadeApplication(); $em = $app->make(EntityManagerInterface::class); $dh = $app->make('date'); $date = new DateTime($dh->getOverridableNow()); $uID = (int) $data['uID']; if ($uID < 1) { if (User::isLoggedIn()) { $uID = (int) (new User())->getUserID(); } else { $uID = 0; } } $fv = new static(); $fv->file = $file; $fv->fvID = 1; $fv->fvFilename = (string) $filename; $fv->fvPrefix = $prefix; $fv->fvDateAdded = $date; $fv->fvActivateDateTime = $date; $fv->fvIsApproved = (bool) $data['fvIsApproved']; $fv->fvAuthorUID = $uID; $fv->fvApproverUID = $uID; $fv->fvTitle = (string) $data['fvTitle']; $fv->fvDescription = (string) $data['fvDescription']; $fv->fvTags = self::cleanTags((string) $data['fvTags']); $em->persist($fv); $em->flush(); $fve = new FileVersionEvent($fv); $app->make(EventDispatcherInterface::class)->dispatch('on_file_version_add', $fve); return $fv; }
php
public static function add(File $file, $filename, $prefix, $data = []) { $data += [ 'uID' => 0, 'fvTitle' => '', 'fvDescription' => '', 'fvTags' => '', 'fvIsApproved' => true, ]; $app = Application::getFacadeApplication(); $em = $app->make(EntityManagerInterface::class); $dh = $app->make('date'); $date = new DateTime($dh->getOverridableNow()); $uID = (int) $data['uID']; if ($uID < 1) { if (User::isLoggedIn()) { $uID = (int) (new User())->getUserID(); } else { $uID = 0; } } $fv = new static(); $fv->file = $file; $fv->fvID = 1; $fv->fvFilename = (string) $filename; $fv->fvPrefix = $prefix; $fv->fvDateAdded = $date; $fv->fvActivateDateTime = $date; $fv->fvIsApproved = (bool) $data['fvIsApproved']; $fv->fvAuthorUID = $uID; $fv->fvApproverUID = $uID; $fv->fvTitle = (string) $data['fvTitle']; $fv->fvDescription = (string) $data['fvDescription']; $fv->fvTags = self::cleanTags((string) $data['fvTags']); $em->persist($fv); $em->flush(); $fve = new FileVersionEvent($fv); $app->make(EventDispatcherInterface::class)->dispatch('on_file_version_add', $fve); return $fv; }
[ "public", "static", "function", "add", "(", "File", "$", "file", ",", "$", "filename", ",", "$", "prefix", ",", "$", "data", "=", "[", "]", ")", "{", "$", "data", "+=", "[", "'uID'", "=>", "0", ",", "'fvTitle'", "=>", "''", ",", "'fvDescription'", "=>", "''", ",", "'fvTags'", "=>", "''", ",", "'fvIsApproved'", "=>", "true", ",", "]", ";", "$", "app", "=", "Application", "::", "getFacadeApplication", "(", ")", ";", "$", "em", "=", "$", "app", "->", "make", "(", "EntityManagerInterface", "::", "class", ")", ";", "$", "dh", "=", "$", "app", "->", "make", "(", "'date'", ")", ";", "$", "date", "=", "new", "DateTime", "(", "$", "dh", "->", "getOverridableNow", "(", ")", ")", ";", "$", "uID", "=", "(", "int", ")", "$", "data", "[", "'uID'", "]", ";", "if", "(", "$", "uID", "<", "1", ")", "{", "if", "(", "User", "::", "isLoggedIn", "(", ")", ")", "{", "$", "uID", "=", "(", "int", ")", "(", "new", "User", "(", ")", ")", "->", "getUserID", "(", ")", ";", "}", "else", "{", "$", "uID", "=", "0", ";", "}", "}", "$", "fv", "=", "new", "static", "(", ")", ";", "$", "fv", "->", "file", "=", "$", "file", ";", "$", "fv", "->", "fvID", "=", "1", ";", "$", "fv", "->", "fvFilename", "=", "(", "string", ")", "$", "filename", ";", "$", "fv", "->", "fvPrefix", "=", "$", "prefix", ";", "$", "fv", "->", "fvDateAdded", "=", "$", "date", ";", "$", "fv", "->", "fvActivateDateTime", "=", "$", "date", ";", "$", "fv", "->", "fvIsApproved", "=", "(", "bool", ")", "$", "data", "[", "'fvIsApproved'", "]", ";", "$", "fv", "->", "fvAuthorUID", "=", "$", "uID", ";", "$", "fv", "->", "fvApproverUID", "=", "$", "uID", ";", "$", "fv", "->", "fvTitle", "=", "(", "string", ")", "$", "data", "[", "'fvTitle'", "]", ";", "$", "fv", "->", "fvDescription", "=", "(", "string", ")", "$", "data", "[", "'fvDescription'", "]", ";", "$", "fv", "->", "fvTags", "=", "self", "::", "cleanTags", "(", "(", "string", ")", "$", "data", "[", "'fvTags'", "]", ")", ";", "$", "em", "->", "persist", "(", "$", "fv", ")", ";", "$", "em", "->", "flush", "(", ")", ";", "$", "fve", "=", "new", "FileVersionEvent", "(", "$", "fv", ")", ";", "$", "app", "->", "make", "(", "EventDispatcherInterface", "::", "class", ")", "->", "dispatch", "(", "'on_file_version_add'", ",", "$", "fve", ")", ";", "return", "$", "fv", ";", "}" ]
Add a new file version. You should call refreshAttributes in order to update the size, extension, type and other attributes. @param \Concrete\Core\Entity\File\File $file the File instance associated to this version @param string $filename The name of the file @param string $prefix the path prefix used to store the file in the file system @param array $data Valid array keys are { @var int|null $uID the ID of the user that creates the file version (if not specified or empty: we'll assume the currently user logged in user) @var string $fvTitle the title of the file version @var string $fvDescription the description of the file version @var string $fvTags the tags to be assigned to the file version (separated by newlines and/or commas) @var bool $fvIsApproved Is this version the approved one for the associated file? (default: true) } @return static
[ "Add", "a", "new", "file", "version", ".", "You", "should", "call", "refreshAttributes", "in", "order", "to", "update", "the", "size", "extension", "type", "and", "other", "attributes", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/File/Version.php#L307-L351
train
concrete5/concrete5
concrete/src/Entity/File/Version.php
Version.cleanTags
public static function cleanTags($tagsStr) { $tagsArray = explode("\n", str_replace(["\r", ','], "\n", $tagsStr)); $cleanTags = []; foreach ($tagsArray as $tag) { $tag = trim($tag); if ($tag !== '') { $cleanTags[] = $tag; } } //the leading and trailing line break char is for searching: fvTag like %\ntag\n% return isset($cleanTags[0]) ? "\n" . implode("\n", $cleanTags) . "\n" : ''; }
php
public static function cleanTags($tagsStr) { $tagsArray = explode("\n", str_replace(["\r", ','], "\n", $tagsStr)); $cleanTags = []; foreach ($tagsArray as $tag) { $tag = trim($tag); if ($tag !== '') { $cleanTags[] = $tag; } } //the leading and trailing line break char is for searching: fvTag like %\ntag\n% return isset($cleanTags[0]) ? "\n" . implode("\n", $cleanTags) . "\n" : ''; }
[ "public", "static", "function", "cleanTags", "(", "$", "tagsStr", ")", "{", "$", "tagsArray", "=", "explode", "(", "\"\\n\"", ",", "str_replace", "(", "[", "\"\\r\"", ",", "','", "]", ",", "\"\\n\"", ",", "$", "tagsStr", ")", ")", ";", "$", "cleanTags", "=", "[", "]", ";", "foreach", "(", "$", "tagsArray", "as", "$", "tag", ")", "{", "$", "tag", "=", "trim", "(", "$", "tag", ")", ";", "if", "(", "$", "tag", "!==", "''", ")", "{", "$", "cleanTags", "[", "]", "=", "$", "tag", ";", "}", "}", "//the leading and trailing line break char is for searching: fvTag like %\\ntag\\n%", "return", "isset", "(", "$", "cleanTags", "[", "0", "]", ")", "?", "\"\\n\"", ".", "implode", "(", "\"\\n\"", ",", "$", "cleanTags", ")", ".", "\"\\n\"", ":", "''", ";", "}" ]
Normalize the tags separator, remove empty tags. @param string $tagsStr The list of tags, delimited by '\n', '\r' or ',' @return string
[ "Normalize", "the", "tags", "separator", "remove", "empty", "tags", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/File/Version.php#L360-L372
train
concrete5/concrete5
concrete/src/Entity/File/Version.php
Version.updateFile
public function updateFile($filename, $prefix) { $this->fvFilename = $filename; $this->fvPrefix = $prefix; $this->save(); $this->logVersionUpdate(self::UT_REPLACE_FILE); }
php
public function updateFile($filename, $prefix) { $this->fvFilename = $filename; $this->fvPrefix = $prefix; $this->save(); $this->logVersionUpdate(self::UT_REPLACE_FILE); }
[ "public", "function", "updateFile", "(", "$", "filename", ",", "$", "prefix", ")", "{", "$", "this", "->", "fvFilename", "=", "$", "filename", ";", "$", "this", "->", "fvPrefix", "=", "$", "prefix", ";", "$", "this", "->", "save", "(", ")", ";", "$", "this", "->", "logVersionUpdate", "(", "self", "::", "UT_REPLACE_FILE", ")", ";", "}" ]
Update the filename and the path prefix of the file. @param string $filename The new name of file @param string $prefix The new path prefix
[ "Update", "the", "filename", "and", "the", "path", "prefix", "of", "the", "file", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/File/Version.php#L460-L466
train
concrete5/concrete5
concrete/src/Entity/File/Version.php
Version.deny
public function deny() { $app = Application::getFacadeApplication(); $this->fvIsApproved = false; $this->save(); $fve = new FileVersionEvent($this); $app->make(EventDispatcherInterface::class)->dispatch('on_file_version_deny', $fve); $app->make('cache/request')->delete('file/version/approved/' . $this->getFileID()); }
php
public function deny() { $app = Application::getFacadeApplication(); $this->fvIsApproved = false; $this->save(); $fve = new FileVersionEvent($this); $app->make(EventDispatcherInterface::class)->dispatch('on_file_version_deny', $fve); $app->make('cache/request')->delete('file/version/approved/' . $this->getFileID()); }
[ "public", "function", "deny", "(", ")", "{", "$", "app", "=", "Application", "::", "getFacadeApplication", "(", ")", ";", "$", "this", "->", "fvIsApproved", "=", "false", ";", "$", "this", "->", "save", "(", ")", ";", "$", "fve", "=", "new", "FileVersionEvent", "(", "$", "this", ")", ";", "$", "app", "->", "make", "(", "EventDispatcherInterface", "::", "class", ")", "->", "dispatch", "(", "'on_file_version_deny'", ",", "$", "fve", ")", ";", "$", "app", "->", "make", "(", "'cache/request'", ")", "->", "delete", "(", "'file/version/approved/'", ".", "$", "this", "->", "getFileID", "(", ")", ")", ";", "}" ]
Mark this file version as not approved.
[ "Mark", "this", "file", "version", "as", "not", "approved", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/File/Version.php#L551-L559
train
concrete5/concrete5
concrete/src/Entity/File/Version.php
Version.updateTitle
public function updateTitle($title) { $app = Application::getFacadeApplication(); $this->fvTitle = $title; $this->save(); $this->logVersionUpdate(self::UT_TITLE); $fve = new FileVersionEvent($this); $app->make(EventDispatcherInterface::class)->dispatch('on_file_version_update_title', $fve); }
php
public function updateTitle($title) { $app = Application::getFacadeApplication(); $this->fvTitle = $title; $this->save(); $this->logVersionUpdate(self::UT_TITLE); $fve = new FileVersionEvent($this); $app->make(EventDispatcherInterface::class)->dispatch('on_file_version_update_title', $fve); }
[ "public", "function", "updateTitle", "(", "$", "title", ")", "{", "$", "app", "=", "Application", "::", "getFacadeApplication", "(", ")", ";", "$", "this", "->", "fvTitle", "=", "$", "title", ";", "$", "this", "->", "save", "(", ")", ";", "$", "this", "->", "logVersionUpdate", "(", "self", "::", "UT_TITLE", ")", ";", "$", "fve", "=", "new", "FileVersionEvent", "(", "$", "this", ")", ";", "$", "app", "->", "make", "(", "EventDispatcherInterface", "::", "class", ")", "->", "dispatch", "(", "'on_file_version_update_title'", ",", "$", "fve", ")", ";", "}" ]
Update the title of the file. @param string $title
[ "Update", "the", "title", "of", "the", "file", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/File/Version.php#L654-L662
train
concrete5/concrete5
concrete/src/Entity/File/Version.php
Version.updateDescription
public function updateDescription($descr) { $app = Application::getFacadeApplication(); $this->fvDescription = $descr; $this->save(); $this->logVersionUpdate(self::UT_DESCRIPTION); $fve = new FileVersionEvent($this); $app->make(EventDispatcherInterface::class)->dispatch('on_file_version_update_description', $fve); }
php
public function updateDescription($descr) { $app = Application::getFacadeApplication(); $this->fvDescription = $descr; $this->save(); $this->logVersionUpdate(self::UT_DESCRIPTION); $fve = new FileVersionEvent($this); $app->make(EventDispatcherInterface::class)->dispatch('on_file_version_update_description', $fve); }
[ "public", "function", "updateDescription", "(", "$", "descr", ")", "{", "$", "app", "=", "Application", "::", "getFacadeApplication", "(", ")", ";", "$", "this", "->", "fvDescription", "=", "$", "descr", ";", "$", "this", "->", "save", "(", ")", ";", "$", "this", "->", "logVersionUpdate", "(", "self", "::", "UT_DESCRIPTION", ")", ";", "$", "fve", "=", "new", "FileVersionEvent", "(", "$", "this", ")", ";", "$", "app", "->", "make", "(", "EventDispatcherInterface", "::", "class", ")", "->", "dispatch", "(", "'on_file_version_update_description'", ",", "$", "fve", ")", ";", "}" ]
Update the description of the file. @param string $descr
[ "Update", "the", "description", "of", "the", "file", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/File/Version.php#L679-L687
train
concrete5/concrete5
concrete/src/Entity/File/Version.php
Version.updateTags
public function updateTags($tags) { $app = Application::getFacadeApplication(); $tags = self::cleanTags($tags); $this->fvTags = $tags; $this->save(); $this->logVersionUpdate(self::UT_TAGS); $fve = new FileVersionEvent($this); $app->make(EventDispatcherInterface::class)->dispatch('on_file_version_update_tags', $fve); }
php
public function updateTags($tags) { $app = Application::getFacadeApplication(); $tags = self::cleanTags($tags); $this->fvTags = $tags; $this->save(); $this->logVersionUpdate(self::UT_TAGS); $fve = new FileVersionEvent($this); $app->make(EventDispatcherInterface::class)->dispatch('on_file_version_update_tags', $fve); }
[ "public", "function", "updateTags", "(", "$", "tags", ")", "{", "$", "app", "=", "Application", "::", "getFacadeApplication", "(", ")", ";", "$", "tags", "=", "self", "::", "cleanTags", "(", "$", "tags", ")", ";", "$", "this", "->", "fvTags", "=", "$", "tags", ";", "$", "this", "->", "save", "(", ")", ";", "$", "this", "->", "logVersionUpdate", "(", "self", "::", "UT_TAGS", ")", ";", "$", "fve", "=", "new", "FileVersionEvent", "(", "$", "this", ")", ";", "$", "app", "->", "make", "(", "EventDispatcherInterface", "::", "class", ")", "->", "dispatch", "(", "'on_file_version_update_tags'", ",", "$", "fve", ")", ";", "}" ]
Update the tags associated to the file. @param string $tags List of tags separated by newlines and/or commas
[ "Update", "the", "tags", "associated", "to", "the", "file", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/File/Version.php#L714-L723
train
concrete5/concrete5
concrete/src/Entity/File/Version.php
Version.getMimeType
public function getMimeType() { try { $fre = $this->getFileResource(); $result = $fre->getMimetype(); } catch (FileNotFoundException $x) { $result = false; } return $result; }
php
public function getMimeType() { try { $fre = $this->getFileResource(); $result = $fre->getMimetype(); } catch (FileNotFoundException $x) { $result = false; } return $result; }
[ "public", "function", "getMimeType", "(", ")", "{", "try", "{", "$", "fre", "=", "$", "this", "->", "getFileResource", "(", ")", ";", "$", "result", "=", "$", "fre", "->", "getMimetype", "(", ")", ";", "}", "catch", "(", "FileNotFoundException", "$", "x", ")", "{", "$", "result", "=", "false", ";", "}", "return", "$", "result", ";", "}" ]
Get the mime type of the file if known. @return string|false
[ "Get", "the", "mime", "type", "of", "the", "file", "if", "known", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/File/Version.php#L759-L769
train
concrete5/concrete5
concrete/src/Entity/File/Version.php
Version.getTypeObject
public function getTypeObject() { $app = Application::getFacadeApplication(); $fh = $app->make('helper/file'); $ext = $fh->getExtension($this->fvFilename); $ftl = FileTypeList::getType($ext); return $ftl; }
php
public function getTypeObject() { $app = Application::getFacadeApplication(); $fh = $app->make('helper/file'); $ext = $fh->getExtension($this->fvFilename); $ftl = FileTypeList::getType($ext); return $ftl; }
[ "public", "function", "getTypeObject", "(", ")", "{", "$", "app", "=", "Application", "::", "getFacadeApplication", "(", ")", ";", "$", "fh", "=", "$", "app", "->", "make", "(", "'helper/file'", ")", ";", "$", "ext", "=", "$", "fh", "->", "getExtension", "(", "$", "this", "->", "fvFilename", ")", ";", "$", "ftl", "=", "FileTypeList", "::", "getType", "(", "$", "ext", ")", ";", "return", "$", "ftl", ";", "}" ]
Get the type of the file. @return \Concrete\Core\File\Type\Type
[ "Get", "the", "type", "of", "the", "file", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/File/Version.php#L776-L784
train
concrete5/concrete5
concrete/src/Entity/File/Version.php
Version.logVersionUpdate
public function logVersionUpdate($updateTypeID, $updateTypeAttributeID = 0) { $app = Application::getFacadeApplication(); $db = $app->make(Connection::class); $db->executeQuery( 'INSERT INTO FileVersionLog (fID, fvID, fvUpdateTypeID, fvUpdateTypeAttributeID) VALUES (?, ?, ?, ?)', [ $this->getFileID(), $this->getFileVersionID(), $updateTypeID, $updateTypeAttributeID, ] ); }
php
public function logVersionUpdate($updateTypeID, $updateTypeAttributeID = 0) { $app = Application::getFacadeApplication(); $db = $app->make(Connection::class); $db->executeQuery( 'INSERT INTO FileVersionLog (fID, fvID, fvUpdateTypeID, fvUpdateTypeAttributeID) VALUES (?, ?, ?, ?)', [ $this->getFileID(), $this->getFileVersionID(), $updateTypeID, $updateTypeAttributeID, ] ); }
[ "public", "function", "logVersionUpdate", "(", "$", "updateTypeID", ",", "$", "updateTypeAttributeID", "=", "0", ")", "{", "$", "app", "=", "Application", "::", "getFacadeApplication", "(", ")", ";", "$", "db", "=", "$", "app", "->", "make", "(", "Connection", "::", "class", ")", ";", "$", "db", "->", "executeQuery", "(", "'INSERT INTO FileVersionLog (fID, fvID, fvUpdateTypeID, fvUpdateTypeAttributeID) VALUES (?, ?, ?, ?)'", ",", "[", "$", "this", "->", "getFileID", "(", ")", ",", "$", "this", "->", "getFileVersionID", "(", ")", ",", "$", "updateTypeID", ",", "$", "updateTypeAttributeID", ",", "]", ")", ";", "}" ]
Log updates to files. @param int $updateTypeID One of the Version::UT_... constants @param int $updateTypeAttributeID the ID of the attribute that has been updated (if any - useful when $updateTypeID is UT_EXTENDED_ATTRIBUTE)
[ "Log", "updates", "to", "files", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/File/Version.php#L828-L841
train
concrete5/concrete5
concrete/src/Entity/File/Version.php
Version.getVersionLogComments
public function getVersionLogComments() { $app = Application::getFacadeApplication(); $db = $app->make(Connection::class); $updates = []; $ga = $db->fetchAll( 'SELECT fvUpdateTypeID, fvUpdateTypeAttributeID FROM FileVersionLog WHERE fID = ? AND fvID = ? ORDER BY fvlID ASC', [$this->getFileID(), $this->getFileVersionID()] ); foreach ($ga as $a) { switch ($a['fvUpdateTypeID']) { case self::UT_REPLACE_FILE: $updates[] = t('File'); break; case self::UT_TITLE: $updates[] = t('Title'); break; case self::UT_DESCRIPTION: $updates[] = t('Description'); break; case self::UT_TAGS: $updates[] = t('Tags'); break; case self::UT_CONTENTS: $updates[] = t('File Content'); break; case self::UT_RENAME: $updates[] = t('File Name'); break; case self::UT_EXTENDED_ATTRIBUTE: $val = $db->fetchColumn( 'SELECT akName FROM AttributeKeys WHERE akID = ?', [$a['fvUpdateTypeAttributeID']] ); if ($val !== false) { $updates[] = $val; } break; } } return array_values(array_unique($updates)); }
php
public function getVersionLogComments() { $app = Application::getFacadeApplication(); $db = $app->make(Connection::class); $updates = []; $ga = $db->fetchAll( 'SELECT fvUpdateTypeID, fvUpdateTypeAttributeID FROM FileVersionLog WHERE fID = ? AND fvID = ? ORDER BY fvlID ASC', [$this->getFileID(), $this->getFileVersionID()] ); foreach ($ga as $a) { switch ($a['fvUpdateTypeID']) { case self::UT_REPLACE_FILE: $updates[] = t('File'); break; case self::UT_TITLE: $updates[] = t('Title'); break; case self::UT_DESCRIPTION: $updates[] = t('Description'); break; case self::UT_TAGS: $updates[] = t('Tags'); break; case self::UT_CONTENTS: $updates[] = t('File Content'); break; case self::UT_RENAME: $updates[] = t('File Name'); break; case self::UT_EXTENDED_ATTRIBUTE: $val = $db->fetchColumn( 'SELECT akName FROM AttributeKeys WHERE akID = ?', [$a['fvUpdateTypeAttributeID']] ); if ($val !== false) { $updates[] = $val; } break; } } return array_values(array_unique($updates)); }
[ "public", "function", "getVersionLogComments", "(", ")", "{", "$", "app", "=", "Application", "::", "getFacadeApplication", "(", ")", ";", "$", "db", "=", "$", "app", "->", "make", "(", "Connection", "::", "class", ")", ";", "$", "updates", "=", "[", "]", ";", "$", "ga", "=", "$", "db", "->", "fetchAll", "(", "'SELECT fvUpdateTypeID, fvUpdateTypeAttributeID FROM FileVersionLog WHERE fID = ? AND fvID = ? ORDER BY fvlID ASC'", ",", "[", "$", "this", "->", "getFileID", "(", ")", ",", "$", "this", "->", "getFileVersionID", "(", ")", "]", ")", ";", "foreach", "(", "$", "ga", "as", "$", "a", ")", "{", "switch", "(", "$", "a", "[", "'fvUpdateTypeID'", "]", ")", "{", "case", "self", "::", "UT_REPLACE_FILE", ":", "$", "updates", "[", "]", "=", "t", "(", "'File'", ")", ";", "break", ";", "case", "self", "::", "UT_TITLE", ":", "$", "updates", "[", "]", "=", "t", "(", "'Title'", ")", ";", "break", ";", "case", "self", "::", "UT_DESCRIPTION", ":", "$", "updates", "[", "]", "=", "t", "(", "'Description'", ")", ";", "break", ";", "case", "self", "::", "UT_TAGS", ":", "$", "updates", "[", "]", "=", "t", "(", "'Tags'", ")", ";", "break", ";", "case", "self", "::", "UT_CONTENTS", ":", "$", "updates", "[", "]", "=", "t", "(", "'File Content'", ")", ";", "break", ";", "case", "self", "::", "UT_RENAME", ":", "$", "updates", "[", "]", "=", "t", "(", "'File Name'", ")", ";", "break", ";", "case", "self", "::", "UT_EXTENDED_ATTRIBUTE", ":", "$", "val", "=", "$", "db", "->", "fetchColumn", "(", "'SELECT akName FROM AttributeKeys WHERE akID = ?'", ",", "[", "$", "a", "[", "'fvUpdateTypeAttributeID'", "]", "]", ")", ";", "if", "(", "$", "val", "!==", "false", ")", "{", "$", "updates", "[", "]", "=", "$", "val", ";", "}", "break", ";", "}", "}", "return", "array_values", "(", "array_unique", "(", "$", "updates", ")", ")", ";", "}" ]
Get an array containing human-readable descriptions of everything that happened to this file version. @return string[]
[ "Get", "an", "array", "containing", "human", "-", "readable", "descriptions", "of", "everything", "that", "happened", "to", "this", "file", "version", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/File/Version.php#L848-L890
train
concrete5/concrete5
concrete/src/Entity/File/Version.php
Version.getDownloadURL
public function getDownloadURL() { $app = Application::getFacadeApplication(); $urlResolver = $app->make(ResolverManagerInterface::class); $c = Page::getCurrentPage(); $cID = $c instanceof Page && !$c->isError() ? $c->getCollectionID() : 0; return $urlResolver->resolve(['/download_file', $this->getFileID(), $cID]); }
php
public function getDownloadURL() { $app = Application::getFacadeApplication(); $urlResolver = $app->make(ResolverManagerInterface::class); $c = Page::getCurrentPage(); $cID = $c instanceof Page && !$c->isError() ? $c->getCollectionID() : 0; return $urlResolver->resolve(['/download_file', $this->getFileID(), $cID]); }
[ "public", "function", "getDownloadURL", "(", ")", "{", "$", "app", "=", "Application", "::", "getFacadeApplication", "(", ")", ";", "$", "urlResolver", "=", "$", "app", "->", "make", "(", "ResolverManagerInterface", "::", "class", ")", ";", "$", "c", "=", "Page", "::", "getCurrentPage", "(", ")", ";", "$", "cID", "=", "$", "c", "instanceof", "Page", "&&", "!", "$", "c", "->", "isError", "(", ")", "?", "$", "c", "->", "getCollectionID", "(", ")", ":", "0", ";", "return", "$", "urlResolver", "->", "resolve", "(", "[", "'/download_file'", ",", "$", "this", "->", "getFileID", "(", ")", ",", "$", "cID", "]", ")", ";", "}" ]
Get an URL that can be used to download the file. This passes through the download_file single page. @return \League\URL\URLInterface
[ "Get", "an", "URL", "that", "can", "be", "used", "to", "download", "the", "file", ".", "This", "passes", "through", "the", "download_file", "single", "page", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/File/Version.php#L955-L963
train
concrete5/concrete5
concrete/src/Entity/File/Version.php
Version.buildForceDownloadResponse
public function buildForceDownloadResponse() { $fre = $this->getFileResource(); $fs = $this->getFile()->getFileStorageLocationObject()->getFileSystemObject(); $response = new FlysystemFileResponse($fre->getPath(), $fs); $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT); return $response; }
php
public function buildForceDownloadResponse() { $fre = $this->getFileResource(); $fs = $this->getFile()->getFileStorageLocationObject()->getFileSystemObject(); $response = new FlysystemFileResponse($fre->getPath(), $fs); $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT); return $response; }
[ "public", "function", "buildForceDownloadResponse", "(", ")", "{", "$", "fre", "=", "$", "this", "->", "getFileResource", "(", ")", ";", "$", "fs", "=", "$", "this", "->", "getFile", "(", ")", "->", "getFileStorageLocationObject", "(", ")", "->", "getFileSystemObject", "(", ")", ";", "$", "response", "=", "new", "FlysystemFileResponse", "(", "$", "fre", "->", "getPath", "(", ")", ",", "$", "fs", ")", ";", "$", "response", "->", "setContentDisposition", "(", "ResponseHeaderBag", "::", "DISPOSITION_ATTACHMENT", ")", ";", "return", "$", "response", ";", "}" ]
Get a Response instance that will force the browser to download the file, even if the browser can display it. @return \Concrete\Core\Http\Response
[ "Get", "a", "Response", "instance", "that", "will", "force", "the", "browser", "to", "download", "the", "file", "even", "if", "the", "browser", "can", "display", "it", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/File/Version.php#L985-L995
train
concrete5/concrete5
concrete/src/Entity/File/Version.php
Version.duplicateUnderlyingFile
public function duplicateUnderlyingFile() { $app = Application::getFacadeApplication(); $importer = new Importer(); $cf = $app->make('helper/concrete/file'); $filesystem = $this->getFile()->getFileStorageLocationObject()->getFileSystemObject(); $fileName = $this->getFileName(); do { $prefix = $importer->generatePrefix(); $path = $cf->prefix($prefix, $fileName); } while ($filesystem->has($path)); $fileContents = $this->getFileResource()->read(); $mimeType = Util::guessMimeType($fileName, $fileContents); $filesystem->write( $path, $fileContents, [ 'visibility' => AdapterInterface::VISIBILITY_PUBLIC, 'mimetype' => $mimeType, ] ); $this->updateFile($fileName, $prefix); }
php
public function duplicateUnderlyingFile() { $app = Application::getFacadeApplication(); $importer = new Importer(); $cf = $app->make('helper/concrete/file'); $filesystem = $this->getFile()->getFileStorageLocationObject()->getFileSystemObject(); $fileName = $this->getFileName(); do { $prefix = $importer->generatePrefix(); $path = $cf->prefix($prefix, $fileName); } while ($filesystem->has($path)); $fileContents = $this->getFileResource()->read(); $mimeType = Util::guessMimeType($fileName, $fileContents); $filesystem->write( $path, $fileContents, [ 'visibility' => AdapterInterface::VISIBILITY_PUBLIC, 'mimetype' => $mimeType, ] ); $this->updateFile($fileName, $prefix); }
[ "public", "function", "duplicateUnderlyingFile", "(", ")", "{", "$", "app", "=", "Application", "::", "getFacadeApplication", "(", ")", ";", "$", "importer", "=", "new", "Importer", "(", ")", ";", "$", "cf", "=", "$", "app", "->", "make", "(", "'helper/concrete/file'", ")", ";", "$", "filesystem", "=", "$", "this", "->", "getFile", "(", ")", "->", "getFileStorageLocationObject", "(", ")", "->", "getFileSystemObject", "(", ")", ";", "$", "fileName", "=", "$", "this", "->", "getFileName", "(", ")", ";", "do", "{", "$", "prefix", "=", "$", "importer", "->", "generatePrefix", "(", ")", ";", "$", "path", "=", "$", "cf", "->", "prefix", "(", "$", "prefix", ",", "$", "fileName", ")", ";", "}", "while", "(", "$", "filesystem", "->", "has", "(", "$", "path", ")", ")", ";", "$", "fileContents", "=", "$", "this", "->", "getFileResource", "(", ")", "->", "read", "(", ")", ";", "$", "mimeType", "=", "Util", "::", "guessMimeType", "(", "$", "fileName", ",", "$", "fileContents", ")", ";", "$", "filesystem", "->", "write", "(", "$", "path", ",", "$", "fileContents", ",", "[", "'visibility'", "=>", "AdapterInterface", "::", "VISIBILITY_PUBLIC", ",", "'mimetype'", "=>", "$", "mimeType", ",", "]", ")", ";", "$", "this", "->", "updateFile", "(", "$", "fileName", ",", "$", "prefix", ")", ";", "}" ]
Duplicate the underlying file and assign its new position to this instance.
[ "Duplicate", "the", "underlying", "file", "and", "assign", "its", "new", "position", "to", "this", "instance", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/File/Version.php#L1068-L1090
train
concrete5/concrete5
concrete/src/Entity/File/Version.php
Version.delete
public function delete($deleteFilesAndThumbnails = false) { $app = Application::getFacadeApplication(); $db = $app->make(Connection::class); $em = $app->make(EntityManagerInterface::class); $category = $this->getObjectAttributeCategory(); foreach ($this->getAttributes() as $attribute) { $category->deleteValue($attribute); } $db->executeQuery('DELETE FROM FileVersionLog WHERE fID = ? AND fvID = ?', [$this->getFileID(), $this->fvID]); if ($deleteFilesAndThumbnails) { if ($this->getTypeObject()->getGenericType() === FileType::T_IMAGE) { $types = ThumbnailType::getVersionList(); foreach ($types as $type) { $this->deleteThumbnail($type); } } try { $fsl = $this->getFile()->getFileStorageLocationObject()->getFileSystemObject(); $fre = $this->getFileResource(); if ($fsl->has($fre->getPath())) { $fsl->delete($fre->getPath()); } } catch (FileNotFoundException $e) { } } $em->remove($this); $em->flush(); }
php
public function delete($deleteFilesAndThumbnails = false) { $app = Application::getFacadeApplication(); $db = $app->make(Connection::class); $em = $app->make(EntityManagerInterface::class); $category = $this->getObjectAttributeCategory(); foreach ($this->getAttributes() as $attribute) { $category->deleteValue($attribute); } $db->executeQuery('DELETE FROM FileVersionLog WHERE fID = ? AND fvID = ?', [$this->getFileID(), $this->fvID]); if ($deleteFilesAndThumbnails) { if ($this->getTypeObject()->getGenericType() === FileType::T_IMAGE) { $types = ThumbnailType::getVersionList(); foreach ($types as $type) { $this->deleteThumbnail($type); } } try { $fsl = $this->getFile()->getFileStorageLocationObject()->getFileSystemObject(); $fre = $this->getFileResource(); if ($fsl->has($fre->getPath())) { $fsl->delete($fre->getPath()); } } catch (FileNotFoundException $e) { } } $em->remove($this); $em->flush(); }
[ "public", "function", "delete", "(", "$", "deleteFilesAndThumbnails", "=", "false", ")", "{", "$", "app", "=", "Application", "::", "getFacadeApplication", "(", ")", ";", "$", "db", "=", "$", "app", "->", "make", "(", "Connection", "::", "class", ")", ";", "$", "em", "=", "$", "app", "->", "make", "(", "EntityManagerInterface", "::", "class", ")", ";", "$", "category", "=", "$", "this", "->", "getObjectAttributeCategory", "(", ")", ";", "foreach", "(", "$", "this", "->", "getAttributes", "(", ")", "as", "$", "attribute", ")", "{", "$", "category", "->", "deleteValue", "(", "$", "attribute", ")", ";", "}", "$", "db", "->", "executeQuery", "(", "'DELETE FROM FileVersionLog WHERE fID = ? AND fvID = ?'", ",", "[", "$", "this", "->", "getFileID", "(", ")", ",", "$", "this", "->", "fvID", "]", ")", ";", "if", "(", "$", "deleteFilesAndThumbnails", ")", "{", "if", "(", "$", "this", "->", "getTypeObject", "(", ")", "->", "getGenericType", "(", ")", "===", "FileType", "::", "T_IMAGE", ")", "{", "$", "types", "=", "ThumbnailType", "::", "getVersionList", "(", ")", ";", "foreach", "(", "$", "types", "as", "$", "type", ")", "{", "$", "this", "->", "deleteThumbnail", "(", "$", "type", ")", ";", "}", "}", "try", "{", "$", "fsl", "=", "$", "this", "->", "getFile", "(", ")", "->", "getFileStorageLocationObject", "(", ")", "->", "getFileSystemObject", "(", ")", ";", "$", "fre", "=", "$", "this", "->", "getFileResource", "(", ")", ";", "if", "(", "$", "fsl", "->", "has", "(", "$", "fre", "->", "getPath", "(", ")", ")", ")", "{", "$", "fsl", "->", "delete", "(", "$", "fre", "->", "getPath", "(", ")", ")", ";", "}", "}", "catch", "(", "FileNotFoundException", "$", "e", ")", "{", "}", "}", "$", "em", "->", "remove", "(", "$", "this", ")", ";", "$", "em", "->", "flush", "(", ")", ";", "}" ]
Delete this version of the file. @param bool $deleteFilesAndThumbnails should we delete the actual file and the thumbnails?
[ "Delete", "this", "version", "of", "the", "file", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/File/Version.php#L1097-L1128
train
concrete5/concrete5
concrete/src/Entity/File/Version.php
Version.updateContents
public function updateContents($contents, $rescanThumbnails = true) { $this->releaseImagineImage(); $storage = $this->getFile()->getFileStorageLocationObject(); if ($storage !== null) { $app = Application::getFacadeApplication(); $cf = $app->make('helper/concrete/file'); $path = $cf->prefix($this->fvPrefix, $this->fvFilename); $filesystem = $storage->getFileSystemObject(); try { if ($filesystem->has($path)) { $filesystem->delete($path); } } catch (FileNotFoundException $x) { } $filesystem->write($path, $contents); $this->logVersionUpdate(self::UT_CONTENTS); $fve = new FileVersionEvent($this); $app->make(EventDispatcherInterface::class)->dispatch('on_file_version_update_contents', $fve); $this->refreshAttributes($rescanThumbnails); } }
php
public function updateContents($contents, $rescanThumbnails = true) { $this->releaseImagineImage(); $storage = $this->getFile()->getFileStorageLocationObject(); if ($storage !== null) { $app = Application::getFacadeApplication(); $cf = $app->make('helper/concrete/file'); $path = $cf->prefix($this->fvPrefix, $this->fvFilename); $filesystem = $storage->getFileSystemObject(); try { if ($filesystem->has($path)) { $filesystem->delete($path); } } catch (FileNotFoundException $x) { } $filesystem->write($path, $contents); $this->logVersionUpdate(self::UT_CONTENTS); $fve = new FileVersionEvent($this); $app->make(EventDispatcherInterface::class)->dispatch('on_file_version_update_contents', $fve); $this->refreshAttributes($rescanThumbnails); } }
[ "public", "function", "updateContents", "(", "$", "contents", ",", "$", "rescanThumbnails", "=", "true", ")", "{", "$", "this", "->", "releaseImagineImage", "(", ")", ";", "$", "storage", "=", "$", "this", "->", "getFile", "(", ")", "->", "getFileStorageLocationObject", "(", ")", ";", "if", "(", "$", "storage", "!==", "null", ")", "{", "$", "app", "=", "Application", "::", "getFacadeApplication", "(", ")", ";", "$", "cf", "=", "$", "app", "->", "make", "(", "'helper/concrete/file'", ")", ";", "$", "path", "=", "$", "cf", "->", "prefix", "(", "$", "this", "->", "fvPrefix", ",", "$", "this", "->", "fvFilename", ")", ";", "$", "filesystem", "=", "$", "storage", "->", "getFileSystemObject", "(", ")", ";", "try", "{", "if", "(", "$", "filesystem", "->", "has", "(", "$", "path", ")", ")", "{", "$", "filesystem", "->", "delete", "(", "$", "path", ")", ";", "}", "}", "catch", "(", "FileNotFoundException", "$", "x", ")", "{", "}", "$", "filesystem", "->", "write", "(", "$", "path", ",", "$", "contents", ")", ";", "$", "this", "->", "logVersionUpdate", "(", "self", "::", "UT_CONTENTS", ")", ";", "$", "fve", "=", "new", "FileVersionEvent", "(", "$", "this", ")", ";", "$", "app", "->", "make", "(", "EventDispatcherInterface", "::", "class", ")", "->", "dispatch", "(", "'on_file_version_update_contents'", ",", "$", "fve", ")", ";", "$", "this", "->", "refreshAttributes", "(", "$", "rescanThumbnails", ")", ";", "}", "}" ]
Update the contents of the file. @param string $contents The new content of the file @param bool $rescanThumbnails Should thumbnails be rescanned as well?
[ "Update", "the", "contents", "of", "the", "file", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/File/Version.php#L1153-L1174
train
concrete5/concrete5
concrete/src/Entity/File/Version.php
Version.getFileContents
public function getFileContents() { $result = null; $fsl = $this->getFile()->getFileStorageLocationObject(); if ($fsl !== null) { $app = Application::getFacadeApplication(); $cf = $app->make('helper/concrete/file'); try { $result = $fsl->getFileSystemObject()->read($cf->prefix($this->fvPrefix, $this->fvFilename)); if ($result === false) { $result = null; } } catch (FileNotFoundException $x) { } } return $result; }
php
public function getFileContents() { $result = null; $fsl = $this->getFile()->getFileStorageLocationObject(); if ($fsl !== null) { $app = Application::getFacadeApplication(); $cf = $app->make('helper/concrete/file'); try { $result = $fsl->getFileSystemObject()->read($cf->prefix($this->fvPrefix, $this->fvFilename)); if ($result === false) { $result = null; } } catch (FileNotFoundException $x) { } } return $result; }
[ "public", "function", "getFileContents", "(", ")", "{", "$", "result", "=", "null", ";", "$", "fsl", "=", "$", "this", "->", "getFile", "(", ")", "->", "getFileStorageLocationObject", "(", ")", ";", "if", "(", "$", "fsl", "!==", "null", ")", "{", "$", "app", "=", "Application", "::", "getFacadeApplication", "(", ")", ";", "$", "cf", "=", "$", "app", "->", "make", "(", "'helper/concrete/file'", ")", ";", "try", "{", "$", "result", "=", "$", "fsl", "->", "getFileSystemObject", "(", ")", "->", "read", "(", "$", "cf", "->", "prefix", "(", "$", "this", "->", "fvPrefix", ",", "$", "this", "->", "fvFilename", ")", ")", ";", "if", "(", "$", "result", "===", "false", ")", "{", "$", "result", "=", "null", ";", "}", "}", "catch", "(", "FileNotFoundException", "$", "x", ")", "{", "}", "}", "return", "$", "result", ";", "}" ]
Get the contents of the file. @return string|null return NULL if the actual file does not exist or can't be read
[ "Get", "the", "contents", "of", "the", "file", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/File/Version.php#L1181-L1198
train
concrete5/concrete5
concrete/src/Entity/File/Version.php
Version.refreshAttributes
public function refreshAttributes($rescanThumbnails = true) { $app = Application::getFacadeApplication(); $storage = $this->getFile()->getFileStorageLocationObject(); if ($storage !== null) { $fs = $storage->getFileSystemObject(); $adapter = $fs->getAdapter(); if ($adapter instanceof CachedAdapter) { $cache = $adapter->getCache(); $cf = $app->make('helper/concrete/file'); $path = Util::normalizePath($cf->prefix($this->fvPrefix, $this->fvFilename)); $cache->delete($path); } } $em = $app->make(EntityManagerInterface::class); $fh = $app->make('helper/file'); $ext = $fh->getExtension($this->fvFilename); $ftl = FileTypeList::getType($ext); $cl = $ftl->getCustomInspector(); if ($cl !== null) { $this->fvGenericType = $ftl->getGenericType(); $cl->inspect($this); } $em->refresh($this); try { $fsr = $this->getFileResource(); if (!$fsr->isFile()) { return Importer::E_FILE_INVALID; } } catch (FileNotFoundException $e) { return Importer::E_FILE_INVALID; } $this->fvExtension = $ext; $this->fvType = $ftl->getGenericType(); if ($this->fvTitle === null) { $this->fvTitle = $this->getFileName(); } $this->fvSize = $fsr->getSize(); if ($rescanThumbnails) { $this->rescanThumbnails(); } $this->save(); $f = $this->getFile(); $f->reindex(); }
php
public function refreshAttributes($rescanThumbnails = true) { $app = Application::getFacadeApplication(); $storage = $this->getFile()->getFileStorageLocationObject(); if ($storage !== null) { $fs = $storage->getFileSystemObject(); $adapter = $fs->getAdapter(); if ($adapter instanceof CachedAdapter) { $cache = $adapter->getCache(); $cf = $app->make('helper/concrete/file'); $path = Util::normalizePath($cf->prefix($this->fvPrefix, $this->fvFilename)); $cache->delete($path); } } $em = $app->make(EntityManagerInterface::class); $fh = $app->make('helper/file'); $ext = $fh->getExtension($this->fvFilename); $ftl = FileTypeList::getType($ext); $cl = $ftl->getCustomInspector(); if ($cl !== null) { $this->fvGenericType = $ftl->getGenericType(); $cl->inspect($this); } $em->refresh($this); try { $fsr = $this->getFileResource(); if (!$fsr->isFile()) { return Importer::E_FILE_INVALID; } } catch (FileNotFoundException $e) { return Importer::E_FILE_INVALID; } $this->fvExtension = $ext; $this->fvType = $ftl->getGenericType(); if ($this->fvTitle === null) { $this->fvTitle = $this->getFileName(); } $this->fvSize = $fsr->getSize(); if ($rescanThumbnails) { $this->rescanThumbnails(); } $this->save(); $f = $this->getFile(); $f->reindex(); }
[ "public", "function", "refreshAttributes", "(", "$", "rescanThumbnails", "=", "true", ")", "{", "$", "app", "=", "Application", "::", "getFacadeApplication", "(", ")", ";", "$", "storage", "=", "$", "this", "->", "getFile", "(", ")", "->", "getFileStorageLocationObject", "(", ")", ";", "if", "(", "$", "storage", "!==", "null", ")", "{", "$", "fs", "=", "$", "storage", "->", "getFileSystemObject", "(", ")", ";", "$", "adapter", "=", "$", "fs", "->", "getAdapter", "(", ")", ";", "if", "(", "$", "adapter", "instanceof", "CachedAdapter", ")", "{", "$", "cache", "=", "$", "adapter", "->", "getCache", "(", ")", ";", "$", "cf", "=", "$", "app", "->", "make", "(", "'helper/concrete/file'", ")", ";", "$", "path", "=", "Util", "::", "normalizePath", "(", "$", "cf", "->", "prefix", "(", "$", "this", "->", "fvPrefix", ",", "$", "this", "->", "fvFilename", ")", ")", ";", "$", "cache", "->", "delete", "(", "$", "path", ")", ";", "}", "}", "$", "em", "=", "$", "app", "->", "make", "(", "EntityManagerInterface", "::", "class", ")", ";", "$", "fh", "=", "$", "app", "->", "make", "(", "'helper/file'", ")", ";", "$", "ext", "=", "$", "fh", "->", "getExtension", "(", "$", "this", "->", "fvFilename", ")", ";", "$", "ftl", "=", "FileTypeList", "::", "getType", "(", "$", "ext", ")", ";", "$", "cl", "=", "$", "ftl", "->", "getCustomInspector", "(", ")", ";", "if", "(", "$", "cl", "!==", "null", ")", "{", "$", "this", "->", "fvGenericType", "=", "$", "ftl", "->", "getGenericType", "(", ")", ";", "$", "cl", "->", "inspect", "(", "$", "this", ")", ";", "}", "$", "em", "->", "refresh", "(", "$", "this", ")", ";", "try", "{", "$", "fsr", "=", "$", "this", "->", "getFileResource", "(", ")", ";", "if", "(", "!", "$", "fsr", "->", "isFile", "(", ")", ")", "{", "return", "Importer", "::", "E_FILE_INVALID", ";", "}", "}", "catch", "(", "FileNotFoundException", "$", "e", ")", "{", "return", "Importer", "::", "E_FILE_INVALID", ";", "}", "$", "this", "->", "fvExtension", "=", "$", "ext", ";", "$", "this", "->", "fvType", "=", "$", "ftl", "->", "getGenericType", "(", ")", ";", "if", "(", "$", "this", "->", "fvTitle", "===", "null", ")", "{", "$", "this", "->", "fvTitle", "=", "$", "this", "->", "getFileName", "(", ")", ";", "}", "$", "this", "->", "fvSize", "=", "$", "fsr", "->", "getSize", "(", ")", ";", "if", "(", "$", "rescanThumbnails", ")", "{", "$", "this", "->", "rescanThumbnails", "(", ")", ";", "}", "$", "this", "->", "save", "(", ")", ";", "$", "f", "=", "$", "this", "->", "getFile", "(", ")", ";", "$", "f", "->", "reindex", "(", ")", ";", "}" ]
Rescan all the attributes of this file version. This will run any type-based import routines, and store those attributes, generate thumbnails, etc... @param bool $rescanThumbnails Should thumbnails be rescanned as well? @return null|int Return one of the \Concrete\Core\File\Importer::E_... constants in case of errors, NULL otherwise.
[ "Rescan", "all", "the", "attributes", "of", "this", "file", "version", ".", "This", "will", "run", "any", "type", "-", "based", "import", "routines", "and", "store", "those", "attributes", "generate", "thumbnails", "etc", "..." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/File/Version.php#L1222-L1275
train
concrete5/concrete5
concrete/src/Entity/File/Version.php
Version.getImagineImage
public function getImagineImage() { if (null === $this->imagineImage) { $app = Application::getFacadeApplication(); $resource = $this->getFileResource(); $mimetype = $resource->getMimeType(); $imageLibrary = $app->make(ImagineInterface::class); switch ($mimetype) { case 'image/svg+xml': case 'image/svg-xml': case 'text/plain': if ($imageLibrary instanceof \Imagine\Gd\Imagine) { try { $imageLibrary = $app->make('image/imagick'); } catch (Exception $x) { $this->imagineImage = false; } catch (Throwable $x) { $this->imagineImage = false; } } break; } if (null === $this->imagineImage) { $metadataReader = $imageLibrary->getMetadataReader(); if (!$metadataReader instanceof ExifMetadataReader) { if ($app->make('config')->get('concrete.file_manager.images.use_exif_data_to_rotate_images')) { try { $imageLibrary->setMetadataReader(new ExifMetadataReader()); } catch (NotSupportedException $e) { } } } try { $this->imagineImage = $imageLibrary->load($resource->read()); } catch (FileNotFoundException $e) { $this->imagineImage = false; } } } return $this->imagineImage ?: null; }
php
public function getImagineImage() { if (null === $this->imagineImage) { $app = Application::getFacadeApplication(); $resource = $this->getFileResource(); $mimetype = $resource->getMimeType(); $imageLibrary = $app->make(ImagineInterface::class); switch ($mimetype) { case 'image/svg+xml': case 'image/svg-xml': case 'text/plain': if ($imageLibrary instanceof \Imagine\Gd\Imagine) { try { $imageLibrary = $app->make('image/imagick'); } catch (Exception $x) { $this->imagineImage = false; } catch (Throwable $x) { $this->imagineImage = false; } } break; } if (null === $this->imagineImage) { $metadataReader = $imageLibrary->getMetadataReader(); if (!$metadataReader instanceof ExifMetadataReader) { if ($app->make('config')->get('concrete.file_manager.images.use_exif_data_to_rotate_images')) { try { $imageLibrary->setMetadataReader(new ExifMetadataReader()); } catch (NotSupportedException $e) { } } } try { $this->imagineImage = $imageLibrary->load($resource->read()); } catch (FileNotFoundException $e) { $this->imagineImage = false; } } } return $this->imagineImage ?: null; }
[ "public", "function", "getImagineImage", "(", ")", "{", "if", "(", "null", "===", "$", "this", "->", "imagineImage", ")", "{", "$", "app", "=", "Application", "::", "getFacadeApplication", "(", ")", ";", "$", "resource", "=", "$", "this", "->", "getFileResource", "(", ")", ";", "$", "mimetype", "=", "$", "resource", "->", "getMimeType", "(", ")", ";", "$", "imageLibrary", "=", "$", "app", "->", "make", "(", "ImagineInterface", "::", "class", ")", ";", "switch", "(", "$", "mimetype", ")", "{", "case", "'image/svg+xml'", ":", "case", "'image/svg-xml'", ":", "case", "'text/plain'", ":", "if", "(", "$", "imageLibrary", "instanceof", "\\", "Imagine", "\\", "Gd", "\\", "Imagine", ")", "{", "try", "{", "$", "imageLibrary", "=", "$", "app", "->", "make", "(", "'image/imagick'", ")", ";", "}", "catch", "(", "Exception", "$", "x", ")", "{", "$", "this", "->", "imagineImage", "=", "false", ";", "}", "catch", "(", "Throwable", "$", "x", ")", "{", "$", "this", "->", "imagineImage", "=", "false", ";", "}", "}", "break", ";", "}", "if", "(", "null", "===", "$", "this", "->", "imagineImage", ")", "{", "$", "metadataReader", "=", "$", "imageLibrary", "->", "getMetadataReader", "(", ")", ";", "if", "(", "!", "$", "metadataReader", "instanceof", "ExifMetadataReader", ")", "{", "if", "(", "$", "app", "->", "make", "(", "'config'", ")", "->", "get", "(", "'concrete.file_manager.images.use_exif_data_to_rotate_images'", ")", ")", "{", "try", "{", "$", "imageLibrary", "->", "setMetadataReader", "(", "new", "ExifMetadataReader", "(", ")", ")", ";", "}", "catch", "(", "NotSupportedException", "$", "e", ")", "{", "}", "}", "}", "try", "{", "$", "this", "->", "imagineImage", "=", "$", "imageLibrary", "->", "load", "(", "$", "resource", "->", "read", "(", ")", ")", ";", "}", "catch", "(", "FileNotFoundException", "$", "e", ")", "{", "$", "this", "->", "imagineImage", "=", "false", ";", "}", "}", "}", "return", "$", "this", "->", "imagineImage", "?", ":", "null", ";", "}" ]
Get an \Imagine\Image\ImageInterface representing the image. @return \Imagine\Image\ImageInterface|null return NULL if the image coulnd't be read, an ImageInterface otherwise
[ "Get", "an", "\\", "Imagine", "\\", "Image", "\\", "ImageInterface", "representing", "the", "image", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/File/Version.php#L1318-L1361
train
concrete5/concrete5
concrete/src/Entity/File/Version.php
Version.releaseImagineImage
public function releaseImagineImage() { $doGarbageCollection = $this->imagineImage ? true : false; $this->imagineImage = null; if ($doGarbageCollection) { gc_collect_cycles(); } }
php
public function releaseImagineImage() { $doGarbageCollection = $this->imagineImage ? true : false; $this->imagineImage = null; if ($doGarbageCollection) { gc_collect_cycles(); } }
[ "public", "function", "releaseImagineImage", "(", ")", "{", "$", "doGarbageCollection", "=", "$", "this", "->", "imagineImage", "?", "true", ":", "false", ";", "$", "this", "->", "imagineImage", "=", "null", ";", "if", "(", "$", "doGarbageCollection", ")", "{", "gc_collect_cycles", "(", ")", ";", "}", "}" ]
Unload the loaded Image instance.
[ "Unload", "the", "loaded", "Image", "instance", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/File/Version.php#L1376-L1383
train
concrete5/concrete5
concrete/src/Entity/File/Version.php
Version.importThumbnail
public function importThumbnail(ThumbnailTypeVersion $version, $path) { $app = Application::getFacadeApplication(); $config = $app->make('config'); $thumbnailPath = $version->getFilePath($this); $filesystem = $this->getFile() ->getFileStorageLocationObject() ->getFileSystemObject(); try { if ($filesystem->has($thumbnailPath)) { $filesystem->delete($thumbnailPath); } } catch (FileNotFoundException $e) { } $fileContents = file_get_contents($path); $mimeType = Util::guessMimeType($path, $fileContents); $filesystem->write( $thumbnailPath, $fileContents, [ 'visibility' => AdapterInterface::VISIBILITY_PUBLIC, 'mimetype' => $mimeType, ] ); if ($version->getHandle() == $config->get('concrete.icons.file_manager_listing.handle')) { $this->fvHasListingThumbnail = true; } if ($version->getHandle() == $config->get('concrete.icons.file_manager_detail.handle')) { $this->fvHasDetailThumbnail = true; } $this->save(); }
php
public function importThumbnail(ThumbnailTypeVersion $version, $path) { $app = Application::getFacadeApplication(); $config = $app->make('config'); $thumbnailPath = $version->getFilePath($this); $filesystem = $this->getFile() ->getFileStorageLocationObject() ->getFileSystemObject(); try { if ($filesystem->has($thumbnailPath)) { $filesystem->delete($thumbnailPath); } } catch (FileNotFoundException $e) { } $fileContents = file_get_contents($path); $mimeType = Util::guessMimeType($path, $fileContents); $filesystem->write( $thumbnailPath, $fileContents, [ 'visibility' => AdapterInterface::VISIBILITY_PUBLIC, 'mimetype' => $mimeType, ] ); if ($version->getHandle() == $config->get('concrete.icons.file_manager_listing.handle')) { $this->fvHasListingThumbnail = true; } if ($version->getHandle() == $config->get('concrete.icons.file_manager_detail.handle')) { $this->fvHasDetailThumbnail = true; } $this->save(); }
[ "public", "function", "importThumbnail", "(", "ThumbnailTypeVersion", "$", "version", ",", "$", "path", ")", "{", "$", "app", "=", "Application", "::", "getFacadeApplication", "(", ")", ";", "$", "config", "=", "$", "app", "->", "make", "(", "'config'", ")", ";", "$", "thumbnailPath", "=", "$", "version", "->", "getFilePath", "(", "$", "this", ")", ";", "$", "filesystem", "=", "$", "this", "->", "getFile", "(", ")", "->", "getFileStorageLocationObject", "(", ")", "->", "getFileSystemObject", "(", ")", ";", "try", "{", "if", "(", "$", "filesystem", "->", "has", "(", "$", "thumbnailPath", ")", ")", "{", "$", "filesystem", "->", "delete", "(", "$", "thumbnailPath", ")", ";", "}", "}", "catch", "(", "FileNotFoundException", "$", "e", ")", "{", "}", "$", "fileContents", "=", "file_get_contents", "(", "$", "path", ")", ";", "$", "mimeType", "=", "Util", "::", "guessMimeType", "(", "$", "path", ",", "$", "fileContents", ")", ";", "$", "filesystem", "->", "write", "(", "$", "thumbnailPath", ",", "$", "fileContents", ",", "[", "'visibility'", "=>", "AdapterInterface", "::", "VISIBILITY_PUBLIC", ",", "'mimetype'", "=>", "$", "mimeType", ",", "]", ")", ";", "if", "(", "$", "version", "->", "getHandle", "(", ")", "==", "$", "config", "->", "get", "(", "'concrete.icons.file_manager_listing.handle'", ")", ")", "{", "$", "this", "->", "fvHasListingThumbnail", "=", "true", ";", "}", "if", "(", "$", "version", "->", "getHandle", "(", ")", "==", "$", "config", "->", "get", "(", "'concrete.icons.file_manager_detail.handle'", ")", ")", "{", "$", "this", "->", "fvHasDetailThumbnail", "=", "true", ";", "}", "$", "this", "->", "save", "(", ")", ";", "}" ]
Import an existing file as a thumbnail type version. @param \Concrete\Core\File\Image\Thumbnail\Type\Version $version @param string $path
[ "Import", "an", "existing", "file", "as", "a", "thumbnail", "type", "version", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/File/Version.php#L1543-L1577
train
concrete5/concrete5
concrete/src/Entity/File/Version.php
Version.getThumbnails
public function getThumbnails() { $thumbnails = []; $imageWidth = (int) $this->getAttribute('width'); $imageHeight = (int) $this->getAttribute('height'); if ($imageWidth < 1 || $imageHeight < 1) { throw new InvalidDimensionException($this->getFile(), $this, t('Invalid dimensions.')); } $types = ThumbnailType::getVersionList(); $file = $this->getFile(); foreach ($types as $type) { if ($type->shouldExistFor($imageWidth, $imageHeight, $file)) { $thumbnailPath = $type->getFilePath($this); $location = $file->getFileStorageLocationObject(); $configuration = $location->getConfigurationObject(); $filesystem = $location->getFileSystemObject(); if ($filesystem->has($thumbnailPath)) { $thumbnails[] = new Thumbnail($type, $configuration->getPublicURLToFile($thumbnailPath)); } } } return $thumbnails; }
php
public function getThumbnails() { $thumbnails = []; $imageWidth = (int) $this->getAttribute('width'); $imageHeight = (int) $this->getAttribute('height'); if ($imageWidth < 1 || $imageHeight < 1) { throw new InvalidDimensionException($this->getFile(), $this, t('Invalid dimensions.')); } $types = ThumbnailType::getVersionList(); $file = $this->getFile(); foreach ($types as $type) { if ($type->shouldExistFor($imageWidth, $imageHeight, $file)) { $thumbnailPath = $type->getFilePath($this); $location = $file->getFileStorageLocationObject(); $configuration = $location->getConfigurationObject(); $filesystem = $location->getFileSystemObject(); if ($filesystem->has($thumbnailPath)) { $thumbnails[] = new Thumbnail($type, $configuration->getPublicURLToFile($thumbnailPath)); } } } return $thumbnails; }
[ "public", "function", "getThumbnails", "(", ")", "{", "$", "thumbnails", "=", "[", "]", ";", "$", "imageWidth", "=", "(", "int", ")", "$", "this", "->", "getAttribute", "(", "'width'", ")", ";", "$", "imageHeight", "=", "(", "int", ")", "$", "this", "->", "getAttribute", "(", "'height'", ")", ";", "if", "(", "$", "imageWidth", "<", "1", "||", "$", "imageHeight", "<", "1", ")", "{", "throw", "new", "InvalidDimensionException", "(", "$", "this", "->", "getFile", "(", ")", ",", "$", "this", ",", "t", "(", "'Invalid dimensions.'", ")", ")", ";", "}", "$", "types", "=", "ThumbnailType", "::", "getVersionList", "(", ")", ";", "$", "file", "=", "$", "this", "->", "getFile", "(", ")", ";", "foreach", "(", "$", "types", "as", "$", "type", ")", "{", "if", "(", "$", "type", "->", "shouldExistFor", "(", "$", "imageWidth", ",", "$", "imageHeight", ",", "$", "file", ")", ")", "{", "$", "thumbnailPath", "=", "$", "type", "->", "getFilePath", "(", "$", "this", ")", ";", "$", "location", "=", "$", "file", "->", "getFileStorageLocationObject", "(", ")", ";", "$", "configuration", "=", "$", "location", "->", "getConfigurationObject", "(", ")", ";", "$", "filesystem", "=", "$", "location", "->", "getFileSystemObject", "(", ")", ";", "if", "(", "$", "filesystem", "->", "has", "(", "$", "thumbnailPath", ")", ")", "{", "$", "thumbnails", "[", "]", "=", "new", "Thumbnail", "(", "$", "type", ",", "$", "configuration", "->", "getPublicURLToFile", "(", "$", "thumbnailPath", ")", ")", ";", "}", "}", "}", "return", "$", "thumbnails", ";", "}" ]
Get the list of all the thumbnails. @throws \Concrete\Core\File\Exception\InvalidDimensionException @return \Concrete\Core\File\Image\Thumbnail\Thumbnail[]
[ "Get", "the", "list", "of", "all", "the", "thumbnails", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/File/Version.php#L1623-L1646
train
concrete5/concrete5
concrete/src/Entity/File/Version.php
Version.deleteThumbnail
public function deleteThumbnail($type) { $app = Application::getFacadeApplication(); $config = $app->make('config'); if (!($type instanceof ThumbnailTypeVersion)) { $type = ThumbnailTypeVersion::getByHandle($type); } $fsl = $this->getFile()->getFileStorageLocationObject()->getFileSystemObject(); $path = $type->getFilePath($this); try { if ($fsl->has($path)) { $fsl->delete($path); $app['director']->dispatch('on_thumbnail_delete', new \Concrete\Core\File\Event\ThumbnailDelete($path, $type) ); } } catch (FileNotFoundException $e) { } if ($type->getHandle() == $config->get('concrete.icons.file_manager_listing.handle') && $this->fvHasListingThumbnail) { $this->fvHasListingThumbnail = false; $this->save(); } if ($type->getHandle() == $config->get('concrete.icons.file_manager_detail.handle') && $this->fvHasDetailThumbnail) { $this->fvHasDetailThumbnail = false; $this->save(); } }
php
public function deleteThumbnail($type) { $app = Application::getFacadeApplication(); $config = $app->make('config'); if (!($type instanceof ThumbnailTypeVersion)) { $type = ThumbnailTypeVersion::getByHandle($type); } $fsl = $this->getFile()->getFileStorageLocationObject()->getFileSystemObject(); $path = $type->getFilePath($this); try { if ($fsl->has($path)) { $fsl->delete($path); $app['director']->dispatch('on_thumbnail_delete', new \Concrete\Core\File\Event\ThumbnailDelete($path, $type) ); } } catch (FileNotFoundException $e) { } if ($type->getHandle() == $config->get('concrete.icons.file_manager_listing.handle') && $this->fvHasListingThumbnail) { $this->fvHasListingThumbnail = false; $this->save(); } if ($type->getHandle() == $config->get('concrete.icons.file_manager_detail.handle') && $this->fvHasDetailThumbnail) { $this->fvHasDetailThumbnail = false; $this->save(); } }
[ "public", "function", "deleteThumbnail", "(", "$", "type", ")", "{", "$", "app", "=", "Application", "::", "getFacadeApplication", "(", ")", ";", "$", "config", "=", "$", "app", "->", "make", "(", "'config'", ")", ";", "if", "(", "!", "(", "$", "type", "instanceof", "ThumbnailTypeVersion", ")", ")", "{", "$", "type", "=", "ThumbnailTypeVersion", "::", "getByHandle", "(", "$", "type", ")", ";", "}", "$", "fsl", "=", "$", "this", "->", "getFile", "(", ")", "->", "getFileStorageLocationObject", "(", ")", "->", "getFileSystemObject", "(", ")", ";", "$", "path", "=", "$", "type", "->", "getFilePath", "(", "$", "this", ")", ";", "try", "{", "if", "(", "$", "fsl", "->", "has", "(", "$", "path", ")", ")", "{", "$", "fsl", "->", "delete", "(", "$", "path", ")", ";", "$", "app", "[", "'director'", "]", "->", "dispatch", "(", "'on_thumbnail_delete'", ",", "new", "\\", "Concrete", "\\", "Core", "\\", "File", "\\", "Event", "\\", "ThumbnailDelete", "(", "$", "path", ",", "$", "type", ")", ")", ";", "}", "}", "catch", "(", "FileNotFoundException", "$", "e", ")", "{", "}", "if", "(", "$", "type", "->", "getHandle", "(", ")", "==", "$", "config", "->", "get", "(", "'concrete.icons.file_manager_listing.handle'", ")", "&&", "$", "this", "->", "fvHasListingThumbnail", ")", "{", "$", "this", "->", "fvHasListingThumbnail", "=", "false", ";", "$", "this", "->", "save", "(", ")", ";", "}", "if", "(", "$", "type", "->", "getHandle", "(", ")", "==", "$", "config", "->", "get", "(", "'concrete.icons.file_manager_detail.handle'", ")", "&&", "$", "this", "->", "fvHasDetailThumbnail", ")", "{", "$", "this", "->", "fvHasDetailThumbnail", "=", "false", ";", "$", "this", "->", "save", "(", ")", ";", "}", "}" ]
Delete the thumbnail for a specific thumbnail type version. @param \Concrete\Core\File\Image\Thumbnail\Type\Version|string $type the thumbnail type version (or its handle)
[ "Delete", "the", "thumbnail", "for", "a", "specific", "thumbnail", "type", "version", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/File/Version.php#L1714-L1741
train
concrete5/concrete5
concrete/src/Entity/File/Version.php
Version.updateThumbnailStorageLocation
public function updateThumbnailStorageLocation($type, StorageLocation $location) { if (!($type instanceof ThumbnailTypeVersion)) { $type = ThumbnailTypeVersion::getByHandle($type); } $fsl = $this->getFile()->getFileStorageLocationObject()->getFileSystemObject(); $path = $type->getFilePath($this); $manager = new MountManager([ 'current' => $fsl, 'new' => $location->getFileSystemObject(), ]); try { $manager->move('current://' . $path, 'new://' . $path); } catch (FileNotFoundException $e) { } }
php
public function updateThumbnailStorageLocation($type, StorageLocation $location) { if (!($type instanceof ThumbnailTypeVersion)) { $type = ThumbnailTypeVersion::getByHandle($type); } $fsl = $this->getFile()->getFileStorageLocationObject()->getFileSystemObject(); $path = $type->getFilePath($this); $manager = new MountManager([ 'current' => $fsl, 'new' => $location->getFileSystemObject(), ]); try { $manager->move('current://' . $path, 'new://' . $path); } catch (FileNotFoundException $e) { } }
[ "public", "function", "updateThumbnailStorageLocation", "(", "$", "type", ",", "StorageLocation", "$", "location", ")", "{", "if", "(", "!", "(", "$", "type", "instanceof", "ThumbnailTypeVersion", ")", ")", "{", "$", "type", "=", "ThumbnailTypeVersion", "::", "getByHandle", "(", "$", "type", ")", ";", "}", "$", "fsl", "=", "$", "this", "->", "getFile", "(", ")", "->", "getFileStorageLocationObject", "(", ")", "->", "getFileSystemObject", "(", ")", ";", "$", "path", "=", "$", "type", "->", "getFilePath", "(", "$", "this", ")", ";", "$", "manager", "=", "new", "MountManager", "(", "[", "'current'", "=>", "$", "fsl", ",", "'new'", "=>", "$", "location", "->", "getFileSystemObject", "(", ")", ",", "]", ")", ";", "try", "{", "$", "manager", "->", "move", "(", "'current://'", ".", "$", "path", ",", "'new://'", ".", "$", "path", ")", ";", "}", "catch", "(", "FileNotFoundException", "$", "e", ")", "{", "}", "}" ]
Move the thumbnail of a specific thumbnail type version to a new storage location. @param \Concrete\Core\File\Image\Thumbnail\Type\Version|string $type the thumbnail type version (or its handle) @param StorageLocation $location The destination storage location
[ "Move", "the", "thumbnail", "of", "a", "specific", "thumbnail", "type", "version", "to", "a", "new", "storage", "location", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/File/Version.php#L1749-L1764
train
concrete5/concrete5
concrete/src/Entity/File/Version.php
Version.getJSONObject
public function getJSONObject() { $app = Application::getFacadeApplication(); $urlResolver = $app->make(ResolverManagerInterface::class); $r = new stdClass(); $fp = new Permissions($this->getFile()); $r->canCopyFile = $fp->canCopyFile(); $r->canEditFileProperties = $fp->canEditFileProperties(); $r->canEditFilePermissions = $fp->canEditFilePermissions(); $r->canDeleteFile = $fp->canDeleteFile(); $r->canReplaceFile = $fp->canEditFileContents(); $r->canEditFileContents = $fp->canEditFileContents(); $r->canViewFileInFileManager = $fp->canRead(); $r->canRead = $fp->canRead(); $r->canViewFile = $this->canView(); $r->canEditFile = $this->canEdit(); $r->url = $this->getURL(); $r->urlInline = (string) $urlResolver->resolve(['/download_file', 'view_inline', $this->getFileID()]); $r->urlDownload = (string) $urlResolver->resolve(['/download_file', 'view', $this->getFileID()]); $r->title = $this->getTitle(); $r->genericTypeText = $this->getGenericTypeText(); $r->description = $this->getDescription(); $r->fileName = $this->getFileName(); $r->resultsThumbnailImg = $this->getListingThumbnailImage(); $r->fID = $this->getFileID(); $r->treeNodeMenu = new Menu($this->getfile()); return $r; }
php
public function getJSONObject() { $app = Application::getFacadeApplication(); $urlResolver = $app->make(ResolverManagerInterface::class); $r = new stdClass(); $fp = new Permissions($this->getFile()); $r->canCopyFile = $fp->canCopyFile(); $r->canEditFileProperties = $fp->canEditFileProperties(); $r->canEditFilePermissions = $fp->canEditFilePermissions(); $r->canDeleteFile = $fp->canDeleteFile(); $r->canReplaceFile = $fp->canEditFileContents(); $r->canEditFileContents = $fp->canEditFileContents(); $r->canViewFileInFileManager = $fp->canRead(); $r->canRead = $fp->canRead(); $r->canViewFile = $this->canView(); $r->canEditFile = $this->canEdit(); $r->url = $this->getURL(); $r->urlInline = (string) $urlResolver->resolve(['/download_file', 'view_inline', $this->getFileID()]); $r->urlDownload = (string) $urlResolver->resolve(['/download_file', 'view', $this->getFileID()]); $r->title = $this->getTitle(); $r->genericTypeText = $this->getGenericTypeText(); $r->description = $this->getDescription(); $r->fileName = $this->getFileName(); $r->resultsThumbnailImg = $this->getListingThumbnailImage(); $r->fID = $this->getFileID(); $r->treeNodeMenu = new Menu($this->getfile()); return $r; }
[ "public", "function", "getJSONObject", "(", ")", "{", "$", "app", "=", "Application", "::", "getFacadeApplication", "(", ")", ";", "$", "urlResolver", "=", "$", "app", "->", "make", "(", "ResolverManagerInterface", "::", "class", ")", ";", "$", "r", "=", "new", "stdClass", "(", ")", ";", "$", "fp", "=", "new", "Permissions", "(", "$", "this", "->", "getFile", "(", ")", ")", ";", "$", "r", "->", "canCopyFile", "=", "$", "fp", "->", "canCopyFile", "(", ")", ";", "$", "r", "->", "canEditFileProperties", "=", "$", "fp", "->", "canEditFileProperties", "(", ")", ";", "$", "r", "->", "canEditFilePermissions", "=", "$", "fp", "->", "canEditFilePermissions", "(", ")", ";", "$", "r", "->", "canDeleteFile", "=", "$", "fp", "->", "canDeleteFile", "(", ")", ";", "$", "r", "->", "canReplaceFile", "=", "$", "fp", "->", "canEditFileContents", "(", ")", ";", "$", "r", "->", "canEditFileContents", "=", "$", "fp", "->", "canEditFileContents", "(", ")", ";", "$", "r", "->", "canViewFileInFileManager", "=", "$", "fp", "->", "canRead", "(", ")", ";", "$", "r", "->", "canRead", "=", "$", "fp", "->", "canRead", "(", ")", ";", "$", "r", "->", "canViewFile", "=", "$", "this", "->", "canView", "(", ")", ";", "$", "r", "->", "canEditFile", "=", "$", "this", "->", "canEdit", "(", ")", ";", "$", "r", "->", "url", "=", "$", "this", "->", "getURL", "(", ")", ";", "$", "r", "->", "urlInline", "=", "(", "string", ")", "$", "urlResolver", "->", "resolve", "(", "[", "'/download_file'", ",", "'view_inline'", ",", "$", "this", "->", "getFileID", "(", ")", "]", ")", ";", "$", "r", "->", "urlDownload", "=", "(", "string", ")", "$", "urlResolver", "->", "resolve", "(", "[", "'/download_file'", ",", "'view'", ",", "$", "this", "->", "getFileID", "(", ")", "]", ")", ";", "$", "r", "->", "title", "=", "$", "this", "->", "getTitle", "(", ")", ";", "$", "r", "->", "genericTypeText", "=", "$", "this", "->", "getGenericTypeText", "(", ")", ";", "$", "r", "->", "description", "=", "$", "this", "->", "getDescription", "(", ")", ";", "$", "r", "->", "fileName", "=", "$", "this", "->", "getFileName", "(", ")", ";", "$", "r", "->", "resultsThumbnailImg", "=", "$", "this", "->", "getListingThumbnailImage", "(", ")", ";", "$", "r", "->", "fID", "=", "$", "this", "->", "getFileID", "(", ")", ";", "$", "r", "->", "treeNodeMenu", "=", "new", "Menu", "(", "$", "this", "->", "getfile", "(", ")", ")", ";", "return", "$", "r", ";", "}" ]
Get a representation of this Version instance that's easily serializable. @return stdClass A \stdClass instance with all the information about a file (including permissions)
[ "Get", "a", "representation", "of", "this", "Version", "instance", "that", "s", "easily", "serializable", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/File/Version.php#L1796-L1824
train
concrete5/concrete5
concrete/src/Entity/File/Version.php
Version.save
protected function save($flush = true) { $app = Application::getFacadeApplication(); $em = $app->make(EntityManagerInterface::class); $em->persist($this); if ($flush) { $em->flush(); } }
php
protected function save($flush = true) { $app = Application::getFacadeApplication(); $em = $app->make(EntityManagerInterface::class); $em->persist($this); if ($flush) { $em->flush(); } }
[ "protected", "function", "save", "(", "$", "flush", "=", "true", ")", "{", "$", "app", "=", "Application", "::", "getFacadeApplication", "(", ")", ";", "$", "em", "=", "$", "app", "->", "make", "(", "EntityManagerInterface", "::", "class", ")", ";", "$", "em", "->", "persist", "(", "$", "this", ")", ";", "if", "(", "$", "flush", ")", "{", "$", "em", "->", "flush", "(", ")", ";", "}", "}" ]
Save the instance changes. @param bool $flush Flush the EM cache?
[ "Save", "the", "instance", "changes", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/File/Version.php#L1876-L1884
train
concrete5/concrete5
concrete/src/Application/Service/Urls.php
Urls.getPackageIconURL
public function getPackageIconURL($pkg) { if ($pkg && file_exists($pkg->getPackagePath() . '/' . FILENAME_BLOCK_ICON)) { return $this->getPackageURL($pkg) . '/' . FILENAME_BLOCK_ICON; } else { return PACKAGE_GENERIC_ICON; } }
php
public function getPackageIconURL($pkg) { if ($pkg && file_exists($pkg->getPackagePath() . '/' . FILENAME_BLOCK_ICON)) { return $this->getPackageURL($pkg) . '/' . FILENAME_BLOCK_ICON; } else { return PACKAGE_GENERIC_ICON; } }
[ "public", "function", "getPackageIconURL", "(", "$", "pkg", ")", "{", "if", "(", "$", "pkg", "&&", "file_exists", "(", "$", "pkg", "->", "getPackagePath", "(", ")", ".", "'/'", ".", "FILENAME_BLOCK_ICON", ")", ")", "{", "return", "$", "this", "->", "getPackageURL", "(", "$", "pkg", ")", ".", "'/'", ".", "FILENAME_BLOCK_ICON", ";", "}", "else", "{", "return", "PACKAGE_GENERIC_ICON", ";", "}", "}" ]
Gets a full URL to an icon for a particular application. @param \Package $pkg @return string URL to the package's icon
[ "Gets", "a", "full", "URL", "to", "an", "icon", "for", "a", "particular", "application", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Application/Service/Urls.php#L28-L35
train
concrete5/concrete5
concrete/src/Application/Service/Urls.php
Urls.getBlockTypeIconURL
public function getBlockTypeIconURL($bt) { $url = $this->getBlockTypeAssetsURL($bt, FILENAME_BLOCK_ICON); if ($url != false) { return $url; } else { return BLOCK_TYPE_GENERIC_ICON; } }
php
public function getBlockTypeIconURL($bt) { $url = $this->getBlockTypeAssetsURL($bt, FILENAME_BLOCK_ICON); if ($url != false) { return $url; } else { return BLOCK_TYPE_GENERIC_ICON; } }
[ "public", "function", "getBlockTypeIconURL", "(", "$", "bt", ")", "{", "$", "url", "=", "$", "this", "->", "getBlockTypeAssetsURL", "(", "$", "bt", ",", "FILENAME_BLOCK_ICON", ")", ";", "if", "(", "$", "url", "!=", "false", ")", "{", "return", "$", "url", ";", "}", "else", "{", "return", "BLOCK_TYPE_GENERIC_ICON", ";", "}", "}" ]
Gets a full URL to an icon for a particular block type. @param \Concrete\Core\Entity\Block\BlockType\BlockType $bt @return string
[ "Gets", "a", "full", "URL", "to", "an", "icon", "for", "a", "particular", "block", "type", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Application/Service/Urls.php#L80-L88
train
concrete5/concrete5
concrete/src/Application/Service/Urls.php
Urls.getBlockTypeAssetsURL
public function getBlockTypeAssetsURL($bt, $file = false) { $ff = ''; if ($file != false) { $ff = '/' . $file; } $url = ''; $packageHandle = null; if (file_exists(DIR_FILES_BLOCK_TYPES . '/' . $bt->getBlockTypeHandle() . $ff)) { $url = REL_DIR_APPLICATION . '/' . DIRNAME_BLOCKS . '/' . $bt->getBlockTypeHandle() . $ff; } elseif ($bt->getPackageID() > 0) { $packageHandle = $bt->getPackageHandle(); $dirp = (is_dir(DIR_PACKAGES . '/' . $packageHandle)) ? DIR_PACKAGES . '/' . $packageHandle : DIR_PACKAGES_CORE . '/' . $packageHandle; if (file_exists($dirp . '/' . DIRNAME_BLOCKS . '/' . $bt->getBlockTypeHandle() . $ff)) { $url = (is_dir(DIR_PACKAGES . '/' . $packageHandle)) ? DIR_REL : ASSETS_URL; $url = $url . '/' . DIRNAME_PACKAGES . '/' . $packageHandle . '/' . DIRNAME_BLOCKS . '/' . $bt->getBlockTypeHandle() . $ff; } } elseif (file_exists(DIR_FILES_BLOCK_TYPES_CORE . '/' . $bt->getBlockTypeHandle() . $ff)) { $url = ASSETS_URL . '/' . DIRNAME_BLOCKS . '/' . $bt->getBlockTypeHandle() . $ff; } if ($url && $file) { $asset = null; if (substr($file, -3) === '.js') { $asset = new JavascriptAsset(''); } elseif (substr($file, -3) === '.css') { $asset = new CssAsset(''); } if ($asset !== null) { $asset->setAssetIsLocal(true); $asset->setAssetURL($url); if ($packageHandle) { $app = Application::getFacadeApplication(); $em = $app->make(EntityManagerInterface::class); $repo = $em->getRepository(Package::class); $asset->setPackageObject($repo->findOneBy(['pkgHandle' => $packageHandle])); } $url = $asset->getAssetURL(); } } return $url; }
php
public function getBlockTypeAssetsURL($bt, $file = false) { $ff = ''; if ($file != false) { $ff = '/' . $file; } $url = ''; $packageHandle = null; if (file_exists(DIR_FILES_BLOCK_TYPES . '/' . $bt->getBlockTypeHandle() . $ff)) { $url = REL_DIR_APPLICATION . '/' . DIRNAME_BLOCKS . '/' . $bt->getBlockTypeHandle() . $ff; } elseif ($bt->getPackageID() > 0) { $packageHandle = $bt->getPackageHandle(); $dirp = (is_dir(DIR_PACKAGES . '/' . $packageHandle)) ? DIR_PACKAGES . '/' . $packageHandle : DIR_PACKAGES_CORE . '/' . $packageHandle; if (file_exists($dirp . '/' . DIRNAME_BLOCKS . '/' . $bt->getBlockTypeHandle() . $ff)) { $url = (is_dir(DIR_PACKAGES . '/' . $packageHandle)) ? DIR_REL : ASSETS_URL; $url = $url . '/' . DIRNAME_PACKAGES . '/' . $packageHandle . '/' . DIRNAME_BLOCKS . '/' . $bt->getBlockTypeHandle() . $ff; } } elseif (file_exists(DIR_FILES_BLOCK_TYPES_CORE . '/' . $bt->getBlockTypeHandle() . $ff)) { $url = ASSETS_URL . '/' . DIRNAME_BLOCKS . '/' . $bt->getBlockTypeHandle() . $ff; } if ($url && $file) { $asset = null; if (substr($file, -3) === '.js') { $asset = new JavascriptAsset(''); } elseif (substr($file, -3) === '.css') { $asset = new CssAsset(''); } if ($asset !== null) { $asset->setAssetIsLocal(true); $asset->setAssetURL($url); if ($packageHandle) { $app = Application::getFacadeApplication(); $em = $app->make(EntityManagerInterface::class); $repo = $em->getRepository(Package::class); $asset->setPackageObject($repo->findOneBy(['pkgHandle' => $packageHandle])); } $url = $asset->getAssetURL(); } } return $url; }
[ "public", "function", "getBlockTypeAssetsURL", "(", "$", "bt", ",", "$", "file", "=", "false", ")", "{", "$", "ff", "=", "''", ";", "if", "(", "$", "file", "!=", "false", ")", "{", "$", "ff", "=", "'/'", ".", "$", "file", ";", "}", "$", "url", "=", "''", ";", "$", "packageHandle", "=", "null", ";", "if", "(", "file_exists", "(", "DIR_FILES_BLOCK_TYPES", ".", "'/'", ".", "$", "bt", "->", "getBlockTypeHandle", "(", ")", ".", "$", "ff", ")", ")", "{", "$", "url", "=", "REL_DIR_APPLICATION", ".", "'/'", ".", "DIRNAME_BLOCKS", ".", "'/'", ".", "$", "bt", "->", "getBlockTypeHandle", "(", ")", ".", "$", "ff", ";", "}", "elseif", "(", "$", "bt", "->", "getPackageID", "(", ")", ">", "0", ")", "{", "$", "packageHandle", "=", "$", "bt", "->", "getPackageHandle", "(", ")", ";", "$", "dirp", "=", "(", "is_dir", "(", "DIR_PACKAGES", ".", "'/'", ".", "$", "packageHandle", ")", ")", "?", "DIR_PACKAGES", ".", "'/'", ".", "$", "packageHandle", ":", "DIR_PACKAGES_CORE", ".", "'/'", ".", "$", "packageHandle", ";", "if", "(", "file_exists", "(", "$", "dirp", ".", "'/'", ".", "DIRNAME_BLOCKS", ".", "'/'", ".", "$", "bt", "->", "getBlockTypeHandle", "(", ")", ".", "$", "ff", ")", ")", "{", "$", "url", "=", "(", "is_dir", "(", "DIR_PACKAGES", ".", "'/'", ".", "$", "packageHandle", ")", ")", "?", "DIR_REL", ":", "ASSETS_URL", ";", "$", "url", "=", "$", "url", ".", "'/'", ".", "DIRNAME_PACKAGES", ".", "'/'", ".", "$", "packageHandle", ".", "'/'", ".", "DIRNAME_BLOCKS", ".", "'/'", ".", "$", "bt", "->", "getBlockTypeHandle", "(", ")", ".", "$", "ff", ";", "}", "}", "elseif", "(", "file_exists", "(", "DIR_FILES_BLOCK_TYPES_CORE", ".", "'/'", ".", "$", "bt", "->", "getBlockTypeHandle", "(", ")", ".", "$", "ff", ")", ")", "{", "$", "url", "=", "ASSETS_URL", ".", "'/'", ".", "DIRNAME_BLOCKS", ".", "'/'", ".", "$", "bt", "->", "getBlockTypeHandle", "(", ")", ".", "$", "ff", ";", "}", "if", "(", "$", "url", "&&", "$", "file", ")", "{", "$", "asset", "=", "null", ";", "if", "(", "substr", "(", "$", "file", ",", "-", "3", ")", "===", "'.js'", ")", "{", "$", "asset", "=", "new", "JavascriptAsset", "(", "''", ")", ";", "}", "elseif", "(", "substr", "(", "$", "file", ",", "-", "3", ")", "===", "'.css'", ")", "{", "$", "asset", "=", "new", "CssAsset", "(", "''", ")", ";", "}", "if", "(", "$", "asset", "!==", "null", ")", "{", "$", "asset", "->", "setAssetIsLocal", "(", "true", ")", ";", "$", "asset", "->", "setAssetURL", "(", "$", "url", ")", ";", "if", "(", "$", "packageHandle", ")", "{", "$", "app", "=", "Application", "::", "getFacadeApplication", "(", ")", ";", "$", "em", "=", "$", "app", "->", "make", "(", "EntityManagerInterface", "::", "class", ")", ";", "$", "repo", "=", "$", "em", "->", "getRepository", "(", "Package", "::", "class", ")", ";", "$", "asset", "->", "setPackageObject", "(", "$", "repo", "->", "findOneBy", "(", "[", "'pkgHandle'", "=>", "$", "packageHandle", "]", ")", ")", ";", "}", "$", "url", "=", "$", "asset", "->", "getAssetURL", "(", ")", ";", "}", "}", "return", "$", "url", ";", "}" ]
Gets a full URL to the directory containing all of a block's items, including JavaScript, tools, icons, etc... @param \Concrete\Core\Entity\Block\BlockType\BlockType $bt @param bool|string $file If provided will get the assets url for a file in a block @return string $url
[ "Gets", "a", "full", "URL", "to", "the", "directory", "containing", "all", "of", "a", "block", "s", "items", "including", "JavaScript", "tools", "icons", "etc", "..." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Application/Service/Urls.php#L98-L140
train
concrete5/concrete5
concrete/src/Block/View/BlockView.php
BlockView.constructView
protected function constructView($mixed) { if ($mixed instanceof Block) { $this->blockType = $mixed->getBlockTypeObject(); $this->block = $mixed; $this->area = $mixed->getBlockAreaObject(); } else { $this->blockType = $mixed; if ($this->blockType->controller) { $this->controller = $this->blockType->controller; } } $this->blockTypePkgHandle = $this->blockType->getPackageHandle(); if (!isset($this->controller)) { if (isset($this->block)) { $this->controller = $this->block->getInstance(); $this->controller->setBlockObject($this->block); } else { $this->controller = $this->blockType->getController(); } } }
php
protected function constructView($mixed) { if ($mixed instanceof Block) { $this->blockType = $mixed->getBlockTypeObject(); $this->block = $mixed; $this->area = $mixed->getBlockAreaObject(); } else { $this->blockType = $mixed; if ($this->blockType->controller) { $this->controller = $this->blockType->controller; } } $this->blockTypePkgHandle = $this->blockType->getPackageHandle(); if (!isset($this->controller)) { if (isset($this->block)) { $this->controller = $this->block->getInstance(); $this->controller->setBlockObject($this->block); } else { $this->controller = $this->blockType->getController(); } } }
[ "protected", "function", "constructView", "(", "$", "mixed", ")", "{", "if", "(", "$", "mixed", "instanceof", "Block", ")", "{", "$", "this", "->", "blockType", "=", "$", "mixed", "->", "getBlockTypeObject", "(", ")", ";", "$", "this", "->", "block", "=", "$", "mixed", ";", "$", "this", "->", "area", "=", "$", "mixed", "->", "getBlockAreaObject", "(", ")", ";", "}", "else", "{", "$", "this", "->", "blockType", "=", "$", "mixed", ";", "if", "(", "$", "this", "->", "blockType", "->", "controller", ")", "{", "$", "this", "->", "controller", "=", "$", "this", "->", "blockType", "->", "controller", ";", "}", "}", "$", "this", "->", "blockTypePkgHandle", "=", "$", "this", "->", "blockType", "->", "getPackageHandle", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "controller", ")", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "block", ")", ")", "{", "$", "this", "->", "controller", "=", "$", "this", "->", "block", "->", "getInstance", "(", ")", ";", "$", "this", "->", "controller", "->", "setBlockObject", "(", "$", "this", "->", "block", ")", ";", "}", "else", "{", "$", "this", "->", "controller", "=", "$", "this", "->", "blockType", "->", "getController", "(", ")", ";", "}", "}", "}" ]
Construct a block view object @param mixed $mixed block or block type to view @return void
[ "Construct", "a", "block", "view", "object" ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Block/View/BlockView.php#L48-L69
train
concrete5/concrete5
concrete/src/Block/View/BlockView.php
BlockView.renderViewContents
public function renderViewContents($scopeItems) { $shouldRender = function() { $app = Application::getFacadeApplication(); // If you hook into this event and use `preventRendering()`, // you can prevent the block from being displayed. $event = new BlockBeforeRender($this->block); $app->make('director')->dispatch('on_block_before_render', $event); return $event->proceed(); }; if (!$shouldRender()) { return; } unset($shouldRender); extract($scopeItems); if (!$this->outputContent) { ob_start(); include $this->template; $this->outputContent = ob_get_contents(); ob_end_clean(); } // The translatable texts in the block header/footer need to be printed // out in the system language. $loc = Localization::getInstance(); $loc->pushActiveContext(Localization::CONTEXT_UI); if ($this->blockViewHeaderFile) { include $this->blockViewHeaderFile; } $this->controller->registerViewAssets($this->outputContent); $this->onBeforeGetContents(); $this->fireOnBlockOutputEvent(); echo $this->outputContent; $this->onAfterGetContents(); if ($this->blockViewFooterFile) { include $this->blockViewFooterFile; } $loc->popActiveContext(); }
php
public function renderViewContents($scopeItems) { $shouldRender = function() { $app = Application::getFacadeApplication(); // If you hook into this event and use `preventRendering()`, // you can prevent the block from being displayed. $event = new BlockBeforeRender($this->block); $app->make('director')->dispatch('on_block_before_render', $event); return $event->proceed(); }; if (!$shouldRender()) { return; } unset($shouldRender); extract($scopeItems); if (!$this->outputContent) { ob_start(); include $this->template; $this->outputContent = ob_get_contents(); ob_end_clean(); } // The translatable texts in the block header/footer need to be printed // out in the system language. $loc = Localization::getInstance(); $loc->pushActiveContext(Localization::CONTEXT_UI); if ($this->blockViewHeaderFile) { include $this->blockViewHeaderFile; } $this->controller->registerViewAssets($this->outputContent); $this->onBeforeGetContents(); $this->fireOnBlockOutputEvent(); echo $this->outputContent; $this->onAfterGetContents(); if ($this->blockViewFooterFile) { include $this->blockViewFooterFile; } $loc->popActiveContext(); }
[ "public", "function", "renderViewContents", "(", "$", "scopeItems", ")", "{", "$", "shouldRender", "=", "function", "(", ")", "{", "$", "app", "=", "Application", "::", "getFacadeApplication", "(", ")", ";", "// If you hook into this event and use `preventRendering()`,", "// you can prevent the block from being displayed.", "$", "event", "=", "new", "BlockBeforeRender", "(", "$", "this", "->", "block", ")", ";", "$", "app", "->", "make", "(", "'director'", ")", "->", "dispatch", "(", "'on_block_before_render'", ",", "$", "event", ")", ";", "return", "$", "event", "->", "proceed", "(", ")", ";", "}", ";", "if", "(", "!", "$", "shouldRender", "(", ")", ")", "{", "return", ";", "}", "unset", "(", "$", "shouldRender", ")", ";", "extract", "(", "$", "scopeItems", ")", ";", "if", "(", "!", "$", "this", "->", "outputContent", ")", "{", "ob_start", "(", ")", ";", "include", "$", "this", "->", "template", ";", "$", "this", "->", "outputContent", "=", "ob_get_contents", "(", ")", ";", "ob_end_clean", "(", ")", ";", "}", "// The translatable texts in the block header/footer need to be printed", "// out in the system language.", "$", "loc", "=", "Localization", "::", "getInstance", "(", ")", ";", "$", "loc", "->", "pushActiveContext", "(", "Localization", "::", "CONTEXT_UI", ")", ";", "if", "(", "$", "this", "->", "blockViewHeaderFile", ")", "{", "include", "$", "this", "->", "blockViewHeaderFile", ";", "}", "$", "this", "->", "controller", "->", "registerViewAssets", "(", "$", "this", "->", "outputContent", ")", ";", "$", "this", "->", "onBeforeGetContents", "(", ")", ";", "$", "this", "->", "fireOnBlockOutputEvent", "(", ")", ";", "echo", "$", "this", "->", "outputContent", ";", "$", "this", "->", "onAfterGetContents", "(", ")", ";", "if", "(", "$", "this", "->", "blockViewFooterFile", ")", "{", "include", "$", "this", "->", "blockViewFooterFile", ";", "}", "$", "loc", "->", "popActiveContext", "(", ")", ";", "}" ]
Echo block contents @param array $scopeItems array of items to render (outputContent, blockViewHeaderFile, blockViewFooterFile) @return void
[ "Echo", "block", "contents" ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Block/View/BlockView.php#L232-L280
train
concrete5/concrete5
concrete/src/Block/View/BlockView.php
BlockView.getBlockPath
public function getBlockPath($filename = null) { $obj = $this->blockType; if (file_exists(DIR_FILES_BLOCK_TYPES . '/' . $obj->getBlockTypeHandle() . '/' . $filename)) { $base = DIR_FILES_BLOCK_TYPES . '/' . $obj->getBlockTypeHandle(); } else { if ($obj->getPackageID() > 0) { if (is_dir(DIR_PACKAGES . '/' . $obj->getPackageHandle())) { $base = DIR_PACKAGES . '/' . $obj->getPackageHandle( ) . '/' . DIRNAME_BLOCKS . '/' . $obj->getBlockTypeHandle(); } else { $base = DIR_PACKAGES_CORE . '/' . $obj->getPackageHandle( ) . '/' . DIRNAME_BLOCKS . '/' . $obj->getBlockTypeHandle(); } } else { $base = DIR_FILES_BLOCK_TYPES_CORE . '/' . $obj->getBlockTypeHandle(); } } return $base; }
php
public function getBlockPath($filename = null) { $obj = $this->blockType; if (file_exists(DIR_FILES_BLOCK_TYPES . '/' . $obj->getBlockTypeHandle() . '/' . $filename)) { $base = DIR_FILES_BLOCK_TYPES . '/' . $obj->getBlockTypeHandle(); } else { if ($obj->getPackageID() > 0) { if (is_dir(DIR_PACKAGES . '/' . $obj->getPackageHandle())) { $base = DIR_PACKAGES . '/' . $obj->getPackageHandle( ) . '/' . DIRNAME_BLOCKS . '/' . $obj->getBlockTypeHandle(); } else { $base = DIR_PACKAGES_CORE . '/' . $obj->getPackageHandle( ) . '/' . DIRNAME_BLOCKS . '/' . $obj->getBlockTypeHandle(); } } else { $base = DIR_FILES_BLOCK_TYPES_CORE . '/' . $obj->getBlockTypeHandle(); } } return $base; }
[ "public", "function", "getBlockPath", "(", "$", "filename", "=", "null", ")", "{", "$", "obj", "=", "$", "this", "->", "blockType", ";", "if", "(", "file_exists", "(", "DIR_FILES_BLOCK_TYPES", ".", "'/'", ".", "$", "obj", "->", "getBlockTypeHandle", "(", ")", ".", "'/'", ".", "$", "filename", ")", ")", "{", "$", "base", "=", "DIR_FILES_BLOCK_TYPES", ".", "'/'", ".", "$", "obj", "->", "getBlockTypeHandle", "(", ")", ";", "}", "else", "{", "if", "(", "$", "obj", "->", "getPackageID", "(", ")", ">", "0", ")", "{", "if", "(", "is_dir", "(", "DIR_PACKAGES", ".", "'/'", ".", "$", "obj", "->", "getPackageHandle", "(", ")", ")", ")", "{", "$", "base", "=", "DIR_PACKAGES", ".", "'/'", ".", "$", "obj", "->", "getPackageHandle", "(", ")", ".", "'/'", ".", "DIRNAME_BLOCKS", ".", "'/'", ".", "$", "obj", "->", "getBlockTypeHandle", "(", ")", ";", "}", "else", "{", "$", "base", "=", "DIR_PACKAGES_CORE", ".", "'/'", ".", "$", "obj", "->", "getPackageHandle", "(", ")", ".", "'/'", ".", "DIRNAME_BLOCKS", ".", "'/'", ".", "$", "obj", "->", "getBlockTypeHandle", "(", ")", ";", "}", "}", "else", "{", "$", "base", "=", "DIR_FILES_BLOCK_TYPES_CORE", ".", "'/'", ".", "$", "obj", "->", "getBlockTypeHandle", "(", ")", ";", "}", "}", "return", "$", "base", ";", "}" ]
Returns the path to the current block's directory. @deprecated @return string
[ "Returns", "the", "path", "to", "the", "current", "block", "s", "directory", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Block/View/BlockView.php#L305-L325
train
concrete5/concrete5
concrete/src/Block/View/BlockView.php
BlockView.getBlockURL
public function getBlockURL($filename = null) { $obj = $this->blockType; if ($obj->getPackageID() > 0) { if (is_dir(DIR_PACKAGES_CORE . '/' . $obj->getPackageHandle())) { $base = ASSETS_URL . '/' . DIRNAME_PACKAGES . '/' . $obj->getPackageHandle( ) . '/' . DIRNAME_BLOCKS . '/' . $obj->getBlockTypeHandle(); } else { $base = DIR_REL . '/' . DIRNAME_PACKAGES . '/' . $obj->getPackageHandle( ) . '/' . DIRNAME_BLOCKS . '/' . $obj->getBlockTypeHandle(); } } else { if (file_exists(DIR_FILES_BLOCK_TYPES . '/' . $obj->getBlockTypeHandle() . '/' . $filename)) { $base = REL_DIR_APPLICATION . '/' . DIRNAME_BLOCKS . '/' . $obj->getBlockTypeHandle(); } else { $base = ASSETS_URL . '/' . DIRNAME_BLOCKS . '/' . $obj->getBlockTypeHandle(); } } return $base; }
php
public function getBlockURL($filename = null) { $obj = $this->blockType; if ($obj->getPackageID() > 0) { if (is_dir(DIR_PACKAGES_CORE . '/' . $obj->getPackageHandle())) { $base = ASSETS_URL . '/' . DIRNAME_PACKAGES . '/' . $obj->getPackageHandle( ) . '/' . DIRNAME_BLOCKS . '/' . $obj->getBlockTypeHandle(); } else { $base = DIR_REL . '/' . DIRNAME_PACKAGES . '/' . $obj->getPackageHandle( ) . '/' . DIRNAME_BLOCKS . '/' . $obj->getBlockTypeHandle(); } } else { if (file_exists(DIR_FILES_BLOCK_TYPES . '/' . $obj->getBlockTypeHandle() . '/' . $filename)) { $base = REL_DIR_APPLICATION . '/' . DIRNAME_BLOCKS . '/' . $obj->getBlockTypeHandle(); } else { $base = ASSETS_URL . '/' . DIRNAME_BLOCKS . '/' . $obj->getBlockTypeHandle(); } } return $base; }
[ "public", "function", "getBlockURL", "(", "$", "filename", "=", "null", ")", "{", "$", "obj", "=", "$", "this", "->", "blockType", ";", "if", "(", "$", "obj", "->", "getPackageID", "(", ")", ">", "0", ")", "{", "if", "(", "is_dir", "(", "DIR_PACKAGES_CORE", ".", "'/'", ".", "$", "obj", "->", "getPackageHandle", "(", ")", ")", ")", "{", "$", "base", "=", "ASSETS_URL", ".", "'/'", ".", "DIRNAME_PACKAGES", ".", "'/'", ".", "$", "obj", "->", "getPackageHandle", "(", ")", ".", "'/'", ".", "DIRNAME_BLOCKS", ".", "'/'", ".", "$", "obj", "->", "getBlockTypeHandle", "(", ")", ";", "}", "else", "{", "$", "base", "=", "DIR_REL", ".", "'/'", ".", "DIRNAME_PACKAGES", ".", "'/'", ".", "$", "obj", "->", "getPackageHandle", "(", ")", ".", "'/'", ".", "DIRNAME_BLOCKS", ".", "'/'", ".", "$", "obj", "->", "getBlockTypeHandle", "(", ")", ";", "}", "}", "else", "{", "if", "(", "file_exists", "(", "DIR_FILES_BLOCK_TYPES", ".", "'/'", ".", "$", "obj", "->", "getBlockTypeHandle", "(", ")", ".", "'/'", ".", "$", "filename", ")", ")", "{", "$", "base", "=", "REL_DIR_APPLICATION", ".", "'/'", ".", "DIRNAME_BLOCKS", ".", "'/'", ".", "$", "obj", "->", "getBlockTypeHandle", "(", ")", ";", "}", "else", "{", "$", "base", "=", "ASSETS_URL", ".", "'/'", ".", "DIRNAME_BLOCKS", ".", "'/'", ".", "$", "obj", "->", "getBlockTypeHandle", "(", ")", ";", "}", "}", "return", "$", "base", ";", "}" ]
Returns a relative path to the current block's directory. If a filename is specified it will be appended and searched for as well. @return string
[ "Returns", "a", "relative", "path", "to", "the", "current", "block", "s", "directory", ".", "If", "a", "filename", "is", "specified", "it", "will", "be", "appended", "and", "searched", "for", "as", "well", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Block/View/BlockView.php#L332-L352
train
concrete5/concrete5
concrete/src/Block/View/BlockView.php
BlockView.fireOnBlockOutputEvent
private function fireOnBlockOutputEvent() { $event = new BlockOutput($this->block); $event->setContents($this->outputContent); $app = Application::getFacadeApplication(); $app->make('director')->dispatch('on_block_output', $event); $this->outputContent = $event->getContents(); }
php
private function fireOnBlockOutputEvent() { $event = new BlockOutput($this->block); $event->setContents($this->outputContent); $app = Application::getFacadeApplication(); $app->make('director')->dispatch('on_block_output', $event); $this->outputContent = $event->getContents(); }
[ "private", "function", "fireOnBlockOutputEvent", "(", ")", "{", "$", "event", "=", "new", "BlockOutput", "(", "$", "this", "->", "block", ")", ";", "$", "event", "->", "setContents", "(", "$", "this", "->", "outputContent", ")", ";", "$", "app", "=", "Application", "::", "getFacadeApplication", "(", ")", ";", "$", "app", "->", "make", "(", "'director'", ")", "->", "dispatch", "(", "'on_block_output'", ",", "$", "event", ")", ";", "$", "this", "->", "outputContent", "=", "$", "event", "->", "getContents", "(", ")", ";", "}" ]
Fire an event just before the block is outputted on the page Custom code can modify the block contents before the block contents are 'echoed' out on the page. @since 8.4.1
[ "Fire", "an", "event", "just", "before", "the", "block", "is", "outputted", "on", "the", "page" ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Block/View/BlockView.php#L470-L479
train
concrete5/concrete5
concrete/src/Tree/Node/Type/FileFolder.php
FileFolder.getChildFolderByName
public function getChildFolderByName($name, $create = false) { $typeHandle = $this->getTreeNodeTypeHandle(); if ($this->childNodesLoaded) { $childNodes = $this->childNodes; } else { $childNodesData = $this->getHierarchicalNodesOfType($typeHandle, 1, true, false, 1); $childNodes = array_map(function ($item) { return $item['treeNodeObject']; }, $childNodesData); } $result = null; foreach ($childNodes as $childNode) { if ($childNode->getTreeNodeTypeHandle() === $typeHandle && $childNode->getTreeNodeName() === $name) { $result = $childNode; break; } } if ($result === null && $create) { $result = static::add($name, $this); } return $result; }
php
public function getChildFolderByName($name, $create = false) { $typeHandle = $this->getTreeNodeTypeHandle(); if ($this->childNodesLoaded) { $childNodes = $this->childNodes; } else { $childNodesData = $this->getHierarchicalNodesOfType($typeHandle, 1, true, false, 1); $childNodes = array_map(function ($item) { return $item['treeNodeObject']; }, $childNodesData); } $result = null; foreach ($childNodes as $childNode) { if ($childNode->getTreeNodeTypeHandle() === $typeHandle && $childNode->getTreeNodeName() === $name) { $result = $childNode; break; } } if ($result === null && $create) { $result = static::add($name, $this); } return $result; }
[ "public", "function", "getChildFolderByName", "(", "$", "name", ",", "$", "create", "=", "false", ")", "{", "$", "typeHandle", "=", "$", "this", "->", "getTreeNodeTypeHandle", "(", ")", ";", "if", "(", "$", "this", "->", "childNodesLoaded", ")", "{", "$", "childNodes", "=", "$", "this", "->", "childNodes", ";", "}", "else", "{", "$", "childNodesData", "=", "$", "this", "->", "getHierarchicalNodesOfType", "(", "$", "typeHandle", ",", "1", ",", "true", ",", "false", ",", "1", ")", ";", "$", "childNodes", "=", "array_map", "(", "function", "(", "$", "item", ")", "{", "return", "$", "item", "[", "'treeNodeObject'", "]", ";", "}", ",", "$", "childNodesData", ")", ";", "}", "$", "result", "=", "null", ";", "foreach", "(", "$", "childNodes", "as", "$", "childNode", ")", "{", "if", "(", "$", "childNode", "->", "getTreeNodeTypeHandle", "(", ")", "===", "$", "typeHandle", "&&", "$", "childNode", "->", "getTreeNodeName", "(", ")", "===", "$", "name", ")", "{", "$", "result", "=", "$", "childNode", ";", "break", ";", "}", "}", "if", "(", "$", "result", "===", "null", "&&", "$", "create", ")", "{", "$", "result", "=", "static", "::", "add", "(", "$", "name", ",", "$", "this", ")", ";", "}", "return", "$", "result", ";", "}" ]
Get the first child folder this folder that has a specific name. @param string $name The name of the child folder @param bool $create Should the child folder be created if it does not exist? @return static|null return NULL if no child folder has the specified name and $create is false
[ "Get", "the", "first", "child", "folder", "this", "folder", "that", "has", "a", "specific", "name", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Tree/Node/Type/FileFolder.php#L96-L117
train
concrete5/concrete5
concrete/src/Tree/Node/Type/FileFolder.php
FileFolder.getChildFolderByPath
public function getChildFolderByPath(array $names, $create = false) { if (count($names) === 0) { $result = $this; } else { $childName = array_shift($names); $result = $this->getChildFolderByName($childName, $create); if ($result !== null) { $result = $result->getChildFolderByPath($names, $create); } } return $result; }
php
public function getChildFolderByPath(array $names, $create = false) { if (count($names) === 0) { $result = $this; } else { $childName = array_shift($names); $result = $this->getChildFolderByName($childName, $create); if ($result !== null) { $result = $result->getChildFolderByPath($names, $create); } } return $result; }
[ "public", "function", "getChildFolderByPath", "(", "array", "$", "names", ",", "$", "create", "=", "false", ")", "{", "if", "(", "count", "(", "$", "names", ")", "===", "0", ")", "{", "$", "result", "=", "$", "this", ";", "}", "else", "{", "$", "childName", "=", "array_shift", "(", "$", "names", ")", ";", "$", "result", "=", "$", "this", "->", "getChildFolderByName", "(", "$", "childName", ",", "$", "create", ")", ";", "if", "(", "$", "result", "!==", "null", ")", "{", "$", "result", "=", "$", "result", "->", "getChildFolderByPath", "(", "$", "names", ",", "$", "create", ")", ";", "}", "}", "return", "$", "result", ";", "}" ]
Get a descendent folder of this folder given its path. @param array $names The names of the child folders (1st item: child folder, 2nd item: grand-child folder, ...) @param bool $create Should the descendent folders be created if they don't exist? @return static|null return NULL if the descendent folder has not been found and $create is false
[ "Get", "a", "descendent", "folder", "of", "this", "folder", "given", "its", "path", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Tree/Node/Type/FileFolder.php#L127-L140
train
concrete5/concrete5
concrete/src/Error/ErrorList/Formatter/JsonFormatter.php
JsonFormatter.asArray
public function asArray() { $error = $this->error; if ($error->has()) { $o = [ 'error' => true, 'errors' => [], 'htmlErrorIndexes' => [], ]; $index = 0; foreach ($error->getList() as $error) { $o['errors'][] = (string) $error; if ($error instanceof HtmlAwareErrorInterface && $error->messageContainsHtml()) { $o['htmlErrorIndexes'][] = $index; } ++$index; } if (empty($o['htmlErrorIndexes'])) { unset($o['htmlErrorIndexes']); } return $o; } }
php
public function asArray() { $error = $this->error; if ($error->has()) { $o = [ 'error' => true, 'errors' => [], 'htmlErrorIndexes' => [], ]; $index = 0; foreach ($error->getList() as $error) { $o['errors'][] = (string) $error; if ($error instanceof HtmlAwareErrorInterface && $error->messageContainsHtml()) { $o['htmlErrorIndexes'][] = $index; } ++$index; } if (empty($o['htmlErrorIndexes'])) { unset($o['htmlErrorIndexes']); } return $o; } }
[ "public", "function", "asArray", "(", ")", "{", "$", "error", "=", "$", "this", "->", "error", ";", "if", "(", "$", "error", "->", "has", "(", ")", ")", "{", "$", "o", "=", "[", "'error'", "=>", "true", ",", "'errors'", "=>", "[", "]", ",", "'htmlErrorIndexes'", "=>", "[", "]", ",", "]", ";", "$", "index", "=", "0", ";", "foreach", "(", "$", "error", "->", "getList", "(", ")", "as", "$", "error", ")", "{", "$", "o", "[", "'errors'", "]", "[", "]", "=", "(", "string", ")", "$", "error", ";", "if", "(", "$", "error", "instanceof", "HtmlAwareErrorInterface", "&&", "$", "error", "->", "messageContainsHtml", "(", ")", ")", "{", "$", "o", "[", "'htmlErrorIndexes'", "]", "[", "]", "=", "$", "index", ";", "}", "++", "$", "index", ";", "}", "if", "(", "empty", "(", "$", "o", "[", "'htmlErrorIndexes'", "]", ")", ")", "{", "unset", "(", "$", "o", "[", "'htmlErrorIndexes'", "]", ")", ";", "}", "return", "$", "o", ";", "}", "}" ]
Build an array describing the errors. @return array|null return NULL if the error list is empty, an array otherwise
[ "Build", "an", "array", "describing", "the", "errors", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Error/ErrorList/Formatter/JsonFormatter.php#L24-L47
train
square/connect-php-sdk
lib/Configuration.php
Configuration.getApiKey
public function getApiKey($apiKeyIdentifier) { return isset($this->apiKeys[$apiKeyIdentifier]) ? $this->apiKeys[$apiKeyIdentifier] : null; }
php
public function getApiKey($apiKeyIdentifier) { return isset($this->apiKeys[$apiKeyIdentifier]) ? $this->apiKeys[$apiKeyIdentifier] : null; }
[ "public", "function", "getApiKey", "(", "$", "apiKeyIdentifier", ")", "{", "return", "isset", "(", "$", "this", "->", "apiKeys", "[", "$", "apiKeyIdentifier", "]", ")", "?", "$", "this", "->", "apiKeys", "[", "$", "apiKeyIdentifier", "]", ":", "null", ";", "}" ]
Gets API key @param string $apiKeyIdentifier API key identifier (authentication scheme) @return string API key or token
[ "Gets", "API", "key" ]
601485d86634286b2d19eb2939b87944176769e1
https://github.com/square/connect-php-sdk/blob/601485d86634286b2d19eb2939b87944176769e1/lib/Configuration.php#L158-L161
train
square/connect-php-sdk
lib/Configuration.php
Configuration.getApiKeyPrefix
public function getApiKeyPrefix($apiKeyIdentifier) { return isset($this->apiKeyPrefixes[$apiKeyIdentifier]) ? $this->apiKeyPrefixes[$apiKeyIdentifier] : null; }
php
public function getApiKeyPrefix($apiKeyIdentifier) { return isset($this->apiKeyPrefixes[$apiKeyIdentifier]) ? $this->apiKeyPrefixes[$apiKeyIdentifier] : null; }
[ "public", "function", "getApiKeyPrefix", "(", "$", "apiKeyIdentifier", ")", "{", "return", "isset", "(", "$", "this", "->", "apiKeyPrefixes", "[", "$", "apiKeyIdentifier", "]", ")", "?", "$", "this", "->", "apiKeyPrefixes", "[", "$", "apiKeyIdentifier", "]", ":", "null", ";", "}" ]
Gets API key prefix @param string $apiKeyIdentifier API key identifier (authentication scheme) @return string
[ "Gets", "API", "key", "prefix" ]
601485d86634286b2d19eb2939b87944176769e1
https://github.com/square/connect-php-sdk/blob/601485d86634286b2d19eb2939b87944176769e1/lib/Configuration.php#L184-L187
train
square/connect-php-sdk
lib/Configuration.php
Configuration.addDefaultHeader
public function addDefaultHeader($headerName, $headerValue) { if (!is_string($headerName)) { throw new \InvalidArgumentException('Header name must be a string.'); } $this->defaultHeaders[$headerName] = $headerValue; return $this; }
php
public function addDefaultHeader($headerName, $headerValue) { if (!is_string($headerName)) { throw new \InvalidArgumentException('Header name must be a string.'); } $this->defaultHeaders[$headerName] = $headerValue; return $this; }
[ "public", "function", "addDefaultHeader", "(", "$", "headerName", ",", "$", "headerValue", ")", "{", "if", "(", "!", "is_string", "(", "$", "headerName", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Header name must be a string.'", ")", ";", "}", "$", "this", "->", "defaultHeaders", "[", "$", "headerName", "]", "=", "$", "headerValue", ";", "return", "$", "this", ";", "}" ]
Adds a default header @param string $headerName header name (e.g. Token) @param string $headerValue header value (e.g. 1z8wp3) @return ApiClient
[ "Adds", "a", "default", "header" ]
601485d86634286b2d19eb2939b87944176769e1
https://github.com/square/connect-php-sdk/blob/601485d86634286b2d19eb2939b87944176769e1/lib/Configuration.php#L266-L274
train
square/connect-php-sdk
lib/Configuration.php
Configuration.setCurlTimeout
public function setCurlTimeout($seconds) { if (!is_numeric($seconds) || $seconds < 0) { throw new \InvalidArgumentException('Timeout value must be numeric and a non-negative number.'); } $this->curlTimeout = $seconds; return $this; }
php
public function setCurlTimeout($seconds) { if (!is_numeric($seconds) || $seconds < 0) { throw new \InvalidArgumentException('Timeout value must be numeric and a non-negative number.'); } $this->curlTimeout = $seconds; return $this; }
[ "public", "function", "setCurlTimeout", "(", "$", "seconds", ")", "{", "if", "(", "!", "is_numeric", "(", "$", "seconds", ")", "||", "$", "seconds", "<", "0", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Timeout value must be numeric and a non-negative number.'", ")", ";", "}", "$", "this", "->", "curlTimeout", "=", "$", "seconds", ";", "return", "$", "this", ";", "}" ]
Sets the HTTP timeout value @param integer $seconds Number of seconds before timing out [set to 0 for no timeout] @return ApiClient
[ "Sets", "the", "HTTP", "timeout", "value" ]
601485d86634286b2d19eb2939b87944176769e1
https://github.com/square/connect-php-sdk/blob/601485d86634286b2d19eb2939b87944176769e1/lib/Configuration.php#L355-L363
train
square/connect-php-sdk
lib/ApiClient.php
ApiClient.getV1BatchTokenFromHeaders
public static function getV1BatchTokenFromHeaders($http_headers) { if (is_array($http_headers) && isset($http_headers['Link'])) { $connect_link_regexp = "/^<([^>]+)>;rel='next'$/"; if (preg_match($connect_link_regexp, $http_headers['Link'], $match) === 1) { $link_uri = $match[1]; if ($query = parse_url($link_uri, PHP_URL_QUERY)) { parse_str($query, $query_params); if (is_array($query_params) && isset($query_params['batch_token'])) { return $query_params['batch_token']; } } } } return null; }
php
public static function getV1BatchTokenFromHeaders($http_headers) { if (is_array($http_headers) && isset($http_headers['Link'])) { $connect_link_regexp = "/^<([^>]+)>;rel='next'$/"; if (preg_match($connect_link_regexp, $http_headers['Link'], $match) === 1) { $link_uri = $match[1]; if ($query = parse_url($link_uri, PHP_URL_QUERY)) { parse_str($query, $query_params); if (is_array($query_params) && isset($query_params['batch_token'])) { return $query_params['batch_token']; } } } } return null; }
[ "public", "static", "function", "getV1BatchTokenFromHeaders", "(", "$", "http_headers", ")", "{", "if", "(", "is_array", "(", "$", "http_headers", ")", "&&", "isset", "(", "$", "http_headers", "[", "'Link'", "]", ")", ")", "{", "$", "connect_link_regexp", "=", "\"/^<([^>]+)>;rel='next'$/\"", ";", "if", "(", "preg_match", "(", "$", "connect_link_regexp", ",", "$", "http_headers", "[", "'Link'", "]", ",", "$", "match", ")", "===", "1", ")", "{", "$", "link_uri", "=", "$", "match", "[", "1", "]", ";", "if", "(", "$", "query", "=", "parse_url", "(", "$", "link_uri", ",", "PHP_URL_QUERY", ")", ")", "{", "parse_str", "(", "$", "query", ",", "$", "query_params", ")", ";", "if", "(", "is_array", "(", "$", "query_params", ")", "&&", "isset", "(", "$", "query_params", "[", "'batch_token'", "]", ")", ")", "{", "return", "$", "query_params", "[", "'batch_token'", "]", ";", "}", "}", "}", "}", "return", "null", ";", "}" ]
Return a batch_token if present on the Link header or null if no token is present @param string[] Array of HTTP response heaers @return
[ "Return", "a", "batch_token", "if", "present", "on", "the", "Link", "header", "or", "null", "if", "no", "token", "is", "present" ]
601485d86634286b2d19eb2939b87944176769e1
https://github.com/square/connect-php-sdk/blob/601485d86634286b2d19eb2939b87944176769e1/lib/ApiClient.php#L288-L307
train
square/connect-php-sdk
lib/ObjectSerializer.php
ObjectSerializer.serializeCollection
public function serializeCollection(array $collection, $collectionFormat, $allowCollectionFormatMulti=false) { if ($allowCollectionFormatMulti && ('multi' === $collectionFormat)) { // http_build_query() almost does the job for us. We just // need to fix the result of multidimensional arrays. return preg_replace('/%5B[0-9]+%5D=/', '=', http_build_query($collection, '', '&')); } switch ($collectionFormat) { case 'pipes': return implode('|', $collection); case 'tsv': return implode("\t", $collection); case 'ssv': return implode(' ', $collection); case 'csv': // Deliberate fall through. CSV is default format. default: return implode(',', $collection); } }
php
public function serializeCollection(array $collection, $collectionFormat, $allowCollectionFormatMulti=false) { if ($allowCollectionFormatMulti && ('multi' === $collectionFormat)) { // http_build_query() almost does the job for us. We just // need to fix the result of multidimensional arrays. return preg_replace('/%5B[0-9]+%5D=/', '=', http_build_query($collection, '', '&')); } switch ($collectionFormat) { case 'pipes': return implode('|', $collection); case 'tsv': return implode("\t", $collection); case 'ssv': return implode(' ', $collection); case 'csv': // Deliberate fall through. CSV is default format. default: return implode(',', $collection); } }
[ "public", "function", "serializeCollection", "(", "array", "$", "collection", ",", "$", "collectionFormat", ",", "$", "allowCollectionFormatMulti", "=", "false", ")", "{", "if", "(", "$", "allowCollectionFormatMulti", "&&", "(", "'multi'", "===", "$", "collectionFormat", ")", ")", "{", "// http_build_query() almost does the job for us. We just", "// need to fix the result of multidimensional arrays.", "return", "preg_replace", "(", "'/%5B[0-9]+%5D=/'", ",", "'='", ",", "http_build_query", "(", "$", "collection", ",", "''", ",", "'&'", ")", ")", ";", "}", "switch", "(", "$", "collectionFormat", ")", "{", "case", "'pipes'", ":", "return", "implode", "(", "'|'", ",", "$", "collection", ")", ";", "case", "'tsv'", ":", "return", "implode", "(", "\"\\t\"", ",", "$", "collection", ")", ";", "case", "'ssv'", ":", "return", "implode", "(", "' '", ",", "$", "collection", ")", ";", "case", "'csv'", ":", "// Deliberate fall through. CSV is default format.", "default", ":", "return", "implode", "(", "','", ",", "$", "collection", ")", ";", "}", "}" ]
Serialize an array to a string. @param array $collection collection to serialize to a string @param string $collectionFormat the format use for serialization (csv, ssv, tsv, pipes, multi) @return string
[ "Serialize", "an", "array", "to", "a", "string", "." ]
601485d86634286b2d19eb2939b87944176769e1
https://github.com/square/connect-php-sdk/blob/601485d86634286b2d19eb2939b87944176769e1/lib/ObjectSerializer.php#L164-L186
train
reactphp/socket
src/TimeoutConnector.php
TimeoutConnector.handler
private static function handler($uri) { return function (\Exception $e) use ($uri) { if ($e instanceof TimeoutException) { throw new \RuntimeException( 'Connection to ' . $uri . ' timed out after ' . $e->getTimeout() . ' seconds', \defined('SOCKET_ETIMEDOUT') ? \SOCKET_ETIMEDOUT : 0 ); } throw $e; }; }
php
private static function handler($uri) { return function (\Exception $e) use ($uri) { if ($e instanceof TimeoutException) { throw new \RuntimeException( 'Connection to ' . $uri . ' timed out after ' . $e->getTimeout() . ' seconds', \defined('SOCKET_ETIMEDOUT') ? \SOCKET_ETIMEDOUT : 0 ); } throw $e; }; }
[ "private", "static", "function", "handler", "(", "$", "uri", ")", "{", "return", "function", "(", "\\", "Exception", "$", "e", ")", "use", "(", "$", "uri", ")", "{", "if", "(", "$", "e", "instanceof", "TimeoutException", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Connection to '", ".", "$", "uri", ".", "' timed out after '", ".", "$", "e", "->", "getTimeout", "(", ")", ".", "' seconds'", ",", "\\", "defined", "(", "'SOCKET_ETIMEDOUT'", ")", "?", "\\", "SOCKET_ETIMEDOUT", ":", "0", ")", ";", "}", "throw", "$", "e", ";", "}", ";", "}" ]
Creates a static rejection handler that reports a proper error message in case of a timeout. This uses a private static helper method to ensure this closure is not bound to this instance and the exception trace does not include a reference to this instance and its connector stack as a result. @param string $uri @return callable
[ "Creates", "a", "static", "rejection", "handler", "that", "reports", "a", "proper", "error", "message", "in", "case", "of", "a", "timeout", "." ]
2cf8dfa7fc30cdadf24aa49b5978838fd3ec7f09
https://github.com/reactphp/socket/blob/2cf8dfa7fc30cdadf24aa49b5978838fd3ec7f09/src/TimeoutConnector.php#L37-L49
train
ConsoleTVs/Charts
src/Classes/Echarts/Dataset.php
Dataset.getValues
protected function getValues(array $labels) { if (in_array(strtolower($this->type), $this->specialDatasets)) { return Collection::make($this->values) ->map(function ($value, $key) use ($labels) { return [ 'name' => $labels[$key], 'value' => $value, ]; })->toArray(); } return $this->values; }
php
protected function getValues(array $labels) { if (in_array(strtolower($this->type), $this->specialDatasets)) { return Collection::make($this->values) ->map(function ($value, $key) use ($labels) { return [ 'name' => $labels[$key], 'value' => $value, ]; })->toArray(); } return $this->values; }
[ "protected", "function", "getValues", "(", "array", "$", "labels", ")", "{", "if", "(", "in_array", "(", "strtolower", "(", "$", "this", "->", "type", ")", ",", "$", "this", "->", "specialDatasets", ")", ")", "{", "return", "Collection", "::", "make", "(", "$", "this", "->", "values", ")", "->", "map", "(", "function", "(", "$", "value", ",", "$", "key", ")", "use", "(", "$", "labels", ")", "{", "return", "[", "'name'", "=>", "$", "labels", "[", "$", "key", "]", ",", "'value'", "=>", "$", "value", ",", "]", ";", "}", ")", "->", "toArray", "(", ")", ";", "}", "return", "$", "this", "->", "values", ";", "}" ]
Get the formated values. @param array $labels @return array
[ "Get", "the", "formated", "values", "." ]
63e8c604e65df77e8844527906ee80b53695e219
https://github.com/ConsoleTVs/Charts/blob/63e8c604e65df77e8844527906ee80b53695e219/src/Classes/Echarts/Dataset.php#L53-L66
train
ConsoleTVs/Charts
src/Classes/BaseChart.php
BaseChart.dataset
public function dataset(string $name, string $type, $data) { if ($data instanceof Collection) { $data = $data->toArray(); } $dataset = new $this->dataset($name, $type, $data); array_push($this->datasets, $dataset); return $dataset; }
php
public function dataset(string $name, string $type, $data) { if ($data instanceof Collection) { $data = $data->toArray(); } $dataset = new $this->dataset($name, $type, $data); array_push($this->datasets, $dataset); return $dataset; }
[ "public", "function", "dataset", "(", "string", "$", "name", ",", "string", "$", "type", ",", "$", "data", ")", "{", "if", "(", "$", "data", "instanceof", "Collection", ")", "{", "$", "data", "=", "$", "data", "->", "toArray", "(", ")", ";", "}", "$", "dataset", "=", "new", "$", "this", "->", "dataset", "(", "$", "name", ",", "$", "type", ",", "$", "data", ")", ";", "array_push", "(", "$", "this", "->", "datasets", ",", "$", "dataset", ")", ";", "return", "$", "dataset", ";", "}" ]
Adds a new dataset to the chart. @param string $name @param array|Collection $data
[ "Adds", "a", "new", "dataset", "to", "the", "chart", "." ]
63e8c604e65df77e8844527906ee80b53695e219
https://github.com/ConsoleTVs/Charts/blob/63e8c604e65df77e8844527906ee80b53695e219/src/Classes/BaseChart.php#L147-L158
train
ConsoleTVs/Charts
src/Classes/BaseChart.php
BaseChart.labels
public function labels($labels) { if ($labels instanceof Collection) { $labels = $labels->toArray(); } $this->labels = $labels; return $this; }
php
public function labels($labels) { if ($labels instanceof Collection) { $labels = $labels->toArray(); } $this->labels = $labels; return $this; }
[ "public", "function", "labels", "(", "$", "labels", ")", "{", "if", "(", "$", "labels", "instanceof", "Collection", ")", "{", "$", "labels", "=", "$", "labels", "->", "toArray", "(", ")", ";", "}", "$", "this", "->", "labels", "=", "$", "labels", ";", "return", "$", "this", ";", "}" ]
Set the chart labels. @param array|Collection $labels @return self
[ "Set", "the", "chart", "labels", "." ]
63e8c604e65df77e8844527906ee80b53695e219
https://github.com/ConsoleTVs/Charts/blob/63e8c604e65df77e8844527906ee80b53695e219/src/Classes/BaseChart.php#L167-L176
train
ConsoleTVs/Charts
src/Classes/BaseChart.php
BaseChart.options
public function options($options, bool $overwrite = false) { if (!empty($options['plugins'])) { $options['plugins'] = new Raw(trim(preg_replace('/\s\s+/', ' ', $options['plugins']))); } if ($options instanceof Collection) { $options = $options->toArray(); } if ($overwrite) { $this->options = $options; } else { $this->options = array_replace_recursive($this->options, $options); } return $this; }
php
public function options($options, bool $overwrite = false) { if (!empty($options['plugins'])) { $options['plugins'] = new Raw(trim(preg_replace('/\s\s+/', ' ', $options['plugins']))); } if ($options instanceof Collection) { $options = $options->toArray(); } if ($overwrite) { $this->options = $options; } else { $this->options = array_replace_recursive($this->options, $options); } return $this; }
[ "public", "function", "options", "(", "$", "options", ",", "bool", "$", "overwrite", "=", "false", ")", "{", "if", "(", "!", "empty", "(", "$", "options", "[", "'plugins'", "]", ")", ")", "{", "$", "options", "[", "'plugins'", "]", "=", "new", "Raw", "(", "trim", "(", "preg_replace", "(", "'/\\s\\s+/'", ",", "' '", ",", "$", "options", "[", "'plugins'", "]", ")", ")", ")", ";", "}", "if", "(", "$", "options", "instanceof", "Collection", ")", "{", "$", "options", "=", "$", "options", "->", "toArray", "(", ")", ";", "}", "if", "(", "$", "overwrite", ")", "{", "$", "this", "->", "options", "=", "$", "options", ";", "}", "else", "{", "$", "this", "->", "options", "=", "array_replace_recursive", "(", "$", "this", "->", "options", ",", "$", "options", ")", ";", "}", "return", "$", "this", ";", "}" ]
Set the chart options. @param array|Collection $options @param bool $overwrite @return self
[ "Set", "the", "chart", "options", "." ]
63e8c604e65df77e8844527906ee80b53695e219
https://github.com/ConsoleTVs/Charts/blob/63e8c604e65df77e8844527906ee80b53695e219/src/Classes/BaseChart.php#L186-L202
train
ConsoleTVs/Charts
src/Classes/BaseChart.php
BaseChart.plugins
public function plugins($plugins, bool $overwrite = true) { if ($plugins instanceof Collection) { $plugins = $plugins->toArray(); } if ($overwrite) { $this->plugins = $plugins; } else { $this->plugins = array_replace_recursive($this->plugins, $plugins); } return $this; }
php
public function plugins($plugins, bool $overwrite = true) { if ($plugins instanceof Collection) { $plugins = $plugins->toArray(); } if ($overwrite) { $this->plugins = $plugins; } else { $this->plugins = array_replace_recursive($this->plugins, $plugins); } return $this; }
[ "public", "function", "plugins", "(", "$", "plugins", ",", "bool", "$", "overwrite", "=", "true", ")", "{", "if", "(", "$", "plugins", "instanceof", "Collection", ")", "{", "$", "plugins", "=", "$", "plugins", "->", "toArray", "(", ")", ";", "}", "if", "(", "$", "overwrite", ")", "{", "$", "this", "->", "plugins", "=", "$", "plugins", ";", "}", "else", "{", "$", "this", "->", "plugins", "=", "array_replace_recursive", "(", "$", "this", "->", "plugins", ",", "$", "plugins", ")", ";", "}", "return", "$", "this", ";", "}" ]
Set the plugins options. @param array|Collection $options @param bool $overwrite @return self
[ "Set", "the", "plugins", "options", "." ]
63e8c604e65df77e8844527906ee80b53695e219
https://github.com/ConsoleTVs/Charts/blob/63e8c604e65df77e8844527906ee80b53695e219/src/Classes/BaseChart.php#L212-L224
train
ConsoleTVs/Charts
src/Classes/BaseChart.php
BaseChart.container
public function container(string $container = null) { if (!$container) { return View::make($this->container, ['chart' => $this]); } $this->container = $container; return $this; }
php
public function container(string $container = null) { if (!$container) { return View::make($this->container, ['chart' => $this]); } $this->container = $container; return $this; }
[ "public", "function", "container", "(", "string", "$", "container", "=", "null", ")", "{", "if", "(", "!", "$", "container", ")", "{", "return", "View", "::", "make", "(", "$", "this", "->", "container", ",", "[", "'chart'", "=>", "$", "this", "]", ")", ";", "}", "$", "this", "->", "container", "=", "$", "container", ";", "return", "$", "this", ";", "}" ]
Set the chart container. @param string $container @return self
[ "Set", "the", "chart", "container", "." ]
63e8c604e65df77e8844527906ee80b53695e219
https://github.com/ConsoleTVs/Charts/blob/63e8c604e65df77e8844527906ee80b53695e219/src/Classes/BaseChart.php#L233-L242
train
ConsoleTVs/Charts
src/Classes/BaseChart.php
BaseChart.script
public function script(string $script = null) { if (count($this->datasets) == 0 && !$this->api_url) { throw new \Exception('No datasets provided, please provide at least one dataset to generate a chart'); } if (!$script) { return View::make($this->script, ['chart' => $this]); } $this->script = $script; return $this; }
php
public function script(string $script = null) { if (count($this->datasets) == 0 && !$this->api_url) { throw new \Exception('No datasets provided, please provide at least one dataset to generate a chart'); } if (!$script) { return View::make($this->script, ['chart' => $this]); } $this->script = $script; return $this; }
[ "public", "function", "script", "(", "string", "$", "script", "=", "null", ")", "{", "if", "(", "count", "(", "$", "this", "->", "datasets", ")", "==", "0", "&&", "!", "$", "this", "->", "api_url", ")", "{", "throw", "new", "\\", "Exception", "(", "'No datasets provided, please provide at least one dataset to generate a chart'", ")", ";", "}", "if", "(", "!", "$", "script", ")", "{", "return", "View", "::", "make", "(", "$", "this", "->", "script", ",", "[", "'chart'", "=>", "$", "this", "]", ")", ";", "}", "$", "this", "->", "script", "=", "$", "script", ";", "return", "$", "this", ";", "}" ]
Set the chart script. @param string $script @return self
[ "Set", "the", "chart", "script", "." ]
63e8c604e65df77e8844527906ee80b53695e219
https://github.com/ConsoleTVs/Charts/blob/63e8c604e65df77e8844527906ee80b53695e219/src/Classes/BaseChart.php#L251-L264
train
ConsoleTVs/Charts
src/Classes/BaseChart.php
BaseChart.formatOptions
public function formatOptions(bool $strict = false, bool $noBraces = false) { if (!$strict && count($this->options) === 0) { return ''; } $options = Encoder::encode($this->options); return $noBraces ? substr($options, 1, -1) : $options; }
php
public function formatOptions(bool $strict = false, bool $noBraces = false) { if (!$strict && count($this->options) === 0) { return ''; } $options = Encoder::encode($this->options); return $noBraces ? substr($options, 1, -1) : $options; }
[ "public", "function", "formatOptions", "(", "bool", "$", "strict", "=", "false", ",", "bool", "$", "noBraces", "=", "false", ")", "{", "if", "(", "!", "$", "strict", "&&", "count", "(", "$", "this", "->", "options", ")", "===", "0", ")", "{", "return", "''", ";", "}", "$", "options", "=", "Encoder", "::", "encode", "(", "$", "this", "->", "options", ")", ";", "return", "$", "noBraces", "?", "substr", "(", "$", "options", ",", "1", ",", "-", "1", ")", ":", "$", "options", ";", "}" ]
Formats the chart options. @param bool $strict @return string
[ "Formats", "the", "chart", "options", "." ]
63e8c604e65df77e8844527906ee80b53695e219
https://github.com/ConsoleTVs/Charts/blob/63e8c604e65df77e8844527906ee80b53695e219/src/Classes/BaseChart.php#L335-L344
train
ConsoleTVs/Charts
src/Classes/BaseChart.php
BaseChart.formatPlugins
public function formatPlugins(bool $strict = false, bool $noBraces = false) { if (!$strict && count($this->plugins) === 0) { return ''; } $plugins = str_replace('"', '', Encoder::encode($this->plugins)); return $noBraces ? substr($plugins, 1, -1) : $plugins; }
php
public function formatPlugins(bool $strict = false, bool $noBraces = false) { if (!$strict && count($this->plugins) === 0) { return ''; } $plugins = str_replace('"', '', Encoder::encode($this->plugins)); return $noBraces ? substr($plugins, 1, -1) : $plugins; }
[ "public", "function", "formatPlugins", "(", "bool", "$", "strict", "=", "false", ",", "bool", "$", "noBraces", "=", "false", ")", "{", "if", "(", "!", "$", "strict", "&&", "count", "(", "$", "this", "->", "plugins", ")", "===", "0", ")", "{", "return", "''", ";", "}", "$", "plugins", "=", "str_replace", "(", "'\"'", ",", "''", ",", "Encoder", "::", "encode", "(", "$", "this", "->", "plugins", ")", ")", ";", "return", "$", "noBraces", "?", "substr", "(", "$", "plugins", ",", "1", ",", "-", "1", ")", ":", "$", "plugins", ";", "}" ]
Formats the plugins options. @param bool $strict @return string
[ "Formats", "the", "plugins", "options", "." ]
63e8c604e65df77e8844527906ee80b53695e219
https://github.com/ConsoleTVs/Charts/blob/63e8c604e65df77e8844527906ee80b53695e219/src/Classes/BaseChart.php#L353-L362
train
ConsoleTVs/Charts
src/Classes/BaseChart.php
BaseChart.formatDatasets
public function formatDatasets() { // This little boy was commented because it's not compatible // in laravel < 5.4 // // return Collection::make($this->datasets) // ->each // ->matchValues(count($this->labels)) // ->map // ->format($this->labels) // ->toJson(); return Encoder::encode( Collection::make($this->datasets) ->each(function ($dataset) { $dataset->matchValues(count($this->labels)); }) ->map(function ($dataset) { return $dataset->format($this->labels); }) ->toArray() ); }
php
public function formatDatasets() { // This little boy was commented because it's not compatible // in laravel < 5.4 // // return Collection::make($this->datasets) // ->each // ->matchValues(count($this->labels)) // ->map // ->format($this->labels) // ->toJson(); return Encoder::encode( Collection::make($this->datasets) ->each(function ($dataset) { $dataset->matchValues(count($this->labels)); }) ->map(function ($dataset) { return $dataset->format($this->labels); }) ->toArray() ); }
[ "public", "function", "formatDatasets", "(", ")", "{", "// This little boy was commented because it's not compatible", "// in laravel < 5.4", "//", "// return Collection::make($this->datasets)", "// ->each", "// ->matchValues(count($this->labels))", "// ->map", "// ->format($this->labels)", "// ->toJson();", "return", "Encoder", "::", "encode", "(", "Collection", "::", "make", "(", "$", "this", "->", "datasets", ")", "->", "each", "(", "function", "(", "$", "dataset", ")", "{", "$", "dataset", "->", "matchValues", "(", "count", "(", "$", "this", "->", "labels", ")", ")", ";", "}", ")", "->", "map", "(", "function", "(", "$", "dataset", ")", "{", "return", "$", "dataset", "->", "format", "(", "$", "this", "->", "labels", ")", ";", "}", ")", "->", "toArray", "(", ")", ")", ";", "}" ]
Formats the datasets for the output. @return string
[ "Formats", "the", "datasets", "for", "the", "output", "." ]
63e8c604e65df77e8844527906ee80b53695e219
https://github.com/ConsoleTVs/Charts/blob/63e8c604e65df77e8844527906ee80b53695e219/src/Classes/BaseChart.php#L392-L414
train
ConsoleTVs/Charts
src/Classes/BaseChart.php
BaseChart.setScriptAttribute
public function setScriptAttribute(string $key, string $value) { $this->scriptAttributes[$key] = $value; return $this; }
php
public function setScriptAttribute(string $key, string $value) { $this->scriptAttributes[$key] = $value; return $this; }
[ "public", "function", "setScriptAttribute", "(", "string", "$", "key", ",", "string", "$", "value", ")", "{", "$", "this", "->", "scriptAttributes", "[", "$", "key", "]", "=", "$", "value", ";", "return", "$", "this", ";", "}" ]
Sets an HTML attribute the the script tag of the chart. @param string $key @param string $value @return self
[ "Sets", "an", "HTML", "attribute", "the", "the", "script", "tag", "of", "the", "chart", "." ]
63e8c604e65df77e8844527906ee80b53695e219
https://github.com/ConsoleTVs/Charts/blob/63e8c604e65df77e8844527906ee80b53695e219/src/Classes/BaseChart.php#L476-L481
train
ConsoleTVs/Charts
src/Classes/BaseChart.php
BaseChart.formatContainerOptions
public function formatContainerOptions(string $type = 'css', bool $maxIfNull = false) { $options = ''; $height = ($maxIfNull && !$this->height) ? '100%' : $this->height; $width = ($maxIfNull && !$this->width) ? '100%' : $this->width; switch ($type) { case 'css': $options .= " style='"; (!$height) ?: $options .= "height: {$height}px !important;"; (!$width) ?: $options .= "width: {$width}px !important;"; $options .= "' "; break; case 'js': if ($height) { if (is_int($height)) { $options .= "height: {$height}, "; } else { $options .= "height: '{$height}', "; } } if ($width) { if (is_int($width)) { $options .= "width: {$width}, "; } else { $options .= "width: '{$width}', "; } } break; default: (!$height) ?: $options .= " height='{$this->height}' "; (!$this->width) ?: $options .= " width='{$this->width}' "; } return $options; }
php
public function formatContainerOptions(string $type = 'css', bool $maxIfNull = false) { $options = ''; $height = ($maxIfNull && !$this->height) ? '100%' : $this->height; $width = ($maxIfNull && !$this->width) ? '100%' : $this->width; switch ($type) { case 'css': $options .= " style='"; (!$height) ?: $options .= "height: {$height}px !important;"; (!$width) ?: $options .= "width: {$width}px !important;"; $options .= "' "; break; case 'js': if ($height) { if (is_int($height)) { $options .= "height: {$height}, "; } else { $options .= "height: '{$height}', "; } } if ($width) { if (is_int($width)) { $options .= "width: {$width}, "; } else { $options .= "width: '{$width}', "; } } break; default: (!$height) ?: $options .= " height='{$this->height}' "; (!$this->width) ?: $options .= " width='{$this->width}' "; } return $options; }
[ "public", "function", "formatContainerOptions", "(", "string", "$", "type", "=", "'css'", ",", "bool", "$", "maxIfNull", "=", "false", ")", "{", "$", "options", "=", "''", ";", "$", "height", "=", "(", "$", "maxIfNull", "&&", "!", "$", "this", "->", "height", ")", "?", "'100%'", ":", "$", "this", "->", "height", ";", "$", "width", "=", "(", "$", "maxIfNull", "&&", "!", "$", "this", "->", "width", ")", "?", "'100%'", ":", "$", "this", "->", "width", ";", "switch", "(", "$", "type", ")", "{", "case", "'css'", ":", "$", "options", ".=", "\" style='\"", ";", "(", "!", "$", "height", ")", "?", ":", "$", "options", ".=", "\"height: {$height}px !important;\"", ";", "(", "!", "$", "width", ")", "?", ":", "$", "options", ".=", "\"width: {$width}px !important;\"", ";", "$", "options", ".=", "\"' \"", ";", "break", ";", "case", "'js'", ":", "if", "(", "$", "height", ")", "{", "if", "(", "is_int", "(", "$", "height", ")", ")", "{", "$", "options", ".=", "\"height: {$height}, \"", ";", "}", "else", "{", "$", "options", ".=", "\"height: '{$height}', \"", ";", "}", "}", "if", "(", "$", "width", ")", "{", "if", "(", "is_int", "(", "$", "width", ")", ")", "{", "$", "options", ".=", "\"width: {$width}, \"", ";", "}", "else", "{", "$", "options", ".=", "\"width: '{$width}', \"", ";", "}", "}", "break", ";", "default", ":", "(", "!", "$", "height", ")", "?", ":", "$", "options", ".=", "\" height='{$this->height}' \"", ";", "(", "!", "$", "this", "->", "width", ")", "?", ":", "$", "options", ".=", "\" width='{$this->width}' \"", ";", "}", "return", "$", "options", ";", "}" ]
Formats the container options. @param string $type @param bool $maxIfNull @return string
[ "Formats", "the", "container", "options", "." ]
63e8c604e65df77e8844527906ee80b53695e219
https://github.com/ConsoleTVs/Charts/blob/63e8c604e65df77e8844527906ee80b53695e219/src/Classes/BaseChart.php#L506-L541
train
ConsoleTVs/Charts
src/Classes/Fusioncharts/Dataset.php
Dataset.format
public function format(array $labels = []) { return array_merge($this->options, [ 'data' => $this->formatValues($labels), 'seriesName' => $this->name, 'renderAs' => strtolower($this->type), ]); }
php
public function format(array $labels = []) { return array_merge($this->options, [ 'data' => $this->formatValues($labels), 'seriesName' => $this->name, 'renderAs' => strtolower($this->type), ]); }
[ "public", "function", "format", "(", "array", "$", "labels", "=", "[", "]", ")", "{", "return", "array_merge", "(", "$", "this", "->", "options", ",", "[", "'data'", "=>", "$", "this", "->", "formatValues", "(", "$", "labels", ")", ",", "'seriesName'", "=>", "$", "this", "->", "name", ",", "'renderAs'", "=>", "strtolower", "(", "$", "this", "->", "type", ")", ",", "]", ")", ";", "}" ]
Dataset representation. @var array
[ "Dataset", "representation", "." ]
63e8c604e65df77e8844527906ee80b53695e219
https://github.com/ConsoleTVs/Charts/blob/63e8c604e65df77e8844527906ee80b53695e219/src/Classes/Fusioncharts/Dataset.php#L37-L44
train
ConsoleTVs/Charts
src/Classes/Fusioncharts/Dataset.php
Dataset.formatValues
protected function formatValues(array $labels) { $values = Collection::make($this->values); if (in_array(strtolower($this->type), $this->specialDatasets)) { $colors = $this->getColors($labels); return $values->map(function ($value, $key) use ($colors, $labels) { $val = [ 'label' => $labels[$key], 'value' => $value, ]; if ($colors->count() > 0) { $val['color'] = $colors->get($key); } return $val; })->toArray(); } return $values->map(function ($value) { return [ 'value' => $value, ]; })->toArray(); }
php
protected function formatValues(array $labels) { $values = Collection::make($this->values); if (in_array(strtolower($this->type), $this->specialDatasets)) { $colors = $this->getColors($labels); return $values->map(function ($value, $key) use ($colors, $labels) { $val = [ 'label' => $labels[$key], 'value' => $value, ]; if ($colors->count() > 0) { $val['color'] = $colors->get($key); } return $val; })->toArray(); } return $values->map(function ($value) { return [ 'value' => $value, ]; })->toArray(); }
[ "protected", "function", "formatValues", "(", "array", "$", "labels", ")", "{", "$", "values", "=", "Collection", "::", "make", "(", "$", "this", "->", "values", ")", ";", "if", "(", "in_array", "(", "strtolower", "(", "$", "this", "->", "type", ")", ",", "$", "this", "->", "specialDatasets", ")", ")", "{", "$", "colors", "=", "$", "this", "->", "getColors", "(", "$", "labels", ")", ";", "return", "$", "values", "->", "map", "(", "function", "(", "$", "value", ",", "$", "key", ")", "use", "(", "$", "colors", ",", "$", "labels", ")", "{", "$", "val", "=", "[", "'label'", "=>", "$", "labels", "[", "$", "key", "]", ",", "'value'", "=>", "$", "value", ",", "]", ";", "if", "(", "$", "colors", "->", "count", "(", ")", ">", "0", ")", "{", "$", "val", "[", "'color'", "]", "=", "$", "colors", "->", "get", "(", "$", "key", ")", ";", "}", "return", "$", "val", ";", "}", ")", "->", "toArray", "(", ")", ";", "}", "return", "$", "values", "->", "map", "(", "function", "(", "$", "value", ")", "{", "return", "[", "'value'", "=>", "$", "value", ",", "]", ";", "}", ")", "->", "toArray", "(", ")", ";", "}" ]
Formats the chart values. @param array $labels @return array
[ "Formats", "the", "chart", "values", "." ]
63e8c604e65df77e8844527906ee80b53695e219
https://github.com/ConsoleTVs/Charts/blob/63e8c604e65df77e8844527906ee80b53695e219/src/Classes/Fusioncharts/Dataset.php#L53-L79
train
ConsoleTVs/Charts
src/Classes/Fusioncharts/Dataset.php
Dataset.getColors
protected function getColors(array $labels) { $colors = Collection::make(array_key_exists('color', $this->options) ? $this->options['color'] : []); while ($colors->count() < count($labels)) { $colors->push($this->undefinedColor); } return $colors; }
php
protected function getColors(array $labels) { $colors = Collection::make(array_key_exists('color', $this->options) ? $this->options['color'] : []); while ($colors->count() < count($labels)) { $colors->push($this->undefinedColor); } return $colors; }
[ "protected", "function", "getColors", "(", "array", "$", "labels", ")", "{", "$", "colors", "=", "Collection", "::", "make", "(", "array_key_exists", "(", "'color'", ",", "$", "this", "->", "options", ")", "?", "$", "this", "->", "options", "[", "'color'", "]", ":", "[", "]", ")", ";", "while", "(", "$", "colors", "->", "count", "(", ")", "<", "count", "(", "$", "labels", ")", ")", "{", "$", "colors", "->", "push", "(", "$", "this", "->", "undefinedColor", ")", ";", "}", "return", "$", "colors", ";", "}" ]
Get the chart colors. @param array $labels @return Collection
[ "Get", "the", "chart", "colors", "." ]
63e8c604e65df77e8844527906ee80b53695e219
https://github.com/ConsoleTVs/Charts/blob/63e8c604e65df77e8844527906ee80b53695e219/src/Classes/Fusioncharts/Dataset.php#L88-L97
train
ConsoleTVs/Charts
src/Features/Fusioncharts/Chart.php
Chart.export
public function export(bool $export, bool $client = true) { return $this->options([ 'exportenabled' => $export, 'exportatclient' => $client, ]); }
php
public function export(bool $export, bool $client = true) { return $this->options([ 'exportenabled' => $export, 'exportatclient' => $client, ]); }
[ "public", "function", "export", "(", "bool", "$", "export", ",", "bool", "$", "client", "=", "true", ")", "{", "return", "$", "this", "->", "options", "(", "[", "'exportenabled'", "=>", "$", "export", ",", "'exportatclient'", "=>", "$", "client", ",", "]", ")", ";", "}" ]
Determines if the chart should show the export button. @param bool $export @param bool $client @return self
[ "Determines", "if", "the", "chart", "should", "show", "the", "export", "button", "." ]
63e8c604e65df77e8844527906ee80b53695e219
https://github.com/ConsoleTVs/Charts/blob/63e8c604e65df77e8844527906ee80b53695e219/src/Features/Fusioncharts/Chart.php#L83-L89
train
ConsoleTVs/Charts
src/Classes/DatasetClass.php
DatasetClass.values
public function values($values) { if ($values instanceof Collection) { $values = $values->toArray(); } $this->values = $values; return $this; }
php
public function values($values) { if ($values instanceof Collection) { $values = $values->toArray(); } $this->values = $values; return $this; }
[ "public", "function", "values", "(", "$", "values", ")", "{", "if", "(", "$", "values", "instanceof", "Collection", ")", "{", "$", "values", "=", "$", "values", "->", "toArray", "(", ")", ";", "}", "$", "this", "->", "values", "=", "$", "values", ";", "return", "$", "this", ";", "}" ]
Set the dataset values. @param array|Collection $values @return self
[ "Set", "the", "dataset", "values", "." ]
63e8c604e65df77e8844527906ee80b53695e219
https://github.com/ConsoleTVs/Charts/blob/63e8c604e65df77e8844527906ee80b53695e219/src/Classes/DatasetClass.php#L81-L90
train
ConsoleTVs/Charts
src/Classes/DatasetClass.php
DatasetClass.options
public function options($options, bool $overwrite = false) { if ($overwrite) { $this->options = $options; } else { $this->options = array_replace_recursive($this->options, $options); } return $this; }
php
public function options($options, bool $overwrite = false) { if ($overwrite) { $this->options = $options; } else { $this->options = array_replace_recursive($this->options, $options); } return $this; }
[ "public", "function", "options", "(", "$", "options", ",", "bool", "$", "overwrite", "=", "false", ")", "{", "if", "(", "$", "overwrite", ")", "{", "$", "this", "->", "options", "=", "$", "options", ";", "}", "else", "{", "$", "this", "->", "options", "=", "array_replace_recursive", "(", "$", "this", "->", "options", ",", "$", "options", ")", ";", "}", "return", "$", "this", ";", "}" ]
Set the dataset options. @param array|Collection $options @param bool $overwrite @return self
[ "Set", "the", "dataset", "options", "." ]
63e8c604e65df77e8844527906ee80b53695e219
https://github.com/ConsoleTVs/Charts/blob/63e8c604e65df77e8844527906ee80b53695e219/src/Classes/DatasetClass.php#L100-L109
train
ConsoleTVs/Charts
src/Classes/DatasetClass.php
DatasetClass.matchValues
public function matchValues(int $values, bool $strict = false) { while (count($this->values) < $values) { array_push($this->values, 0); } if ($strict) { $this->values = array_slice($this->values, 0, $values); } }
php
public function matchValues(int $values, bool $strict = false) { while (count($this->values) < $values) { array_push($this->values, 0); } if ($strict) { $this->values = array_slice($this->values, 0, $values); } }
[ "public", "function", "matchValues", "(", "int", "$", "values", ",", "bool", "$", "strict", "=", "false", ")", "{", "while", "(", "count", "(", "$", "this", "->", "values", ")", "<", "$", "values", ")", "{", "array_push", "(", "$", "this", "->", "values", ",", "0", ")", ";", "}", "if", "(", "$", "strict", ")", "{", "$", "this", "->", "values", "=", "array_slice", "(", "$", "this", "->", "values", ",", "0", ",", "$", "values", ")", ";", "}", "}" ]
Matches the values of the dataset with the given number. @param int $values @param bool $strict @return void
[ "Matches", "the", "values", "of", "the", "dataset", "with", "the", "given", "number", "." ]
63e8c604e65df77e8844527906ee80b53695e219
https://github.com/ConsoleTVs/Charts/blob/63e8c604e65df77e8844527906ee80b53695e219/src/Classes/DatasetClass.php#L119-L128
train
ConsoleTVs/Charts
src/Features/Echarts/Chart.php
Chart.minimalist
public function minimalist(bool $minimalist = true) { $this->displayAxes(!$minimalist); $this->displayLegend(!$minimalist); return $this->options([ 'xAxis' => [ 'axisLabel' => [ 'show' => !$minimalist, ], 'splitLine' => [ 'show' => !$minimalist, ], ], 'yAxis' => [ 'axisLabel' => [ 'show' => !$minimalist, ], 'splitLine' => [ 'show' => !$minimalist, ], ], ]); }
php
public function minimalist(bool $minimalist = true) { $this->displayAxes(!$minimalist); $this->displayLegend(!$minimalist); return $this->options([ 'xAxis' => [ 'axisLabel' => [ 'show' => !$minimalist, ], 'splitLine' => [ 'show' => !$minimalist, ], ], 'yAxis' => [ 'axisLabel' => [ 'show' => !$minimalist, ], 'splitLine' => [ 'show' => !$minimalist, ], ], ]); }
[ "public", "function", "minimalist", "(", "bool", "$", "minimalist", "=", "true", ")", "{", "$", "this", "->", "displayAxes", "(", "!", "$", "minimalist", ")", ";", "$", "this", "->", "displayLegend", "(", "!", "$", "minimalist", ")", ";", "return", "$", "this", "->", "options", "(", "[", "'xAxis'", "=>", "[", "'axisLabel'", "=>", "[", "'show'", "=>", "!", "$", "minimalist", ",", "]", ",", "'splitLine'", "=>", "[", "'show'", "=>", "!", "$", "minimalist", ",", "]", ",", "]", ",", "'yAxis'", "=>", "[", "'axisLabel'", "=>", "[", "'show'", "=>", "!", "$", "minimalist", ",", "]", ",", "'splitLine'", "=>", "[", "'show'", "=>", "!", "$", "minimalist", ",", "]", ",", "]", ",", "]", ")", ";", "}" ]
Show the minimalistic. @param bool $minimalist @return self
[ "Show", "the", "minimalistic", "." ]
63e8c604e65df77e8844527906ee80b53695e219
https://github.com/ConsoleTVs/Charts/blob/63e8c604e65df77e8844527906ee80b53695e219/src/Features/Echarts/Chart.php#L63-L86
train
ConsoleTVs/Charts
src/Features/Echarts/Chart.php
Chart.displayAxes
public function displayAxes(bool $display) { return $this->options([ 'xAxis' => [ 'show' => $display, 'axisLine' => [ 'show' => $display, ], 'axisTick' => [ 'show' => $display, ], ], 'yAxis' => [ 'show' => $display, 'axisLine' => [ 'show' => $display, ], 'axisTick' => [ 'show' => $display, ], ], ]); }
php
public function displayAxes(bool $display) { return $this->options([ 'xAxis' => [ 'show' => $display, 'axisLine' => [ 'show' => $display, ], 'axisTick' => [ 'show' => $display, ], ], 'yAxis' => [ 'show' => $display, 'axisLine' => [ 'show' => $display, ], 'axisTick' => [ 'show' => $display, ], ], ]); }
[ "public", "function", "displayAxes", "(", "bool", "$", "display", ")", "{", "return", "$", "this", "->", "options", "(", "[", "'xAxis'", "=>", "[", "'show'", "=>", "$", "display", ",", "'axisLine'", "=>", "[", "'show'", "=>", "$", "display", ",", "]", ",", "'axisTick'", "=>", "[", "'show'", "=>", "$", "display", ",", "]", ",", "]", ",", "'yAxis'", "=>", "[", "'show'", "=>", "$", "display", ",", "'axisLine'", "=>", "[", "'show'", "=>", "$", "display", ",", "]", ",", "'axisTick'", "=>", "[", "'show'", "=>", "$", "display", ",", "]", ",", "]", ",", "]", ")", ";", "}" ]
Display the chart axes. @param bool $display @return self
[ "Display", "the", "chart", "axes", "." ]
63e8c604e65df77e8844527906ee80b53695e219
https://github.com/ConsoleTVs/Charts/blob/63e8c604e65df77e8844527906ee80b53695e219/src/Features/Echarts/Chart.php#L95-L117
train
ConsoleTVs/Charts
src/Features/Echarts/Chart.php
Chart.export
public function export(bool $export = true, string $title = ' ') { return $this->options([ 'toolbox' => [ 'show' => true, 'feature' => [ 'saveAsImage' => [ 'title' => $title, ], ], ], ]); }
php
public function export(bool $export = true, string $title = ' ') { return $this->options([ 'toolbox' => [ 'show' => true, 'feature' => [ 'saveAsImage' => [ 'title' => $title, ], ], ], ]); }
[ "public", "function", "export", "(", "bool", "$", "export", "=", "true", ",", "string", "$", "title", "=", "' '", ")", "{", "return", "$", "this", "->", "options", "(", "[", "'toolbox'", "=>", "[", "'show'", "=>", "true", ",", "'feature'", "=>", "[", "'saveAsImage'", "=>", "[", "'title'", "=>", "$", "title", ",", "]", ",", "]", ",", "]", ",", "]", ")", ";", "}" ]
ALlow to export the chart. @return self
[ "ALlow", "to", "export", "the", "chart", "." ]
63e8c604e65df77e8844527906ee80b53695e219
https://github.com/ConsoleTVs/Charts/blob/63e8c604e65df77e8844527906ee80b53695e219/src/Features/Echarts/Chart.php#L124-L136
train
ConsoleTVs/Charts
src/Classes/C3/Chart.php
Chart.formatDatasets
public function formatDatasets() { $datasets = Collection::make($this->datasets); return json_encode([ 'columns' => Collection::make($this->datasets) ->each(function ($dataset) { $dataset->matchValues(count($this->labels)); }) ->map(function ($dataset) { return $dataset->format($this->labels); }) ->toArray(), 'type' => $datasets->first()->type, 'types' => $datasets->mapWithKeys(function ($d) { return [$d->name => $d->type]; })->toArray(), ]); }
php
public function formatDatasets() { $datasets = Collection::make($this->datasets); return json_encode([ 'columns' => Collection::make($this->datasets) ->each(function ($dataset) { $dataset->matchValues(count($this->labels)); }) ->map(function ($dataset) { return $dataset->format($this->labels); }) ->toArray(), 'type' => $datasets->first()->type, 'types' => $datasets->mapWithKeys(function ($d) { return [$d->name => $d->type]; })->toArray(), ]); }
[ "public", "function", "formatDatasets", "(", ")", "{", "$", "datasets", "=", "Collection", "::", "make", "(", "$", "this", "->", "datasets", ")", ";", "return", "json_encode", "(", "[", "'columns'", "=>", "Collection", "::", "make", "(", "$", "this", "->", "datasets", ")", "->", "each", "(", "function", "(", "$", "dataset", ")", "{", "$", "dataset", "->", "matchValues", "(", "count", "(", "$", "this", "->", "labels", ")", ")", ";", "}", ")", "->", "map", "(", "function", "(", "$", "dataset", ")", "{", "return", "$", "dataset", "->", "format", "(", "$", "this", "->", "labels", ")", ";", "}", ")", "->", "toArray", "(", ")", ",", "'type'", "=>", "$", "datasets", "->", "first", "(", ")", "->", "type", ",", "'types'", "=>", "$", "datasets", "->", "mapWithKeys", "(", "function", "(", "$", "d", ")", "{", "return", "[", "$", "d", "->", "name", "=>", "$", "d", "->", "type", "]", ";", "}", ")", "->", "toArray", "(", ")", ",", "]", ")", ";", "}" ]
Formats the datasets. @return void
[ "Formats", "the", "datasets", "." ]
63e8c604e65df77e8844527906ee80b53695e219
https://github.com/ConsoleTVs/Charts/blob/63e8c604e65df77e8844527906ee80b53695e219/src/Classes/C3/Chart.php#L40-L58
train
ConsoleTVs/Charts
src/Features/Chartjs/Chart.php
Chart.displayAxes
public function displayAxes(bool $axes, bool $strict = false) { if ($strict) { return $this->options([ 'scale' => [ 'display' => $axes, ], ]); } return $this->options([ 'scales' => [ 'xAxes' => [ [ 'display' => $axes, ], ], 'yAxes' => [ [ 'display' => $axes, ], ], ], ]); }
php
public function displayAxes(bool $axes, bool $strict = false) { if ($strict) { return $this->options([ 'scale' => [ 'display' => $axes, ], ]); } return $this->options([ 'scales' => [ 'xAxes' => [ [ 'display' => $axes, ], ], 'yAxes' => [ [ 'display' => $axes, ], ], ], ]); }
[ "public", "function", "displayAxes", "(", "bool", "$", "axes", ",", "bool", "$", "strict", "=", "false", ")", "{", "if", "(", "$", "strict", ")", "{", "return", "$", "this", "->", "options", "(", "[", "'scale'", "=>", "[", "'display'", "=>", "$", "axes", ",", "]", ",", "]", ")", ";", "}", "return", "$", "this", "->", "options", "(", "[", "'scales'", "=>", "[", "'xAxes'", "=>", "[", "[", "'display'", "=>", "$", "axes", ",", "]", ",", "]", ",", "'yAxes'", "=>", "[", "[", "'display'", "=>", "$", "axes", ",", "]", ",", "]", ",", "]", ",", "]", ")", ";", "}" ]
Display the chart axis. @param bool $axes @return self
[ "Display", "the", "chart", "axis", "." ]
63e8c604e65df77e8844527906ee80b53695e219
https://github.com/ConsoleTVs/Charts/blob/63e8c604e65df77e8844527906ee80b53695e219/src/Features/Chartjs/Chart.php#L42-L66
train
ConsoleTVs/Charts
src/Features/Highcharts/Chart.php
Chart.minimalist
public function minimalist(bool $display = false) { $this->displayLegend(!$display); return $this->displayAxes(!$display); }
php
public function minimalist(bool $display = false) { $this->displayLegend(!$display); return $this->displayAxes(!$display); }
[ "public", "function", "minimalist", "(", "bool", "$", "display", "=", "false", ")", "{", "$", "this", "->", "displayLegend", "(", "!", "$", "display", ")", ";", "return", "$", "this", "->", "displayAxes", "(", "!", "$", "display", ")", ";", "}" ]
Set the chart style to minimalist. @param bool $display @return self
[ "Set", "the", "chart", "style", "to", "minimalist", "." ]
63e8c604e65df77e8844527906ee80b53695e219
https://github.com/ConsoleTVs/Charts/blob/63e8c604e65df77e8844527906ee80b53695e219/src/Features/Highcharts/Chart.php#L67-L72
train
ConsoleTVs/Charts
src/Features/Fusioncharts/Dataset.php
Dataset.color
public function color($color) { if ($color instanceof Collection) { $color = $color->toArray(); } return $this->options([ 'color' => $color, ]); }
php
public function color($color) { if ($color instanceof Collection) { $color = $color->toArray(); } return $this->options([ 'color' => $color, ]); }
[ "public", "function", "color", "(", "$", "color", ")", "{", "if", "(", "$", "color", "instanceof", "Collection", ")", "{", "$", "color", "=", "$", "color", "->", "toArray", "(", ")", ";", "}", "return", "$", "this", "->", "options", "(", "[", "'color'", "=>", "$", "color", ",", "]", ")", ";", "}" ]
Set the dataset color. @param string|array|Collection $color @return self
[ "Set", "the", "dataset", "color", "." ]
63e8c604e65df77e8844527906ee80b53695e219
https://github.com/ConsoleTVs/Charts/blob/63e8c604e65df77e8844527906ee80b53695e219/src/Features/Fusioncharts/Dataset.php#L16-L25
train
ConsoleTVs/Charts
src/Classes/Echarts/Chart.php
Chart.formatOptions
public function formatOptions(bool $strict = false, bool $noBraces = false) { $this->options([ 'xAxis' => [ 'data' => json_decode($this->formatLabels()), ], ]); return parent::formatOptions($strict, $noBraces); }
php
public function formatOptions(bool $strict = false, bool $noBraces = false) { $this->options([ 'xAxis' => [ 'data' => json_decode($this->formatLabels()), ], ]); return parent::formatOptions($strict, $noBraces); }
[ "public", "function", "formatOptions", "(", "bool", "$", "strict", "=", "false", ",", "bool", "$", "noBraces", "=", "false", ")", "{", "$", "this", "->", "options", "(", "[", "'xAxis'", "=>", "[", "'data'", "=>", "json_decode", "(", "$", "this", "->", "formatLabels", "(", ")", ")", ",", "]", ",", "]", ")", ";", "return", "parent", "::", "formatOptions", "(", "$", "strict", ",", "$", "noBraces", ")", ";", "}" ]
Formats the options. @return self
[ "Formats", "the", "options", "." ]
63e8c604e65df77e8844527906ee80b53695e219
https://github.com/ConsoleTVs/Charts/blob/63e8c604e65df77e8844527906ee80b53695e219/src/Classes/Echarts/Chart.php#L59-L68
train
ConsoleTVs/Charts
src/Classes/Frappe/Chart.php
Chart.formatOptions
public function formatOptions(bool $strict = false, bool $noBraces = false) { $colors = []; $default = 0; foreach ($this->datasets as $dataset) { $color = $this->default_colors[$default]; if (array_key_exists('color', $dataset->options)) { $color = $dataset->options['color']; unset($dataset->options['color']); } else { $default++; } array_push($colors, $color); } $this->options([ 'colors' => $colors, ]); return parent::formatOptions($strict, $noBraces); }
php
public function formatOptions(bool $strict = false, bool $noBraces = false) { $colors = []; $default = 0; foreach ($this->datasets as $dataset) { $color = $this->default_colors[$default]; if (array_key_exists('color', $dataset->options)) { $color = $dataset->options['color']; unset($dataset->options['color']); } else { $default++; } array_push($colors, $color); } $this->options([ 'colors' => $colors, ]); return parent::formatOptions($strict, $noBraces); }
[ "public", "function", "formatOptions", "(", "bool", "$", "strict", "=", "false", ",", "bool", "$", "noBraces", "=", "false", ")", "{", "$", "colors", "=", "[", "]", ";", "$", "default", "=", "0", ";", "foreach", "(", "$", "this", "->", "datasets", "as", "$", "dataset", ")", "{", "$", "color", "=", "$", "this", "->", "default_colors", "[", "$", "default", "]", ";", "if", "(", "array_key_exists", "(", "'color'", ",", "$", "dataset", "->", "options", ")", ")", "{", "$", "color", "=", "$", "dataset", "->", "options", "[", "'color'", "]", ";", "unset", "(", "$", "dataset", "->", "options", "[", "'color'", "]", ")", ";", "}", "else", "{", "$", "default", "++", ";", "}", "array_push", "(", "$", "colors", ",", "$", "color", ")", ";", "}", "$", "this", "->", "options", "(", "[", "'colors'", "=>", "$", "colors", ",", "]", ")", ";", "return", "parent", "::", "formatOptions", "(", "$", "strict", ",", "$", "noBraces", ")", ";", "}" ]
Format the datasets. @param bool $strict @param bool $noBraces @return self
[ "Format", "the", "datasets", "." ]
63e8c604e65df77e8844527906ee80b53695e219
https://github.com/ConsoleTVs/Charts/blob/63e8c604e65df77e8844527906ee80b53695e219/src/Classes/Frappe/Chart.php#L64-L84
train
ConsoleTVs/Charts
src/Classes/Chartjs/Dataset.php
Dataset.format
public function format() { return array_merge($this->options, [ 'data' => $this->values, 'label' => $this->name, 'type' => $this->type, ]); }
php
public function format() { return array_merge($this->options, [ 'data' => $this->values, 'label' => $this->name, 'type' => $this->type, ]); }
[ "public", "function", "format", "(", ")", "{", "return", "array_merge", "(", "$", "this", "->", "options", ",", "[", "'data'", "=>", "$", "this", "->", "values", ",", "'label'", "=>", "$", "this", "->", "name", ",", "'type'", "=>", "$", "this", "->", "type", ",", "]", ")", ";", "}" ]
Formats the dataset for chartjs. @return array
[ "Formats", "the", "dataset", "for", "chartjs", "." ]
63e8c604e65df77e8844527906ee80b53695e219
https://github.com/ConsoleTVs/Charts/blob/63e8c604e65df77e8844527906ee80b53695e219/src/Classes/Chartjs/Dataset.php#L33-L40
train
hirak/prestissimo
src/Plugin.php
Plugin.onPreFileDownload
public function onPreFileDownload(CPlugin\PreFileDownloadEvent $ev) { if ($this->disabled) { return; } $scheme = parse_url($ev->getProcessedUrl(), PHP_URL_SCHEME); if (!in_array($scheme, self::$supportedSchemes, true)) { return; } $rfs = $ev->getRemoteFilesystem(); $curlrfs = new CurlRemoteFilesystem( $this->io, $this->config, $rfs->getOptions() ); $ev->setRemoteFilesystem($curlrfs); }
php
public function onPreFileDownload(CPlugin\PreFileDownloadEvent $ev) { if ($this->disabled) { return; } $scheme = parse_url($ev->getProcessedUrl(), PHP_URL_SCHEME); if (!in_array($scheme, self::$supportedSchemes, true)) { return; } $rfs = $ev->getRemoteFilesystem(); $curlrfs = new CurlRemoteFilesystem( $this->io, $this->config, $rfs->getOptions() ); $ev->setRemoteFilesystem($curlrfs); }
[ "public", "function", "onPreFileDownload", "(", "CPlugin", "\\", "PreFileDownloadEvent", "$", "ev", ")", "{", "if", "(", "$", "this", "->", "disabled", ")", "{", "return", ";", "}", "$", "scheme", "=", "parse_url", "(", "$", "ev", "->", "getProcessedUrl", "(", ")", ",", "PHP_URL_SCHEME", ")", ";", "if", "(", "!", "in_array", "(", "$", "scheme", ",", "self", "::", "$", "supportedSchemes", ",", "true", ")", ")", "{", "return", ";", "}", "$", "rfs", "=", "$", "ev", "->", "getRemoteFilesystem", "(", ")", ";", "$", "curlrfs", "=", "new", "CurlRemoteFilesystem", "(", "$", "this", "->", "io", ",", "$", "this", "->", "config", ",", "$", "rfs", "->", "getOptions", "(", ")", ")", ";", "$", "ev", "->", "setRemoteFilesystem", "(", "$", "curlrfs", ")", ";", "}" ]
Keep-Alived file downloader
[ "Keep", "-", "Alived", "file", "downloader" ]
01bed92c45e84d01a96f5d15c6e49958cbd57f36
https://github.com/hirak/prestissimo/blob/01bed92c45e84d01a96f5d15c6e49958cbd57f36/src/Plugin.php#L107-L125
train
hirak/prestissimo
src/Plugin.php
Plugin.onPostDependenciesSolving
public function onPostDependenciesSolving(Installer\InstallerEvent $ev) { if ($this->disabled) { return; } $prefetcher = new Prefetcher; $prefetcher->fetchAllFromOperations( $this->io, $this->config, $ev->getOperations() ); }
php
public function onPostDependenciesSolving(Installer\InstallerEvent $ev) { if ($this->disabled) { return; } $prefetcher = new Prefetcher; $prefetcher->fetchAllFromOperations( $this->io, $this->config, $ev->getOperations() ); }
[ "public", "function", "onPostDependenciesSolving", "(", "Installer", "\\", "InstallerEvent", "$", "ev", ")", "{", "if", "(", "$", "this", "->", "disabled", ")", "{", "return", ";", "}", "$", "prefetcher", "=", "new", "Prefetcher", ";", "$", "prefetcher", "->", "fetchAllFromOperations", "(", "$", "this", "->", "io", ",", "$", "this", "->", "config", ",", "$", "ev", "->", "getOperations", "(", ")", ")", ";", "}" ]
pre-fetch parallel by curl_multi
[ "pre", "-", "fetch", "parallel", "by", "curl_multi" ]
01bed92c45e84d01a96f5d15c6e49958cbd57f36
https://github.com/hirak/prestissimo/blob/01bed92c45e84d01a96f5d15c6e49958cbd57f36/src/Plugin.php#L159-L170
train
tightenco/jigsaw
src/Parsers/FrontMatterParser.php
FrontMatterParser.extractContent
public function extractContent($content) { $regex = '~^(' . '---' // $matches[1] start separator . "){1}[\r\n|\n]*(.*?)[\r\n|\n]+(" // $matches[2] front matter . '---' // $matches[3] end separator . "){1}[\r\n|\n]*(.*)$~s"; // $matches[4] document content return preg_match($regex, $content, $matches) === 1 ? ltrim($matches[4]) : $content; }
php
public function extractContent($content) { $regex = '~^(' . '---' // $matches[1] start separator . "){1}[\r\n|\n]*(.*?)[\r\n|\n]+(" // $matches[2] front matter . '---' // $matches[3] end separator . "){1}[\r\n|\n]*(.*)$~s"; // $matches[4] document content return preg_match($regex, $content, $matches) === 1 ? ltrim($matches[4]) : $content; }
[ "public", "function", "extractContent", "(", "$", "content", ")", "{", "$", "regex", "=", "'~^('", ".", "'---'", "// $matches[1] start separator", ".", "\"){1}[\\r\\n|\\n]*(.*?)[\\r\\n|\\n]+(\"", "// $matches[2] front matter", ".", "'---'", "// $matches[3] end separator", ".", "\"){1}[\\r\\n|\\n]*(.*)$~s\"", ";", "// $matches[4] document content", "return", "preg_match", "(", "$", "regex", ",", "$", "content", ",", "$", "matches", ")", "===", "1", "?", "ltrim", "(", "$", "matches", "[", "4", "]", ")", ":", "$", "content", ";", "}" ]
Adapted from Mni\FrontYAML.
[ "Adapted", "from", "Mni", "\\", "FrontYAML", "." ]
d29a4fc6ae49fe2ed1c3d2184878ff62479f36e5
https://github.com/tightenco/jigsaw/blob/d29a4fc6ae49fe2ed1c3d2184878ff62479f36e5/src/Parsers/FrontMatterParser.php#L68-L77
train
phpMussel/phpMussel
vault/classes/Maikuolan/Demojibakefier.php
Demojibakefier.dropVariants
private function dropVariants(&$Arr) { if (isset($Arr['GB18030'], $Arr['GB2312'])) { unset($Arr['GB2312']); } if (isset($Arr['UCS-2']) && (isset($Arr['UTF-16BE']) || isset($Arr['UTF-16LE']))) { unset($Arr['UCS-2']); } if (isset($Arr['UCS-4']) && (isset($Arr['UTF-32BE']) || isset($Arr['UTF-32LE']))) { unset($Arr['UCS-4']); } if ( isset($Arr['UTF-8']) || isset($Arr['UTF-16BE']) || isset($Arr['UTF-16LE']) || isset($Arr['UCS-2']) || isset($Arr['UTF-32BE']) || isset($Arr['UTF-32LE']) || isset($Arr['UCS-4']) || isset($Arr['GB18030']) || isset($Arr['GB2312']) || isset($Arr['BIG5']) || isset($Arr['SHIFT-JIS']) || isset($Arr['JOHAB']) || isset($Arr['UCS-4']) ) { foreach ($Arr as $Key => $Value) { if (!preg_match('~^(?:UTF|UCS|GB|BIG5|SHIFT-JIS|JOHAB)~', $Key)) { unset($Arr[$Key]); } } } }
php
private function dropVariants(&$Arr) { if (isset($Arr['GB18030'], $Arr['GB2312'])) { unset($Arr['GB2312']); } if (isset($Arr['UCS-2']) && (isset($Arr['UTF-16BE']) || isset($Arr['UTF-16LE']))) { unset($Arr['UCS-2']); } if (isset($Arr['UCS-4']) && (isset($Arr['UTF-32BE']) || isset($Arr['UTF-32LE']))) { unset($Arr['UCS-4']); } if ( isset($Arr['UTF-8']) || isset($Arr['UTF-16BE']) || isset($Arr['UTF-16LE']) || isset($Arr['UCS-2']) || isset($Arr['UTF-32BE']) || isset($Arr['UTF-32LE']) || isset($Arr['UCS-4']) || isset($Arr['GB18030']) || isset($Arr['GB2312']) || isset($Arr['BIG5']) || isset($Arr['SHIFT-JIS']) || isset($Arr['JOHAB']) || isset($Arr['UCS-4']) ) { foreach ($Arr as $Key => $Value) { if (!preg_match('~^(?:UTF|UCS|GB|BIG5|SHIFT-JIS|JOHAB)~', $Key)) { unset($Arr[$Key]); } } } }
[ "private", "function", "dropVariants", "(", "&", "$", "Arr", ")", "{", "if", "(", "isset", "(", "$", "Arr", "[", "'GB18030'", "]", ",", "$", "Arr", "[", "'GB2312'", "]", ")", ")", "{", "unset", "(", "$", "Arr", "[", "'GB2312'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "Arr", "[", "'UCS-2'", "]", ")", "&&", "(", "isset", "(", "$", "Arr", "[", "'UTF-16BE'", "]", ")", "||", "isset", "(", "$", "Arr", "[", "'UTF-16LE'", "]", ")", ")", ")", "{", "unset", "(", "$", "Arr", "[", "'UCS-2'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "Arr", "[", "'UCS-4'", "]", ")", "&&", "(", "isset", "(", "$", "Arr", "[", "'UTF-32BE'", "]", ")", "||", "isset", "(", "$", "Arr", "[", "'UTF-32LE'", "]", ")", ")", ")", "{", "unset", "(", "$", "Arr", "[", "'UCS-4'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "Arr", "[", "'UTF-8'", "]", ")", "||", "isset", "(", "$", "Arr", "[", "'UTF-16BE'", "]", ")", "||", "isset", "(", "$", "Arr", "[", "'UTF-16LE'", "]", ")", "||", "isset", "(", "$", "Arr", "[", "'UCS-2'", "]", ")", "||", "isset", "(", "$", "Arr", "[", "'UTF-32BE'", "]", ")", "||", "isset", "(", "$", "Arr", "[", "'UTF-32LE'", "]", ")", "||", "isset", "(", "$", "Arr", "[", "'UCS-4'", "]", ")", "||", "isset", "(", "$", "Arr", "[", "'GB18030'", "]", ")", "||", "isset", "(", "$", "Arr", "[", "'GB2312'", "]", ")", "||", "isset", "(", "$", "Arr", "[", "'BIG5'", "]", ")", "||", "isset", "(", "$", "Arr", "[", "'SHIFT-JIS'", "]", ")", "||", "isset", "(", "$", "Arr", "[", "'JOHAB'", "]", ")", "||", "isset", "(", "$", "Arr", "[", "'UCS-4'", "]", ")", ")", "{", "foreach", "(", "$", "Arr", "as", "$", "Key", "=>", "$", "Value", ")", "{", "if", "(", "!", "preg_match", "(", "'~^(?:UTF|UCS|GB|BIG5|SHIFT-JIS|JOHAB)~'", ",", "$", "Key", ")", ")", "{", "unset", "(", "$", "Arr", "[", "$", "Key", "]", ")", ";", "}", "}", "}", "}" ]
Drop candidates belonging to encodings that are outdated subsets or variants of other encodings with valid candidates. @param array $Arr An array of potential candidates. @return array The input array, hopefully reduced, if possible.
[ "Drop", "candidates", "belonging", "to", "encodings", "that", "are", "outdated", "subsets", "or", "variants", "of", "other", "encodings", "with", "valid", "candidates", "." ]
949bdf1c3c13a6fa24774fb205c3fc6c701b5102
https://github.com/phpMussel/phpMussel/blob/949bdf1c3c13a6fa24774fb205c3fc6c701b5102/vault/classes/Maikuolan/Demojibakefier.php#L463-L495
train
phpMussel/phpMussel
vault/classes/Maikuolan/Demojibakefier.php
Demojibakefier.normalise
public function normalise($String) { $this->Last = ''; $this->Len = strlen($String); /** Potential valid candidates will be populated here. */ $Valid = []; /** Suppress errors (because every failed normalisation attempt will generate errors and fill logs otherwise). */ set_error_handler(function ($errno) { return; }); /** Cycle through supported encodings and attempt to generate valid candidates. */ foreach ($this->supported() as $Encoding) { if (!$this->checkConformity($String, $Encoding)) { continue; } $Attempt = iconv($Encoding, $this->NormaliseTo, $String); if ($Attempt === false || !$this->checkConformity($Attempt, $this->NormaliseTo)) { continue; } if (strcmp(iconv($this->NormaliseTo, $Encoding, $Attempt), $String) === 0) { $Valid[$Encoding] = $Attempt; if ($Encoding === $this->NormaliseTo) { break; } } } /** We're done.. Restore the error handler. */ restore_error_handler(); /** If the string conforms to our desired encoding, and can be reversed to it, we'll go with that. */ if (isset($Valid[$this->NormaliseTo])) { $this->Last = $this->NormaliseTo; return $Valid[$this->NormaliseTo]; } /** Okay.. Doesn't conform or can't be reversed. Time to apply weighting and some fuzzy heuristic guesswork. */ foreach ($Valid as $Key => $Value) { $Valid[$Key] = ['String' => $Value, 'Weight' => 0]; } $this->weigh($String, $Valid); /** Sort weights from highest to lowest and attempt to reduce candidates by the largest weight. */ uasort($Valid, function ($A, $B) { return $A['Weight'] === $B['Weight'] ? 0 : ($A['Weight'] < $B['Weight'] ? 1 : -1); }); $this->dropVariants($Valid); $Current = key($Valid); foreach ($Valid as $Key => $Value) { if ($Value['Weight'] < $Valid[$Current]['Weight']) { unset($Valid[$Key]); } } /** Check whether we can return a single possible value. */ if (($Count = count($Valid)) === 1) { $this->Last = $Current; return $Valid[$Current]['String']; } /** If we haven't decided on a particular candidate by this pointm we'll just give up and return the original string. */ return $String; }
php
public function normalise($String) { $this->Last = ''; $this->Len = strlen($String); /** Potential valid candidates will be populated here. */ $Valid = []; /** Suppress errors (because every failed normalisation attempt will generate errors and fill logs otherwise). */ set_error_handler(function ($errno) { return; }); /** Cycle through supported encodings and attempt to generate valid candidates. */ foreach ($this->supported() as $Encoding) { if (!$this->checkConformity($String, $Encoding)) { continue; } $Attempt = iconv($Encoding, $this->NormaliseTo, $String); if ($Attempt === false || !$this->checkConformity($Attempt, $this->NormaliseTo)) { continue; } if (strcmp(iconv($this->NormaliseTo, $Encoding, $Attempt), $String) === 0) { $Valid[$Encoding] = $Attempt; if ($Encoding === $this->NormaliseTo) { break; } } } /** We're done.. Restore the error handler. */ restore_error_handler(); /** If the string conforms to our desired encoding, and can be reversed to it, we'll go with that. */ if (isset($Valid[$this->NormaliseTo])) { $this->Last = $this->NormaliseTo; return $Valid[$this->NormaliseTo]; } /** Okay.. Doesn't conform or can't be reversed. Time to apply weighting and some fuzzy heuristic guesswork. */ foreach ($Valid as $Key => $Value) { $Valid[$Key] = ['String' => $Value, 'Weight' => 0]; } $this->weigh($String, $Valid); /** Sort weights from highest to lowest and attempt to reduce candidates by the largest weight. */ uasort($Valid, function ($A, $B) { return $A['Weight'] === $B['Weight'] ? 0 : ($A['Weight'] < $B['Weight'] ? 1 : -1); }); $this->dropVariants($Valid); $Current = key($Valid); foreach ($Valid as $Key => $Value) { if ($Value['Weight'] < $Valid[$Current]['Weight']) { unset($Valid[$Key]); } } /** Check whether we can return a single possible value. */ if (($Count = count($Valid)) === 1) { $this->Last = $Current; return $Valid[$Current]['String']; } /** If we haven't decided on a particular candidate by this pointm we'll just give up and return the original string. */ return $String; }
[ "public", "function", "normalise", "(", "$", "String", ")", "{", "$", "this", "->", "Last", "=", "''", ";", "$", "this", "->", "Len", "=", "strlen", "(", "$", "String", ")", ";", "/** Potential valid candidates will be populated here. */", "$", "Valid", "=", "[", "]", ";", "/** Suppress errors (because every failed normalisation attempt will generate errors and fill logs otherwise). */", "set_error_handler", "(", "function", "(", "$", "errno", ")", "{", "return", ";", "}", ")", ";", "/** Cycle through supported encodings and attempt to generate valid candidates. */", "foreach", "(", "$", "this", "->", "supported", "(", ")", "as", "$", "Encoding", ")", "{", "if", "(", "!", "$", "this", "->", "checkConformity", "(", "$", "String", ",", "$", "Encoding", ")", ")", "{", "continue", ";", "}", "$", "Attempt", "=", "iconv", "(", "$", "Encoding", ",", "$", "this", "->", "NormaliseTo", ",", "$", "String", ")", ";", "if", "(", "$", "Attempt", "===", "false", "||", "!", "$", "this", "->", "checkConformity", "(", "$", "Attempt", ",", "$", "this", "->", "NormaliseTo", ")", ")", "{", "continue", ";", "}", "if", "(", "strcmp", "(", "iconv", "(", "$", "this", "->", "NormaliseTo", ",", "$", "Encoding", ",", "$", "Attempt", ")", ",", "$", "String", ")", "===", "0", ")", "{", "$", "Valid", "[", "$", "Encoding", "]", "=", "$", "Attempt", ";", "if", "(", "$", "Encoding", "===", "$", "this", "->", "NormaliseTo", ")", "{", "break", ";", "}", "}", "}", "/** We're done.. Restore the error handler. */", "restore_error_handler", "(", ")", ";", "/** If the string conforms to our desired encoding, and can be reversed to it, we'll go with that. */", "if", "(", "isset", "(", "$", "Valid", "[", "$", "this", "->", "NormaliseTo", "]", ")", ")", "{", "$", "this", "->", "Last", "=", "$", "this", "->", "NormaliseTo", ";", "return", "$", "Valid", "[", "$", "this", "->", "NormaliseTo", "]", ";", "}", "/** Okay.. Doesn't conform or can't be reversed. Time to apply weighting and some fuzzy heuristic guesswork. */", "foreach", "(", "$", "Valid", "as", "$", "Key", "=>", "$", "Value", ")", "{", "$", "Valid", "[", "$", "Key", "]", "=", "[", "'String'", "=>", "$", "Value", ",", "'Weight'", "=>", "0", "]", ";", "}", "$", "this", "->", "weigh", "(", "$", "String", ",", "$", "Valid", ")", ";", "/** Sort weights from highest to lowest and attempt to reduce candidates by the largest weight. */", "uasort", "(", "$", "Valid", ",", "function", "(", "$", "A", ",", "$", "B", ")", "{", "return", "$", "A", "[", "'Weight'", "]", "===", "$", "B", "[", "'Weight'", "]", "?", "0", ":", "(", "$", "A", "[", "'Weight'", "]", "<", "$", "B", "[", "'Weight'", "]", "?", "1", ":", "-", "1", ")", ";", "}", ")", ";", "$", "this", "->", "dropVariants", "(", "$", "Valid", ")", ";", "$", "Current", "=", "key", "(", "$", "Valid", ")", ";", "foreach", "(", "$", "Valid", "as", "$", "Key", "=>", "$", "Value", ")", "{", "if", "(", "$", "Value", "[", "'Weight'", "]", "<", "$", "Valid", "[", "$", "Current", "]", "[", "'Weight'", "]", ")", "{", "unset", "(", "$", "Valid", "[", "$", "Key", "]", ")", ";", "}", "}", "/** Check whether we can return a single possible value. */", "if", "(", "(", "$", "Count", "=", "count", "(", "$", "Valid", ")", ")", "===", "1", ")", "{", "$", "this", "->", "Last", "=", "$", "Current", ";", "return", "$", "Valid", "[", "$", "Current", "]", "[", "'String'", "]", ";", "}", "/** If we haven't decided on a particular candidate by this pointm we'll just give up and return the original string. */", "return", "$", "String", ";", "}" ]
Attempts to normalise a string. @param string $String The string to normalise. @return string The normalised string (could be the same as the input, if there isn't anything to normalise).
[ "Attempts", "to", "normalise", "a", "string", "." ]
949bdf1c3c13a6fa24774fb205c3fc6c701b5102
https://github.com/phpMussel/phpMussel/blob/949bdf1c3c13a6fa24774fb205c3fc6c701b5102/vault/classes/Maikuolan/Demojibakefier.php#L530-L586
train
phpMussel/phpMussel
vault/classes/Maikuolan/Demojibakefier.php
Demojibakefier.guard
public function guard($String) { return !function_exists('iconv') || $this->checkConformity($String, $this->NormaliseTo) ? $String : $this->normalise($String); }
php
public function guard($String) { return !function_exists('iconv') || $this->checkConformity($String, $this->NormaliseTo) ? $String : $this->normalise($String); }
[ "public", "function", "guard", "(", "$", "String", ")", "{", "return", "!", "function_exists", "(", "'iconv'", ")", "||", "$", "this", "->", "checkConformity", "(", "$", "String", ",", "$", "this", "->", "NormaliseTo", ")", "?", "$", "String", ":", "$", "this", "->", "normalise", "(", "$", "String", ")", ";", "}" ]
Checks if the class requirements are met. If met, then calls checkConformity. If the string is non-conformant, then calls normalise. If the class requirements aren't met, or if the string is already conformant, return the original string immediately. @param string $String The string to normalise. @return string The normalised string (could be the same as the input, if there isn't anything to normalise).
[ "Checks", "if", "the", "class", "requirements", "are", "met", ".", "If", "met", "then", "calls", "checkConformity", ".", "If", "the", "string", "is", "non", "-", "conformant", "then", "calls", "normalise", ".", "If", "the", "class", "requirements", "aren", "t", "met", "or", "if", "the", "string", "is", "already", "conformant", "return", "the", "original", "string", "immediately", "." ]
949bdf1c3c13a6fa24774fb205c3fc6c701b5102
https://github.com/phpMussel/phpMussel/blob/949bdf1c3c13a6fa24774fb205c3fc6c701b5102/vault/classes/Maikuolan/Demojibakefier.php#L596-L599
train
phpMussel/phpMussel
vault/classes/Maikuolan/Cache.php
Cache.getEntry
public function getEntry($Entry) { if ($this->Using === 'APCu') { return $this->unserializeEntry(apcu_fetch($Entry)); } if ($this->Using === 'Memcached' || $this->Using === 'Redis') { return $this->unserializeEntry($this->WorkingData->get($Entry)); } if ($this->Using === 'PDO') { if ($this->clearExpiredPDO()) { $this->Modified = true; } $PDO = $this->WorkingData->prepare(self::getQuery); if ($PDO !== false && $PDO->execute(['key' => $Entry])) { $Data = $PDO->fetch(\PDO::FETCH_ASSOC); return isset($Data['Data']) ? $this->unserializeEntry($Data['Data']) : false; } return false; } if (is_array($this->WorkingData) && isset($this->WorkingData[$Entry])) { if (isset($this->WorkingData[$Entry]['Data']) && !empty($this->WorkingData[$Entry]['Time'])) { if ($this->WorkingData[$Entry]['Time'] <= 0 || $this->WorkingData[$Entry]['Time'] > time()) { return $this->unserializeEntry($this->WorkingData[$Entry]['Data']); } unset($this->WorkingData[$Entry]); $this->Modified = true; return false; } return $this->unserializeEntry($this->WorkingData[$Entry]); } return false; }
php
public function getEntry($Entry) { if ($this->Using === 'APCu') { return $this->unserializeEntry(apcu_fetch($Entry)); } if ($this->Using === 'Memcached' || $this->Using === 'Redis') { return $this->unserializeEntry($this->WorkingData->get($Entry)); } if ($this->Using === 'PDO') { if ($this->clearExpiredPDO()) { $this->Modified = true; } $PDO = $this->WorkingData->prepare(self::getQuery); if ($PDO !== false && $PDO->execute(['key' => $Entry])) { $Data = $PDO->fetch(\PDO::FETCH_ASSOC); return isset($Data['Data']) ? $this->unserializeEntry($Data['Data']) : false; } return false; } if (is_array($this->WorkingData) && isset($this->WorkingData[$Entry])) { if (isset($this->WorkingData[$Entry]['Data']) && !empty($this->WorkingData[$Entry]['Time'])) { if ($this->WorkingData[$Entry]['Time'] <= 0 || $this->WorkingData[$Entry]['Time'] > time()) { return $this->unserializeEntry($this->WorkingData[$Entry]['Data']); } unset($this->WorkingData[$Entry]); $this->Modified = true; return false; } return $this->unserializeEntry($this->WorkingData[$Entry]); } return false; }
[ "public", "function", "getEntry", "(", "$", "Entry", ")", "{", "if", "(", "$", "this", "->", "Using", "===", "'APCu'", ")", "{", "return", "$", "this", "->", "unserializeEntry", "(", "apcu_fetch", "(", "$", "Entry", ")", ")", ";", "}", "if", "(", "$", "this", "->", "Using", "===", "'Memcached'", "||", "$", "this", "->", "Using", "===", "'Redis'", ")", "{", "return", "$", "this", "->", "unserializeEntry", "(", "$", "this", "->", "WorkingData", "->", "get", "(", "$", "Entry", ")", ")", ";", "}", "if", "(", "$", "this", "->", "Using", "===", "'PDO'", ")", "{", "if", "(", "$", "this", "->", "clearExpiredPDO", "(", ")", ")", "{", "$", "this", "->", "Modified", "=", "true", ";", "}", "$", "PDO", "=", "$", "this", "->", "WorkingData", "->", "prepare", "(", "self", "::", "getQuery", ")", ";", "if", "(", "$", "PDO", "!==", "false", "&&", "$", "PDO", "->", "execute", "(", "[", "'key'", "=>", "$", "Entry", "]", ")", ")", "{", "$", "Data", "=", "$", "PDO", "->", "fetch", "(", "\\", "PDO", "::", "FETCH_ASSOC", ")", ";", "return", "isset", "(", "$", "Data", "[", "'Data'", "]", ")", "?", "$", "this", "->", "unserializeEntry", "(", "$", "Data", "[", "'Data'", "]", ")", ":", "false", ";", "}", "return", "false", ";", "}", "if", "(", "is_array", "(", "$", "this", "->", "WorkingData", ")", "&&", "isset", "(", "$", "this", "->", "WorkingData", "[", "$", "Entry", "]", ")", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "WorkingData", "[", "$", "Entry", "]", "[", "'Data'", "]", ")", "&&", "!", "empty", "(", "$", "this", "->", "WorkingData", "[", "$", "Entry", "]", "[", "'Time'", "]", ")", ")", "{", "if", "(", "$", "this", "->", "WorkingData", "[", "$", "Entry", "]", "[", "'Time'", "]", "<=", "0", "||", "$", "this", "->", "WorkingData", "[", "$", "Entry", "]", "[", "'Time'", "]", ">", "time", "(", ")", ")", "{", "return", "$", "this", "->", "unserializeEntry", "(", "$", "this", "->", "WorkingData", "[", "$", "Entry", "]", "[", "'Data'", "]", ")", ";", "}", "unset", "(", "$", "this", "->", "WorkingData", "[", "$", "Entry", "]", ")", ";", "$", "this", "->", "Modified", "=", "true", ";", "return", "false", ";", "}", "return", "$", "this", "->", "unserializeEntry", "(", "$", "this", "->", "WorkingData", "[", "$", "Entry", "]", ")", ";", "}", "return", "false", ";", "}" ]
Get a cache entry. @param string $Entry The name of the cache entry to get. @return mixed The retrieved cache entry, or false on failure (e.g., if the cache entry doesn't exist).
[ "Get", "a", "cache", "entry", "." ]
949bdf1c3c13a6fa24774fb205c3fc6c701b5102
https://github.com/phpMussel/phpMussel/blob/949bdf1c3c13a6fa24774fb205c3fc6c701b5102/vault/classes/Maikuolan/Cache.php#L258-L289
train
phpMussel/phpMussel
vault/classes/Maikuolan/Cache.php
Cache.setEntry
public function setEntry($Key, $Value, $TTL = 3600) { $Value = $this->serializeEntry($Value); if ($this->Using === 'APCu') { if (apcu_store($Key, $Value, $TTL)) { return $this->Modified = true; } return false; } if ($this->Using === 'Memcached') { if ($TTL >= 2592000) { $TTL += time(); } if ($this->WorkingData->set($Key, $Value, $TTL)) { return $this->Modified = true; } return false; } if ($this->Using === 'Redis') { if ($this->WorkingData->set($Key, $Value, $TTL)) { return $this->Modified = true; } return false; } if ($this->Using === 'PDO') { if ($TTL > 0) { $TTL += time(); } $PDO = $this->WorkingData->prepare(self::setQuery); if ($PDO !== false && $PDO->execute([ 'key' => $Key, 'data' => $Value, 'time' => $TTL, 'key2' => $Key, 'data2' => $Value, 'time2' => $TTL ])) { return ($PDO->rowCount() > 0 && $this->Modified = true); } return false; } if (is_array($this->WorkingData)) { if ($TTL > 0) { $TTL += time(); $this->WorkingData[$Key] = ['Data' => $Value, 'Time' => $TTL]; } else { $this->WorkingData[$Key] = $Value; } return $this->Modified = true; } return false; }
php
public function setEntry($Key, $Value, $TTL = 3600) { $Value = $this->serializeEntry($Value); if ($this->Using === 'APCu') { if (apcu_store($Key, $Value, $TTL)) { return $this->Modified = true; } return false; } if ($this->Using === 'Memcached') { if ($TTL >= 2592000) { $TTL += time(); } if ($this->WorkingData->set($Key, $Value, $TTL)) { return $this->Modified = true; } return false; } if ($this->Using === 'Redis') { if ($this->WorkingData->set($Key, $Value, $TTL)) { return $this->Modified = true; } return false; } if ($this->Using === 'PDO') { if ($TTL > 0) { $TTL += time(); } $PDO = $this->WorkingData->prepare(self::setQuery); if ($PDO !== false && $PDO->execute([ 'key' => $Key, 'data' => $Value, 'time' => $TTL, 'key2' => $Key, 'data2' => $Value, 'time2' => $TTL ])) { return ($PDO->rowCount() > 0 && $this->Modified = true); } return false; } if (is_array($this->WorkingData)) { if ($TTL > 0) { $TTL += time(); $this->WorkingData[$Key] = ['Data' => $Value, 'Time' => $TTL]; } else { $this->WorkingData[$Key] = $Value; } return $this->Modified = true; } return false; }
[ "public", "function", "setEntry", "(", "$", "Key", ",", "$", "Value", ",", "$", "TTL", "=", "3600", ")", "{", "$", "Value", "=", "$", "this", "->", "serializeEntry", "(", "$", "Value", ")", ";", "if", "(", "$", "this", "->", "Using", "===", "'APCu'", ")", "{", "if", "(", "apcu_store", "(", "$", "Key", ",", "$", "Value", ",", "$", "TTL", ")", ")", "{", "return", "$", "this", "->", "Modified", "=", "true", ";", "}", "return", "false", ";", "}", "if", "(", "$", "this", "->", "Using", "===", "'Memcached'", ")", "{", "if", "(", "$", "TTL", ">=", "2592000", ")", "{", "$", "TTL", "+=", "time", "(", ")", ";", "}", "if", "(", "$", "this", "->", "WorkingData", "->", "set", "(", "$", "Key", ",", "$", "Value", ",", "$", "TTL", ")", ")", "{", "return", "$", "this", "->", "Modified", "=", "true", ";", "}", "return", "false", ";", "}", "if", "(", "$", "this", "->", "Using", "===", "'Redis'", ")", "{", "if", "(", "$", "this", "->", "WorkingData", "->", "set", "(", "$", "Key", ",", "$", "Value", ",", "$", "TTL", ")", ")", "{", "return", "$", "this", "->", "Modified", "=", "true", ";", "}", "return", "false", ";", "}", "if", "(", "$", "this", "->", "Using", "===", "'PDO'", ")", "{", "if", "(", "$", "TTL", ">", "0", ")", "{", "$", "TTL", "+=", "time", "(", ")", ";", "}", "$", "PDO", "=", "$", "this", "->", "WorkingData", "->", "prepare", "(", "self", "::", "setQuery", ")", ";", "if", "(", "$", "PDO", "!==", "false", "&&", "$", "PDO", "->", "execute", "(", "[", "'key'", "=>", "$", "Key", ",", "'data'", "=>", "$", "Value", ",", "'time'", "=>", "$", "TTL", ",", "'key2'", "=>", "$", "Key", ",", "'data2'", "=>", "$", "Value", ",", "'time2'", "=>", "$", "TTL", "]", ")", ")", "{", "return", "(", "$", "PDO", "->", "rowCount", "(", ")", ">", "0", "&&", "$", "this", "->", "Modified", "=", "true", ")", ";", "}", "return", "false", ";", "}", "if", "(", "is_array", "(", "$", "this", "->", "WorkingData", ")", ")", "{", "if", "(", "$", "TTL", ">", "0", ")", "{", "$", "TTL", "+=", "time", "(", ")", ";", "$", "this", "->", "WorkingData", "[", "$", "Key", "]", "=", "[", "'Data'", "=>", "$", "Value", ",", "'Time'", "=>", "$", "TTL", "]", ";", "}", "else", "{", "$", "this", "->", "WorkingData", "[", "$", "Key", "]", "=", "$", "Value", ";", "}", "return", "$", "this", "->", "Modified", "=", "true", ";", "}", "return", "false", ";", "}" ]
Set a cache entry. @param string $Key The name of the cache entry to set. @param mixed $Value The value of the cache entry to get. @param int $TTL The number of seconds that the cache entry should persist. @return bool True on success; False on failure.
[ "Set", "a", "cache", "entry", "." ]
949bdf1c3c13a6fa24774fb205c3fc6c701b5102
https://github.com/phpMussel/phpMussel/blob/949bdf1c3c13a6fa24774fb205c3fc6c701b5102/vault/classes/Maikuolan/Cache.php#L299-L350
train
phpMussel/phpMussel
vault/classes/Maikuolan/Cache.php
Cache.deleteEntry
public function deleteEntry($Entry) { if ($this->Using === 'APCu') { if (apcu_delete($Entry)) { return $this->Modified = true; } return false; } if ($this->Using === 'Memcached' || $this->Using === 'Redis') { if ($this->WorkingData->delete($Entry)) { return $this->Modified = true; } return false; } if ($this->Using === 'PDO') { $PDO = $this->WorkingData->prepare(self::deleteQuery); if ($PDO !== false && $PDO->execute(['key' => $Entry])) { return ($PDO->rowCount() > 0 && $this->Modified = true); } return false; } if (is_array($this->WorkingData)) { if (isset($this->WorkingData[$Entry])) { unset($this->WorkingData[$Entry]); return $this->Modified = true; } } return false; }
php
public function deleteEntry($Entry) { if ($this->Using === 'APCu') { if (apcu_delete($Entry)) { return $this->Modified = true; } return false; } if ($this->Using === 'Memcached' || $this->Using === 'Redis') { if ($this->WorkingData->delete($Entry)) { return $this->Modified = true; } return false; } if ($this->Using === 'PDO') { $PDO = $this->WorkingData->prepare(self::deleteQuery); if ($PDO !== false && $PDO->execute(['key' => $Entry])) { return ($PDO->rowCount() > 0 && $this->Modified = true); } return false; } if (is_array($this->WorkingData)) { if (isset($this->WorkingData[$Entry])) { unset($this->WorkingData[$Entry]); return $this->Modified = true; } } return false; }
[ "public", "function", "deleteEntry", "(", "$", "Entry", ")", "{", "if", "(", "$", "this", "->", "Using", "===", "'APCu'", ")", "{", "if", "(", "apcu_delete", "(", "$", "Entry", ")", ")", "{", "return", "$", "this", "->", "Modified", "=", "true", ";", "}", "return", "false", ";", "}", "if", "(", "$", "this", "->", "Using", "===", "'Memcached'", "||", "$", "this", "->", "Using", "===", "'Redis'", ")", "{", "if", "(", "$", "this", "->", "WorkingData", "->", "delete", "(", "$", "Entry", ")", ")", "{", "return", "$", "this", "->", "Modified", "=", "true", ";", "}", "return", "false", ";", "}", "if", "(", "$", "this", "->", "Using", "===", "'PDO'", ")", "{", "$", "PDO", "=", "$", "this", "->", "WorkingData", "->", "prepare", "(", "self", "::", "deleteQuery", ")", ";", "if", "(", "$", "PDO", "!==", "false", "&&", "$", "PDO", "->", "execute", "(", "[", "'key'", "=>", "$", "Entry", "]", ")", ")", "{", "return", "(", "$", "PDO", "->", "rowCount", "(", ")", ">", "0", "&&", "$", "this", "->", "Modified", "=", "true", ")", ";", "}", "return", "false", ";", "}", "if", "(", "is_array", "(", "$", "this", "->", "WorkingData", ")", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "WorkingData", "[", "$", "Entry", "]", ")", ")", "{", "unset", "(", "$", "this", "->", "WorkingData", "[", "$", "Entry", "]", ")", ";", "return", "$", "this", "->", "Modified", "=", "true", ";", "}", "}", "return", "false", ";", "}" ]
Delete a specific cache entry. @param string $Entry The name of the cache entry to delete. @return bool True on success; False on failure.
[ "Delete", "a", "specific", "cache", "entry", "." ]
949bdf1c3c13a6fa24774fb205c3fc6c701b5102
https://github.com/phpMussel/phpMussel/blob/949bdf1c3c13a6fa24774fb205c3fc6c701b5102/vault/classes/Maikuolan/Cache.php#L358-L386
train
phpMussel/phpMussel
vault/classes/Maikuolan/Cache.php
Cache.clearCache
public function clearCache() { if ($this->Using === 'APCu') { return $this->Modified = apcu_clear_cache(); } if ($this->Using === 'Memcached') { return ($this->WorkingData->flush() && ($this->Modified = true)); } if ($this->Using === 'Redis') { return ($this->WorkingData->flushDb() && ($this->Modified = true)); } if ($this->Using === 'PDO') { $PDO = $this->WorkingData->prepare(self::clearQuery); if ($PDO !== false && $PDO->execute()) { return ($PDO->rowCount() > 0 && $this->Modified = true); } return false; } if (is_array($this->WorkingData)) { $this->WorkingData = []; return $this->Modified = true; } return false; }
php
public function clearCache() { if ($this->Using === 'APCu') { return $this->Modified = apcu_clear_cache(); } if ($this->Using === 'Memcached') { return ($this->WorkingData->flush() && ($this->Modified = true)); } if ($this->Using === 'Redis') { return ($this->WorkingData->flushDb() && ($this->Modified = true)); } if ($this->Using === 'PDO') { $PDO = $this->WorkingData->prepare(self::clearQuery); if ($PDO !== false && $PDO->execute()) { return ($PDO->rowCount() > 0 && $this->Modified = true); } return false; } if (is_array($this->WorkingData)) { $this->WorkingData = []; return $this->Modified = true; } return false; }
[ "public", "function", "clearCache", "(", ")", "{", "if", "(", "$", "this", "->", "Using", "===", "'APCu'", ")", "{", "return", "$", "this", "->", "Modified", "=", "apcu_clear_cache", "(", ")", ";", "}", "if", "(", "$", "this", "->", "Using", "===", "'Memcached'", ")", "{", "return", "(", "$", "this", "->", "WorkingData", "->", "flush", "(", ")", "&&", "(", "$", "this", "->", "Modified", "=", "true", ")", ")", ";", "}", "if", "(", "$", "this", "->", "Using", "===", "'Redis'", ")", "{", "return", "(", "$", "this", "->", "WorkingData", "->", "flushDb", "(", ")", "&&", "(", "$", "this", "->", "Modified", "=", "true", ")", ")", ";", "}", "if", "(", "$", "this", "->", "Using", "===", "'PDO'", ")", "{", "$", "PDO", "=", "$", "this", "->", "WorkingData", "->", "prepare", "(", "self", "::", "clearQuery", ")", ";", "if", "(", "$", "PDO", "!==", "false", "&&", "$", "PDO", "->", "execute", "(", ")", ")", "{", "return", "(", "$", "PDO", "->", "rowCount", "(", ")", ">", "0", "&&", "$", "this", "->", "Modified", "=", "true", ")", ";", "}", "return", "false", ";", "}", "if", "(", "is_array", "(", "$", "this", "->", "WorkingData", ")", ")", "{", "$", "this", "->", "WorkingData", "=", "[", "]", ";", "return", "$", "this", "->", "Modified", "=", "true", ";", "}", "return", "false", ";", "}" ]
Clears the entire cache. @return bool True on success; False on failure.
[ "Clears", "the", "entire", "cache", "." ]
949bdf1c3c13a6fa24774fb205c3fc6c701b5102
https://github.com/phpMussel/phpMussel/blob/949bdf1c3c13a6fa24774fb205c3fc6c701b5102/vault/classes/Maikuolan/Cache.php#L393-L416
train
phpMussel/phpMussel
vault/classes/Maikuolan/Cache.php
Cache.clearExpiredPDO
public function clearExpiredPDO() { if ($this->Using !== 'PDO') { return false; } $PDO = $this->WorkingData->prepare(self::clearExpiredQuery); if ($PDO !== false && $PDO->execute(['time' => time()])) { return ($PDO->rowCount() > 0); } return false; }
php
public function clearExpiredPDO() { if ($this->Using !== 'PDO') { return false; } $PDO = $this->WorkingData->prepare(self::clearExpiredQuery); if ($PDO !== false && $PDO->execute(['time' => time()])) { return ($PDO->rowCount() > 0); } return false; }
[ "public", "function", "clearExpiredPDO", "(", ")", "{", "if", "(", "$", "this", "->", "Using", "!==", "'PDO'", ")", "{", "return", "false", ";", "}", "$", "PDO", "=", "$", "this", "->", "WorkingData", "->", "prepare", "(", "self", "::", "clearExpiredQuery", ")", ";", "if", "(", "$", "PDO", "!==", "false", "&&", "$", "PDO", "->", "execute", "(", "[", "'time'", "=>", "time", "(", ")", "]", ")", ")", "{", "return", "(", "$", "PDO", "->", "rowCount", "(", ")", ">", "0", ")", ";", "}", "return", "false", ";", "}" ]
Clears expired entries stored via PDO. @return bool True if anything is cleared; False otherwise.
[ "Clears", "expired", "entries", "stored", "via", "PDO", "." ]
949bdf1c3c13a6fa24774fb205c3fc6c701b5102
https://github.com/phpMussel/phpMussel/blob/949bdf1c3c13a6fa24774fb205c3fc6c701b5102/vault/classes/Maikuolan/Cache.php#L544-L554
train
phpMussel/phpMussel
vault/classes/Maikuolan/Cache.php
Cache.unserializeEntry
public function unserializeEntry($Entry) { if (!$Entry || !is_string($Entry) || !preg_match('~^a\:\d+\:\{.*\}$~', $Entry)) { return $Entry; } $Arr = unserialize($Entry); if (is_array($Arr)) { $this->clearExpired($Arr); return $Arr; } return $Entry; }
php
public function unserializeEntry($Entry) { if (!$Entry || !is_string($Entry) || !preg_match('~^a\:\d+\:\{.*\}$~', $Entry)) { return $Entry; } $Arr = unserialize($Entry); if (is_array($Arr)) { $this->clearExpired($Arr); return $Arr; } return $Entry; }
[ "public", "function", "unserializeEntry", "(", "$", "Entry", ")", "{", "if", "(", "!", "$", "Entry", "||", "!", "is_string", "(", "$", "Entry", ")", "||", "!", "preg_match", "(", "'~^a\\:\\d+\\:\\{.*\\}$~'", ",", "$", "Entry", ")", ")", "{", "return", "$", "Entry", ";", "}", "$", "Arr", "=", "unserialize", "(", "$", "Entry", ")", ";", "if", "(", "is_array", "(", "$", "Arr", ")", ")", "{", "$", "this", "->", "clearExpired", "(", "$", "Arr", ")", ";", "return", "$", "Arr", ";", "}", "return", "$", "Entry", ";", "}" ]
Unserialize a returned cache entry if necessary. @param mixed $Entry The returned cache entry. @return mixed An unserialized array, if the returned cache entry is a serialized array, else the returned cache entry as verbatim.
[ "Unserialize", "a", "returned", "cache", "entry", "if", "necessary", "." ]
949bdf1c3c13a6fa24774fb205c3fc6c701b5102
https://github.com/phpMussel/phpMussel/blob/949bdf1c3c13a6fa24774fb205c3fc6c701b5102/vault/classes/Maikuolan/Cache.php#L563-L574
train
phpMussel/phpMussel
vault/classes/Maikuolan/ComplexStringHandler.php
ComplexStringHandler.generateMarkers
public function generateMarkers($Pattern) { preg_match_all($Pattern, $this->Input, $this->Markers, PREG_OFFSET_CAPTURE | PREG_SET_ORDER); $Start = 0; $this->Working = []; foreach ($this->Markers as $Marker) { if (!is_array($Marker[0]) || !isset($Marker[0][0]) || is_array($Marker[0][0]) || !isset($Marker[0][1])) { break; } $this->Working[] = substr($this->Input, $Start, $Marker[0][1] - $Start); $Start = $Marker[0][1] + strlen($Marker[0][0]); } $this->Working[] = substr($this->Input, $Start); }
php
public function generateMarkers($Pattern) { preg_match_all($Pattern, $this->Input, $this->Markers, PREG_OFFSET_CAPTURE | PREG_SET_ORDER); $Start = 0; $this->Working = []; foreach ($this->Markers as $Marker) { if (!is_array($Marker[0]) || !isset($Marker[0][0]) || is_array($Marker[0][0]) || !isset($Marker[0][1])) { break; } $this->Working[] = substr($this->Input, $Start, $Marker[0][1] - $Start); $Start = $Marker[0][1] + strlen($Marker[0][0]); } $this->Working[] = substr($this->Input, $Start); }
[ "public", "function", "generateMarkers", "(", "$", "Pattern", ")", "{", "preg_match_all", "(", "$", "Pattern", ",", "$", "this", "->", "Input", ",", "$", "this", "->", "Markers", ",", "PREG_OFFSET_CAPTURE", "|", "PREG_SET_ORDER", ")", ";", "$", "Start", "=", "0", ";", "$", "this", "->", "Working", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "Markers", "as", "$", "Marker", ")", "{", "if", "(", "!", "is_array", "(", "$", "Marker", "[", "0", "]", ")", "||", "!", "isset", "(", "$", "Marker", "[", "0", "]", "[", "0", "]", ")", "||", "is_array", "(", "$", "Marker", "[", "0", "]", "[", "0", "]", ")", "||", "!", "isset", "(", "$", "Marker", "[", "0", "]", "[", "1", "]", ")", ")", "{", "break", ";", "}", "$", "this", "->", "Working", "[", "]", "=", "substr", "(", "$", "this", "->", "Input", ",", "$", "Start", ",", "$", "Marker", "[", "0", "]", "[", "1", "]", "-", "$", "Start", ")", ";", "$", "Start", "=", "$", "Marker", "[", "0", "]", "[", "1", "]", "+", "strlen", "(", "$", "Marker", "[", "0", "]", "[", "0", "]", ")", ";", "}", "$", "this", "->", "Working", "[", "]", "=", "substr", "(", "$", "this", "->", "Input", ",", "$", "Start", ")", ";", "}" ]
Generate markers and working data. @param string $Pattern The pattern to use to generate the markers.
[ "Generate", "markers", "and", "working", "data", "." ]
949bdf1c3c13a6fa24774fb205c3fc6c701b5102
https://github.com/phpMussel/phpMussel/blob/949bdf1c3c13a6fa24774fb205c3fc6c701b5102/vault/classes/Maikuolan/ComplexStringHandler.php#L52-L65
train
phpMussel/phpMussel
vault/classes/Maikuolan/ComplexStringHandler.php
ComplexStringHandler.iterateClosure
public function iterateClosure($Closure, $Glue = false) { if (!is_callable($Closure) || empty($this->Input)) { return; } if (!$Glue) { foreach ($this->Working as &$Segment) { $Segment = $Closure($Segment); } return; } foreach ($this->Markers as &$Segment) { if (isset($Segment[0][0]) && !is_array($Segment[0][0])) { $Segment[0][0] = $Closure($Segment[0][0]); } } }
php
public function iterateClosure($Closure, $Glue = false) { if (!is_callable($Closure) || empty($this->Input)) { return; } if (!$Glue) { foreach ($this->Working as &$Segment) { $Segment = $Closure($Segment); } return; } foreach ($this->Markers as &$Segment) { if (isset($Segment[0][0]) && !is_array($Segment[0][0])) { $Segment[0][0] = $Closure($Segment[0][0]); } } }
[ "public", "function", "iterateClosure", "(", "$", "Closure", ",", "$", "Glue", "=", "false", ")", "{", "if", "(", "!", "is_callable", "(", "$", "Closure", ")", "||", "empty", "(", "$", "this", "->", "Input", ")", ")", "{", "return", ";", "}", "if", "(", "!", "$", "Glue", ")", "{", "foreach", "(", "$", "this", "->", "Working", "as", "&", "$", "Segment", ")", "{", "$", "Segment", "=", "$", "Closure", "(", "$", "Segment", ")", ";", "}", "return", ";", "}", "foreach", "(", "$", "this", "->", "Markers", "as", "&", "$", "Segment", ")", "{", "if", "(", "isset", "(", "$", "Segment", "[", "0", "]", "[", "0", "]", ")", "&&", "!", "is_array", "(", "$", "Segment", "[", "0", "]", "[", "0", "]", ")", ")", "{", "$", "Segment", "[", "0", "]", "[", "0", "]", "=", "$", "Closure", "(", "$", "Segment", "[", "0", "]", "[", "0", "]", ")", ";", "}", "}", "}" ]
Iterate over the working data using a given closure. @param callable $Closure @param bool $Glue Whether to work on the markers or the working data.
[ "Iterate", "over", "the", "working", "data", "using", "a", "given", "closure", "." ]
949bdf1c3c13a6fa24774fb205c3fc6c701b5102
https://github.com/phpMussel/phpMussel/blob/949bdf1c3c13a6fa24774fb205c3fc6c701b5102/vault/classes/Maikuolan/ComplexStringHandler.php#L73-L89
train
phpMussel/phpMussel
vault/classes/Maikuolan/ComplexStringHandler.php
ComplexStringHandler.recompile
public function recompile() { $Output = ''; $Glue = 0; foreach ($this->Working as $Segment) { $Output .= $Segment; if (isset($this->Markers[$Glue][0][0]) && !is_array($this->Markers[$Glue][0][0])) { $Output .= $this->Markers[$Glue][0][0]; $Glue++; } } return $Output; }
php
public function recompile() { $Output = ''; $Glue = 0; foreach ($this->Working as $Segment) { $Output .= $Segment; if (isset($this->Markers[$Glue][0][0]) && !is_array($this->Markers[$Glue][0][0])) { $Output .= $this->Markers[$Glue][0][0]; $Glue++; } } return $Output; }
[ "public", "function", "recompile", "(", ")", "{", "$", "Output", "=", "''", ";", "$", "Glue", "=", "0", ";", "foreach", "(", "$", "this", "->", "Working", "as", "$", "Segment", ")", "{", "$", "Output", ".=", "$", "Segment", ";", "if", "(", "isset", "(", "$", "this", "->", "Markers", "[", "$", "Glue", "]", "[", "0", "]", "[", "0", "]", ")", "&&", "!", "is_array", "(", "$", "this", "->", "Markers", "[", "$", "Glue", "]", "[", "0", "]", "[", "0", "]", ")", ")", "{", "$", "Output", ".=", "$", "this", "->", "Markers", "[", "$", "Glue", "]", "[", "0", "]", "[", "0", "]", ";", "$", "Glue", "++", ";", "}", "}", "return", "$", "Output", ";", "}" ]
Recompile all data after all work has finished and return it.
[ "Recompile", "all", "data", "after", "all", "work", "has", "finished", "and", "return", "it", "." ]
949bdf1c3c13a6fa24774fb205c3fc6c701b5102
https://github.com/phpMussel/phpMussel/blob/949bdf1c3c13a6fa24774fb205c3fc6c701b5102/vault/classes/Maikuolan/ComplexStringHandler.php#L92-L104
train