id
int32
0
241k
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
45,300
xibosignage/oauth2-xibo-cms
src/Entity/XiboLayout.php
XiboLayout.getByTemplateId
public function getByTemplateId($id) { $this->getLogger()->info('Getting template ID ' . $this->templateId); $response = $this->doGet('/template', [ 'templateId' => $id ]); if (count($response) <= 0) throw new XiboApiException('Expecting a single record, found ' . count($response)); $this->getLogger()->debug('Passing the response to Hydrate'); return $this->hydrate($response[0]); }
php
public function getByTemplateId($id) { $this->getLogger()->info('Getting template ID ' . $this->templateId); $response = $this->doGet('/template', [ 'templateId' => $id ]); if (count($response) <= 0) throw new XiboApiException('Expecting a single record, found ' . count($response)); $this->getLogger()->debug('Passing the response to Hydrate'); return $this->hydrate($response[0]); }
[ "public", "function", "getByTemplateId", "(", "$", "id", ")", "{", "$", "this", "->", "getLogger", "(", ")", "->", "info", "(", "'Getting template ID '", ".", "$", "this", "->", "templateId", ")", ";", "$", "response", "=", "$", "this", "->", "doGet", ...
Get the template by ID @param int $id template ID @return XiboLayout @throws XiboApiException
[ "Get", "the", "template", "by", "ID" ]
8e6ddb4be070257233c225f8829b8117f9d978c3
https://github.com/xibosignage/oauth2-xibo-cms/blob/8e6ddb4be070257233c225f8829b8117f9d978c3/src/Entity/XiboLayout.php#L463-L475
45,301
xibosignage/oauth2-xibo-cms
src/Entity/XiboLayout.php
XiboLayout.createTemplate
public function createTemplate($layoutId, $includeWidgets, $name, $tags, $description) { $this->userId = $this->getEntityProvider()->getMe()->getId(); $this->layoutId = $layoutId; $this->includeWidgets = $includeWidgets; $this->name = $name; $this->tags = $tags; $this->description = $description; $this->getLogger()->info('Creating Template ' . $name . ' from layout ID ' . $layoutId); $response = $this->doPost('/template/' . $layoutId, $this->toArray()); return $this->hydrate($response); }
php
public function createTemplate($layoutId, $includeWidgets, $name, $tags, $description) { $this->userId = $this->getEntityProvider()->getMe()->getId(); $this->layoutId = $layoutId; $this->includeWidgets = $includeWidgets; $this->name = $name; $this->tags = $tags; $this->description = $description; $this->getLogger()->info('Creating Template ' . $name . ' from layout ID ' . $layoutId); $response = $this->doPost('/template/' . $layoutId, $this->toArray()); return $this->hydrate($response); }
[ "public", "function", "createTemplate", "(", "$", "layoutId", ",", "$", "includeWidgets", ",", "$", "name", ",", "$", "tags", ",", "$", "description", ")", "{", "$", "this", "->", "userId", "=", "$", "this", "->", "getEntityProvider", "(", ")", "->", "...
Create Template from provided layout ID. @param int $layoutId The layout ID to create a template from @param int $includeWidgets Flag indicating whether to include widgets in the template @param string $name name of the template @param string $tags comma separeted list of tags for the template @param string $description description of the template @return XiboLayout
[ "Create", "Template", "from", "provided", "layout", "ID", "." ]
8e6ddb4be070257233c225f8829b8117f9d978c3
https://github.com/xibosignage/oauth2-xibo-cms/blob/8e6ddb4be070257233c225f8829b8117f9d978c3/src/Entity/XiboLayout.php#L487-L499
45,302
xibosignage/oauth2-xibo-cms
src/Entity/XiboLayout.php
XiboLayout.addTag
public function addTag($tag) { $this->tag = $tag; $this->getLogger()->info('Adding tag: ' . $tag . ' to layout ID ' . $this->layoutId); $response = $this->doPost('/layout/' . $this->layoutId . '/tag', [ 'tag' => [$tag] ]); $tags = $this->hydrate($response); foreach ($response['tags'] as $item) { $tag = new XiboLayout($this->getEntityProvider()); $tag->hydrate($item); $tags->tags[] = $tag; } return $this; }
php
public function addTag($tag) { $this->tag = $tag; $this->getLogger()->info('Adding tag: ' . $tag . ' to layout ID ' . $this->layoutId); $response = $this->doPost('/layout/' . $this->layoutId . '/tag', [ 'tag' => [$tag] ]); $tags = $this->hydrate($response); foreach ($response['tags'] as $item) { $tag = new XiboLayout($this->getEntityProvider()); $tag->hydrate($item); $tags->tags[] = $tag; } return $this; }
[ "public", "function", "addTag", "(", "$", "tag", ")", "{", "$", "this", "->", "tag", "=", "$", "tag", ";", "$", "this", "->", "getLogger", "(", ")", "->", "info", "(", "'Adding tag: '", ".", "$", "tag", ".", "' to layout ID '", ".", "$", "this", "-...
Add tag. Adds specified tag to the specified layout @param string $tag name of the tag to add @return XiboLayout
[ "Add", "tag", ".", "Adds", "specified", "tag", "to", "the", "specified", "layout" ]
8e6ddb4be070257233c225f8829b8117f9d978c3
https://github.com/xibosignage/oauth2-xibo-cms/blob/8e6ddb4be070257233c225f8829b8117f9d978c3/src/Entity/XiboLayout.php#L508-L522
45,303
xibosignage/oauth2-xibo-cms
src/Entity/XiboLayout.php
XiboLayout.removeTag
public function removeTag($tag) { $this->tag = $tag; $this->getLogger()->info('Removing tag: ' . $tag . ' from layout ID ' . $this->layoutId); $this->doPost('/layout/' . $this->layoutId . '/untag', [ 'tag' => [$tag] ]); return $this; }
php
public function removeTag($tag) { $this->tag = $tag; $this->getLogger()->info('Removing tag: ' . $tag . ' from layout ID ' . $this->layoutId); $this->doPost('/layout/' . $this->layoutId . '/untag', [ 'tag' => [$tag] ]); return $this; }
[ "public", "function", "removeTag", "(", "$", "tag", ")", "{", "$", "this", "->", "tag", "=", "$", "tag", ";", "$", "this", "->", "getLogger", "(", ")", "->", "info", "(", "'Removing tag: '", ".", "$", "tag", ".", "' from layout ID '", ".", "$", "this...
Remove tag. Removes specified tag from the specified layout @param string $tag name of the taf to remove @return XiboLayout
[ "Remove", "tag", ".", "Removes", "specified", "tag", "from", "the", "specified", "layout" ]
8e6ddb4be070257233c225f8829b8117f9d978c3
https://github.com/xibosignage/oauth2-xibo-cms/blob/8e6ddb4be070257233c225f8829b8117f9d978c3/src/Entity/XiboLayout.php#L530-L539
45,304
xibosignage/oauth2-xibo-cms
src/Entity/XiboLayout.php
XiboLayout.getStatus
public function getStatus() { $this->getLogger()->info('Getting status for layout ID ' . $this->layoutId); $response = $this->doGet('/layout/status/' . $this->layoutId); if (count($response) <= 0) throw new XiboApiException('Expecting a single record, found ' . count($response)); $this->getLogger()->debug('Passing the response to Hydrate'); return $this->hydrate($response); }
php
public function getStatus() { $this->getLogger()->info('Getting status for layout ID ' . $this->layoutId); $response = $this->doGet('/layout/status/' . $this->layoutId); if (count($response) <= 0) throw new XiboApiException('Expecting a single record, found ' . count($response)); $this->getLogger()->debug('Passing the response to Hydrate'); return $this->hydrate($response); }
[ "public", "function", "getStatus", "(", ")", "{", "$", "this", "->", "getLogger", "(", ")", "->", "info", "(", "'Getting status for layout ID '", ".", "$", "this", "->", "layoutId", ")", ";", "$", "response", "=", "$", "this", "->", "doGet", "(", "'/layo...
Get Layout status. @param int layoutId The ID of the layout to get the status @return XiboLayout @throws XiboApiException
[ "Get", "Layout", "status", "." ]
8e6ddb4be070257233c225f8829b8117f9d978c3
https://github.com/xibosignage/oauth2-xibo-cms/blob/8e6ddb4be070257233c225f8829b8117f9d978c3/src/Entity/XiboLayout.php#L549-L559
45,305
xibosignage/oauth2-xibo-cms
src/Entity/XiboLayout.php
XiboLayout.checkout
public function checkout($layoutId) { $this->getLogger()->info('Checking out layout ID ' . $layoutId); $response = $this->doPut('/layout/checkout/' . $layoutId); $layout = $this->constructLayoutFromResponse($response); $this->getLogger()->info('LayoutId is now: ' . $layout->layoutId); return $layout; }
php
public function checkout($layoutId) { $this->getLogger()->info('Checking out layout ID ' . $layoutId); $response = $this->doPut('/layout/checkout/' . $layoutId); $layout = $this->constructLayoutFromResponse($response); $this->getLogger()->info('LayoutId is now: ' . $layout->layoutId); return $layout; }
[ "public", "function", "checkout", "(", "$", "layoutId", ")", "{", "$", "this", "->", "getLogger", "(", ")", "->", "info", "(", "'Checking out layout ID '", ".", "$", "layoutId", ")", ";", "$", "response", "=", "$", "this", "->", "doPut", "(", "'/layout/c...
Checkout a layout @param int layoutId The ID of the layout to checkout @return XiboLayout
[ "Checkout", "a", "layout" ]
8e6ddb4be070257233c225f8829b8117f9d978c3
https://github.com/xibosignage/oauth2-xibo-cms/blob/8e6ddb4be070257233c225f8829b8117f9d978c3/src/Entity/XiboLayout.php#L566-L576
45,306
xibosignage/oauth2-xibo-cms
src/Entity/XiboLayout.php
XiboLayout.discard
public function discard($layoutId) { $this->getLogger()->info('Discarding draft of layout ID ' . $layoutId); $response = $this->doPut('/layout/discard/' . $layoutId); $layout = $this->constructLayoutFromResponse($response); $this->getLogger()->debug('LayoutId is now: ' . $layout->layoutId); return $layout; }
php
public function discard($layoutId) { $this->getLogger()->info('Discarding draft of layout ID ' . $layoutId); $response = $this->doPut('/layout/discard/' . $layoutId); $layout = $this->constructLayoutFromResponse($response); $this->getLogger()->debug('LayoutId is now: ' . $layout->layoutId); return $layout; }
[ "public", "function", "discard", "(", "$", "layoutId", ")", "{", "$", "this", "->", "getLogger", "(", ")", "->", "info", "(", "'Discarding draft of layout ID '", ".", "$", "layoutId", ")", ";", "$", "response", "=", "$", "this", "->", "doPut", "(", "'/la...
Discard a layouts draft @param int layoutId The ID of the layout to checkout @return XiboLayout
[ "Discard", "a", "layouts", "draft" ]
8e6ddb4be070257233c225f8829b8117f9d978c3
https://github.com/xibosignage/oauth2-xibo-cms/blob/8e6ddb4be070257233c225f8829b8117f9d978c3/src/Entity/XiboLayout.php#L600-L610
45,307
seatgeek/djjob
DJJob.php
DJBase.getConnection
protected static function getConnection() { if (self::$db === null) { try { self::$db = new PDO(self::$dsn, self::$user, self::$password); self::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { throw new Exception("DJJob couldn't connect to the database. PDO said [{$e->getMessage()}]"); } } return self::$db; }
php
protected static function getConnection() { if (self::$db === null) { try { self::$db = new PDO(self::$dsn, self::$user, self::$password); self::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { throw new Exception("DJJob couldn't connect to the database. PDO said [{$e->getMessage()}]"); } } return self::$db; }
[ "protected", "static", "function", "getConnection", "(", ")", "{", "if", "(", "self", "::", "$", "db", "===", "null", ")", "{", "try", "{", "self", "::", "$", "db", "=", "new", "PDO", "(", "self", "::", "$", "dsn", ",", "self", "::", "$", "user",...
Returns the connection DJBase knows about. Tries to connect if no connection is present. @return null|PDO The connection if a valid connection is present. @throws Exception
[ "Returns", "the", "connection", "DJBase", "knows", "about", "." ]
bc83642f9e28cf06bbadcd783d3d5ae1162c714b
https://github.com/seatgeek/djjob/blob/bc83642f9e28cf06bbadcd783d3d5ae1162c714b/DJJob.php#L203-L213
45,308
seatgeek/djjob
DJJob.php
DJBase.runQuery
public static function runQuery($sql, $params = array()) { for ($attempts = 0; $attempts < self::$retries; $attempts++) { try { $stmt = self::getConnection()->prepare($sql); $stmt->execute($params); $ret = array(); if ($stmt->rowCount()) { // calling fetchAll on a result set with no rows throws a // "general error" exception foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $r) $ret []= $r; } $stmt->closeCursor(); return $ret; } catch (PDOException $e) { // Catch "MySQL server has gone away" error. if ($e->errorInfo[1] == 2006) { self::$db = null; } // Throw all other errors as expected. else { throw $e; } } } throw new DJException("DJJob exhausted retries connecting to database"); }
php
public static function runQuery($sql, $params = array()) { for ($attempts = 0; $attempts < self::$retries; $attempts++) { try { $stmt = self::getConnection()->prepare($sql); $stmt->execute($params); $ret = array(); if ($stmt->rowCount()) { // calling fetchAll on a result set with no rows throws a // "general error" exception foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $r) $ret []= $r; } $stmt->closeCursor(); return $ret; } catch (PDOException $e) { // Catch "MySQL server has gone away" error. if ($e->errorInfo[1] == 2006) { self::$db = null; } // Throw all other errors as expected. else { throw $e; } } } throw new DJException("DJJob exhausted retries connecting to database"); }
[ "public", "static", "function", "runQuery", "(", "$", "sql", ",", "$", "params", "=", "array", "(", ")", ")", "{", "for", "(", "$", "attempts", "=", "0", ";", "$", "attempts", "<", "self", "::", "$", "retries", ";", "$", "attempts", "++", ")", "{...
Runs a query with a resultset against the database. @param string $sql The query to execute. @param array $params The params necessary for a prepared statement. @return array Returns the complete resultset. @throws DJException Throws if the query couldn't be executed.
[ "Runs", "a", "query", "with", "a", "resultset", "against", "the", "database", "." ]
bc83642f9e28cf06bbadcd783d3d5ae1162c714b
https://github.com/seatgeek/djjob/blob/bc83642f9e28cf06bbadcd783d3d5ae1162c714b/DJJob.php#L224-L253
45,309
seatgeek/djjob
DJJob.php
DJBase.runUpdate
public static function runUpdate($sql, $params = array()) { for ($attempts = 0; $attempts < self::$retries; $attempts++) { try { $stmt = self::getConnection()->prepare($sql); $stmt->execute($params); return $stmt->rowCount(); } catch (PDOException $e) { // Catch "MySQL server has gone away" error. if ($e->errorInfo[1] == 2006) { self::$db = null; } // Throw all other errors as expected. else { throw $e; } } } throw new DJException("DJJob exhausted retries connecting to database"); }
php
public static function runUpdate($sql, $params = array()) { for ($attempts = 0; $attempts < self::$retries; $attempts++) { try { $stmt = self::getConnection()->prepare($sql); $stmt->execute($params); return $stmt->rowCount(); } catch (PDOException $e) { // Catch "MySQL server has gone away" error. if ($e->errorInfo[1] == 2006) { self::$db = null; } // Throw all other errors as expected. else { throw $e; } } } throw new DJException("DJJob exhausted retries connecting to database"); }
[ "public", "static", "function", "runUpdate", "(", "$", "sql", ",", "$", "params", "=", "array", "(", ")", ")", "{", "for", "(", "$", "attempts", "=", "0", ";", "$", "attempts", "<", "self", "::", "$", "retries", ";", "$", "attempts", "++", ")", "...
Runs an update query against the database. @param string $sql The query to execute. @param array $params The params necessary for the prepared statement. @return int The amount of affected rows. @throws DJException Throws if the query couldn't be executed.
[ "Runs", "an", "update", "query", "against", "the", "database", "." ]
bc83642f9e28cf06bbadcd783d3d5ae1162c714b
https://github.com/seatgeek/djjob/blob/bc83642f9e28cf06bbadcd783d3d5ae1162c714b/DJJob.php#L264-L284
45,310
seatgeek/djjob
DJJob.php
DJBase.log
protected static function log($mesg, $severity=self::CRITICAL) { if ($severity >= self::$log_level) { printf("[%s] %s\n", date('c'), $mesg); } }
php
protected static function log($mesg, $severity=self::CRITICAL) { if ($severity >= self::$log_level) { printf("[%s] %s\n", date('c'), $mesg); } }
[ "protected", "static", "function", "log", "(", "$", "mesg", ",", "$", "severity", "=", "self", "::", "CRITICAL", ")", "{", "if", "(", "$", "severity", ">=", "self", "::", "$", "log_level", ")", "{", "printf", "(", "\"[%s] %s\\n\"", ",", "date", "(", ...
Logs a message to the output. @param string $mesg The message to log. @param int $severity The log level necessary for this message to display.
[ "Logs", "a", "message", "to", "the", "output", "." ]
bc83642f9e28cf06bbadcd783d3d5ae1162c714b
https://github.com/seatgeek/djjob/blob/bc83642f9e28cf06bbadcd783d3d5ae1162c714b/DJJob.php#L292-L296
45,311
seatgeek/djjob
DJJob.php
DJWorker.handleSignal
public function handleSignal($signo) { $signals = array( SIGTERM => "SIGTERM", SIGINT => "SIGINT" ); $signal = $signals[$signo]; $this->log("[WORKER] Received received {$signal}... Shutting down", self::INFO); $this->releaseLocks(); die(0); }
php
public function handleSignal($signo) { $signals = array( SIGTERM => "SIGTERM", SIGINT => "SIGINT" ); $signal = $signals[$signo]; $this->log("[WORKER] Received received {$signal}... Shutting down", self::INFO); $this->releaseLocks(); die(0); }
[ "public", "function", "handleSignal", "(", "$", "signo", ")", "{", "$", "signals", "=", "array", "(", "SIGTERM", "=>", "\"SIGTERM\"", ",", "SIGINT", "=>", "\"SIGINT\"", ")", ";", "$", "signal", "=", "$", "signals", "[", "$", "signo", "]", ";", "$", "...
Handles a signal from the operating system. @param string $signo The signal received from the OS.
[ "Handles", "a", "signal", "from", "the", "operating", "system", "." ]
bc83642f9e28cf06bbadcd783d3d5ae1162c714b
https://github.com/seatgeek/djjob/blob/bc83642f9e28cf06bbadcd783d3d5ae1162c714b/DJJob.php#L343-L353
45,312
seatgeek/djjob
DJJob.php
DJWorker.getNewJob
public function getNewJob() { # we can grab a locked job if we own the lock $rs = $this->runQuery(" SELECT id FROM " . self::$jobsTable . " WHERE queue = ? AND (run_at IS NULL OR NOW() >= run_at) AND (locked_at IS NULL OR locked_by = ?) AND failed_at IS NULL AND attempts < ? ORDER BY created_at DESC LIMIT 10 ", array($this->queue, $this->name, $this->max_attempts)); // randomly order the 10 to prevent lock contention among workers shuffle($rs); foreach ($rs as $r) { $job = new DJJob($this->name, $r["id"], array( "max_attempts" => $this->max_attempts, "fail_on_output" => $this->fail_on_output )); if ($job->acquireLock()) return $job; } return false; }
php
public function getNewJob() { # we can grab a locked job if we own the lock $rs = $this->runQuery(" SELECT id FROM " . self::$jobsTable . " WHERE queue = ? AND (run_at IS NULL OR NOW() >= run_at) AND (locked_at IS NULL OR locked_by = ?) AND failed_at IS NULL AND attempts < ? ORDER BY created_at DESC LIMIT 10 ", array($this->queue, $this->name, $this->max_attempts)); // randomly order the 10 to prevent lock contention among workers shuffle($rs); foreach ($rs as $r) { $job = new DJJob($this->name, $r["id"], array( "max_attempts" => $this->max_attempts, "fail_on_output" => $this->fail_on_output )); if ($job->acquireLock()) return $job; } return false; }
[ "public", "function", "getNewJob", "(", ")", "{", "# we can grab a locked job if we own the lock", "$", "rs", "=", "$", "this", "->", "runQuery", "(", "\"\n SELECT id\n FROM \"", ".", "self", "::", "$", "jobsTable", ".", "\"\n WHERE que...
Returns a new job ordered by most recent first why this? run newest first, some jobs get left behind run oldest first, all jobs get left behind @return \DJJob|false A job if one was successfully locked. Otherwise false.
[ "Returns", "a", "new", "job", "ordered", "by", "most", "recent", "first", "why", "this?", "run", "newest", "first", "some", "jobs", "get", "left", "behind", "run", "oldest", "first", "all", "jobs", "get", "left", "behind" ]
bc83642f9e28cf06bbadcd783d3d5ae1162c714b
https://github.com/seatgeek/djjob/blob/bc83642f9e28cf06bbadcd783d3d5ae1162c714b/DJJob.php#L375-L401
45,313
seatgeek/djjob
DJJob.php
DJWorker.start
public function start() { $this->log("[JOB] Starting worker {$this->name} on queue::{$this->queue}", self::INFO); $count = 0; $job_count = 0; try { while ($this->count == 0 || $count < $this->count) { if (function_exists("pcntl_signal_dispatch")) pcntl_signal_dispatch(); $count += 1; $job = $this->getNewJob($this->queue); if (!$job) { $this->log("[JOB] Failed to get a job, queue::{$this->queue} may be empty", self::DEBUG); sleep($this->sleep); continue; } $job_count += 1; $job->run(); } } catch (Exception $e) { $this->log("[JOB] unhandled exception::\"{$e->getMessage()}\"", self::ERROR); } $this->log("[JOB] worker shutting down after running {$job_count} jobs, over {$count} polling iterations", self::INFO); }
php
public function start() { $this->log("[JOB] Starting worker {$this->name} on queue::{$this->queue}", self::INFO); $count = 0; $job_count = 0; try { while ($this->count == 0 || $count < $this->count) { if (function_exists("pcntl_signal_dispatch")) pcntl_signal_dispatch(); $count += 1; $job = $this->getNewJob($this->queue); if (!$job) { $this->log("[JOB] Failed to get a job, queue::{$this->queue} may be empty", self::DEBUG); sleep($this->sleep); continue; } $job_count += 1; $job->run(); } } catch (Exception $e) { $this->log("[JOB] unhandled exception::\"{$e->getMessage()}\"", self::ERROR); } $this->log("[JOB] worker shutting down after running {$job_count} jobs, over {$count} polling iterations", self::INFO); }
[ "public", "function", "start", "(", ")", "{", "$", "this", "->", "log", "(", "\"[JOB] Starting worker {$this->name} on queue::{$this->queue}\"", ",", "self", "::", "INFO", ")", ";", "$", "count", "=", "0", ";", "$", "job_count", "=", "0", ";", "try", "{", ...
Starts the worker process.
[ "Starts", "the", "worker", "process", "." ]
bc83642f9e28cf06bbadcd783d3d5ae1162c714b
https://github.com/seatgeek/djjob/blob/bc83642f9e28cf06bbadcd783d3d5ae1162c714b/DJJob.php#L406-L432
45,314
seatgeek/djjob
DJJob.php
DJJob.run
public function run() { # pull the handler from the db $handler = $this->getHandler(); if (!is_object($handler)) { $msg = "[JOB] bad handler for job::{$this->job_id}"; $this->finishWithError($msg); return false; } # run the handler try { if ($this->fail_on_output) { ob_start(); } $handler->perform(); if ($this->fail_on_output) { $output = ob_get_contents(); ob_end_clean(); if (!empty($output)) { throw new Exception("Job produced unexpected output: $output"); } } # cleanup $this->finish(); return true; } catch (DJRetryException $e) { if ($this->fail_on_output) { ob_end_flush(); } # attempts hasn't been incremented yet. $attempts = $this->getAttempts()+1; $msg = "Caught DJRetryException \"{$e->getMessage()}\" on attempt $attempts/{$this->max_attempts}."; if($attempts == $this->max_attempts) { $msg = "[JOB] job::{$this->job_id} $msg Giving up."; $this->finishWithError($msg, $handler); } else { $this->log("[JOB] job::{$this->job_id} $msg Try again in {$e->getDelay()} seconds.", self::WARN); $this->retryLater($e->getDelay()); } return false; } catch (Exception $e) { if ($this->fail_on_output) { ob_end_flush(); } $this->finishWithError($e->getMessage(), $handler); return false; } }
php
public function run() { # pull the handler from the db $handler = $this->getHandler(); if (!is_object($handler)) { $msg = "[JOB] bad handler for job::{$this->job_id}"; $this->finishWithError($msg); return false; } # run the handler try { if ($this->fail_on_output) { ob_start(); } $handler->perform(); if ($this->fail_on_output) { $output = ob_get_contents(); ob_end_clean(); if (!empty($output)) { throw new Exception("Job produced unexpected output: $output"); } } # cleanup $this->finish(); return true; } catch (DJRetryException $e) { if ($this->fail_on_output) { ob_end_flush(); } # attempts hasn't been incremented yet. $attempts = $this->getAttempts()+1; $msg = "Caught DJRetryException \"{$e->getMessage()}\" on attempt $attempts/{$this->max_attempts}."; if($attempts == $this->max_attempts) { $msg = "[JOB] job::{$this->job_id} $msg Giving up."; $this->finishWithError($msg, $handler); } else { $this->log("[JOB] job::{$this->job_id} $msg Try again in {$e->getDelay()} seconds.", self::WARN); $this->retryLater($e->getDelay()); } return false; } catch (Exception $e) { if ($this->fail_on_output) { ob_end_flush(); } $this->finishWithError($e->getMessage(), $handler); return false; } }
[ "public", "function", "run", "(", ")", "{", "# pull the handler from the db", "$", "handler", "=", "$", "this", "->", "getHandler", "(", ")", ";", "if", "(", "!", "is_object", "(", "$", "handler", ")", ")", "{", "$", "msg", "=", "\"[JOB] bad handler for jo...
Runs this job. First retrieves the handler fro the database. Then perform the job. @return bool Whether or not the job succeeded.
[ "Runs", "this", "job", "." ]
bc83642f9e28cf06bbadcd783d3d5ae1162c714b
https://github.com/seatgeek/djjob/blob/bc83642f9e28cf06bbadcd783d3d5ae1162c714b/DJJob.php#L469-L528
45,315
seatgeek/djjob
DJJob.php
DJJob.acquireLock
public function acquireLock() { $this->log("[JOB] attempting to acquire lock for job::{$this->job_id} on {$this->worker_name}", self::INFO); $lock = $this->runUpdate(" UPDATE " . self::$jobsTable . " SET locked_at = NOW(), locked_by = ? WHERE id = ? AND (locked_at IS NULL OR locked_by = ?) AND failed_at IS NULL ", array($this->worker_name, $this->job_id, $this->worker_name)); if (!$lock) { $this->log("[JOB] failed to acquire lock for job::{$this->job_id}", self::INFO); return false; } return true; }
php
public function acquireLock() { $this->log("[JOB] attempting to acquire lock for job::{$this->job_id} on {$this->worker_name}", self::INFO); $lock = $this->runUpdate(" UPDATE " . self::$jobsTable . " SET locked_at = NOW(), locked_by = ? WHERE id = ? AND (locked_at IS NULL OR locked_by = ?) AND failed_at IS NULL ", array($this->worker_name, $this->job_id, $this->worker_name)); if (!$lock) { $this->log("[JOB] failed to acquire lock for job::{$this->job_id}", self::INFO); return false; } return true; }
[ "public", "function", "acquireLock", "(", ")", "{", "$", "this", "->", "log", "(", "\"[JOB] attempting to acquire lock for job::{$this->job_id} on {$this->worker_name}\"", ",", "self", "::", "INFO", ")", ";", "$", "lock", "=", "$", "this", "->", "runUpdate", "(", ...
Acquires lock on this job. @return bool Whether or not acquiring the lock succeeded.
[ "Acquires", "lock", "on", "this", "job", "." ]
bc83642f9e28cf06bbadcd783d3d5ae1162c714b
https://github.com/seatgeek/djjob/blob/bc83642f9e28cf06bbadcd783d3d5ae1162c714b/DJJob.php#L535-L550
45,316
seatgeek/djjob
DJJob.php
DJJob.finish
public function finish() { $this->runUpdate( "DELETE FROM " . self::$jobsTable . " WHERE id = ?", array($this->job_id) ); $this->log("[JOB] completed job::{$this->job_id}", self::INFO); }
php
public function finish() { $this->runUpdate( "DELETE FROM " . self::$jobsTable . " WHERE id = ?", array($this->job_id) ); $this->log("[JOB] completed job::{$this->job_id}", self::INFO); }
[ "public", "function", "finish", "(", ")", "{", "$", "this", "->", "runUpdate", "(", "\"DELETE FROM \"", ".", "self", "::", "$", "jobsTable", ".", "\" WHERE id = ?\"", ",", "array", "(", "$", "this", "->", "job_id", ")", ")", ";", "$", "this", "->", "lo...
Finishes this job. Will delete it from the jobs table.
[ "Finishes", "this", "job", ".", "Will", "delete", "it", "from", "the", "jobs", "table", "." ]
bc83642f9e28cf06bbadcd783d3d5ae1162c714b
https://github.com/seatgeek/djjob/blob/bc83642f9e28cf06bbadcd783d3d5ae1162c714b/DJJob.php#L567-L573
45,317
seatgeek/djjob
DJJob.php
DJJob.finishWithError
public function finishWithError($error, $handler = null) { $this->runUpdate(" UPDATE " . self::$jobsTable . " SET attempts = attempts + 1, failed_at = IF(attempts >= ?, NOW(), NULL), error = IF(attempts >= ?, ?, NULL) WHERE id = ?", array( $this->max_attempts, $this->max_attempts, $error, $this->job_id ) ); $this->log($error, self::ERROR); $this->log("[JOB] failure in job::{$this->job_id}", self::ERROR); $this->releaseLock(); if ($handler && ($this->getAttempts() == $this->max_attempts) && method_exists($handler, '_onDjjobRetryError')) { $handler->_onDjjobRetryError($error); } }
php
public function finishWithError($error, $handler = null) { $this->runUpdate(" UPDATE " . self::$jobsTable . " SET attempts = attempts + 1, failed_at = IF(attempts >= ?, NOW(), NULL), error = IF(attempts >= ?, ?, NULL) WHERE id = ?", array( $this->max_attempts, $this->max_attempts, $error, $this->job_id ) ); $this->log($error, self::ERROR); $this->log("[JOB] failure in job::{$this->job_id}", self::ERROR); $this->releaseLock(); if ($handler && ($this->getAttempts() == $this->max_attempts) && method_exists($handler, '_onDjjobRetryError')) { $handler->_onDjjobRetryError($error); } }
[ "public", "function", "finishWithError", "(", "$", "error", ",", "$", "handler", "=", "null", ")", "{", "$", "this", "->", "runUpdate", "(", "\"\n UPDATE \"", ".", "self", "::", "$", "jobsTable", ".", "\"\n SET attempts = attempts + 1,\n ...
Finishes this job, but with an error. Keeps the job in the jobs table. @param string $error The error message to write to the job. @param null|object $handler The handler that ran this job.
[ "Finishes", "this", "job", "but", "with", "an", "error", ".", "Keeps", "the", "job", "in", "the", "jobs", "table", "." ]
bc83642f9e28cf06bbadcd783d3d5ae1162c714b
https://github.com/seatgeek/djjob/blob/bc83642f9e28cf06bbadcd783d3d5ae1162c714b/DJJob.php#L581-L602
45,318
seatgeek/djjob
DJJob.php
DJJob.retryLater
public function retryLater($delay) { $this->runUpdate(" UPDATE " . self::$jobsTable . " SET run_at = DATE_ADD(NOW(), INTERVAL ? SECOND), attempts = attempts + 1 WHERE id = ?", array( $delay, $this->job_id ) ); $this->releaseLock(); }
php
public function retryLater($delay) { $this->runUpdate(" UPDATE " . self::$jobsTable . " SET run_at = DATE_ADD(NOW(), INTERVAL ? SECOND), attempts = attempts + 1 WHERE id = ?", array( $delay, $this->job_id ) ); $this->releaseLock(); }
[ "public", "function", "retryLater", "(", "$", "delay", ")", "{", "$", "this", "->", "runUpdate", "(", "\"\n UPDATE \"", ".", "self", "::", "$", "jobsTable", ".", "\"\n SET run_at = DATE_ADD(NOW(), INTERVAL ? SECOND),\n attempts = attempts ...
Saves a retry date to this job. @param int $delay The amount of seconds to delay this job.
[ "Saves", "a", "retry", "date", "to", "this", "job", "." ]
bc83642f9e28cf06bbadcd783d3d5ae1162c714b
https://github.com/seatgeek/djjob/blob/bc83642f9e28cf06bbadcd783d3d5ae1162c714b/DJJob.php#L609-L621
45,319
seatgeek/djjob
DJJob.php
DJJob.getHandler
public function getHandler() { $rs = $this->runQuery( "SELECT handler FROM " . self::$jobsTable . " WHERE id = ?", array($this->job_id) ); foreach ($rs as $r) return unserialize($r["handler"]); return false; }
php
public function getHandler() { $rs = $this->runQuery( "SELECT handler FROM " . self::$jobsTable . " WHERE id = ?", array($this->job_id) ); foreach ($rs as $r) return unserialize($r["handler"]); return false; }
[ "public", "function", "getHandler", "(", ")", "{", "$", "rs", "=", "$", "this", "->", "runQuery", "(", "\"SELECT handler FROM \"", ".", "self", "::", "$", "jobsTable", ".", "\" WHERE id = ?\"", ",", "array", "(", "$", "this", "->", "job_id", ")", ")", ";...
Returns the handler for this job. @return bool|object The handler object for this job. Or false if it failed.
[ "Returns", "the", "handler", "for", "this", "job", "." ]
bc83642f9e28cf06bbadcd783d3d5ae1162c714b
https://github.com/seatgeek/djjob/blob/bc83642f9e28cf06bbadcd783d3d5ae1162c714b/DJJob.php#L628-L635
45,320
seatgeek/djjob
DJJob.php
DJJob.getAttempts
public function getAttempts() { $rs = $this->runQuery( "SELECT attempts FROM " . self::$jobsTable . " WHERE id = ?", array($this->job_id) ); foreach ($rs as $r) return $r["attempts"]; return false; }
php
public function getAttempts() { $rs = $this->runQuery( "SELECT attempts FROM " . self::$jobsTable . " WHERE id = ?", array($this->job_id) ); foreach ($rs as $r) return $r["attempts"]; return false; }
[ "public", "function", "getAttempts", "(", ")", "{", "$", "rs", "=", "$", "this", "->", "runQuery", "(", "\"SELECT attempts FROM \"", ".", "self", "::", "$", "jobsTable", ".", "\" WHERE id = ?\"", ",", "array", "(", "$", "this", "->", "job_id", ")", ")", ...
Returns the amount of attempts left for this job. @return bool The amount of attempts left.
[ "Returns", "the", "amount", "of", "attempts", "left", "for", "this", "job", "." ]
bc83642f9e28cf06bbadcd783d3d5ae1162c714b
https://github.com/seatgeek/djjob/blob/bc83642f9e28cf06bbadcd783d3d5ae1162c714b/DJJob.php#L642-L649
45,321
seatgeek/djjob
DJJob.php
DJJob.enqueue
public static function enqueue($handler, $queue = "default", $run_at = null) { $affected = self::runUpdate( "INSERT INTO " . self::$jobsTable . " (handler, queue, run_at, created_at) VALUES(?, ?, ?, NOW())", array(serialize($handler), (string) $queue, $run_at) ); if ($affected < 1) { self::log("[JOB] failed to enqueue new job", self::ERROR); return false; } return self::getConnection()->lastInsertId(); // return the job ID, for manipulation later }
php
public static function enqueue($handler, $queue = "default", $run_at = null) { $affected = self::runUpdate( "INSERT INTO " . self::$jobsTable . " (handler, queue, run_at, created_at) VALUES(?, ?, ?, NOW())", array(serialize($handler), (string) $queue, $run_at) ); if ($affected < 1) { self::log("[JOB] failed to enqueue new job", self::ERROR); return false; } return self::getConnection()->lastInsertId(); // return the job ID, for manipulation later }
[ "public", "static", "function", "enqueue", "(", "$", "handler", ",", "$", "queue", "=", "\"default\"", ",", "$", "run_at", "=", "null", ")", "{", "$", "affected", "=", "self", "::", "runUpdate", "(", "\"INSERT INTO \"", ".", "self", "::", "$", "jobsTable...
Enqueues a job to the database. @param object $handler The handler that can execute this job. @param string $queue The queue to enqueue this job to. All queues are saved in the same table. @param string $run_at A valid mysql DATETIME string at which to run the jobs. @return bool|string Returns the last inserted ID or false if enqueuing failed.
[ "Enqueues", "a", "job", "to", "the", "database", "." ]
bc83642f9e28cf06bbadcd783d3d5ae1162c714b
https://github.com/seatgeek/djjob/blob/bc83642f9e28cf06bbadcd783d3d5ae1162c714b/DJJob.php#L660-L672
45,322
seatgeek/djjob
DJJob.php
DJJob.bulkEnqueue
public static function bulkEnqueue($handlers, $queue = "default", $run_at = null) { $sql = "INSERT INTO " . self::$jobsTable . " (handler, queue, run_at, created_at) VALUES"; $sql .= implode(",", array_fill(0, count($handlers), "(?, ?, ?, NOW())")); $parameters = array(); foreach ($handlers as $handler) { $parameters []= serialize($handler); $parameters []= (string) $queue; $parameters []= $run_at; } $affected = self::runUpdate($sql, $parameters); if ($affected < 1) { self::log("[JOB] failed to enqueue new jobs", self::ERROR); return false; } if ($affected != count($handlers)) self::log("[JOB] failed to enqueue some new jobs", self::ERROR); return true; }
php
public static function bulkEnqueue($handlers, $queue = "default", $run_at = null) { $sql = "INSERT INTO " . self::$jobsTable . " (handler, queue, run_at, created_at) VALUES"; $sql .= implode(",", array_fill(0, count($handlers), "(?, ?, ?, NOW())")); $parameters = array(); foreach ($handlers as $handler) { $parameters []= serialize($handler); $parameters []= (string) $queue; $parameters []= $run_at; } $affected = self::runUpdate($sql, $parameters); if ($affected < 1) { self::log("[JOB] failed to enqueue new jobs", self::ERROR); return false; } if ($affected != count($handlers)) self::log("[JOB] failed to enqueue some new jobs", self::ERROR); return true; }
[ "public", "static", "function", "bulkEnqueue", "(", "$", "handlers", ",", "$", "queue", "=", "\"default\"", ",", "$", "run_at", "=", "null", ")", "{", "$", "sql", "=", "\"INSERT INTO \"", ".", "self", "::", "$", "jobsTable", ".", "\" (handler, queue, run_at,...
Bulk enqueues a lot of jobs to the database. @param object[] $handlers An array of handlers to enqueue. @param string $queue The queue to enqueue the handlers to. @param string $run_at A valid mysql DATETIME string at which to run the jobs. @return bool
[ "Bulk", "enqueues", "a", "lot", "of", "jobs", "to", "the", "database", "." ]
bc83642f9e28cf06bbadcd783d3d5ae1162c714b
https://github.com/seatgeek/djjob/blob/bc83642f9e28cf06bbadcd783d3d5ae1162c714b/DJJob.php#L683-L704
45,323
seatgeek/djjob
DJJob.php
DJJob.status
public static function status($queue = "default") { $rs = self::runQuery(" SELECT COUNT(*) as total, COUNT(failed_at) as failed, COUNT(locked_at) as locked FROM `" . self::$jobsTable . "` WHERE queue = ? ", array($queue)); $rs = $rs[0]; $failed = $rs["failed"]; $locked = $rs["locked"]; $total = $rs["total"]; $outstanding = $total - $locked - $failed; return array( "outstanding" => $outstanding, "locked" => $locked, "failed" => $failed, "total" => $total ); }
php
public static function status($queue = "default") { $rs = self::runQuery(" SELECT COUNT(*) as total, COUNT(failed_at) as failed, COUNT(locked_at) as locked FROM `" . self::$jobsTable . "` WHERE queue = ? ", array($queue)); $rs = $rs[0]; $failed = $rs["failed"]; $locked = $rs["locked"]; $total = $rs["total"]; $outstanding = $total - $locked - $failed; return array( "outstanding" => $outstanding, "locked" => $locked, "failed" => $failed, "total" => $total ); }
[ "public", "static", "function", "status", "(", "$", "queue", "=", "\"default\"", ")", "{", "$", "rs", "=", "self", "::", "runQuery", "(", "\"\n SELECT COUNT(*) as total, COUNT(failed_at) as failed, COUNT(locked_at) as locked\n FROM `\"", ".", "self", "...
Returns the general status of the jobs table. @param string $queue The queue of which to see the status for. @return array Information about the status.
[ "Returns", "the", "general", "status", "of", "the", "jobs", "table", "." ]
bc83642f9e28cf06bbadcd783d3d5ae1162c714b
https://github.com/seatgeek/djjob/blob/bc83642f9e28cf06bbadcd783d3d5ae1162c714b/DJJob.php#L713-L732
45,324
symbiote/silverstripe-multivaluefield
src/Fields/MultiValueCheckboxField.php
MultiValueCheckboxField.dataValue
public function dataValue() { if ($this->value && is_array($this->value)) { $filtered = []; foreach ($this->value as $item) { if ($item) { $filtered[] = str_replace(",", "{comma}", $item); } } return implode(',', $filtered); } return ''; }
php
public function dataValue() { if ($this->value && is_array($this->value)) { $filtered = []; foreach ($this->value as $item) { if ($item) { $filtered[] = str_replace(",", "{comma}", $item); } } return implode(',', $filtered); } return ''; }
[ "public", "function", "dataValue", "(", ")", "{", "if", "(", "$", "this", "->", "value", "&&", "is_array", "(", "$", "this", "->", "value", ")", ")", "{", "$", "filtered", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "value", "as", "$",...
Return the CheckboxSetField value as a string selected item keys. @return string
[ "Return", "the", "CheckboxSetField", "value", "as", "a", "string", "selected", "item", "keys", "." ]
7b0d579530a8914ddf8fc7c912d9559d59d1582a
https://github.com/symbiote/silverstripe-multivaluefield/blob/7b0d579530a8914ddf8fc7c912d9559d59d1582a/src/Fields/MultiValueCheckboxField.php#L212-L226
45,325
symbiote/silverstripe-multivaluefield
src/Fields/MultiValueCheckboxField.php
MultiValueCheckboxField.performReadonlyTransformation
public function performReadonlyTransformation() { $values = ''; $data = []; $items = $this->value; if ($this->source) { foreach ($this->source as $source) { if (is_object($source)) { $sourceTitles[$source->ID] = $source->Title; } } } if ($items) { // Items is a DO Set if (is_a($items, 'DataList')) { foreach ($items as $item) { $data[] = $item->Title; } if ($data) $values = implode(', ', $data); // Items is an array or single piece of string (including comma seperated string) } else { if (!is_array($items)) { $items = preg_split('/ *, */', trim($items)); } foreach ($items as $item) { if (is_array($item)) { $data[] = $item['Title']; } elseif (is_array($this->source) && !empty($this->source[$item])) { $data[] = $this->source[$item]; } elseif (is_a($this->source, 'DataList')) { $data[] = $sourceTitles[$item]; } else { $data[] = $item; } } $values = implode(', ', $data); } } $title = ($this->title) ? $this->title : ''; $field = new ReadonlyField($this->name, $title, $values); $field->setForm($this->form); return $field; }
php
public function performReadonlyTransformation() { $values = ''; $data = []; $items = $this->value; if ($this->source) { foreach ($this->source as $source) { if (is_object($source)) { $sourceTitles[$source->ID] = $source->Title; } } } if ($items) { // Items is a DO Set if (is_a($items, 'DataList')) { foreach ($items as $item) { $data[] = $item->Title; } if ($data) $values = implode(', ', $data); // Items is an array or single piece of string (including comma seperated string) } else { if (!is_array($items)) { $items = preg_split('/ *, */', trim($items)); } foreach ($items as $item) { if (is_array($item)) { $data[] = $item['Title']; } elseif (is_array($this->source) && !empty($this->source[$item])) { $data[] = $this->source[$item]; } elseif (is_a($this->source, 'DataList')) { $data[] = $sourceTitles[$item]; } else { $data[] = $item; } } $values = implode(', ', $data); } } $title = ($this->title) ? $this->title : ''; $field = new ReadonlyField($this->name, $title, $values); $field->setForm($this->form); return $field; }
[ "public", "function", "performReadonlyTransformation", "(", ")", "{", "$", "values", "=", "''", ";", "$", "data", "=", "[", "]", ";", "$", "items", "=", "$", "this", "->", "value", ";", "if", "(", "$", "this", "->", "source", ")", "{", "foreach", "...
Transforms the source data for this CheckboxSetField into a comma separated list of values. @return ReadonlyField
[ "Transforms", "the", "source", "data", "for", "this", "CheckboxSetField", "into", "a", "comma", "separated", "list", "of", "values", "." ]
7b0d579530a8914ddf8fc7c912d9559d59d1582a
https://github.com/symbiote/silverstripe-multivaluefield/blob/7b0d579530a8914ddf8fc7c912d9559d59d1582a/src/Fields/MultiValueCheckboxField.php#L242-L292
45,326
symbiote/silverstripe-multivaluefield
src/ORM/FieldType/MultiValueField.php
MultiValueField.getValue
public function getValue() { $value = $this->value; if (is_null($value)) { $value = $this->getField('Value'); } $this->value = is_string($value) ? $this->unserializeData($value) : $value; return $this->value; }
php
public function getValue() { $value = $this->value; if (is_null($value)) { $value = $this->getField('Value'); } $this->value = is_string($value) ? $this->unserializeData($value) : $value; return $this->value; }
[ "public", "function", "getValue", "(", ")", "{", "$", "value", "=", "$", "this", "->", "value", ";", "if", "(", "is_null", "(", "$", "value", ")", ")", "{", "$", "value", "=", "$", "this", "->", "getField", "(", "'Value'", ")", ";", "}", "$", "...
Returns the value of this field. @return mixed
[ "Returns", "the", "value", "of", "this", "field", "." ]
7b0d579530a8914ddf8fc7c912d9559d59d1582a
https://github.com/symbiote/silverstripe-multivaluefield/blob/7b0d579530a8914ddf8fc7c912d9559d59d1582a/src/ORM/FieldType/MultiValueField.php#L35-L43
45,327
symbiote/silverstripe-multivaluefield
src/ORM/FieldType/MultiValueField.php
MultiValueField.setValue
public function setValue($value, $record = null, $markChanged = true) { $this->changed = $this->changed || $markChanged; if (!is_null($value)) { // so that subsequent getValue calls re-load the value item correctly $this->value = null; if (!is_string($value)) { $value = $this->serializeValue($value); } $value = ['Value' => $value]; } return parent::setValue($value, $record, $markChanged); }
php
public function setValue($value, $record = null, $markChanged = true) { $this->changed = $this->changed || $markChanged; if (!is_null($value)) { // so that subsequent getValue calls re-load the value item correctly $this->value = null; if (!is_string($value)) { $value = $this->serializeValue($value); } $value = ['Value' => $value]; } return parent::setValue($value, $record, $markChanged); }
[ "public", "function", "setValue", "(", "$", "value", ",", "$", "record", "=", "null", ",", "$", "markChanged", "=", "true", ")", "{", "$", "this", "->", "changed", "=", "$", "this", "->", "changed", "||", "$", "markChanged", ";", "if", "(", "!", "i...
Set the value on the field. Ensures the underlying composite field logic that looks for Value will trigger if the value set is For a multivalue field, this will deserialise the value if it is a string @param mixed $value @param array $record @return $this
[ "Set", "the", "value", "on", "the", "field", ".", "Ensures", "the", "underlying", "composite", "field", "logic", "that", "looks", "for", "Value", "will", "trigger", "if", "the", "value", "set", "is" ]
7b0d579530a8914ddf8fc7c912d9559d59d1582a
https://github.com/symbiote/silverstripe-multivaluefield/blob/7b0d579530a8914ddf8fc7c912d9559d59d1582a/src/ORM/FieldType/MultiValueField.php#L61-L73
45,328
symbiote/silverstripe-multivaluefield
src/ORM/FieldType/MultiValueField.php
MultiValueField.serializeValue
protected function serializeValue($value) { if (is_string($value)) { return $value; } if (is_object($value) || is_array($value)) { return json_encode($value); } }
php
protected function serializeValue($value) { if (is_string($value)) { return $value; } if (is_object($value) || is_array($value)) { return json_encode($value); } }
[ "protected", "function", "serializeValue", "(", "$", "value", ")", "{", "if", "(", "is_string", "(", "$", "value", ")", ")", "{", "return", "$", "value", ";", "}", "if", "(", "is_object", "(", "$", "value", ")", "||", "is_array", "(", "$", "value", ...
Serializes a value object to a json string @param array|object $value @return string
[ "Serializes", "a", "value", "object", "to", "a", "json", "string" ]
7b0d579530a8914ddf8fc7c912d9559d59d1582a
https://github.com/symbiote/silverstripe-multivaluefield/blob/7b0d579530a8914ddf8fc7c912d9559d59d1582a/src/ORM/FieldType/MultiValueField.php#L81-L89
45,329
symbiote/silverstripe-multivaluefield
src/ORM/FieldType/MultiValueField.php
MultiValueField.unserializeData
protected function unserializeData($data) { $value = null; // if we're not deserialised yet, do so if (is_string($data) && strlen($data) > 1) { // are we json encoded? if ($data{1} === ':') { $value = \unserialize($data); } else { $value = \json_decode($data, true); } } return $value; }
php
protected function unserializeData($data) { $value = null; // if we're not deserialised yet, do so if (is_string($data) && strlen($data) > 1) { // are we json encoded? if ($data{1} === ':') { $value = \unserialize($data); } else { $value = \json_decode($data, true); } } return $value; }
[ "protected", "function", "unserializeData", "(", "$", "data", ")", "{", "$", "value", "=", "null", ";", "// if we're not deserialised yet, do so", "if", "(", "is_string", "(", "$", "data", ")", "&&", "strlen", "(", "$", "data", ")", ">", "1", ")", "{", "...
Unserialises data, depending on new or old format @param string $data @return array
[ "Unserialises", "data", "depending", "on", "new", "or", "old", "format" ]
7b0d579530a8914ddf8fc7c912d9559d59d1582a
https://github.com/symbiote/silverstripe-multivaluefield/blob/7b0d579530a8914ddf8fc7c912d9559d59d1582a/src/ORM/FieldType/MultiValueField.php#L98-L111
45,330
ochi51/cybozu-http
src/Api/User/Csv.php
Csv.get
public function get($type): string { if (!in_array($type, self::$type, true)) { throw new \InvalidArgumentException('Invalid type parameter'); } $content = (string)$this->client ->get(UserApi::generateUrl("csv/{$type}.csv")) ->getBody(); return $content; }
php
public function get($type): string { if (!in_array($type, self::$type, true)) { throw new \InvalidArgumentException('Invalid type parameter'); } $content = (string)$this->client ->get(UserApi::generateUrl("csv/{$type}.csv")) ->getBody(); return $content; }
[ "public", "function", "get", "(", "$", "type", ")", ":", "string", "{", "if", "(", "!", "in_array", "(", "$", "type", ",", "self", "::", "$", "type", ",", "true", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Invalid type para...
Get csv file @param string $type @return string @throws \InvalidArgumentException
[ "Get", "csv", "file" ]
dd137ef775099d7ab2734b6a3764433c18d7937b
https://github.com/ochi51/cybozu-http/blob/dd137ef775099d7ab2734b6a3764433c18d7937b/src/Api/User/Csv.php#L42-L53
45,331
ochi51/cybozu-http
src/Api/User/Csv.php
Csv.post
public function post($type, $filename): int { return $this->postKey($type, $this->file($filename)); }
php
public function post($type, $filename): int { return $this->postKey($type, $this->file($filename)); }
[ "public", "function", "post", "(", "$", "type", ",", "$", "filename", ")", ":", "int", "{", "return", "$", "this", "->", "postKey", "(", "$", "type", ",", "$", "this", "->", "file", "(", "$", "filename", ")", ")", ";", "}" ]
Post csv file @param string $type @param string $filename @return int @throws \InvalidArgumentException
[ "Post", "csv", "file" ]
dd137ef775099d7ab2734b6a3764433c18d7937b
https://github.com/ochi51/cybozu-http/blob/dd137ef775099d7ab2734b6a3764433c18d7937b/src/Api/User/Csv.php#L63-L66
45,332
ochi51/cybozu-http
src/Api/User/Csv.php
Csv.postKey
public function postKey($type, $fileKey): int { if (!in_array($type, self::$type, true)) { throw new \InvalidArgumentException('Invalid type parameter'); } $options = ['json' => ['fileKey' => $fileKey]]; /** @var JsonStream $stream */ $stream = $this->client ->post(UserApi::generateUrl("csv/{$type}.json"), $options) ->getBody(); return $stream->jsonSerialize()['id']; }
php
public function postKey($type, $fileKey): int { if (!in_array($type, self::$type, true)) { throw new \InvalidArgumentException('Invalid type parameter'); } $options = ['json' => ['fileKey' => $fileKey]]; /** @var JsonStream $stream */ $stream = $this->client ->post(UserApi::generateUrl("csv/{$type}.json"), $options) ->getBody(); return $stream->jsonSerialize()['id']; }
[ "public", "function", "postKey", "(", "$", "type", ",", "$", "fileKey", ")", ":", "int", "{", "if", "(", "!", "in_array", "(", "$", "type", ",", "self", "::", "$", "type", ",", "true", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", ...
Post file key @param string $type @param string $fileKey @return int @throws \InvalidArgumentException
[ "Post", "file", "key" ]
dd137ef775099d7ab2734b6a3764433c18d7937b
https://github.com/ochi51/cybozu-http/blob/dd137ef775099d7ab2734b6a3764433c18d7937b/src/Api/User/Csv.php#L76-L90
45,333
ScriptFUSION/Porter
src/Connector/ImportConnector.php
ImportConnector.findBaseConnector
public function findBaseConnector() { $connector = $this->connector; while ($connector instanceof ConnectorWrapper) { $connector = $connector->getWrappedConnector(); } return $connector; }
php
public function findBaseConnector() { $connector = $this->connector; while ($connector instanceof ConnectorWrapper) { $connector = $connector->getWrappedConnector(); } return $connector; }
[ "public", "function", "findBaseConnector", "(", ")", "{", "$", "connector", "=", "$", "this", "->", "connector", ";", "while", "(", "$", "connector", "instanceof", "ConnectorWrapper", ")", "{", "$", "connector", "=", "$", "connector", "->", "getWrappedConnecto...
Finds the base connector by traversing the stack of wrapped connectors. @return Connector Base connector.
[ "Finds", "the", "base", "connector", "by", "traversing", "the", "stack", "of", "wrapped", "connectors", "." ]
c50bc62e56993c4860b1d62819679a6c6e9ec913
https://github.com/ScriptFUSION/Porter/blob/c50bc62e56993c4860b1d62819679a6c6e9ec913/src/Connector/ImportConnector.php#L49-L58
45,334
FriendsOfPHP/Sismo
src/Sismo/Contrib/WallpaperNotifier.php
WallpaperNotifier.updateBackground
private function updateBackground($data) { $this->updatedAt = microtime(true); $this->image = imagecreatetruecolor($this->get('image_width'), $this->get('image_height')); imageantialias($this->image, true); $this->initializeColors(); imagefill($this->image, 0, 0, $this->get('background_color')); $numProject = 0; foreach ($data['projects'] as $project => $builds) { // the most recent build is always shown on top rsort($builds); $x1 = $this->get('horizontal_padding') + (($this->get('bar_width') + $this->get('horizontal_gutter')) * $numProject); $x2 = $x1 + $this->get('bar_width'); // plot each project slug $this->addTextToImage( substr($project, 0, $this->get('max_number_letters')), $x1, $this->get('vertical_padding') - 0.2 * $this->get('font_size') ); foreach ($builds as $i => $build) { $y1 = $this->get('vertical_padding') + $this->get('font_size') + (($this->get('bar_height') + $this->get('vertical_gutter')) * $i); $y2 = $y1 + $this->get('bar_height'); $color = 'ok' == $build ? $this->get('success_color') : $this->get('failure_color'); // plot a bar for each project build imageFilledRectangle($this->image, $x1, $y1, $x2, $y2, $color); } $numProject++; } $this->addTextToImage( 'Last update: '.$data['last_update'], $this->get('horizontal_padding'), $this->get('image_height') - $this->get('font_size') ); // Hack: two different images are needed to update the wallpaper // One holds the current wallpaper and the other is the new one // If you use just one image and modify it, the OS doesn't reload it if (file_exists($this->evenBackgroundImagePath)) { $this->imagePath = $this->oddBackgroundImagePath; unlink($this->evenBackgroundImagePath); } elseif (file_exists($this->oddBackgroundImagePath)) { $this->imagePath = $this->evenBackgroundImagePath; unlink($this->oddBackgroundImagePath); } else { $this->imagePath = $this->oddBackgroundImagePath; } imagepng($this->image, $this->imagePath); imagedestroy($this->image); // Wallpaper is reloaded via AppleScript $scriptPath = $this->dir.'/update-background.scpt'; file_put_contents($scriptPath, <<<END tell application "System Events" tell current desktop set picture to POSIX file "file://localhost/$this->imagePath" end tell end tell END ); system("osascript $scriptPath"); }
php
private function updateBackground($data) { $this->updatedAt = microtime(true); $this->image = imagecreatetruecolor($this->get('image_width'), $this->get('image_height')); imageantialias($this->image, true); $this->initializeColors(); imagefill($this->image, 0, 0, $this->get('background_color')); $numProject = 0; foreach ($data['projects'] as $project => $builds) { // the most recent build is always shown on top rsort($builds); $x1 = $this->get('horizontal_padding') + (($this->get('bar_width') + $this->get('horizontal_gutter')) * $numProject); $x2 = $x1 + $this->get('bar_width'); // plot each project slug $this->addTextToImage( substr($project, 0, $this->get('max_number_letters')), $x1, $this->get('vertical_padding') - 0.2 * $this->get('font_size') ); foreach ($builds as $i => $build) { $y1 = $this->get('vertical_padding') + $this->get('font_size') + (($this->get('bar_height') + $this->get('vertical_gutter')) * $i); $y2 = $y1 + $this->get('bar_height'); $color = 'ok' == $build ? $this->get('success_color') : $this->get('failure_color'); // plot a bar for each project build imageFilledRectangle($this->image, $x1, $y1, $x2, $y2, $color); } $numProject++; } $this->addTextToImage( 'Last update: '.$data['last_update'], $this->get('horizontal_padding'), $this->get('image_height') - $this->get('font_size') ); // Hack: two different images are needed to update the wallpaper // One holds the current wallpaper and the other is the new one // If you use just one image and modify it, the OS doesn't reload it if (file_exists($this->evenBackgroundImagePath)) { $this->imagePath = $this->oddBackgroundImagePath; unlink($this->evenBackgroundImagePath); } elseif (file_exists($this->oddBackgroundImagePath)) { $this->imagePath = $this->evenBackgroundImagePath; unlink($this->oddBackgroundImagePath); } else { $this->imagePath = $this->oddBackgroundImagePath; } imagepng($this->image, $this->imagePath); imagedestroy($this->image); // Wallpaper is reloaded via AppleScript $scriptPath = $this->dir.'/update-background.scpt'; file_put_contents($scriptPath, <<<END tell application "System Events" tell current desktop set picture to POSIX file "file://localhost/$this->imagePath" end tell end tell END ); system("osascript $scriptPath"); }
[ "private", "function", "updateBackground", "(", "$", "data", ")", "{", "$", "this", "->", "updatedAt", "=", "microtime", "(", "true", ")", ";", "$", "this", "->", "image", "=", "imagecreatetruecolor", "(", "$", "this", "->", "get", "(", "'image_width'", ...
Generates a wallpaper with the latest data and updates desktop background @param array $data Array with the latest build history per project
[ "Generates", "a", "wallpaper", "with", "the", "latest", "data", "and", "updates", "desktop", "background" ]
0b35bd0033a6c3b509ce7bf417ddc83bccfb2f68
https://github.com/FriendsOfPHP/Sismo/blob/0b35bd0033a6c3b509ce7bf417ddc83bccfb2f68/src/Sismo/Contrib/WallpaperNotifier.php#L68-L138
45,335
FriendsOfPHP/Sismo
src/Sismo/Contrib/WallpaperNotifier.php
WallpaperNotifier.addTextToImage
private function addTextToImage($text, $x, $y) { imagettftext($this->image, $this->get('font_size'), 0, $x, $y, $this->get('text_color'), $this->dir.'/instruction.ttf', $text); }
php
private function addTextToImage($text, $x, $y) { imagettftext($this->image, $this->get('font_size'), 0, $x, $y, $this->get('text_color'), $this->dir.'/instruction.ttf', $text); }
[ "private", "function", "addTextToImage", "(", "$", "text", ",", "$", "x", ",", "$", "y", ")", "{", "imagettftext", "(", "$", "this", "->", "image", ",", "$", "this", "->", "get", "(", "'font_size'", ")", ",", "0", ",", "$", "x", ",", "$", "y", ...
Convenience method to add text to a GD image. @param string $text The string to be plotted @param int $x The x coordinate where the string will be plotted @param int $y The y coordinate where the string will be plotted
[ "Convenience", "method", "to", "add", "text", "to", "a", "GD", "image", "." ]
0b35bd0033a6c3b509ce7bf417ddc83bccfb2f68
https://github.com/FriendsOfPHP/Sismo/blob/0b35bd0033a6c3b509ce7bf417ddc83bccfb2f68/src/Sismo/Contrib/WallpaperNotifier.php#L147-L150
45,336
FriendsOfPHP/Sismo
src/Sismo/Contrib/WallpaperNotifier.php
WallpaperNotifier.initializeImageOptions
private function initializeImageOptions($userOptions) { $this->imageOptions = array_merge(array( 'bar_width' => 80, 'bar_height' => 10, 'horizontal_gutter' => 20, 'vertical_gutter' => 10, 'horizontal_padding' => 20, 'vertical_padding' => 50, 'image_width' => 1920, 'image_height' => 1080, 'background_color' => '#161616', 'text_color' => '#CCCCCC', 'success_color' => '#267326', 'failure_color' => '#B30F00', 'font_size' => 10, ), $userOptions); $this->set('max_number_bars', ($this->get('image_height') - $this->get('vertical_padding') - (2 * $this->get('font_size')) - (2 * $this->get('vertical_gutter'))) / ($this->get('bar_height') + $this->get('vertical_gutter'))); $this->set('max_number_letters', floor($this->get('bar_width') / (0.7 * $this->get('font_size')))); $this->image = null; }
php
private function initializeImageOptions($userOptions) { $this->imageOptions = array_merge(array( 'bar_width' => 80, 'bar_height' => 10, 'horizontal_gutter' => 20, 'vertical_gutter' => 10, 'horizontal_padding' => 20, 'vertical_padding' => 50, 'image_width' => 1920, 'image_height' => 1080, 'background_color' => '#161616', 'text_color' => '#CCCCCC', 'success_color' => '#267326', 'failure_color' => '#B30F00', 'font_size' => 10, ), $userOptions); $this->set('max_number_bars', ($this->get('image_height') - $this->get('vertical_padding') - (2 * $this->get('font_size')) - (2 * $this->get('vertical_gutter'))) / ($this->get('bar_height') + $this->get('vertical_gutter'))); $this->set('max_number_letters', floor($this->get('bar_width') / (0.7 * $this->get('font_size')))); $this->image = null; }
[ "private", "function", "initializeImageOptions", "(", "$", "userOptions", ")", "{", "$", "this", "->", "imageOptions", "=", "array_merge", "(", "array", "(", "'bar_width'", "=>", "80", ",", "'bar_height'", "=>", "10", ",", "'horizontal_gutter'", "=>", "20", ",...
Initializes the options that control wallpaper design @param array $userOptions The options given by the user, which override default values
[ "Initializes", "the", "options", "that", "control", "wallpaper", "design" ]
0b35bd0033a6c3b509ce7bf417ddc83bccfb2f68
https://github.com/FriendsOfPHP/Sismo/blob/0b35bd0033a6c3b509ce7bf417ddc83bccfb2f68/src/Sismo/Contrib/WallpaperNotifier.php#L179-L202
45,337
FriendsOfPHP/Sismo
src/Sismo/Contrib/WallpaperNotifier.php
WallpaperNotifier.initializeTempDirectory
private function initializeTempDirectory() { $this->dir = __DIR__.'/.wallpaperNotifier'; if (!file_exists($this->dir)) { try { mkdir($this->dir); } catch (Exception $e) { throw new \RuntimeException(sprintf( "Wallpaper notifier requires a directory to hold its contents\n" ."'%s' directory couldn't be created", $this->dir )); } } // Hack: two different images are needed to reload the desktop background // One holds the current wallpaper, the other one is the new background // If you have just one image and modify it, the OS doesn't reload it $this->evenBackgroundImagePath = realpath($this->dir).'/even-background.png'; $this->oddBackgroundImagePath = realpath($this->dir).'/odd-background.png'; }
php
private function initializeTempDirectory() { $this->dir = __DIR__.'/.wallpaperNotifier'; if (!file_exists($this->dir)) { try { mkdir($this->dir); } catch (Exception $e) { throw new \RuntimeException(sprintf( "Wallpaper notifier requires a directory to hold its contents\n" ."'%s' directory couldn't be created", $this->dir )); } } // Hack: two different images are needed to reload the desktop background // One holds the current wallpaper, the other one is the new background // If you have just one image and modify it, the OS doesn't reload it $this->evenBackgroundImagePath = realpath($this->dir).'/even-background.png'; $this->oddBackgroundImagePath = realpath($this->dir).'/odd-background.png'; }
[ "private", "function", "initializeTempDirectory", "(", ")", "{", "$", "this", "->", "dir", "=", "__DIR__", ".", "'/.wallpaperNotifier'", ";", "if", "(", "!", "file_exists", "(", "$", "this", "->", "dir", ")", ")", "{", "try", "{", "mkdir", "(", "$", "t...
This notifier requires a directory to save several files. This method creates a hidden directory called `.wallpaperNotifier` if it doesn't exist.
[ "This", "notifier", "requires", "a", "directory", "to", "save", "several", "files", ".", "This", "method", "creates", "a", "hidden", "directory", "called", ".", "wallpaperNotifier", "if", "it", "doesn", "t", "exist", "." ]
0b35bd0033a6c3b509ce7bf417ddc83bccfb2f68
https://github.com/FriendsOfPHP/Sismo/blob/0b35bd0033a6c3b509ce7bf417ddc83bccfb2f68/src/Sismo/Contrib/WallpaperNotifier.php#L208-L229
45,338
FriendsOfPHP/Sismo
src/Sismo/Contrib/WallpaperNotifier.php
WallpaperNotifier.initializeLogFile
private function initializeLogFile() { $this->log = $this->dir.'/builds.log'; if (!file_exists($this->log)) { $data = array( 'last_update' => null, 'projects' => array(), ); file_put_contents($this->log, serialize($data)); } }
php
private function initializeLogFile() { $this->log = $this->dir.'/builds.log'; if (!file_exists($this->log)) { $data = array( 'last_update' => null, 'projects' => array(), ); file_put_contents($this->log, serialize($data)); } }
[ "private", "function", "initializeLogFile", "(", ")", "{", "$", "this", "->", "log", "=", "$", "this", "->", "dir", ".", "'/builds.log'", ";", "if", "(", "!", "file_exists", "(", "$", "this", "->", "log", ")", ")", "{", "$", "data", "=", "array", "...
This method checks that the build history log file exists. If it doesn't exist, the method creates and initializes it.
[ "This", "method", "checks", "that", "the", "build", "history", "log", "file", "exists", ".", "If", "it", "doesn", "t", "exist", "the", "method", "creates", "and", "initializes", "it", "." ]
0b35bd0033a6c3b509ce7bf417ddc83bccfb2f68
https://github.com/FriendsOfPHP/Sismo/blob/0b35bd0033a6c3b509ce7bf417ddc83bccfb2f68/src/Sismo/Contrib/WallpaperNotifier.php#L235-L247
45,339
FriendsOfPHP/Sismo
src/Sismo/Contrib/WallpaperNotifier.php
WallpaperNotifier.initializeColors
private function initializeColors() { $rgb = $this->hex2rgb($this->get('background_color')); $this->set('background_color', imagecolorallocate($this->image, $rgb[0], $rgb[1], $rgb[2])); $rgb = $this->hex2rgb($this->get('text_color')); $this->set('text_color', imagecolorallocate($this->image, $rgb[0], $rgb[1], $rgb[2])); $rgb = $this->hex2rgb($this->get('success_color')); $this->set('success_color', imagecolorallocate($this->image, $rgb[0], $rgb[1], $rgb[2])); $rgb = $this->hex2rgb($this->get('failure_color')); $this->set('failure_color', imagecolorallocate($this->image, $rgb[0], $rgb[1], $rgb[2])); }
php
private function initializeColors() { $rgb = $this->hex2rgb($this->get('background_color')); $this->set('background_color', imagecolorallocate($this->image, $rgb[0], $rgb[1], $rgb[2])); $rgb = $this->hex2rgb($this->get('text_color')); $this->set('text_color', imagecolorallocate($this->image, $rgb[0], $rgb[1], $rgb[2])); $rgb = $this->hex2rgb($this->get('success_color')); $this->set('success_color', imagecolorallocate($this->image, $rgb[0], $rgb[1], $rgb[2])); $rgb = $this->hex2rgb($this->get('failure_color')); $this->set('failure_color', imagecolorallocate($this->image, $rgb[0], $rgb[1], $rgb[2])); }
[ "private", "function", "initializeColors", "(", ")", "{", "$", "rgb", "=", "$", "this", "->", "hex2rgb", "(", "$", "this", "->", "get", "(", "'background_color'", ")", ")", ";", "$", "this", "->", "set", "(", "'background_color'", ",", "imagecolorallocate"...
Transforms hexadecimal colors to the color format used by GD images.
[ "Transforms", "hexadecimal", "colors", "to", "the", "color", "format", "used", "by", "GD", "images", "." ]
0b35bd0033a6c3b509ce7bf417ddc83bccfb2f68
https://github.com/FriendsOfPHP/Sismo/blob/0b35bd0033a6c3b509ce7bf417ddc83bccfb2f68/src/Sismo/Contrib/WallpaperNotifier.php#L853-L866
45,340
FriendsOfPHP/Sismo
src/Sismo/Contrib/WallpaperNotifier.php
WallpaperNotifier.hex2rgb
private function hex2rgb($hex) { $hex = str_replace('#', '', $hex); // expand shorthand notation (#36A -> #3366AA) if (3 == strlen($hex)) { $hex = $hex{0} .$hex{0} .$hex{1} .$hex{1} .$hex{2} .$hex{2}; } return array( hexdec(substr($hex, 0, 2)), hexdec(substr($hex, 2, 2)), hexdec(substr($hex, 4, 2)), ); }
php
private function hex2rgb($hex) { $hex = str_replace('#', '', $hex); // expand shorthand notation (#36A -> #3366AA) if (3 == strlen($hex)) { $hex = $hex{0} .$hex{0} .$hex{1} .$hex{1} .$hex{2} .$hex{2}; } return array( hexdec(substr($hex, 0, 2)), hexdec(substr($hex, 2, 2)), hexdec(substr($hex, 4, 2)), ); }
[ "private", "function", "hex2rgb", "(", "$", "hex", ")", "{", "$", "hex", "=", "str_replace", "(", "'#'", ",", "''", ",", "$", "hex", ")", ";", "// expand shorthand notation (#36A -> #3366AA)", "if", "(", "3", "==", "strlen", "(", "$", "hex", ")", ")", ...
Convenience method to transform a color from hexadecimal to RGB. @param string $hex The color in hexadecimal format (full or shorthand) @return array The RGB color as an array with R, G and B components
[ "Convenience", "method", "to", "transform", "a", "color", "from", "hexadecimal", "to", "RGB", "." ]
0b35bd0033a6c3b509ce7bf417ddc83bccfb2f68
https://github.com/FriendsOfPHP/Sismo/blob/0b35bd0033a6c3b509ce7bf417ddc83bccfb2f68/src/Sismo/Contrib/WallpaperNotifier.php#L875-L894
45,341
ScriptFUSION/Porter
src/Options/EncapsulatedOptions.php
EncapsulatedOptions.get
final protected function get($option) { if (array_key_exists($key = "$option", $this->options)) { return $this->options[$key]; } if (array_key_exists($key, $this->defaults)) { return $this->defaults[$key]; } }
php
final protected function get($option) { if (array_key_exists($key = "$option", $this->options)) { return $this->options[$key]; } if (array_key_exists($key, $this->defaults)) { return $this->defaults[$key]; } }
[ "final", "protected", "function", "get", "(", "$", "option", ")", "{", "if", "(", "array_key_exists", "(", "$", "key", "=", "\"$option\"", ",", "$", "this", "->", "options", ")", ")", "{", "return", "$", "this", "->", "options", "[", "$", "key", "]",...
Gets the value for the specified option name. When option name is not set the default value is retrieved, if defined, otherwise null. @param string $option Option name. @return mixed Option value, default value or null.
[ "Gets", "the", "value", "for", "the", "specified", "option", "name", ".", "When", "option", "name", "is", "not", "set", "the", "default", "value", "is", "retrieved", "if", "defined", "otherwise", "null", "." ]
c50bc62e56993c4860b1d62819679a6c6e9ec913
https://github.com/ScriptFUSION/Porter/blob/c50bc62e56993c4860b1d62819679a6c6e9ec913/src/Options/EncapsulatedOptions.php#L31-L40
45,342
FriendsOfPHP/Sismo
src/Sismo/Contrib/CrossFingerNotifier.php
CrossFingerNotifier.commitNeedNotification
protected function commitNeedNotification(Commit $commit) { if (!$commit->isSuccessful()) { return true; } //getProject()->getLatestCommit() actually contains the previous build $previousCommit = $commit->getProject()->getLatestCommit(); return !$previousCommit || $previousCommit->getStatusCode() != $commit->getStatusCode(); }
php
protected function commitNeedNotification(Commit $commit) { if (!$commit->isSuccessful()) { return true; } //getProject()->getLatestCommit() actually contains the previous build $previousCommit = $commit->getProject()->getLatestCommit(); return !$previousCommit || $previousCommit->getStatusCode() != $commit->getStatusCode(); }
[ "protected", "function", "commitNeedNotification", "(", "Commit", "$", "commit", ")", "{", "if", "(", "!", "$", "commit", "->", "isSuccessful", "(", ")", ")", "{", "return", "true", ";", "}", "//getProject()->getLatestCommit() actually contains the previous build", ...
Determines if a build needs to be notify based on his status and his predecessor's one @param Commit $commit The commit to analyse @return bool whether the commit need notification or not
[ "Determines", "if", "a", "build", "needs", "to", "be", "notify", "based", "on", "his", "status", "and", "his", "predecessor", "s", "one" ]
0b35bd0033a6c3b509ce7bf417ddc83bccfb2f68
https://github.com/FriendsOfPHP/Sismo/blob/0b35bd0033a6c3b509ce7bf417ddc83bccfb2f68/src/Sismo/Contrib/CrossFingerNotifier.php#L76-L86
45,343
FriendsOfPHP/Sismo
src/Sismo/Contrib/GrowlNotifier.php
GrowlNotifier.notify
public function notify(Commit $commit) { try { $this->growl->register(); $name = $commit->isSuccessful() ? self::NOTIFY_SUCCESS : self::NOTIFY_FAILURE; $notifications = $this->growl->getApplication()->getGrowlNotifications(); $this->growl->publish( $name, $commit->getProject()->getName(), $this->format($this->format, $commit), $notifications[$name] ); } catch (\Net_Growl_Exception $e) { return false; } return true; }
php
public function notify(Commit $commit) { try { $this->growl->register(); $name = $commit->isSuccessful() ? self::NOTIFY_SUCCESS : self::NOTIFY_FAILURE; $notifications = $this->growl->getApplication()->getGrowlNotifications(); $this->growl->publish( $name, $commit->getProject()->getName(), $this->format($this->format, $commit), $notifications[$name] ); } catch (\Net_Growl_Exception $e) { return false; } return true; }
[ "public", "function", "notify", "(", "Commit", "$", "commit", ")", "{", "try", "{", "$", "this", "->", "growl", "->", "register", "(", ")", ";", "$", "name", "=", "$", "commit", "->", "isSuccessful", "(", ")", "?", "self", "::", "NOTIFY_SUCCESS", ":"...
Notify a project commit @param Sismo\Commit $commit The latest project commit @return bool TRUE on a succesfull notification, FALSE on failure
[ "Notify", "a", "project", "commit" ]
0b35bd0033a6c3b509ce7bf417ddc83bccfb2f68
https://github.com/FriendsOfPHP/Sismo/blob/0b35bd0033a6c3b509ce7bf417ddc83bccfb2f68/src/Sismo/Contrib/GrowlNotifier.php#L103-L123
45,344
FriendsOfPHP/Sismo
src/Sismo/Project.php
Project.getSubName
public function getSubName() { if (false !== $pos = strpos($this->name, '(')) { return trim(substr($this->name, $pos + 1, -1)); } return ''; }
php
public function getSubName() { if (false !== $pos = strpos($this->name, '(')) { return trim(substr($this->name, $pos + 1, -1)); } return ''; }
[ "public", "function", "getSubName", "(", ")", "{", "if", "(", "false", "!==", "$", "pos", "=", "strpos", "(", "$", "this", "->", "name", ",", "'('", ")", ")", "{", "return", "trim", "(", "substr", "(", "$", "this", "->", "name", ",", "$", "pos", ...
Gets the project sub name. @return string The project sub name
[ "Gets", "the", "project", "sub", "name", "." ]
0b35bd0033a6c3b509ce7bf417ddc83bccfb2f68
https://github.com/FriendsOfPHP/Sismo/blob/0b35bd0033a6c3b509ce7bf417ddc83bccfb2f68/src/Sismo/Project.php#L251-L258
45,345
FriendsOfPHP/Sismo
src/Sismo/Project.php
Project.setRepository
public function setRepository($url) { if (false !== strpos($url, '@')) { list($url, $branch) = explode('@', $url); $this->branch = $branch; } $this->repository = $url; return $this; }
php
public function setRepository($url) { if (false !== strpos($url, '@')) { list($url, $branch) = explode('@', $url); $this->branch = $branch; } $this->repository = $url; return $this; }
[ "public", "function", "setRepository", "(", "$", "url", ")", "{", "if", "(", "false", "!==", "strpos", "(", "$", "url", ",", "'@'", ")", ")", "{", "list", "(", "$", "url", ",", "$", "branch", ")", "=", "explode", "(", "'@'", ",", "$", "url", ")...
Sets the project repository URL. @param string $url The project repository URL
[ "Sets", "the", "project", "repository", "URL", "." ]
0b35bd0033a6c3b509ce7bf417ddc83bccfb2f68
https://github.com/FriendsOfPHP/Sismo/blob/0b35bd0033a6c3b509ce7bf417ddc83bccfb2f68/src/Sismo/Project.php#L297-L307
45,346
ScriptFUSION/Porter
src/Connector/ConnectionContext.php
ConnectionContext.retry
public function retry(callable $callback) { $userHandlerCloned = $providerHandlerCloned = false; return \ScriptFUSION\Retry\retry( $this->maxFetchAttempts, $callback, function (\Exception $exception) use (&$userHandlerCloned, &$providerHandlerCloned) { // Throw exception instead of retrying, if unrecoverable. if (!$exception instanceof RecoverableConnectorException) { throw $exception; } // Call provider's exception handler, if defined. if ($this->resourceFetchExceptionHandler) { self::invokeHandler($this->resourceFetchExceptionHandler, $exception, $providerHandlerCloned); } // Call user's exception handler. self::invokeHandler($this->fetchExceptionHandler, $exception, $userHandlerCloned); } ); }
php
public function retry(callable $callback) { $userHandlerCloned = $providerHandlerCloned = false; return \ScriptFUSION\Retry\retry( $this->maxFetchAttempts, $callback, function (\Exception $exception) use (&$userHandlerCloned, &$providerHandlerCloned) { // Throw exception instead of retrying, if unrecoverable. if (!$exception instanceof RecoverableConnectorException) { throw $exception; } // Call provider's exception handler, if defined. if ($this->resourceFetchExceptionHandler) { self::invokeHandler($this->resourceFetchExceptionHandler, $exception, $providerHandlerCloned); } // Call user's exception handler. self::invokeHandler($this->fetchExceptionHandler, $exception, $userHandlerCloned); } ); }
[ "public", "function", "retry", "(", "callable", "$", "callback", ")", "{", "$", "userHandlerCloned", "=", "$", "providerHandlerCloned", "=", "false", ";", "return", "\\", "ScriptFUSION", "\\", "Retry", "\\", "retry", "(", "$", "this", "->", "maxFetchAttempts",...
Retries the specified callback a predefined number of times with a predefined exception handler. @param callable $callback Callback. @return mixed The result of the callback invocation.
[ "Retries", "the", "specified", "callback", "a", "predefined", "number", "of", "times", "with", "a", "predefined", "exception", "handler", "." ]
c50bc62e56993c4860b1d62819679a6c6e9ec913
https://github.com/ScriptFUSION/Porter/blob/c50bc62e56993c4860b1d62819679a6c6e9ec913/src/Connector/ConnectionContext.php#L54-L76
45,347
ScriptFUSION/Porter
src/Connector/ConnectionContext.php
ConnectionContext.invokeHandler
private static function invokeHandler(FetchExceptionHandler &$handler, \Exception $exception, &$cloned) { if (!$cloned && !$handler instanceof StatelessFetchExceptionHandler) { $handler = clone $handler; $handler->initialize(); $cloned = true; } $handler($exception); }
php
private static function invokeHandler(FetchExceptionHandler &$handler, \Exception $exception, &$cloned) { if (!$cloned && !$handler instanceof StatelessFetchExceptionHandler) { $handler = clone $handler; $handler->initialize(); $cloned = true; } $handler($exception); }
[ "private", "static", "function", "invokeHandler", "(", "FetchExceptionHandler", "&", "$", "handler", ",", "\\", "Exception", "$", "exception", ",", "&", "$", "cloned", ")", "{", "if", "(", "!", "$", "cloned", "&&", "!", "$", "handler", "instanceof", "State...
Invokes the specified fetch exception handler, cloning it if required. @param FetchExceptionHandler $handler Fetch exception handler. @param \Exception $exception Exception to pass to the handler. @param bool $cloned False if handler requires cloning, true if handler has already been cloned.
[ "Invokes", "the", "specified", "fetch", "exception", "handler", "cloning", "it", "if", "required", "." ]
c50bc62e56993c4860b1d62819679a6c6e9ec913
https://github.com/ScriptFUSION/Porter/blob/c50bc62e56993c4860b1d62819679a6c6e9ec913/src/Connector/ConnectionContext.php#L85-L94
45,348
FriendsOfPHP/Sismo
src/Sismo/Storage/PdoStorage.php
PdoStorage.create
public static function create($dsn, $username = null, $passwd = null, array $options = array()) { return new self(new \PDO($dsn, $username, $passwd, $options)); }
php
public static function create($dsn, $username = null, $passwd = null, array $options = array()) { return new self(new \PDO($dsn, $username, $passwd, $options)); }
[ "public", "static", "function", "create", "(", "$", "dsn", ",", "$", "username", "=", "null", ",", "$", "passwd", "=", "null", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "return", "new", "self", "(", "new", "\\", "PDO", "(", ...
Create a PdoStorage by establishing a PDO connection. @throws \PDOException If the attempt to connect to the requested database fails. @param string $dsn The data source name. @param string $username The username to login with. @param string $passwd The password of the given user. @param array $options Additional options to pass to the PDO driver. @return PdoStorage The created storage on the defined connection.
[ "Create", "a", "PdoStorage", "by", "establishing", "a", "PDO", "connection", "." ]
0b35bd0033a6c3b509ce7bf417ddc83bccfb2f68
https://github.com/FriendsOfPHP/Sismo/blob/0b35bd0033a6c3b509ce7bf417ddc83bccfb2f68/src/Sismo/Storage/PdoStorage.php#L54-L57
45,349
FriendsOfPHP/Sismo
src/Sismo/Storage/PdoStorage.php
PdoStorage.getCommit
public function getCommit(Project $project, $sha) { $stmt = $this->db->prepare('SELECT slug, sha, author, date, build_date, message, status, output FROM `commit` WHERE slug = :slug AND sha = :sha'); $stmt->bindValue(':slug', $project->getSlug(), \PDO::PARAM_STR); $stmt->bindValue(':sha', $sha, \PDO::PARAM_STR); if ($stmt->execute()) { if (false !== $result = $stmt->fetch(\PDO::FETCH_ASSOC)) { return $this->createCommit($project, $result); } } else { // @codeCoverageIgnoreStart throw new \RuntimeException(sprintf('Unable to retrieve commit "%s" from project "%s".', $sha, $project), 1); // @codeCoverageIgnoreEnd } return false; }
php
public function getCommit(Project $project, $sha) { $stmt = $this->db->prepare('SELECT slug, sha, author, date, build_date, message, status, output FROM `commit` WHERE slug = :slug AND sha = :sha'); $stmt->bindValue(':slug', $project->getSlug(), \PDO::PARAM_STR); $stmt->bindValue(':sha', $sha, \PDO::PARAM_STR); if ($stmt->execute()) { if (false !== $result = $stmt->fetch(\PDO::FETCH_ASSOC)) { return $this->createCommit($project, $result); } } else { // @codeCoverageIgnoreStart throw new \RuntimeException(sprintf('Unable to retrieve commit "%s" from project "%s".', $sha, $project), 1); // @codeCoverageIgnoreEnd } return false; }
[ "public", "function", "getCommit", "(", "Project", "$", "project", ",", "$", "sha", ")", "{", "$", "stmt", "=", "$", "this", "->", "db", "->", "prepare", "(", "'SELECT slug, sha, author, date, build_date, message, status, output FROM `commit` WHERE slug = :slug AND sha = ...
Retrieves a commit out of a project. @param Project $project The project this commit is part of. @param string $sha The hash of the commit to retrieve. @return Commit
[ "Retrieves", "a", "commit", "out", "of", "a", "project", "." ]
0b35bd0033a6c3b509ce7bf417ddc83bccfb2f68
https://github.com/FriendsOfPHP/Sismo/blob/0b35bd0033a6c3b509ce7bf417ddc83bccfb2f68/src/Sismo/Storage/PdoStorage.php#L67-L84
45,350
FriendsOfPHP/Sismo
src/Sismo/Storage/PdoStorage.php
PdoStorage.initCommit
public function initCommit(Project $project, $sha, $author, \DateTime $date, $message) { $stmt = $this->db->prepare('SELECT COUNT(*) FROM `commit` WHERE slug = :slug'); $stmt->bindValue(':slug', $project->getSlug(), \PDO::PARAM_STR); if (false === $stmt->execute()) { // @codeCoverageIgnoreStart throw new \RuntimeException(sprintf('Unable to verify existence of commit "%s" from project "%s".', $sha, $project->getName())); // @codeCoverageIgnoreEnd } if ($stmt->fetchColumn(0)) { $stmt = $this->db->prepare('UPDATE `commit` SET slug = :slug, sha = :sha, author = :author, date = :date, message = :message, status = :status, output = :output, build_date = :build_date WHERE slug = :slug'); } else { $stmt = $this->db->prepare('INSERT INTO `commit` (slug, sha, author, date, message, status, output, build_date) VALUES (:slug, :sha, :author, :date, :message, :status, :output, :build_date)'); } $stmt->bindValue(':slug', $project->getSlug(), \PDO::PARAM_STR); $stmt->bindValue(':sha', $sha, \PDO::PARAM_STR); $stmt->bindValue(':author', $author, \PDO::PARAM_STR); $stmt->bindValue(':date', $date->format('Y-m-d H:i:s'), \PDO::PARAM_STR); $stmt->bindValue(':message', $message, \PDO::PARAM_STR); $stmt->bindValue(':status', 'building', \PDO::PARAM_STR); $stmt->bindValue(':output', '', \PDO::PARAM_STR); $stmt->bindValue(':build_date', '', \PDO::PARAM_STR); if (false === $stmt->execute()) { // @codeCoverageIgnoreStart throw new \RuntimeException(sprintf('Unable to save commit "%s" from project "%s".', $sha, $project->getName())); // @codeCoverageIgnoreEnd } $commit = new Commit($project, $sha); $commit->setAuthor($author); $commit->setMessage($message); $commit->setDate($date); return $commit; }
php
public function initCommit(Project $project, $sha, $author, \DateTime $date, $message) { $stmt = $this->db->prepare('SELECT COUNT(*) FROM `commit` WHERE slug = :slug'); $stmt->bindValue(':slug', $project->getSlug(), \PDO::PARAM_STR); if (false === $stmt->execute()) { // @codeCoverageIgnoreStart throw new \RuntimeException(sprintf('Unable to verify existence of commit "%s" from project "%s".', $sha, $project->getName())); // @codeCoverageIgnoreEnd } if ($stmt->fetchColumn(0)) { $stmt = $this->db->prepare('UPDATE `commit` SET slug = :slug, sha = :sha, author = :author, date = :date, message = :message, status = :status, output = :output, build_date = :build_date WHERE slug = :slug'); } else { $stmt = $this->db->prepare('INSERT INTO `commit` (slug, sha, author, date, message, status, output, build_date) VALUES (:slug, :sha, :author, :date, :message, :status, :output, :build_date)'); } $stmt->bindValue(':slug', $project->getSlug(), \PDO::PARAM_STR); $stmt->bindValue(':sha', $sha, \PDO::PARAM_STR); $stmt->bindValue(':author', $author, \PDO::PARAM_STR); $stmt->bindValue(':date', $date->format('Y-m-d H:i:s'), \PDO::PARAM_STR); $stmt->bindValue(':message', $message, \PDO::PARAM_STR); $stmt->bindValue(':status', 'building', \PDO::PARAM_STR); $stmt->bindValue(':output', '', \PDO::PARAM_STR); $stmt->bindValue(':build_date', '', \PDO::PARAM_STR); if (false === $stmt->execute()) { // @codeCoverageIgnoreStart throw new \RuntimeException(sprintf('Unable to save commit "%s" from project "%s".', $sha, $project->getName())); // @codeCoverageIgnoreEnd } $commit = new Commit($project, $sha); $commit->setAuthor($author); $commit->setMessage($message); $commit->setDate($date); return $commit; }
[ "public", "function", "initCommit", "(", "Project", "$", "project", ",", "$", "sha", ",", "$", "author", ",", "\\", "DateTime", "$", "date", ",", "$", "message", ")", "{", "$", "stmt", "=", "$", "this", "->", "db", "->", "prepare", "(", "'SELECT COUN...
Initiate, create and save a new commit. @param Project $project The project of the new commit. @param string $sha The hash of the commit. @param string $author The name of the author of the new commit. @param \DateTime $date The date the new commit was created originally (e.g. by external resources). @param string $message The commit message. @return Commit The newly created commit.
[ "Initiate", "create", "and", "save", "a", "new", "commit", "." ]
0b35bd0033a6c3b509ce7bf417ddc83bccfb2f68
https://github.com/FriendsOfPHP/Sismo/blob/0b35bd0033a6c3b509ce7bf417ddc83bccfb2f68/src/Sismo/Storage/PdoStorage.php#L97-L135
45,351
FriendsOfPHP/Sismo
src/Sismo/Storage/PdoStorage.php
PdoStorage.updateCommit
public function updateCommit(Commit $commit) { $stmt = $this->db->prepare('UPDATE `commit` SET status = :status, output = :output, build_date = :current_date WHERE slug = :slug AND sha = :sha'); $stmt->bindValue(':slug', $commit->getProject()->getSlug(), \PDO::PARAM_STR); $stmt->bindValue(':sha', $commit->getSha(), \PDO::PARAM_STR); $stmt->bindValue(':status', $commit->getStatusCode(), \PDO::PARAM_STR); $stmt->bindValue(':output', $commit->getOutput(), \PDO::PARAM_STR); $stmt->bindValue(':current_date', date('Y-m-d H:i:s'), \PDO::PARAM_STR); if (false === $stmt->execute()) { // @codeCoverageIgnoreStart throw new \RuntimeException(sprintf('Unable to save build "%s@%s".', $commit->getProject()->getName(), $commit->getSha())); // @codeCoverageIgnoreEnd } }
php
public function updateCommit(Commit $commit) { $stmt = $this->db->prepare('UPDATE `commit` SET status = :status, output = :output, build_date = :current_date WHERE slug = :slug AND sha = :sha'); $stmt->bindValue(':slug', $commit->getProject()->getSlug(), \PDO::PARAM_STR); $stmt->bindValue(':sha', $commit->getSha(), \PDO::PARAM_STR); $stmt->bindValue(':status', $commit->getStatusCode(), \PDO::PARAM_STR); $stmt->bindValue(':output', $commit->getOutput(), \PDO::PARAM_STR); $stmt->bindValue(':current_date', date('Y-m-d H:i:s'), \PDO::PARAM_STR); if (false === $stmt->execute()) { // @codeCoverageIgnoreStart throw new \RuntimeException(sprintf('Unable to save build "%s@%s".', $commit->getProject()->getName(), $commit->getSha())); // @codeCoverageIgnoreEnd } }
[ "public", "function", "updateCommit", "(", "Commit", "$", "commit", ")", "{", "$", "stmt", "=", "$", "this", "->", "db", "->", "prepare", "(", "'UPDATE `commit` SET status = :status, output = :output, build_date = :current_date WHERE slug = :slug AND sha = :sha'", ")", ";",...
Update the commits information. The commit is identified by its sha hash. @param Commit $commit @return StorageInterface $this
[ "Update", "the", "commits", "information", "." ]
0b35bd0033a6c3b509ce7bf417ddc83bccfb2f68
https://github.com/FriendsOfPHP/Sismo/blob/0b35bd0033a6c3b509ce7bf417ddc83bccfb2f68/src/Sismo/Storage/PdoStorage.php#L214-L228
45,352
ScriptFUSION/Porter
src/Porter.php
Porter.import
public function import(ImportSpecification $specification) { $specification = clone $specification; $records = $this->fetch( $specification->getResource(), $specification->getProviderName(), ConnectionContextFactory::create($specification) ); if (!$records instanceof ProviderRecords) { $records = $this->createProviderRecords($records, $specification->getResource()); } $records = $this->transformRecords($records, $specification->getTransformers(), $specification->getContext()); return $this->createPorterRecords($records, $specification); }
php
public function import(ImportSpecification $specification) { $specification = clone $specification; $records = $this->fetch( $specification->getResource(), $specification->getProviderName(), ConnectionContextFactory::create($specification) ); if (!$records instanceof ProviderRecords) { $records = $this->createProviderRecords($records, $specification->getResource()); } $records = $this->transformRecords($records, $specification->getTransformers(), $specification->getContext()); return $this->createPorterRecords($records, $specification); }
[ "public", "function", "import", "(", "ImportSpecification", "$", "specification", ")", "{", "$", "specification", "=", "clone", "$", "specification", ";", "$", "records", "=", "$", "this", "->", "fetch", "(", "$", "specification", "->", "getResource", "(", "...
Imports data according to the design of the specified import specification. @param ImportSpecification $specification Import specification. @return PorterRecords|CountablePorterRecords @throws ImportException Provider failed to return an iterator.
[ "Imports", "data", "according", "to", "the", "design", "of", "the", "specified", "import", "specification", "." ]
c50bc62e56993c4860b1d62819679a6c6e9ec913
https://github.com/ScriptFUSION/Porter/blob/c50bc62e56993c4860b1d62819679a6c6e9ec913/src/Porter.php#L56-L73
45,353
ScriptFUSION/Porter
src/Porter.php
Porter.importOne
public function importOne(ImportSpecification $specification) { $results = $this->import($specification); if (!$results->valid()) { return null; } $one = $results->current(); if ($results->next() || $results->valid()) { throw new ImportException('Cannot import one: more than one record imported.'); } return $one; }
php
public function importOne(ImportSpecification $specification) { $results = $this->import($specification); if (!$results->valid()) { return null; } $one = $results->current(); if ($results->next() || $results->valid()) { throw new ImportException('Cannot import one: more than one record imported.'); } return $one; }
[ "public", "function", "importOne", "(", "ImportSpecification", "$", "specification", ")", "{", "$", "results", "=", "$", "this", "->", "import", "(", "$", "specification", ")", ";", "if", "(", "!", "$", "results", "->", "valid", "(", ")", ")", "{", "re...
Imports one record according to the design of the specified import specification. @param ImportSpecification $specification Import specification. @return array|null Record. @throws ImportException More than one record was imported.
[ "Imports", "one", "record", "according", "to", "the", "design", "of", "the", "specified", "import", "specification", "." ]
c50bc62e56993c4860b1d62819679a6c6e9ec913
https://github.com/ScriptFUSION/Porter/blob/c50bc62e56993c4860b1d62819679a6c6e9ec913/src/Porter.php#L84-L99
45,354
ScriptFUSION/Porter
src/Porter.php
Porter.getProvider
private function getProvider($name) { if ($this->providers->has($name)) { return $this->providers->get($name); } try { return $this->getOrCreateProviderFactory()->createProvider("$name"); } catch (ObjectNotCreatedException $exception) { throw new ProviderNotFoundException("No such provider registered: \"$name\".", $exception); } }
php
private function getProvider($name) { if ($this->providers->has($name)) { return $this->providers->get($name); } try { return $this->getOrCreateProviderFactory()->createProvider("$name"); } catch (ObjectNotCreatedException $exception) { throw new ProviderNotFoundException("No such provider registered: \"$name\".", $exception); } }
[ "private", "function", "getProvider", "(", "$", "name", ")", "{", "if", "(", "$", "this", "->", "providers", "->", "has", "(", "$", "name", ")", ")", "{", "return", "$", "this", "->", "providers", "->", "get", "(", "$", "name", ")", ";", "}", "tr...
Gets the provider matching the specified name. @param string $name Provider name. @return Provider @throws ProviderNotFoundException The specified provider was not found.
[ "Gets", "the", "provider", "matching", "the", "specified", "name", "." ]
c50bc62e56993c4860b1d62819679a6c6e9ec913
https://github.com/ScriptFUSION/Porter/blob/c50bc62e56993c4860b1d62819679a6c6e9ec913/src/Porter.php#L178-L189
45,355
ScriptFUSION/Porter
src/Specification/ImportSpecification.php
ImportSpecification.addTransformer
final public function addTransformer(Transformer $transformer) { if ($this->hasTransformer($transformer)) { throw new DuplicateTransformerException('Transformer already added.'); } $this->transformers[spl_object_hash($transformer)] = $transformer; return $this; }
php
final public function addTransformer(Transformer $transformer) { if ($this->hasTransformer($transformer)) { throw new DuplicateTransformerException('Transformer already added.'); } $this->transformers[spl_object_hash($transformer)] = $transformer; return $this; }
[ "final", "public", "function", "addTransformer", "(", "Transformer", "$", "transformer", ")", "{", "if", "(", "$", "this", "->", "hasTransformer", "(", "$", "transformer", ")", ")", "{", "throw", "new", "DuplicateTransformerException", "(", "'Transformer already a...
Adds the specified transformer. @param Transformer $transformer Transformer. @return $this
[ "Adds", "the", "specified", "transformer", "." ]
c50bc62e56993c4860b1d62819679a6c6e9ec913
https://github.com/ScriptFUSION/Porter/blob/c50bc62e56993c4860b1d62819679a6c6e9ec913/src/Specification/ImportSpecification.php#L123-L132
45,356
ScriptFUSION/Porter
src/Specification/ImportSpecification.php
ImportSpecification.setMaxFetchAttempts
final public function setMaxFetchAttempts($attempts) { if (!is_int($attempts) || $attempts < 1) { throw new \InvalidArgumentException('Fetch attempts must be greater than or equal to 1.'); } $this->maxFetchAttempts = $attempts; return $this; }
php
final public function setMaxFetchAttempts($attempts) { if (!is_int($attempts) || $attempts < 1) { throw new \InvalidArgumentException('Fetch attempts must be greater than or equal to 1.'); } $this->maxFetchAttempts = $attempts; return $this; }
[ "final", "public", "function", "setMaxFetchAttempts", "(", "$", "attempts", ")", "{", "if", "(", "!", "is_int", "(", "$", "attempts", ")", "||", "$", "attempts", "<", "1", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Fetch attempts must...
Sets the maximum number of fetch attempts per connection before failure is considered permanent. @param int $attempts Maximum fetch attempts. @return $this
[ "Sets", "the", "maximum", "number", "of", "fetch", "attempts", "per", "connection", "before", "failure", "is", "considered", "permanent", "." ]
c50bc62e56993c4860b1d62819679a6c6e9ec913
https://github.com/ScriptFUSION/Porter/blob/c50bc62e56993c4860b1d62819679a6c6e9ec913/src/Specification/ImportSpecification.php#L230-L239
45,357
FriendsOfPHP/Sismo
src/Sismo/Commit.php
Commit.setStatusCode
public function setStatusCode($status) { if (!in_array($status, array('building', 'success', 'failed'))) { throw new \InvalidArgumentException(sprintf('Invalid status code "%s".', $status)); } $this->status = $status; }
php
public function setStatusCode($status) { if (!in_array($status, array('building', 'success', 'failed'))) { throw new \InvalidArgumentException(sprintf('Invalid status code "%s".', $status)); } $this->status = $status; }
[ "public", "function", "setStatusCode", "(", "$", "status", ")", "{", "if", "(", "!", "in_array", "(", "$", "status", ",", "array", "(", "'building'", ",", "'success'", ",", "'failed'", ")", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", ...
Sets the build status code of the commit. Can be one of "building", "success", or "failed". @param string $status The commit build status code
[ "Sets", "the", "build", "status", "code", "of", "the", "commit", "." ]
0b35bd0033a6c3b509ce7bf417ddc83bccfb2f68
https://github.com/FriendsOfPHP/Sismo/blob/0b35bd0033a6c3b509ce7bf417ddc83bccfb2f68/src/Sismo/Commit.php#L91-L98
45,358
FriendsOfPHP/Sismo
src/Sismo/Sismo.php
Sismo.build
public function build(Project $project, $revision = null, $flags = 0, $callback = null) { // project already has a running build if ($project->isBuilding() && Sismo::FORCE_BUILD !== ($flags & Sismo::FORCE_BUILD)) { return; } $this->builder->init($project, $callback); list($sha, $author, $date, $message) = $this->builder->prepare($revision, Sismo::LOCAL_BUILD !== ($flags & Sismo::LOCAL_BUILD)); $commit = $this->storage->getCommit($project, $sha); // commit has already been built if ($commit && $commit->isBuilt() && Sismo::FORCE_BUILD !== ($flags & Sismo::FORCE_BUILD)) { return; } $commit = $this->storage->initCommit($project, $sha, $author, \DateTime::createFromFormat('Y-m-d H:i:s O', $date), $message); $process = $this->builder->build(); if (!$process->isSuccessful()) { $commit->setStatusCode('failed'); $commit->setOutput(sprintf("\033[31mBuild failed\033[0m\n\n\033[33mOutput\033[0m\n%s\n\n\033[33m Error\033[0m%s", $process->getOutput(), $process->getErrorOutput())); } else { $commit->setStatusCode('success'); $commit->setOutput($process->getOutput()); } $this->storage->updateCommit($commit); if (Sismo::SILENT_BUILD !== ($flags & Sismo::SILENT_BUILD)) { foreach ($project->getNotifiers() as $notifier) { $notifier->notify($commit); } } }
php
public function build(Project $project, $revision = null, $flags = 0, $callback = null) { // project already has a running build if ($project->isBuilding() && Sismo::FORCE_BUILD !== ($flags & Sismo::FORCE_BUILD)) { return; } $this->builder->init($project, $callback); list($sha, $author, $date, $message) = $this->builder->prepare($revision, Sismo::LOCAL_BUILD !== ($flags & Sismo::LOCAL_BUILD)); $commit = $this->storage->getCommit($project, $sha); // commit has already been built if ($commit && $commit->isBuilt() && Sismo::FORCE_BUILD !== ($flags & Sismo::FORCE_BUILD)) { return; } $commit = $this->storage->initCommit($project, $sha, $author, \DateTime::createFromFormat('Y-m-d H:i:s O', $date), $message); $process = $this->builder->build(); if (!$process->isSuccessful()) { $commit->setStatusCode('failed'); $commit->setOutput(sprintf("\033[31mBuild failed\033[0m\n\n\033[33mOutput\033[0m\n%s\n\n\033[33m Error\033[0m%s", $process->getOutput(), $process->getErrorOutput())); } else { $commit->setStatusCode('success'); $commit->setOutput($process->getOutput()); } $this->storage->updateCommit($commit); if (Sismo::SILENT_BUILD !== ($flags & Sismo::SILENT_BUILD)) { foreach ($project->getNotifiers() as $notifier) { $notifier->notify($commit); } } }
[ "public", "function", "build", "(", "Project", "$", "project", ",", "$", "revision", "=", "null", ",", "$", "flags", "=", "0", ",", "$", "callback", "=", "null", ")", "{", "// project already has a running build", "if", "(", "$", "project", "->", "isBuildi...
Builds a project. @param Project $project A Project instance @param string $revision The revision to build (or null for the latest revision) @param integer $flags Flags (a combinaison of FORCE_BUILD, LOCAL_BUILD, and SILENT_BUILD) @param mixed $callback A PHP callback
[ "Builds", "a", "project", "." ]
0b35bd0033a6c3b509ce7bf417ddc83bccfb2f68
https://github.com/FriendsOfPHP/Sismo/blob/0b35bd0033a6c3b509ce7bf417ddc83bccfb2f68/src/Sismo/Sismo.php#L53-L90
45,359
FriendsOfPHP/Sismo
src/Sismo/Sismo.php
Sismo.getProject
public function getProject($slug) { if (!isset($this->projects[$slug])) { throw new \InvalidArgumentException(sprintf('Project "%s" does not exist.', $slug)); } return $this->projects[$slug]; }
php
public function getProject($slug) { if (!isset($this->projects[$slug])) { throw new \InvalidArgumentException(sprintf('Project "%s" does not exist.', $slug)); } return $this->projects[$slug]; }
[ "public", "function", "getProject", "(", "$", "slug", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "projects", "[", "$", "slug", "]", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Project \"%s\" doe...
Gets a project. @param string $slug A project slug
[ "Gets", "a", "project", "." ]
0b35bd0033a6c3b509ce7bf417ddc83bccfb2f68
https://github.com/FriendsOfPHP/Sismo/blob/0b35bd0033a6c3b509ce7bf417ddc83bccfb2f68/src/Sismo/Sismo.php#L107-L114
45,360
FriendsOfPHP/Sismo
src/Sismo/Sismo.php
Sismo.addProject
public function addProject(Project $project) { $this->storage->updateProject($project); $this->projects[$project->getSlug()] = $project; }
php
public function addProject(Project $project) { $this->storage->updateProject($project); $this->projects[$project->getSlug()] = $project; }
[ "public", "function", "addProject", "(", "Project", "$", "project", ")", "{", "$", "this", "->", "storage", "->", "updateProject", "(", "$", "project", ")", ";", "$", "this", "->", "projects", "[", "$", "project", "->", "getSlug", "(", ")", "]", "=", ...
Adds a project. @param Project $project A Project instance
[ "Adds", "a", "project", "." ]
0b35bd0033a6c3b509ce7bf417ddc83bccfb2f68
https://github.com/FriendsOfPHP/Sismo/blob/0b35bd0033a6c3b509ce7bf417ddc83bccfb2f68/src/Sismo/Sismo.php#L121-L126
45,361
flarum/tags
src/Access/DiscussionPolicy.php
DiscussionPolicy.tag
public function tag(User $actor, Discussion $discussion) { if ($discussion->user_id == $actor->id && $actor->can('reply', $discussion)) { $allowEditTags = $this->settings->get('allow_tag_change'); if ($allowEditTags === '-1' || ($allowEditTags === 'reply' && $discussion->participant_count <= 1) || (is_numeric($allowEditTags) && $discussion->created_at->diffInMinutes(new Carbon) < $allowEditTags) ) { return true; } } }
php
public function tag(User $actor, Discussion $discussion) { if ($discussion->user_id == $actor->id && $actor->can('reply', $discussion)) { $allowEditTags = $this->settings->get('allow_tag_change'); if ($allowEditTags === '-1' || ($allowEditTags === 'reply' && $discussion->participant_count <= 1) || (is_numeric($allowEditTags) && $discussion->created_at->diffInMinutes(new Carbon) < $allowEditTags) ) { return true; } } }
[ "public", "function", "tag", "(", "User", "$", "actor", ",", "Discussion", "$", "discussion", ")", "{", "if", "(", "$", "discussion", "->", "user_id", "==", "$", "actor", "->", "id", "&&", "$", "actor", "->", "can", "(", "'reply'", ",", "$", "discuss...
This method checks, if the user is still allowed to edit the tags based on the configuration item. @param User $actor @param Discussion $discussion @return bool
[ "This", "method", "checks", "if", "the", "user", "is", "still", "allowed", "to", "edit", "the", "tags", "based", "on", "the", "configuration", "item", "." ]
85ca89dd63b5c629a10c1faf9cd53df070794f08
https://github.com/flarum/tags/blob/85ca89dd63b5c629a10c1faf9cd53df070794f08/src/Access/DiscussionPolicy.php#L121-L133
45,362
flarum/tags
src/Tag.php
Tag.refreshLastPostedDiscussion
public function refreshLastPostedDiscussion() { if ($lastPostedDiscussion = $this->discussions()->latest('last_posted_at')->first()) { $this->setLastPostedDiscussion($lastPostedDiscussion); } return $this; }
php
public function refreshLastPostedDiscussion() { if ($lastPostedDiscussion = $this->discussions()->latest('last_posted_at')->first()) { $this->setLastPostedDiscussion($lastPostedDiscussion); } return $this; }
[ "public", "function", "refreshLastPostedDiscussion", "(", ")", "{", "if", "(", "$", "lastPostedDiscussion", "=", "$", "this", "->", "discussions", "(", ")", "->", "latest", "(", "'last_posted_at'", ")", "->", "first", "(", ")", ")", "{", "$", "this", "->",...
Refresh a tag's last discussion details. @return $this
[ "Refresh", "a", "tag", "s", "last", "discussion", "details", "." ]
85ca89dd63b5c629a10c1faf9cd53df070794f08
https://github.com/flarum/tags/blob/85ca89dd63b5c629a10c1faf9cd53df070794f08/src/Tag.php#L107-L114
45,363
flarum/tags
src/Tag.php
Tag.setLastPostedDiscussion
public function setLastPostedDiscussion(Discussion $discussion) { $this->last_posted_at = $discussion->last_posted_at; $this->last_posted_discussion_id = $discussion->id; $this->last_posted_user_id = $discussion->last_posted_user_id; return $this; }
php
public function setLastPostedDiscussion(Discussion $discussion) { $this->last_posted_at = $discussion->last_posted_at; $this->last_posted_discussion_id = $discussion->id; $this->last_posted_user_id = $discussion->last_posted_user_id; return $this; }
[ "public", "function", "setLastPostedDiscussion", "(", "Discussion", "$", "discussion", ")", "{", "$", "this", "->", "last_posted_at", "=", "$", "discussion", "->", "last_posted_at", ";", "$", "this", "->", "last_posted_discussion_id", "=", "$", "discussion", "->",...
Set the tag's last discussion details. @param Discussion $discussion @return $this
[ "Set", "the", "tag", "s", "last", "discussion", "details", "." ]
85ca89dd63b5c629a10c1faf9cd53df070794f08
https://github.com/flarum/tags/blob/85ca89dd63b5c629a10c1faf9cd53df070794f08/src/Tag.php#L122-L129
45,364
flarum/tags
src/TagRepository.php
TagRepository.all
public function all(User $user = null) { $query = Tag::query(); return $this->scopeVisibleTo($query, $user)->get(); }
php
public function all(User $user = null) { $query = Tag::query(); return $this->scopeVisibleTo($query, $user)->get(); }
[ "public", "function", "all", "(", "User", "$", "user", "=", "null", ")", "{", "$", "query", "=", "Tag", "::", "query", "(", ")", ";", "return", "$", "this", "->", "scopeVisibleTo", "(", "$", "query", ",", "$", "user", ")", "->", "get", "(", ")", ...
Find all tags, optionally making sure they are visible to a certain user. @param User|null $user @return \Illuminate\Database\Eloquent\Collection
[ "Find", "all", "tags", "optionally", "making", "sure", "they", "are", "visible", "to", "a", "certain", "user", "." ]
85ca89dd63b5c629a10c1faf9cd53df070794f08
https://github.com/flarum/tags/blob/85ca89dd63b5c629a10c1faf9cd53df070794f08/src/TagRepository.php#L52-L57
45,365
flarum/tags
src/TagRepository.php
TagRepository.getIdForSlug
public function getIdForSlug($slug, User $user = null) { $query = Tag::where('slug', 'like', $slug); return $this->scopeVisibleTo($query, $user)->pluck('id'); }
php
public function getIdForSlug($slug, User $user = null) { $query = Tag::where('slug', 'like', $slug); return $this->scopeVisibleTo($query, $user)->pluck('id'); }
[ "public", "function", "getIdForSlug", "(", "$", "slug", ",", "User", "$", "user", "=", "null", ")", "{", "$", "query", "=", "Tag", "::", "where", "(", "'slug'", ",", "'like'", ",", "$", "slug", ")", ";", "return", "$", "this", "->", "scopeVisibleTo",...
Get the ID of a tag with the given slug. @param string $slug @param User|null $user @return int
[ "Get", "the", "ID", "of", "a", "tag", "with", "the", "given", "slug", "." ]
85ca89dd63b5c629a10c1faf9cd53df070794f08
https://github.com/flarum/tags/blob/85ca89dd63b5c629a10c1faf9cd53df070794f08/src/TagRepository.php#L66-L71
45,366
Sylius/SyliusGridBundle
src/Bundle/Doctrine/PHPCRODM/ExpressionVisitor.php
ExpressionVisitor.dispatch
public function dispatch(Expression $expr, ?AbstractNode $parentNode = null) { if ($parentNode === null) { $parentNode = $this->queryBuilder->where(); } switch (true) { case $expr instanceof Comparison: return $this->walkComparison($expr, $parentNode); case $expr instanceof CompositeExpression: return $this->walkCompositeExpression($expr, $parentNode); } throw new \RuntimeException('Unknown Expression: ' . get_class($expr)); }
php
public function dispatch(Expression $expr, ?AbstractNode $parentNode = null) { if ($parentNode === null) { $parentNode = $this->queryBuilder->where(); } switch (true) { case $expr instanceof Comparison: return $this->walkComparison($expr, $parentNode); case $expr instanceof CompositeExpression: return $this->walkCompositeExpression($expr, $parentNode); } throw new \RuntimeException('Unknown Expression: ' . get_class($expr)); }
[ "public", "function", "dispatch", "(", "Expression", "$", "expr", ",", "?", "AbstractNode", "$", "parentNode", "=", "null", ")", "{", "if", "(", "$", "parentNode", "===", "null", ")", "{", "$", "parentNode", "=", "$", "this", "->", "queryBuilder", "->", ...
Walk the given expression to build up the PHPCR-ODM query builder. @throws \RuntimeException
[ "Walk", "the", "given", "expression", "to", "build", "up", "the", "PHPCR", "-", "ODM", "query", "builder", "." ]
dfc5f4a0920010550b1af60801179bea7ada5632
https://github.com/Sylius/SyliusGridBundle/blob/dfc5f4a0920010550b1af60801179bea7ada5632/src/Bundle/Doctrine/PHPCRODM/ExpressionVisitor.php#L133-L147
45,367
drupal-pattern-lab/unified-twig-extensions
src/TwigExtension/ExtensionLoader.php
ExtensionLoader.loadAll
static protected function loadAll($type) { $theme = \Drupal::config('system.theme')->get('default'); $themeLocation = drupal_get_path('theme', $theme); $themePath = DRUPAL_ROOT . '/' . $themeLocation . '/'; $extensionPaths = glob($themePath . '*/_twig-components/'); foreach ($extensionPaths as $extensionPath) { $fullPath = $extensionPath; foreach (scandir($fullPath . $type) as $file) { $fileInfo = pathinfo($file); if ($fileInfo['extension'] === 'php') { if ($file[0] != '.' && $file[0] != '_' && substr($file, 0, 3) != 'pl_') { static::load($type, $fullPath . $type . '/' . $file); } } } } }
php
static protected function loadAll($type) { $theme = \Drupal::config('system.theme')->get('default'); $themeLocation = drupal_get_path('theme', $theme); $themePath = DRUPAL_ROOT . '/' . $themeLocation . '/'; $extensionPaths = glob($themePath . '*/_twig-components/'); foreach ($extensionPaths as $extensionPath) { $fullPath = $extensionPath; foreach (scandir($fullPath . $type) as $file) { $fileInfo = pathinfo($file); if ($fileInfo['extension'] === 'php') { if ($file[0] != '.' && $file[0] != '_' && substr($file, 0, 3) != 'pl_') { static::load($type, $fullPath . $type . '/' . $file); } } } } }
[ "static", "protected", "function", "loadAll", "(", "$", "type", ")", "{", "$", "theme", "=", "\\", "Drupal", "::", "config", "(", "'system.theme'", ")", "->", "get", "(", "'default'", ")", ";", "$", "themeLocation", "=", "drupal_get_path", "(", "'theme'", ...
Loads all plugins of a given type. This should be called once per $type. @param string $type The type to load all plugins for.
[ "Loads", "all", "plugins", "of", "a", "given", "type", "." ]
862b9deccab544ca68e3aaaccc257d14acc9b1f6
https://github.com/drupal-pattern-lab/unified-twig-extensions/blob/862b9deccab544ca68e3aaaccc257d14acc9b1f6/src/TwigExtension/ExtensionLoader.php#L46-L64
45,368
drupal-pattern-lab/unified-twig-extensions
src/TwigExtension/ExtensionLoader.php
ExtensionLoader.load
static protected function load($type, $file) { include $file; switch ($type) { case 'filters': self::$objects['filters'][] = $filter; break; case 'functions': self::$objects['functions'][] = $function; break; case 'tags': if (preg_match('/^([^\.]+)\.tag\.php$/', basename($file), $matches)) { $class = "Project_{$matches[1]}_TokenParser"; if (class_exists($class)) { self::$objects['parsers'][] = new $class(); } } break; } }
php
static protected function load($type, $file) { include $file; switch ($type) { case 'filters': self::$objects['filters'][] = $filter; break; case 'functions': self::$objects['functions'][] = $function; break; case 'tags': if (preg_match('/^([^\.]+)\.tag\.php$/', basename($file), $matches)) { $class = "Project_{$matches[1]}_TokenParser"; if (class_exists($class)) { self::$objects['parsers'][] = new $class(); } } break; } }
[ "static", "protected", "function", "load", "(", "$", "type", ",", "$", "file", ")", "{", "include", "$", "file", ";", "switch", "(", "$", "type", ")", "{", "case", "'filters'", ":", "self", "::", "$", "objects", "[", "'filters'", "]", "[", "]", "="...
Loads a specific plugin instance. @param string $type The type of the plugin to be loaded. @param string $file The fully qualified path of the plugin to be loaded.
[ "Loads", "a", "specific", "plugin", "instance", "." ]
862b9deccab544ca68e3aaaccc257d14acc9b1f6
https://github.com/drupal-pattern-lab/unified-twig-extensions/blob/862b9deccab544ca68e3aaaccc257d14acc9b1f6/src/TwigExtension/ExtensionLoader.php#L74-L92
45,369
takeit/AmpHtmlBundle
Request/ParamConverter/ResolveEntityParamConverter.php
ResolveEntityParamConverter.resolveTargetEntity
protected function resolveTargetEntity(ParamConverter $configuration) { $class = $configuration->getClass(); if (isset($this->mapping[$class])) { if ($this->mapping[$class] !== $class) { $configuration->setClass($this->mapping[$class]); } } return $configuration; }
php
protected function resolveTargetEntity(ParamConverter $configuration) { $class = $configuration->getClass(); if (isset($this->mapping[$class])) { if ($this->mapping[$class] !== $class) { $configuration->setClass($this->mapping[$class]); } } return $configuration; }
[ "protected", "function", "resolveTargetEntity", "(", "ParamConverter", "$", "configuration", ")", "{", "$", "class", "=", "$", "configuration", "->", "getClass", "(", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "mapping", "[", "$", "class", "]", ...
Resolves the target entity. @param ParamConverter $configuration Contains the name, class and options of the object @return ParamConverter
[ "Resolves", "the", "target", "entity", "." ]
335df4373fd3516e3fce96c90a211511ee5d8fbf
https://github.com/takeit/AmpHtmlBundle/blob/335df4373fd3516e3fce96c90a211511ee5d8fbf/Request/ParamConverter/ResolveEntityParamConverter.php#L76-L86
45,370
e-moe/guzzle6-bundle
src/Middleware/RequestLoggerMiddleware.php
RequestLoggerMiddleware.onRequestBeforeSend
private function onRequestBeforeSend(RequestInterface $request) { $hash = $this->hash($request); $this->stopwatch->start($hash, self::NAME); }
php
private function onRequestBeforeSend(RequestInterface $request) { $hash = $this->hash($request); $this->stopwatch->start($hash, self::NAME); }
[ "private", "function", "onRequestBeforeSend", "(", "RequestInterface", "$", "request", ")", "{", "$", "hash", "=", "$", "this", "->", "hash", "(", "$", "request", ")", ";", "$", "this", "->", "stopwatch", "->", "start", "(", "$", "hash", ",", "self", "...
Starts the stopwatch. @param RequestInterface $request
[ "Starts", "the", "stopwatch", "." ]
83ed405c40e7297ff512e5ccae8780691eb975c5
https://github.com/e-moe/guzzle6-bundle/blob/83ed405c40e7297ff512e5ccae8780691eb975c5/src/Middleware/RequestLoggerMiddleware.php#L74-L78
45,371
e-moe/guzzle6-bundle
src/Middleware/RequestLoggerMiddleware.php
RequestLoggerMiddleware.onRequestComplete
private function onRequestComplete(RequestInterface $request, ResponseInterface $response) { $hash = $this->hash($request); // Send the log message to the adapter, adding a category and host $priority = $response && $this->isError($response) ? LOG_ERR : LOG_DEBUG; $message = $this->formatter->format($request, $response); $event = $this->stopwatch->stop($hash); $this->logAdapter->log($message, $priority, array( 'request' => $request, 'response' => $response, 'time' => $event->getDuration(), )); }
php
private function onRequestComplete(RequestInterface $request, ResponseInterface $response) { $hash = $this->hash($request); // Send the log message to the adapter, adding a category and host $priority = $response && $this->isError($response) ? LOG_ERR : LOG_DEBUG; $message = $this->formatter->format($request, $response); $event = $this->stopwatch->stop($hash); $this->logAdapter->log($message, $priority, array( 'request' => $request, 'response' => $response, 'time' => $event->getDuration(), )); }
[ "private", "function", "onRequestComplete", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "{", "$", "hash", "=", "$", "this", "->", "hash", "(", "$", "request", ")", ";", "// Send the log message to the adapter, adding a ca...
Stops the stopwatch. @param RequestInterface $request @param ResponseInterface $response
[ "Stops", "the", "stopwatch", "." ]
83ed405c40e7297ff512e5ccae8780691eb975c5
https://github.com/e-moe/guzzle6-bundle/blob/83ed405c40e7297ff512e5ccae8780691eb975c5/src/Middleware/RequestLoggerMiddleware.php#L86-L98
45,372
sizuhiko/Fabricate
src/Factory/FabricateAbstractFactory.php
FabricateAbstractFactory.applyNestedDefinitions
private function applyNestedDefinitions($definitions, $record, $world) { foreach ($definitions as $definition) { $result = $definition->run($record, $world); $record = $this->applyTraits($record, $world); $record = array_merge($record, $result); } return $record; }
php
private function applyNestedDefinitions($definitions, $record, $world) { foreach ($definitions as $definition) { $result = $definition->run($record, $world); $record = $this->applyTraits($record, $world); $record = array_merge($record, $result); } return $record; }
[ "private", "function", "applyNestedDefinitions", "(", "$", "definitions", ",", "$", "record", ",", "$", "world", ")", "{", "foreach", "(", "$", "definitions", "as", "$", "definition", ")", "{", "$", "result", "=", "$", "definition", "->", "run", "(", "$"...
Apply nested definitions @param array $definitions array of FabricateDefinition @param array $record data @param FabricateContext $world context @return array record applied nested definitions
[ "Apply", "nested", "definitions" ]
57adf9d081c3136d25686fed19b60b930e600a5f
https://github.com/sizuhiko/Fabricate/blob/57adf9d081c3136d25686fed19b60b930e600a5f/src/Factory/FabricateAbstractFactory.php#L100-L108
45,373
sizuhiko/Fabricate
src/Factory/FabricateFactory.php
FabricateFactory.create
public static function create($definition) { if ($definition instanceof FabricateDefinition) { return new FabricateDefinitionFactory($definition); } if ($definition instanceof FabricateModel) { return new FabricateModelFactory($definition); } throw new \InvalidArgumentException("FabricateFactory is not support instance"); }
php
public static function create($definition) { if ($definition instanceof FabricateDefinition) { return new FabricateDefinitionFactory($definition); } if ($definition instanceof FabricateModel) { return new FabricateModelFactory($definition); } throw new \InvalidArgumentException("FabricateFactory is not support instance"); }
[ "public", "static", "function", "create", "(", "$", "definition", ")", "{", "if", "(", "$", "definition", "instanceof", "FabricateDefinition", ")", "{", "return", "new", "FabricateDefinitionFactory", "(", "$", "definition", ")", ";", "}", "if", "(", "$", "de...
Create factory depends with definition @param mixed $definition FabricateDifinition or FabricateModel instance. @return FabricateAbstractFactory @throws InvalidArgumentException
[ "Create", "factory", "depends", "with", "definition" ]
57adf9d081c3136d25686fed19b60b930e600a5f
https://github.com/sizuhiko/Fabricate/blob/57adf9d081c3136d25686fed19b60b930e600a5f/src/Factory/FabricateFactory.php#L26-L35
45,374
sizuhiko/Fabricate
src/FabricateContext.php
FabricateContext.sequence
public function sequence($name, $start = null, $callback = null) { if (is_callable($start)) { $callback = $start; $start = null; } if (!array_key_exists($name, $this->sequences)) { if ($start === null) { $start = $this->config->sequence_start; } $this->sequences[$name] = new FabricateSequence($start); } $ret = $this->sequences[$name]->current(); if (is_callable($callback)) { $ret = $callback($ret); } $this->sequences[$name]->next(); return $ret; }
php
public function sequence($name, $start = null, $callback = null) { if (is_callable($start)) { $callback = $start; $start = null; } if (!array_key_exists($name, $this->sequences)) { if ($start === null) { $start = $this->config->sequence_start; } $this->sequences[$name] = new FabricateSequence($start); } $ret = $this->sequences[$name]->current(); if (is_callable($callback)) { $ret = $callback($ret); } $this->sequences[$name]->next(); return $ret; }
[ "public", "function", "sequence", "(", "$", "name", ",", "$", "start", "=", "null", ",", "$", "callback", "=", "null", ")", "{", "if", "(", "is_callable", "(", "$", "start", ")", ")", "{", "$", "callback", "=", "$", "start", ";", "$", "start", "=...
sequence allows you to get a series of numbers unique within the fabricate context. @param string $name sequence name @param int $start If you want to specify the starting number, you can do it with a second parameter. default value is 1. @param callback $callback If you are generating something like an email address, you can pass it a block and the block response will be returned. @return mixed generated sequence
[ "sequence", "allows", "you", "to", "get", "a", "series", "of", "numbers", "unique", "within", "the", "fabricate", "context", "." ]
57adf9d081c3136d25686fed19b60b930e600a5f
https://github.com/sizuhiko/Fabricate/blob/57adf9d081c3136d25686fed19b60b930e600a5f/src/FabricateContext.php#L64-L82
45,375
sizuhiko/Fabricate
src/FabricateContext.php
FabricateContext.traits
public function traits($name) { if (is_array($name)) { $this->traits = array_merge($this->traits, $name); } else { $this->traits[] = $name; } }
php
public function traits($name) { if (is_array($name)) { $this->traits = array_merge($this->traits, $name); } else { $this->traits[] = $name; } }
[ "public", "function", "traits", "(", "$", "name", ")", "{", "if", "(", "is_array", "(", "$", "name", ")", ")", "{", "$", "this", "->", "traits", "=", "array_merge", "(", "$", "this", "->", "traits", ",", "$", "name", ")", ";", "}", "else", "{", ...
Add apply trait in the scope. @param string|array $name use trait name(s) @return void
[ "Add", "apply", "trait", "in", "the", "scope", "." ]
57adf9d081c3136d25686fed19b60b930e600a5f
https://github.com/sizuhiko/Fabricate/blob/57adf9d081c3136d25686fed19b60b930e600a5f/src/FabricateContext.php#L90-L97
45,376
sizuhiko/Fabricate
src/FabricateContext.php
FabricateContext.association
public function association($association, $recordCount = 1, $callback = null) { if (!is_array($association)) { $association = [$association, 'association' => $association]; } $attributes = Fabricate::association($association[0], $recordCount, $callback); if ($this->model) { $associations = $this->model->getAssociated(); if (isset($associations[$association['association']]) && $associations[$association['association']] !== 'hasMany' && !empty($attributes)) { $attributes = $attributes[0]; } } return $attributes; }
php
public function association($association, $recordCount = 1, $callback = null) { if (!is_array($association)) { $association = [$association, 'association' => $association]; } $attributes = Fabricate::association($association[0], $recordCount, $callback); if ($this->model) { $associations = $this->model->getAssociated(); if (isset($associations[$association['association']]) && $associations[$association['association']] !== 'hasMany' && !empty($attributes)) { $attributes = $attributes[0]; } } return $attributes; }
[ "public", "function", "association", "(", "$", "association", ",", "$", "recordCount", "=", "1", ",", "$", "callback", "=", "null", ")", "{", "if", "(", "!", "is_array", "(", "$", "association", ")", ")", "{", "$", "association", "=", "[", "$", "asso...
Only create model attributes array for association. @param mixed $association association name @param int $recordCount count for creating. @param mixed $callback callback or array can change fablicated data if you want to overwrite @return array model attributes array.
[ "Only", "create", "model", "attributes", "array", "for", "association", "." ]
57adf9d081c3136d25686fed19b60b930e600a5f
https://github.com/sizuhiko/Fabricate/blob/57adf9d081c3136d25686fed19b60b930e600a5f/src/FabricateContext.php#L119-L134
45,377
sizuhiko/Fabricate
src/FabricateRegistry.php
FabricateRegistry.find
public function find($name) { if ($this->is_registered($name)) { return $this->items[$name]; } $model = $this->adaptor->getModel($name); if ($model) { return $model; } throw new \InvalidArgumentException("{$name} not registered"); }
php
public function find($name) { if ($this->is_registered($name)) { return $this->items[$name]; } $model = $this->adaptor->getModel($name); if ($model) { return $model; } throw new \InvalidArgumentException("{$name} not registered"); }
[ "public", "function", "find", "(", "$", "name", ")", "{", "if", "(", "$", "this", "->", "is_registered", "(", "$", "name", ")", ")", "{", "return", "$", "this", "->", "items", "[", "$", "name", "]", ";", "}", "$", "model", "=", "$", "this", "->...
Find from registred or model by name @param string $name model name @return mixed registerd object @throws InvalidArgumentException
[ "Find", "from", "registred", "or", "model", "by", "name" ]
57adf9d081c3136d25686fed19b60b930e600a5f
https://github.com/sizuhiko/Fabricate/blob/57adf9d081c3136d25686fed19b60b930e600a5f/src/FabricateRegistry.php#L67-L77
45,378
sizuhiko/Fabricate
src/Fabricate.php
Fabricate.getInstance
private static function getInstance() { if (self::$_instance == null) { self::$_instance = new Fabricate(); self::$_instance->config = new FabricateConfig(); self::$_instance->registry = new FabricateRegistry('Fabricate', null); self::$_instance->traits = []; } return self::$_instance; }
php
private static function getInstance() { if (self::$_instance == null) { self::$_instance = new Fabricate(); self::$_instance->config = new FabricateConfig(); self::$_instance->registry = new FabricateRegistry('Fabricate', null); self::$_instance->traits = []; } return self::$_instance; }
[ "private", "static", "function", "getInstance", "(", ")", "{", "if", "(", "self", "::", "$", "_instance", "==", "null", ")", "{", "self", "::", "$", "_instance", "=", "new", "Fabricate", "(", ")", ";", "self", "::", "$", "_instance", "->", "config", ...
Return Fabricator instance @return Fabricate
[ "Return", "Fabricator", "instance" ]
57adf9d081c3136d25686fed19b60b930e600a5f
https://github.com/sizuhiko/Fabricate/blob/57adf9d081c3136d25686fed19b60b930e600a5f/src/Fabricate.php#L59-L68
45,379
sizuhiko/Fabricate
src/Fabricate.php
Fabricate.config
public static function config($callback) { $instance = self::getInstance(); $callback($instance->config); $instance->registry->setAdaptor($instance->config->adaptor); if ($instance->config->faker == null) { $instance->config->faker = \Faker\Factory::create(); } }
php
public static function config($callback) { $instance = self::getInstance(); $callback($instance->config); $instance->registry->setAdaptor($instance->config->adaptor); if ($instance->config->faker == null) { $instance->config->faker = \Faker\Factory::create(); } }
[ "public", "static", "function", "config", "(", "$", "callback", ")", "{", "$", "instance", "=", "self", "::", "getInstance", "(", ")", ";", "$", "callback", "(", "$", "instance", "->", "config", ")", ";", "$", "instance", "->", "registry", "->", "setAd...
To override these settings @param mixed $callback can override $config(class of FabricateConfig) attributes @return void
[ "To", "override", "these", "settings" ]
57adf9d081c3136d25686fed19b60b930e600a5f
https://github.com/sizuhiko/Fabricate/blob/57adf9d081c3136d25686fed19b60b930e600a5f/src/Fabricate.php#L93-L101
45,380
sizuhiko/Fabricate
src/Fabricate.php
Fabricate.create
public static function create($modelName, $recordCount = 1, $callback = null) { $attributes = self::attributes_for($modelName, $recordCount, $callback); $instance = self::getInstance(); $definition = $instance->definition($recordCount, $callback); $recordCount = $instance->recordCount($recordCount); return $instance->factory->create($attributes, $recordCount, $definition); }
php
public static function create($modelName, $recordCount = 1, $callback = null) { $attributes = self::attributes_for($modelName, $recordCount, $callback); $instance = self::getInstance(); $definition = $instance->definition($recordCount, $callback); $recordCount = $instance->recordCount($recordCount); return $instance->factory->create($attributes, $recordCount, $definition); }
[ "public", "static", "function", "create", "(", "$", "modelName", ",", "$", "recordCount", "=", "1", ",", "$", "callback", "=", "null", ")", "{", "$", "attributes", "=", "self", "::", "attributes_for", "(", "$", "modelName", ",", "$", "recordCount", ",", ...
Create and Save fablicated model data to database. @param string $modelName name of model or defined @param mixed $recordCount $recordCount number for creation or $callback if not require $recordCount @param mixed $callback callback can chenge fablicated data if you want to overwrite @return mixed results of creation
[ "Create", "and", "Save", "fablicated", "model", "data", "to", "database", "." ]
57adf9d081c3136d25686fed19b60b930e600a5f
https://github.com/sizuhiko/Fabricate/blob/57adf9d081c3136d25686fed19b60b930e600a5f/src/Fabricate.php#L111-L118
45,381
sizuhiko/Fabricate
src/Fabricate.php
Fabricate.build
public static function build($modelName, $callback = null) { $data = self::attributes_for($modelName, 1, $callback); $instance = self::getInstance(); $definition = $instance->definition(1, $callback); return $instance->factory->build($data, $definition); }
php
public static function build($modelName, $callback = null) { $data = self::attributes_for($modelName, 1, $callback); $instance = self::getInstance(); $definition = $instance->definition(1, $callback); return $instance->factory->build($data, $definition); }
[ "public", "static", "function", "build", "(", "$", "modelName", ",", "$", "callback", "=", "null", ")", "{", "$", "data", "=", "self", "::", "attributes_for", "(", "$", "modelName", ",", "1", ",", "$", "callback", ")", ";", "$", "instance", "=", "sel...
Only create a model instance. @param string $modelName name of model or defined @param mixed $callback callback can chenge fablicated data if you want to overwrite @return Model Initializes the model for writing a new record
[ "Only", "create", "a", "model", "instance", "." ]
57adf9d081c3136d25686fed19b60b930e600a5f
https://github.com/sizuhiko/Fabricate/blob/57adf9d081c3136d25686fed19b60b930e600a5f/src/Fabricate.php#L126-L132
45,382
sizuhiko/Fabricate
src/Fabricate.php
Fabricate.attributes_for
public static function attributes_for($modelName, $recordCount = 1, $callback = null) { $instance = self::getInstance(); $instance->factory = $instance->factory($modelName); $definition = $instance->definition($recordCount, $callback); $recordCount = $instance->recordCount($recordCount); return $instance->factory->attributes_for($recordCount, $definition); }
php
public static function attributes_for($modelName, $recordCount = 1, $callback = null) { $instance = self::getInstance(); $instance->factory = $instance->factory($modelName); $definition = $instance->definition($recordCount, $callback); $recordCount = $instance->recordCount($recordCount); return $instance->factory->attributes_for($recordCount, $definition); }
[ "public", "static", "function", "attributes_for", "(", "$", "modelName", ",", "$", "recordCount", "=", "1", ",", "$", "callback", "=", "null", ")", "{", "$", "instance", "=", "self", "::", "getInstance", "(", ")", ";", "$", "instance", "->", "factory", ...
Only create model attributes array. @param string $modelName name of model or defined @param mixed $recordCount $recordCount number for creation or $callback if not require $recordCount @param mixed $callback callback can chenge fablicated data if you want to overwrite @return array model attributes array.
[ "Only", "create", "model", "attributes", "array", "." ]
57adf9d081c3136d25686fed19b60b930e600a5f
https://github.com/sizuhiko/Fabricate/blob/57adf9d081c3136d25686fed19b60b930e600a5f/src/Fabricate.php#L141-L148
45,383
sizuhiko/Fabricate
src/Fabricate.php
Fabricate.define
public static function define($name, $define) { $instance = self::getInstance(); $parent = false; $base = false; $trait = false; if (is_array($name)) { $parent = array_key_exists('parent', $name)?$name['parent']:false; $base = array_key_exists('class', $name)?$name['class']:false; if (array_key_exists('trait', $name)) { $name = $name['trait']; $parent = $base = false; $trait = true; } else { $name = $name[0]; } } if (empty($name)) { throw new \InvalidArgumentException("name is empty"); } if ($parent && !$instance->registry->is_registered($parent)) { throw new \InvalidArgumentException("parent `{$parent}` is not registered"); } if ($base && in_array($instance->config->adaptor->getModel($base), [false, null])) { throw new \InvalidArgumentException("class `{$base}` is not found"); } $definition = new FabricateDefinition($define); if ($trait) { $instance->traits[$name] = $definition; return; } if (!$parent && !$base) { $base = $name; } $definition->parent = $parent?FabricateFactory::create($instance->registry->find($parent)):false; $definition->parent = $base?FabricateFactory::create($instance->config->adaptor->getModel($base)):$definition->parent; $definition->parent->setConfig(self::getInstance()->config); $instance->registry->register($name, $definition); }
php
public static function define($name, $define) { $instance = self::getInstance(); $parent = false; $base = false; $trait = false; if (is_array($name)) { $parent = array_key_exists('parent', $name)?$name['parent']:false; $base = array_key_exists('class', $name)?$name['class']:false; if (array_key_exists('trait', $name)) { $name = $name['trait']; $parent = $base = false; $trait = true; } else { $name = $name[0]; } } if (empty($name)) { throw new \InvalidArgumentException("name is empty"); } if ($parent && !$instance->registry->is_registered($parent)) { throw new \InvalidArgumentException("parent `{$parent}` is not registered"); } if ($base && in_array($instance->config->adaptor->getModel($base), [false, null])) { throw new \InvalidArgumentException("class `{$base}` is not found"); } $definition = new FabricateDefinition($define); if ($trait) { $instance->traits[$name] = $definition; return; } if (!$parent && !$base) { $base = $name; } $definition->parent = $parent?FabricateFactory::create($instance->registry->find($parent)):false; $definition->parent = $base?FabricateFactory::create($instance->config->adaptor->getModel($base)):$definition->parent; $definition->parent->setConfig(self::getInstance()->config); $instance->registry->register($name, $definition); }
[ "public", "static", "function", "define", "(", "$", "name", ",", "$", "define", ")", "{", "$", "instance", "=", "self", "::", "getInstance", "(", ")", ";", "$", "parent", "=", "false", ";", "$", "base", "=", "false", ";", "$", "trait", "=", "false"...
Define fabrication object @param mixed $name name or with attributes @param mixed $define definition @return void @throws InvalidArgumentException
[ "Define", "fabrication", "object" ]
57adf9d081c3136d25686fed19b60b930e600a5f
https://github.com/sizuhiko/Fabricate/blob/57adf9d081c3136d25686fed19b60b930e600a5f/src/Fabricate.php#L185-L224
45,384
sizuhiko/Fabricate
src/Definition/FabricateDefinition.php
FabricateDefinition.run
public function run($data, $world) { $result = []; if (is_callable($this->define)) { $callback = $this->define; $result = $callback($data, $world); } elseif (is_array($this->define)) { $result = $this->define; } return $result; }
php
public function run($data, $world) { $result = []; if (is_callable($this->define)) { $callback = $this->define; $result = $callback($data, $world); } elseif (is_array($this->define)) { $result = $this->define; } return $result; }
[ "public", "function", "run", "(", "$", "data", ",", "$", "world", ")", "{", "$", "result", "=", "[", "]", ";", "if", "(", "is_callable", "(", "$", "this", "->", "define", ")", ")", "{", "$", "callback", "=", "$", "this", "->", "define", ";", "$...
Run to apply this definition @param array $data data @param FabricateContext $world fabricate context @return array applied data
[ "Run", "to", "apply", "this", "definition" ]
57adf9d081c3136d25686fed19b60b930e600a5f
https://github.com/sizuhiko/Fabricate/blob/57adf9d081c3136d25686fed19b60b930e600a5f/src/Definition/FabricateDefinition.php#L47-L57
45,385
sizuhiko/Fabricate
src/Model/FabricateModel.php
FabricateModel.addColumn
public function addColumn($columnName, $type, $options = []) { $this->columns[$columnName] = ['type' => $type, 'options' => $options]; return $this; }
php
public function addColumn($columnName, $type, $options = []) { $this->columns[$columnName] = ['type' => $type, 'options' => $options]; return $this; }
[ "public", "function", "addColumn", "(", "$", "columnName", ",", "$", "type", ",", "$", "options", "=", "[", "]", ")", "{", "$", "this", "->", "columns", "[", "$", "columnName", "]", "=", "[", "'type'", "=>", "$", "type", ",", "'options'", "=>", "$"...
Add column to the model Valid Column Types Column types are specified as strings and can be one of: <ul> <li>string</li> <li>text</li> <li>integer</li> <li>biginteger</li> <li>float</li> <li>decimal</li> <li>datetime</li> <li>timestamp</li> <li>time</li> <li>date</li> <li>binary</li> <li>boolean</li> </ul> @param string $columnName Column Name @param string $type Column Type @param array $options Column Options @return FabricateModel $this
[ "Add", "column", "to", "the", "model" ]
57adf9d081c3136d25686fed19b60b930e600a5f
https://github.com/sizuhiko/Fabricate/blob/57adf9d081c3136d25686fed19b60b930e600a5f/src/Model/FabricateModel.php#L61-L65
45,386
sizuhiko/Fabricate
src/Model/FabricateModel.php
FabricateModel.hasMany
public function hasMany($name, $foreignKey, $modelName = null) { $this->addAssociation('hasMany', $name, $foreignKey, $modelName); return $this; }
php
public function hasMany($name, $foreignKey, $modelName = null) { $this->addAssociation('hasMany', $name, $foreignKey, $modelName); return $this; }
[ "public", "function", "hasMany", "(", "$", "name", ",", "$", "foreignKey", ",", "$", "modelName", "=", "null", ")", "{", "$", "this", "->", "addAssociation", "(", "'hasMany'", ",", "$", "name", ",", "$", "foreignKey", ",", "$", "modelName", ")", ";", ...
Add hasMany association @param string $name Association Name @param string $foreignKey Forreign Key Column Name @param string $modelName If association name is not model name then should set Model Name. @return FabricateModel $this
[ "Add", "hasMany", "association" ]
57adf9d081c3136d25686fed19b60b930e600a5f
https://github.com/sizuhiko/Fabricate/blob/57adf9d081c3136d25686fed19b60b930e600a5f/src/Model/FabricateModel.php#L95-L99
45,387
sizuhiko/Fabricate
src/Model/FabricateModel.php
FabricateModel.hasOne
public function hasOne($name, $foreignKey, $modelName = null) { $this->addAssociation('hasOne', $name, $foreignKey, $modelName); return $this; }
php
public function hasOne($name, $foreignKey, $modelName = null) { $this->addAssociation('hasOne', $name, $foreignKey, $modelName); return $this; }
[ "public", "function", "hasOne", "(", "$", "name", ",", "$", "foreignKey", ",", "$", "modelName", "=", "null", ")", "{", "$", "this", "->", "addAssociation", "(", "'hasOne'", ",", "$", "name", ",", "$", "foreignKey", ",", "$", "modelName", ")", ";", "...
Add hasOne association @param string $name Association Name @param string $foreignKey Forreign Key Column Name @param string $modelName If association name is not model name then should set Model Name. @return FabricateModel $this
[ "Add", "hasOne", "association" ]
57adf9d081c3136d25686fed19b60b930e600a5f
https://github.com/sizuhiko/Fabricate/blob/57adf9d081c3136d25686fed19b60b930e600a5f/src/Model/FabricateModel.php#L109-L113
45,388
sizuhiko/Fabricate
src/Model/FabricateModel.php
FabricateModel.belongsTo
public function belongsTo($name, $foreignKey, $modelName = null) { $this->addAssociation('belongsTo', $name, $foreignKey, $modelName); return $this; }
php
public function belongsTo($name, $foreignKey, $modelName = null) { $this->addAssociation('belongsTo', $name, $foreignKey, $modelName); return $this; }
[ "public", "function", "belongsTo", "(", "$", "name", ",", "$", "foreignKey", ",", "$", "modelName", "=", "null", ")", "{", "$", "this", "->", "addAssociation", "(", "'belongsTo'", ",", "$", "name", ",", "$", "foreignKey", ",", "$", "modelName", ")", ";...
Set belongsTo association @param string $name Association Name @param string $foreignKey Forreign Key Column Name @param string $modelName If association name is not model name then should set Model Name. @return FabricateModel $this
[ "Set", "belongsTo", "association" ]
57adf9d081c3136d25686fed19b60b930e600a5f
https://github.com/sizuhiko/Fabricate/blob/57adf9d081c3136d25686fed19b60b930e600a5f/src/Model/FabricateModel.php#L123-L127
45,389
SidRoberts/phalcon-cron
src/Manager.php
Manager.runInForeground
public function runInForeground(DateTime $now = null) : array { $jobs = $this->getDueJobs($now); $outputs = []; foreach ($jobs as $job) { $outputs[] = $job->runInForeground(); } return $outputs; }
php
public function runInForeground(DateTime $now = null) : array { $jobs = $this->getDueJobs($now); $outputs = []; foreach ($jobs as $job) { $outputs[] = $job->runInForeground(); } return $outputs; }
[ "public", "function", "runInForeground", "(", "DateTime", "$", "now", "=", "null", ")", ":", "array", "{", "$", "jobs", "=", "$", "this", "->", "getDueJobs", "(", "$", "now", ")", ";", "$", "outputs", "=", "[", "]", ";", "foreach", "(", "$", "jobs"...
Run all due jobs in the foreground.
[ "Run", "all", "due", "jobs", "in", "the", "foreground", "." ]
6d59c94c274949400a6b563d1e37f0e85ed32ba7
https://github.com/SidRoberts/phalcon-cron/blob/6d59c94c274949400a6b563d1e37f0e85ed32ba7/src/Manager.php#L32-L43
45,390
SidRoberts/phalcon-cron
src/Manager.php
Manager.runInBackground
public function runInBackground(DateTime $now = null) : array { $jobs = $this->getDueJobs($now); foreach ($jobs as $job) { $this->processes[] = $job->runInBackground(); } return $this->processes; }
php
public function runInBackground(DateTime $now = null) : array { $jobs = $this->getDueJobs($now); foreach ($jobs as $job) { $this->processes[] = $job->runInBackground(); } return $this->processes; }
[ "public", "function", "runInBackground", "(", "DateTime", "$", "now", "=", "null", ")", ":", "array", "{", "$", "jobs", "=", "$", "this", "->", "getDueJobs", "(", "$", "now", ")", ";", "foreach", "(", "$", "jobs", "as", "$", "job", ")", "{", "$", ...
Run all due jobs in the background.
[ "Run", "all", "due", "jobs", "in", "the", "background", "." ]
6d59c94c274949400a6b563d1e37f0e85ed32ba7
https://github.com/SidRoberts/phalcon-cron/blob/6d59c94c274949400a6b563d1e37f0e85ed32ba7/src/Manager.php#L48-L57
45,391
contributte/application
src/UI/BasePresenter.php
BasePresenter.isModuleCurrent
public function isModuleCurrent(string $module): bool { return strpos($this->getAction(true), $module) !== false; }
php
public function isModuleCurrent(string $module): bool { return strpos($this->getAction(true), $module) !== false; }
[ "public", "function", "isModuleCurrent", "(", "string", "$", "module", ")", ":", "bool", "{", "return", "strpos", "(", "$", "this", "->", "getAction", "(", "true", ")", ",", "$", "module", ")", "!==", "false", ";", "}" ]
Is current module active? @param string $module Module name
[ "Is", "current", "module", "active?" ]
b5c46efaabb27ccd7aeb1ae80d9c9598976465e5
https://github.com/contributte/application/blob/b5c46efaabb27ccd7aeb1ae80d9c9598976465e5/src/UI/BasePresenter.php#L25-L28
45,392
TwistoPayments/Twisto.php
src/Twisto/Twisto.php
Twisto.encrypt
private function encrypt($data) { $bin_key = pack("H*", substr($this->secret_key, 8)); $aes_key = substr($bin_key, 0, 16); $salt = substr($bin_key, 16, 16); $iv = openssl_random_pseudo_bytes(16); $encrypted = openssl_encrypt($data, 'aes-128-cbc', $aes_key, true, $iv); $digest = hash_hmac('sha256', $data . $iv, $salt, true); return base64_encode($iv . $digest . $encrypted); }
php
private function encrypt($data) { $bin_key = pack("H*", substr($this->secret_key, 8)); $aes_key = substr($bin_key, 0, 16); $salt = substr($bin_key, 16, 16); $iv = openssl_random_pseudo_bytes(16); $encrypted = openssl_encrypt($data, 'aes-128-cbc', $aes_key, true, $iv); $digest = hash_hmac('sha256', $data . $iv, $salt, true); return base64_encode($iv . $digest . $encrypted); }
[ "private", "function", "encrypt", "(", "$", "data", ")", "{", "$", "bin_key", "=", "pack", "(", "\"H*\"", ",", "substr", "(", "$", "this", "->", "secret_key", ",", "8", ")", ")", ";", "$", "aes_key", "=", "substr", "(", "$", "bin_key", ",", "0", ...
Encrypt data with AES-128-CBC and HMAC-SHA-256 @param string $data @return string
[ "Encrypt", "data", "with", "AES", "-", "128", "-", "CBC", "and", "HMAC", "-", "SHA", "-", "256" ]
89a9361830766205ce9141bfde88515043600161
https://github.com/TwistoPayments/Twisto.php/blob/89a9361830766205ce9141bfde88515043600161/src/Twisto/Twisto.php#L53-L62
45,393
TwistoPayments/Twisto.php
src/Twisto/Twisto.php
Twisto.requestJson
public function requestJson($method, $url, $data = null) { $response = $this->request($method, $url, $data); $json = json_decode($response, true); if ($json === null) { throw new Error('API responded with invalid JSON'); } return $json; }
php
public function requestJson($method, $url, $data = null) { $response = $this->request($method, $url, $data); $json = json_decode($response, true); if ($json === null) { throw new Error('API responded with invalid JSON'); } return $json; }
[ "public", "function", "requestJson", "(", "$", "method", ",", "$", "url", ",", "$", "data", "=", "null", ")", "{", "$", "response", "=", "$", "this", "->", "request", "(", "$", "method", ",", "$", "url", ",", "$", "data", ")", ";", "$", "json", ...
Perform API request and decode response JSON @param string $method @param string $url @param array $data @return mixed @throws Error
[ "Perform", "API", "request", "and", "decode", "response", "JSON" ]
89a9361830766205ce9141bfde88515043600161
https://github.com/TwistoPayments/Twisto.php/blob/89a9361830766205ce9141bfde88515043600161/src/Twisto/Twisto.php#L83-L93
45,394
TwistoPayments/Twisto.php
src/Twisto/Twisto.php
Twisto.request
public function request($method, $url, $data = null) { $curl = curl_init(); curl_setopt($curl, CURLOPT_HTTPHEADER, array( "Content-Type: application/json", "Authorization: {$this->public_key},{$this->secret_key}" )); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_URL, $this->api_url . $url); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); if ($data !== null) { curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); } $response = curl_exec($curl); if (curl_errno($curl)) { throw new Error('Curl error: ' . curl_error($curl)); } $info = curl_getinfo($curl); if ($info['http_code'] != 200) { throw new Error('API responded with wrong status code (' . $info['http_code'] . ')', json_decode($response)); } return $response; }
php
public function request($method, $url, $data = null) { $curl = curl_init(); curl_setopt($curl, CURLOPT_HTTPHEADER, array( "Content-Type: application/json", "Authorization: {$this->public_key},{$this->secret_key}" )); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_URL, $this->api_url . $url); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); if ($data !== null) { curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); } $response = curl_exec($curl); if (curl_errno($curl)) { throw new Error('Curl error: ' . curl_error($curl)); } $info = curl_getinfo($curl); if ($info['http_code'] != 200) { throw new Error('API responded with wrong status code (' . $info['http_code'] . ')', json_decode($response)); } return $response; }
[ "public", "function", "request", "(", "$", "method", ",", "$", "url", ",", "$", "data", "=", "null", ")", "{", "$", "curl", "=", "curl_init", "(", ")", ";", "curl_setopt", "(", "$", "curl", ",", "CURLOPT_HTTPHEADER", ",", "array", "(", "\"Content-Type:...
Perform API request @param string $method @param string $url @param array $data @return mixed @throws Error
[ "Perform", "API", "request" ]
89a9361830766205ce9141bfde88515043600161
https://github.com/TwistoPayments/Twisto.php/blob/89a9361830766205ce9141bfde88515043600161/src/Twisto/Twisto.php#L104-L130
45,395
TwistoPayments/Twisto.php
src/Twisto/Twisto.php
Twisto.getCheckPayload
public function getCheckPayload(Customer $customer, Order $order, $previous_orders) { $payload = json_encode(array( 'random_nonce' => uniqid('', true), 'customer' => $customer->serialize(), 'order' => $order->serialize(), 'previous_orders' => array_map(function (Order $item) { return $item->serialize(); }, $previous_orders) )); return $this->encrypt($this->compress($payload)); }
php
public function getCheckPayload(Customer $customer, Order $order, $previous_orders) { $payload = json_encode(array( 'random_nonce' => uniqid('', true), 'customer' => $customer->serialize(), 'order' => $order->serialize(), 'previous_orders' => array_map(function (Order $item) { return $item->serialize(); }, $previous_orders) )); return $this->encrypt($this->compress($payload)); }
[ "public", "function", "getCheckPayload", "(", "Customer", "$", "customer", ",", "Order", "$", "order", ",", "$", "previous_orders", ")", "{", "$", "payload", "=", "json_encode", "(", "array", "(", "'random_nonce'", "=>", "uniqid", "(", "''", ",", "true", "...
Create check payload @param Customer $customer @param Order $order @param Order[] $previous_orders @return string
[ "Create", "check", "payload" ]
89a9361830766205ce9141bfde88515043600161
https://github.com/TwistoPayments/Twisto.php/blob/89a9361830766205ce9141bfde88515043600161/src/Twisto/Twisto.php#L139-L150
45,396
TwistoPayments/Twisto.php
src/Twisto/Invoice.php
Invoice.get
public function get() { $data = $this->twisto->requestJson('GET', 'invoice/' . urlencode($this->invoice_id) . '/'); $this->deserialize($data); }
php
public function get() { $data = $this->twisto->requestJson('GET', 'invoice/' . urlencode($this->invoice_id) . '/'); $this->deserialize($data); }
[ "public", "function", "get", "(", ")", "{", "$", "data", "=", "$", "this", "->", "twisto", "->", "requestJson", "(", "'GET'", ",", "'invoice/'", ".", "urlencode", "(", "$", "this", "->", "invoice_id", ")", ".", "'/'", ")", ";", "$", "this", "->", "...
Fetch invoice data from API
[ "Fetch", "invoice", "data", "from", "API" ]
89a9361830766205ce9141bfde88515043600161
https://github.com/TwistoPayments/Twisto.php/blob/89a9361830766205ce9141bfde88515043600161/src/Twisto/Invoice.php#L68-L72
45,397
TwistoPayments/Twisto.php
src/Twisto/Invoice.php
Invoice.cancel
public function cancel() { $data = $this->twisto->requestJson('POST', 'invoice/' . urlencode($this->invoice_id) . '/cancel/'); $this->deserialize($data); }
php
public function cancel() { $data = $this->twisto->requestJson('POST', 'invoice/' . urlencode($this->invoice_id) . '/cancel/'); $this->deserialize($data); }
[ "public", "function", "cancel", "(", ")", "{", "$", "data", "=", "$", "this", "->", "twisto", "->", "requestJson", "(", "'POST'", ",", "'invoice/'", ".", "urlencode", "(", "$", "this", "->", "invoice_id", ")", ".", "'/cancel/'", ")", ";", "$", "this", ...
Perform cancel invoice API request
[ "Perform", "cancel", "invoice", "API", "request" ]
89a9361830766205ce9141bfde88515043600161
https://github.com/TwistoPayments/Twisto.php/blob/89a9361830766205ce9141bfde88515043600161/src/Twisto/Invoice.php#L78-L82
45,398
TwistoPayments/Twisto.php
src/Twisto/Invoice.php
Invoice.activate
public function activate() { $data = $this->twisto->requestJson('POST', 'invoice/' . urlencode($this->invoice_id) . '/activate/'); $this->deserialize($data); }
php
public function activate() { $data = $this->twisto->requestJson('POST', 'invoice/' . urlencode($this->invoice_id) . '/activate/'); $this->deserialize($data); }
[ "public", "function", "activate", "(", ")", "{", "$", "data", "=", "$", "this", "->", "twisto", "->", "requestJson", "(", "'POST'", ",", "'invoice/'", ".", "urlencode", "(", "$", "this", "->", "invoice_id", ")", ".", "'/activate/'", ")", ";", "$", "thi...
Perform activate invoice API request
[ "Perform", "activate", "invoice", "API", "request" ]
89a9361830766205ce9141bfde88515043600161
https://github.com/TwistoPayments/Twisto.php/blob/89a9361830766205ce9141bfde88515043600161/src/Twisto/Invoice.php#L87-L91
45,399
TwistoPayments/Twisto.php
src/Twisto/Invoice.php
Invoice.save
public function save() { $data = $this->twisto->requestJson('POST', 'invoice/' . urlencode($this->invoice_id) . '/edit/', $this->serialize()); $this->deserialize($data); }
php
public function save() { $data = $this->twisto->requestJson('POST', 'invoice/' . urlencode($this->invoice_id) . '/edit/', $this->serialize()); $this->deserialize($data); }
[ "public", "function", "save", "(", ")", "{", "$", "data", "=", "$", "this", "->", "twisto", "->", "requestJson", "(", "'POST'", ",", "'invoice/'", ".", "urlencode", "(", "$", "this", "->", "invoice_id", ")", ".", "'/edit/'", ",", "$", "this", "->", "...
Save invoice items
[ "Save", "invoice", "items" ]
89a9361830766205ce9141bfde88515043600161
https://github.com/TwistoPayments/Twisto.php/blob/89a9361830766205ce9141bfde88515043600161/src/Twisto/Invoice.php#L96-L100