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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
235,300
|
nattreid/app-manager
|
src/Helpers/Info.php
|
Info.getSystem
|
protected function getSystem(): Obj
{
$system = new Obj;
$system->hostname = $this->readFile('/etc/hostname');
$system->ip = $this->getIp();
$system->distribution = Strings::replace($this->readCommand('lsb_release -d'), '/Description:\s/');
$system->kernel = $this->readCommand('uname -r') . ' ' . $this->readCommand('uname -i');
$uptime = $this->readFileAsArray('/proc/uptime', ' ');
if ($uptime) {
$system->uptime = new Obj;
$system->uptime->days = (int) gmdate("d", (int) $uptime[0]) - 1;
$system->uptime->hours = (int) gmdate("H", (int) $uptime[0]);
$system->uptime->minutes = (int) gmdate("i", (int) $uptime[0]);
}
$system->users = $this->readCommandAsArray('users', ' ');
$system->load = $this->getLoad();
$system->processes = new Obj;
$system->processes->total = $this->readCommand('ps axo state | wc -l');
$system->processes->running = $this->readCommand('ps axo state | grep "R" | wc -l');
$system->processes->sleeping = $system->processes->total - $system->processes->running;
return $system;
}
|
php
|
protected function getSystem(): Obj
{
$system = new Obj;
$system->hostname = $this->readFile('/etc/hostname');
$system->ip = $this->getIp();
$system->distribution = Strings::replace($this->readCommand('lsb_release -d'), '/Description:\s/');
$system->kernel = $this->readCommand('uname -r') . ' ' . $this->readCommand('uname -i');
$uptime = $this->readFileAsArray('/proc/uptime', ' ');
if ($uptime) {
$system->uptime = new Obj;
$system->uptime->days = (int) gmdate("d", (int) $uptime[0]) - 1;
$system->uptime->hours = (int) gmdate("H", (int) $uptime[0]);
$system->uptime->minutes = (int) gmdate("i", (int) $uptime[0]);
}
$system->users = $this->readCommandAsArray('users', ' ');
$system->load = $this->getLoad();
$system->processes = new Obj;
$system->processes->total = $this->readCommand('ps axo state | wc -l');
$system->processes->running = $this->readCommand('ps axo state | grep "R" | wc -l');
$system->processes->sleeping = $system->processes->total - $system->processes->running;
return $system;
}
|
[
"protected",
"function",
"getSystem",
"(",
")",
":",
"Obj",
"{",
"$",
"system",
"=",
"new",
"Obj",
";",
"$",
"system",
"->",
"hostname",
"=",
"$",
"this",
"->",
"readFile",
"(",
"'/etc/hostname'",
")",
";",
"$",
"system",
"->",
"ip",
"=",
"$",
"this",
"->",
"getIp",
"(",
")",
";",
"$",
"system",
"->",
"distribution",
"=",
"Strings",
"::",
"replace",
"(",
"$",
"this",
"->",
"readCommand",
"(",
"'lsb_release -d'",
")",
",",
"'/Description:\\s/'",
")",
";",
"$",
"system",
"->",
"kernel",
"=",
"$",
"this",
"->",
"readCommand",
"(",
"'uname -r'",
")",
".",
"' '",
".",
"$",
"this",
"->",
"readCommand",
"(",
"'uname -i'",
")",
";",
"$",
"uptime",
"=",
"$",
"this",
"->",
"readFileAsArray",
"(",
"'/proc/uptime'",
",",
"' '",
")",
";",
"if",
"(",
"$",
"uptime",
")",
"{",
"$",
"system",
"->",
"uptime",
"=",
"new",
"Obj",
";",
"$",
"system",
"->",
"uptime",
"->",
"days",
"=",
"(",
"int",
")",
"gmdate",
"(",
"\"d\"",
",",
"(",
"int",
")",
"$",
"uptime",
"[",
"0",
"]",
")",
"-",
"1",
";",
"$",
"system",
"->",
"uptime",
"->",
"hours",
"=",
"(",
"int",
")",
"gmdate",
"(",
"\"H\"",
",",
"(",
"int",
")",
"$",
"uptime",
"[",
"0",
"]",
")",
";",
"$",
"system",
"->",
"uptime",
"->",
"minutes",
"=",
"(",
"int",
")",
"gmdate",
"(",
"\"i\"",
",",
"(",
"int",
")",
"$",
"uptime",
"[",
"0",
"]",
")",
";",
"}",
"$",
"system",
"->",
"users",
"=",
"$",
"this",
"->",
"readCommandAsArray",
"(",
"'users'",
",",
"' '",
")",
";",
"$",
"system",
"->",
"load",
"=",
"$",
"this",
"->",
"getLoad",
"(",
")",
";",
"$",
"system",
"->",
"processes",
"=",
"new",
"Obj",
";",
"$",
"system",
"->",
"processes",
"->",
"total",
"=",
"$",
"this",
"->",
"readCommand",
"(",
"'ps axo state | wc -l'",
")",
";",
"$",
"system",
"->",
"processes",
"->",
"running",
"=",
"$",
"this",
"->",
"readCommand",
"(",
"'ps axo state | grep \"R\" | wc -l'",
")",
";",
"$",
"system",
"->",
"processes",
"->",
"sleeping",
"=",
"$",
"system",
"->",
"processes",
"->",
"total",
"-",
"$",
"system",
"->",
"processes",
"->",
"running",
";",
"return",
"$",
"system",
";",
"}"
] |
Vrati informace o systemu
@return Obj
|
[
"Vrati",
"informace",
"o",
"systemu"
] |
7821d09a0b3e58ba9c6eb81d44e35aacce55de75
|
https://github.com/nattreid/app-manager/blob/7821d09a0b3e58ba9c6eb81d44e35aacce55de75/src/Helpers/Info.php#L86-L113
|
235,301
|
nattreid/app-manager
|
src/Helpers/Info.php
|
Info.getLoad
|
protected function getLoad(): ?string
{
$load = $this->readFileAsArray('/proc/loadavg', ' ');
if ($load) {
unset($load[3], $load[4]);
return implode(' ', $load);
}
return null;
}
|
php
|
protected function getLoad(): ?string
{
$load = $this->readFileAsArray('/proc/loadavg', ' ');
if ($load) {
unset($load[3], $load[4]);
return implode(' ', $load);
}
return null;
}
|
[
"protected",
"function",
"getLoad",
"(",
")",
":",
"?",
"string",
"{",
"$",
"load",
"=",
"$",
"this",
"->",
"readFileAsArray",
"(",
"'/proc/loadavg'",
",",
"' '",
")",
";",
"if",
"(",
"$",
"load",
")",
"{",
"unset",
"(",
"$",
"load",
"[",
"3",
"]",
",",
"$",
"load",
"[",
"4",
"]",
")",
";",
"return",
"implode",
"(",
"' '",
",",
"$",
"load",
")",
";",
"}",
"return",
"null",
";",
"}"
] |
Vrati vytizeni serveru
@return string|null
|
[
"Vrati",
"vytizeni",
"serveru"
] |
7821d09a0b3e58ba9c6eb81d44e35aacce55de75
|
https://github.com/nattreid/app-manager/blob/7821d09a0b3e58ba9c6eb81d44e35aacce55de75/src/Helpers/Info.php#L128-L136
|
235,302
|
nattreid/app-manager
|
src/Helpers/Info.php
|
Info.getHardware
|
protected function getHardware(): Obj
{
$hardware = new Obj;
$product = $this->readFile('/sys/devices/virtual/dmi/id/product_name');
$board = $this->readFile('/sys/devices/virtual/dmi/id/board_name');
$bios = $this->readFile('/sys/devices/virtual/dmi/id/bios_version');
$biosDate = $this->readFile('/sys/devices/virtual/dmi/id/bios_date');
$hardware->server = $product
. ($board ? '/' . $board : null)
. ($bios ? ', BIOS ' . $bios : null)
. ($biosDate ? ' ' . $biosDate : null);
$hardware->cpu = $this->getCpu();
$hardware->scsi = $this->getScsi();
$hardware->data = !empty($hardware->server) || !empty($hardware->cpu) || !empty($hardware->scsi);
return $hardware;
}
|
php
|
protected function getHardware(): Obj
{
$hardware = new Obj;
$product = $this->readFile('/sys/devices/virtual/dmi/id/product_name');
$board = $this->readFile('/sys/devices/virtual/dmi/id/board_name');
$bios = $this->readFile('/sys/devices/virtual/dmi/id/bios_version');
$biosDate = $this->readFile('/sys/devices/virtual/dmi/id/bios_date');
$hardware->server = $product
. ($board ? '/' . $board : null)
. ($bios ? ', BIOS ' . $bios : null)
. ($biosDate ? ' ' . $biosDate : null);
$hardware->cpu = $this->getCpu();
$hardware->scsi = $this->getScsi();
$hardware->data = !empty($hardware->server) || !empty($hardware->cpu) || !empty($hardware->scsi);
return $hardware;
}
|
[
"protected",
"function",
"getHardware",
"(",
")",
":",
"Obj",
"{",
"$",
"hardware",
"=",
"new",
"Obj",
";",
"$",
"product",
"=",
"$",
"this",
"->",
"readFile",
"(",
"'/sys/devices/virtual/dmi/id/product_name'",
")",
";",
"$",
"board",
"=",
"$",
"this",
"->",
"readFile",
"(",
"'/sys/devices/virtual/dmi/id/board_name'",
")",
";",
"$",
"bios",
"=",
"$",
"this",
"->",
"readFile",
"(",
"'/sys/devices/virtual/dmi/id/bios_version'",
")",
";",
"$",
"biosDate",
"=",
"$",
"this",
"->",
"readFile",
"(",
"'/sys/devices/virtual/dmi/id/bios_date'",
")",
";",
"$",
"hardware",
"->",
"server",
"=",
"$",
"product",
".",
"(",
"$",
"board",
"?",
"'/'",
".",
"$",
"board",
":",
"null",
")",
".",
"(",
"$",
"bios",
"?",
"', BIOS '",
".",
"$",
"bios",
":",
"null",
")",
".",
"(",
"$",
"biosDate",
"?",
"' '",
".",
"$",
"biosDate",
":",
"null",
")",
";",
"$",
"hardware",
"->",
"cpu",
"=",
"$",
"this",
"->",
"getCpu",
"(",
")",
";",
"$",
"hardware",
"->",
"scsi",
"=",
"$",
"this",
"->",
"getScsi",
"(",
")",
";",
"$",
"hardware",
"->",
"data",
"=",
"!",
"empty",
"(",
"$",
"hardware",
"->",
"server",
")",
"||",
"!",
"empty",
"(",
"$",
"hardware",
"->",
"cpu",
")",
"||",
"!",
"empty",
"(",
"$",
"hardware",
"->",
"scsi",
")",
";",
"return",
"$",
"hardware",
";",
"}"
] |
Vrati informace o hardware
@return Obj
|
[
"Vrati",
"informace",
"o",
"hardware"
] |
7821d09a0b3e58ba9c6eb81d44e35aacce55de75
|
https://github.com/nattreid/app-manager/blob/7821d09a0b3e58ba9c6eb81d44e35aacce55de75/src/Helpers/Info.php#L142-L161
|
235,303
|
nattreid/app-manager
|
src/Helpers/Info.php
|
Info.getScsi
|
private function getScsi(): array
{
$get_type = false;
$device = null;
$scsi = [];
$data = $this->readFile('/proc/scsi/scsi');
if ($data !== null) {
$bufe = preg_split("/\n/", $data, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
if (preg_match('/Vendor: (.*) Model: (.*) Rev: (.*)/i', $buf, $devices)) {
$get_type = true;
$device = $devices;
continue;
}
if ($get_type) {
preg_match('/Type:\s+(\S+)/i', $buf, $dev_type);
$dev = new Obj;
$dev->name = trim($device[1]) . ' ' . trim($device[2]);
$dev->type = trim($dev_type[1]);
$scsi[] = $dev;
$get_type = false;
}
}
}
return $scsi;
}
|
php
|
private function getScsi(): array
{
$get_type = false;
$device = null;
$scsi = [];
$data = $this->readFile('/proc/scsi/scsi');
if ($data !== null) {
$bufe = preg_split("/\n/", $data, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
if (preg_match('/Vendor: (.*) Model: (.*) Rev: (.*)/i', $buf, $devices)) {
$get_type = true;
$device = $devices;
continue;
}
if ($get_type) {
preg_match('/Type:\s+(\S+)/i', $buf, $dev_type);
$dev = new Obj;
$dev->name = trim($device[1]) . ' ' . trim($device[2]);
$dev->type = trim($dev_type[1]);
$scsi[] = $dev;
$get_type = false;
}
}
}
return $scsi;
}
|
[
"private",
"function",
"getScsi",
"(",
")",
":",
"array",
"{",
"$",
"get_type",
"=",
"false",
";",
"$",
"device",
"=",
"null",
";",
"$",
"scsi",
"=",
"[",
"]",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"readFile",
"(",
"'/proc/scsi/scsi'",
")",
";",
"if",
"(",
"$",
"data",
"!==",
"null",
")",
"{",
"$",
"bufe",
"=",
"preg_split",
"(",
"\"/\\n/\"",
",",
"$",
"data",
",",
"-",
"1",
",",
"PREG_SPLIT_NO_EMPTY",
")",
";",
"foreach",
"(",
"$",
"bufe",
"as",
"$",
"buf",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/Vendor: (.*) Model: (.*) Rev: (.*)/i'",
",",
"$",
"buf",
",",
"$",
"devices",
")",
")",
"{",
"$",
"get_type",
"=",
"true",
";",
"$",
"device",
"=",
"$",
"devices",
";",
"continue",
";",
"}",
"if",
"(",
"$",
"get_type",
")",
"{",
"preg_match",
"(",
"'/Type:\\s+(\\S+)/i'",
",",
"$",
"buf",
",",
"$",
"dev_type",
")",
";",
"$",
"dev",
"=",
"new",
"Obj",
";",
"$",
"dev",
"->",
"name",
"=",
"trim",
"(",
"$",
"device",
"[",
"1",
"]",
")",
".",
"' '",
".",
"trim",
"(",
"$",
"device",
"[",
"2",
"]",
")",
";",
"$",
"dev",
"->",
"type",
"=",
"trim",
"(",
"$",
"dev_type",
"[",
"1",
"]",
")",
";",
"$",
"scsi",
"[",
"]",
"=",
"$",
"dev",
";",
"$",
"get_type",
"=",
"false",
";",
"}",
"}",
"}",
"return",
"$",
"scsi",
";",
"}"
] |
Vrati informace o scsi
@return Obj[]
|
[
"Vrati",
"informace",
"o",
"scsi"
] |
7821d09a0b3e58ba9c6eb81d44e35aacce55de75
|
https://github.com/nattreid/app-manager/blob/7821d09a0b3e58ba9c6eb81d44e35aacce55de75/src/Helpers/Info.php#L311-L337
|
235,304
|
nattreid/app-manager
|
src/Helpers/Info.php
|
Info.getMemory
|
protected function getMemory(): ?Obj
{
$memory = null;
$meminfo = $this->readFile('/proc/meminfo');
if ($meminfo) {
$bufer = preg_split("/\n/", $meminfo, -1, PREG_SPLIT_NO_EMPTY);
$memory = new Obj;
foreach ($bufer as $buf) {
if (preg_match('/^MemTotal:\s+(.*)\s*kB/i', $buf, $ar_buf)) {
$memory->total = ((float) $ar_buf[1]) * 1024;
} elseif (preg_match('/^MemFree:\s+(.*)\s*kB/i', $buf, $ar_buf)) {
$memory->free = ((float) $ar_buf[1]) * 1024;
} elseif (preg_match('/^Cached:\s+(.*)\s*kB/i', $buf, $ar_buf)) {
$memory->cache = ((float) $ar_buf[1]) * 1024;
} elseif (preg_match('/^Buffers:\s+(.*)\s*kB/i', $buf, $ar_buf)) {
$memory->buffer = ((float) $ar_buf[1]) * 1024;
}
}
$memory->used = $memory->total - $memory->free;
if ($memory->cache !== null && $memory->buffer !== null) {
$memory->application = $memory->used - $memory->cache - $memory->buffer;
}
$memory->swap = [];
$swaps = preg_split("/\n/", $this->readFile('/proc/swaps'), -1, PREG_SPLIT_NO_EMPTY);
unset($swaps[0]);
foreach ($swaps as $swap) {
$ar_buf = preg_split('/\s+/', $swap, PREG_BAD_UTF8_OFFSET_ERROR);
$swap = new Obj;
$swap->mount = $ar_buf[0];
$swap->name = 'SWAP';
$swap->total = $ar_buf[2] * 1024;
$swap->used = $ar_buf[3] * 1024;
$swap->free = $swap->total - $swap->used;
$memory->swap[] = $swap;
}
}
return $memory;
}
|
php
|
protected function getMemory(): ?Obj
{
$memory = null;
$meminfo = $this->readFile('/proc/meminfo');
if ($meminfo) {
$bufer = preg_split("/\n/", $meminfo, -1, PREG_SPLIT_NO_EMPTY);
$memory = new Obj;
foreach ($bufer as $buf) {
if (preg_match('/^MemTotal:\s+(.*)\s*kB/i', $buf, $ar_buf)) {
$memory->total = ((float) $ar_buf[1]) * 1024;
} elseif (preg_match('/^MemFree:\s+(.*)\s*kB/i', $buf, $ar_buf)) {
$memory->free = ((float) $ar_buf[1]) * 1024;
} elseif (preg_match('/^Cached:\s+(.*)\s*kB/i', $buf, $ar_buf)) {
$memory->cache = ((float) $ar_buf[1]) * 1024;
} elseif (preg_match('/^Buffers:\s+(.*)\s*kB/i', $buf, $ar_buf)) {
$memory->buffer = ((float) $ar_buf[1]) * 1024;
}
}
$memory->used = $memory->total - $memory->free;
if ($memory->cache !== null && $memory->buffer !== null) {
$memory->application = $memory->used - $memory->cache - $memory->buffer;
}
$memory->swap = [];
$swaps = preg_split("/\n/", $this->readFile('/proc/swaps'), -1, PREG_SPLIT_NO_EMPTY);
unset($swaps[0]);
foreach ($swaps as $swap) {
$ar_buf = preg_split('/\s+/', $swap, PREG_BAD_UTF8_OFFSET_ERROR);
$swap = new Obj;
$swap->mount = $ar_buf[0];
$swap->name = 'SWAP';
$swap->total = $ar_buf[2] * 1024;
$swap->used = $ar_buf[3] * 1024;
$swap->free = $swap->total - $swap->used;
$memory->swap[] = $swap;
}
}
return $memory;
}
|
[
"protected",
"function",
"getMemory",
"(",
")",
":",
"?",
"Obj",
"{",
"$",
"memory",
"=",
"null",
";",
"$",
"meminfo",
"=",
"$",
"this",
"->",
"readFile",
"(",
"'/proc/meminfo'",
")",
";",
"if",
"(",
"$",
"meminfo",
")",
"{",
"$",
"bufer",
"=",
"preg_split",
"(",
"\"/\\n/\"",
",",
"$",
"meminfo",
",",
"-",
"1",
",",
"PREG_SPLIT_NO_EMPTY",
")",
";",
"$",
"memory",
"=",
"new",
"Obj",
";",
"foreach",
"(",
"$",
"bufer",
"as",
"$",
"buf",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/^MemTotal:\\s+(.*)\\s*kB/i'",
",",
"$",
"buf",
",",
"$",
"ar_buf",
")",
")",
"{",
"$",
"memory",
"->",
"total",
"=",
"(",
"(",
"float",
")",
"$",
"ar_buf",
"[",
"1",
"]",
")",
"*",
"1024",
";",
"}",
"elseif",
"(",
"preg_match",
"(",
"'/^MemFree:\\s+(.*)\\s*kB/i'",
",",
"$",
"buf",
",",
"$",
"ar_buf",
")",
")",
"{",
"$",
"memory",
"->",
"free",
"=",
"(",
"(",
"float",
")",
"$",
"ar_buf",
"[",
"1",
"]",
")",
"*",
"1024",
";",
"}",
"elseif",
"(",
"preg_match",
"(",
"'/^Cached:\\s+(.*)\\s*kB/i'",
",",
"$",
"buf",
",",
"$",
"ar_buf",
")",
")",
"{",
"$",
"memory",
"->",
"cache",
"=",
"(",
"(",
"float",
")",
"$",
"ar_buf",
"[",
"1",
"]",
")",
"*",
"1024",
";",
"}",
"elseif",
"(",
"preg_match",
"(",
"'/^Buffers:\\s+(.*)\\s*kB/i'",
",",
"$",
"buf",
",",
"$",
"ar_buf",
")",
")",
"{",
"$",
"memory",
"->",
"buffer",
"=",
"(",
"(",
"float",
")",
"$",
"ar_buf",
"[",
"1",
"]",
")",
"*",
"1024",
";",
"}",
"}",
"$",
"memory",
"->",
"used",
"=",
"$",
"memory",
"->",
"total",
"-",
"$",
"memory",
"->",
"free",
";",
"if",
"(",
"$",
"memory",
"->",
"cache",
"!==",
"null",
"&&",
"$",
"memory",
"->",
"buffer",
"!==",
"null",
")",
"{",
"$",
"memory",
"->",
"application",
"=",
"$",
"memory",
"->",
"used",
"-",
"$",
"memory",
"->",
"cache",
"-",
"$",
"memory",
"->",
"buffer",
";",
"}",
"$",
"memory",
"->",
"swap",
"=",
"[",
"]",
";",
"$",
"swaps",
"=",
"preg_split",
"(",
"\"/\\n/\"",
",",
"$",
"this",
"->",
"readFile",
"(",
"'/proc/swaps'",
")",
",",
"-",
"1",
",",
"PREG_SPLIT_NO_EMPTY",
")",
";",
"unset",
"(",
"$",
"swaps",
"[",
"0",
"]",
")",
";",
"foreach",
"(",
"$",
"swaps",
"as",
"$",
"swap",
")",
"{",
"$",
"ar_buf",
"=",
"preg_split",
"(",
"'/\\s+/'",
",",
"$",
"swap",
",",
"PREG_BAD_UTF8_OFFSET_ERROR",
")",
";",
"$",
"swap",
"=",
"new",
"Obj",
";",
"$",
"swap",
"->",
"mount",
"=",
"$",
"ar_buf",
"[",
"0",
"]",
";",
"$",
"swap",
"->",
"name",
"=",
"'SWAP'",
";",
"$",
"swap",
"->",
"total",
"=",
"$",
"ar_buf",
"[",
"2",
"]",
"*",
"1024",
";",
"$",
"swap",
"->",
"used",
"=",
"$",
"ar_buf",
"[",
"3",
"]",
"*",
"1024",
";",
"$",
"swap",
"->",
"free",
"=",
"$",
"swap",
"->",
"total",
"-",
"$",
"swap",
"->",
"used",
";",
"$",
"memory",
"->",
"swap",
"[",
"]",
"=",
"$",
"swap",
";",
"}",
"}",
"return",
"$",
"memory",
";",
"}"
] |
Vrati informace o pameti
@return Obj|null
|
[
"Vrati",
"informace",
"o",
"pameti"
] |
7821d09a0b3e58ba9c6eb81d44e35aacce55de75
|
https://github.com/nattreid/app-manager/blob/7821d09a0b3e58ba9c6eb81d44e35aacce55de75/src/Helpers/Info.php#L343-L383
|
235,305
|
nattreid/app-manager
|
src/Helpers/Info.php
|
Info.getFileSystem
|
protected function getFileSystem(): array
{
$fileSystem = [];
$command = $this->readCommand('df -T');
if ($command) {
$bufe = preg_split("/\n/", $command, -1, PREG_SPLIT_NO_EMPTY);
unset($bufe[0]);
foreach ($bufe as $buf) {
$data = preg_split('/\s+/', $buf);
$mounted = new Obj;
$mounted->partition = $data[0];
$mounted->type = $data[1];
$mounted->size = $data[2] * 1024;
$mounted->used = $data[3] * 1024;
$mounted->free = $data[4] * 1024;
$mounted->usage = $data[5];
$mounted->mountPoint = $data[6];
$fileSystem[] = $mounted;
}
}
return $fileSystem;
}
|
php
|
protected function getFileSystem(): array
{
$fileSystem = [];
$command = $this->readCommand('df -T');
if ($command) {
$bufe = preg_split("/\n/", $command, -1, PREG_SPLIT_NO_EMPTY);
unset($bufe[0]);
foreach ($bufe as $buf) {
$data = preg_split('/\s+/', $buf);
$mounted = new Obj;
$mounted->partition = $data[0];
$mounted->type = $data[1];
$mounted->size = $data[2] * 1024;
$mounted->used = $data[3] * 1024;
$mounted->free = $data[4] * 1024;
$mounted->usage = $data[5];
$mounted->mountPoint = $data[6];
$fileSystem[] = $mounted;
}
}
return $fileSystem;
}
|
[
"protected",
"function",
"getFileSystem",
"(",
")",
":",
"array",
"{",
"$",
"fileSystem",
"=",
"[",
"]",
";",
"$",
"command",
"=",
"$",
"this",
"->",
"readCommand",
"(",
"'df -T'",
")",
";",
"if",
"(",
"$",
"command",
")",
"{",
"$",
"bufe",
"=",
"preg_split",
"(",
"\"/\\n/\"",
",",
"$",
"command",
",",
"-",
"1",
",",
"PREG_SPLIT_NO_EMPTY",
")",
";",
"unset",
"(",
"$",
"bufe",
"[",
"0",
"]",
")",
";",
"foreach",
"(",
"$",
"bufe",
"as",
"$",
"buf",
")",
"{",
"$",
"data",
"=",
"preg_split",
"(",
"'/\\s+/'",
",",
"$",
"buf",
")",
";",
"$",
"mounted",
"=",
"new",
"Obj",
";",
"$",
"mounted",
"->",
"partition",
"=",
"$",
"data",
"[",
"0",
"]",
";",
"$",
"mounted",
"->",
"type",
"=",
"$",
"data",
"[",
"1",
"]",
";",
"$",
"mounted",
"->",
"size",
"=",
"$",
"data",
"[",
"2",
"]",
"*",
"1024",
";",
"$",
"mounted",
"->",
"used",
"=",
"$",
"data",
"[",
"3",
"]",
"*",
"1024",
";",
"$",
"mounted",
"->",
"free",
"=",
"$",
"data",
"[",
"4",
"]",
"*",
"1024",
";",
"$",
"mounted",
"->",
"usage",
"=",
"$",
"data",
"[",
"5",
"]",
";",
"$",
"mounted",
"->",
"mountPoint",
"=",
"$",
"data",
"[",
"6",
"]",
";",
"$",
"fileSystem",
"[",
"]",
"=",
"$",
"mounted",
";",
"}",
"}",
"return",
"$",
"fileSystem",
";",
"}"
] |
Vrati informace o souborovem system
@return Obj[]
|
[
"Vrati",
"informace",
"o",
"souborovem",
"system"
] |
7821d09a0b3e58ba9c6eb81d44e35aacce55de75
|
https://github.com/nattreid/app-manager/blob/7821d09a0b3e58ba9c6eb81d44e35aacce55de75/src/Helpers/Info.php#L389-L414
|
235,306
|
nattreid/app-manager
|
src/Helpers/Info.php
|
Info.getNetwork
|
protected function getNetwork(): array
{
$network = [];
$data = $this->readFile('/proc/net/dev');
if ($data !== null) {
$bufe = preg_split("/\n/", $data, -1, PREG_SPLIT_NO_EMPTY);
unset($bufe[0], $bufe[1]);
foreach ($bufe as $buf) {
list($dev_name, $stats_list) = preg_split('/:/', $buf, 2);
$stats = preg_split('/\s+/', trim($stats_list));
$dev = new Obj;
$dev->name = trim($dev_name);
$dev->recieve = (int) $stats[0];
$dev->sent = (int) $stats[8];
$dev->error = (int) $stats[2] + (int) $stats[10];
$dev->drop = (int) $stats[3] + (int) $stats[11];
$ipBuff = preg_split("/\n/", $this->readCommand('ip addr show ' . $dev->name), -1, PREG_SPLIT_NO_EMPTY);
foreach ($ipBuff as $line) {
if (preg_match('/^\s*link\/ether\s+(.*)\s+brd.*/i', $line, $ar_buf)) {
$dev->mac = $ar_buf[1];
} elseif (preg_match('/^\s*inet6\s+(.*)\/.*/i', $line, $ar_buf)) {
$dev->ip6 = $ar_buf[1];
} elseif (preg_match('/^\s*inet\s+(.*)\/.*/i', $line, $ar_buf)) {
$dev->ip = $ar_buf[1];
}
}
$network[] = $dev;
}
}
return $network;
}
|
php
|
protected function getNetwork(): array
{
$network = [];
$data = $this->readFile('/proc/net/dev');
if ($data !== null) {
$bufe = preg_split("/\n/", $data, -1, PREG_SPLIT_NO_EMPTY);
unset($bufe[0], $bufe[1]);
foreach ($bufe as $buf) {
list($dev_name, $stats_list) = preg_split('/:/', $buf, 2);
$stats = preg_split('/\s+/', trim($stats_list));
$dev = new Obj;
$dev->name = trim($dev_name);
$dev->recieve = (int) $stats[0];
$dev->sent = (int) $stats[8];
$dev->error = (int) $stats[2] + (int) $stats[10];
$dev->drop = (int) $stats[3] + (int) $stats[11];
$ipBuff = preg_split("/\n/", $this->readCommand('ip addr show ' . $dev->name), -1, PREG_SPLIT_NO_EMPTY);
foreach ($ipBuff as $line) {
if (preg_match('/^\s*link\/ether\s+(.*)\s+brd.*/i', $line, $ar_buf)) {
$dev->mac = $ar_buf[1];
} elseif (preg_match('/^\s*inet6\s+(.*)\/.*/i', $line, $ar_buf)) {
$dev->ip6 = $ar_buf[1];
} elseif (preg_match('/^\s*inet\s+(.*)\/.*/i', $line, $ar_buf)) {
$dev->ip = $ar_buf[1];
}
}
$network[] = $dev;
}
}
return $network;
}
|
[
"protected",
"function",
"getNetwork",
"(",
")",
":",
"array",
"{",
"$",
"network",
"=",
"[",
"]",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"readFile",
"(",
"'/proc/net/dev'",
")",
";",
"if",
"(",
"$",
"data",
"!==",
"null",
")",
"{",
"$",
"bufe",
"=",
"preg_split",
"(",
"\"/\\n/\"",
",",
"$",
"data",
",",
"-",
"1",
",",
"PREG_SPLIT_NO_EMPTY",
")",
";",
"unset",
"(",
"$",
"bufe",
"[",
"0",
"]",
",",
"$",
"bufe",
"[",
"1",
"]",
")",
";",
"foreach",
"(",
"$",
"bufe",
"as",
"$",
"buf",
")",
"{",
"list",
"(",
"$",
"dev_name",
",",
"$",
"stats_list",
")",
"=",
"preg_split",
"(",
"'/:/'",
",",
"$",
"buf",
",",
"2",
")",
";",
"$",
"stats",
"=",
"preg_split",
"(",
"'/\\s+/'",
",",
"trim",
"(",
"$",
"stats_list",
")",
")",
";",
"$",
"dev",
"=",
"new",
"Obj",
";",
"$",
"dev",
"->",
"name",
"=",
"trim",
"(",
"$",
"dev_name",
")",
";",
"$",
"dev",
"->",
"recieve",
"=",
"(",
"int",
")",
"$",
"stats",
"[",
"0",
"]",
";",
"$",
"dev",
"->",
"sent",
"=",
"(",
"int",
")",
"$",
"stats",
"[",
"8",
"]",
";",
"$",
"dev",
"->",
"error",
"=",
"(",
"int",
")",
"$",
"stats",
"[",
"2",
"]",
"+",
"(",
"int",
")",
"$",
"stats",
"[",
"10",
"]",
";",
"$",
"dev",
"->",
"drop",
"=",
"(",
"int",
")",
"$",
"stats",
"[",
"3",
"]",
"+",
"(",
"int",
")",
"$",
"stats",
"[",
"11",
"]",
";",
"$",
"ipBuff",
"=",
"preg_split",
"(",
"\"/\\n/\"",
",",
"$",
"this",
"->",
"readCommand",
"(",
"'ip addr show '",
".",
"$",
"dev",
"->",
"name",
")",
",",
"-",
"1",
",",
"PREG_SPLIT_NO_EMPTY",
")",
";",
"foreach",
"(",
"$",
"ipBuff",
"as",
"$",
"line",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/^\\s*link\\/ether\\s+(.*)\\s+brd.*/i'",
",",
"$",
"line",
",",
"$",
"ar_buf",
")",
")",
"{",
"$",
"dev",
"->",
"mac",
"=",
"$",
"ar_buf",
"[",
"1",
"]",
";",
"}",
"elseif",
"(",
"preg_match",
"(",
"'/^\\s*inet6\\s+(.*)\\/.*/i'",
",",
"$",
"line",
",",
"$",
"ar_buf",
")",
")",
"{",
"$",
"dev",
"->",
"ip6",
"=",
"$",
"ar_buf",
"[",
"1",
"]",
";",
"}",
"elseif",
"(",
"preg_match",
"(",
"'/^\\s*inet\\s+(.*)\\/.*/i'",
",",
"$",
"line",
",",
"$",
"ar_buf",
")",
")",
"{",
"$",
"dev",
"->",
"ip",
"=",
"$",
"ar_buf",
"[",
"1",
"]",
";",
"}",
"}",
"$",
"network",
"[",
"]",
"=",
"$",
"dev",
";",
"}",
"}",
"return",
"$",
"network",
";",
"}"
] |
Vrati informace o siti
@return Obj[]
|
[
"Vrati",
"informace",
"o",
"siti"
] |
7821d09a0b3e58ba9c6eb81d44e35aacce55de75
|
https://github.com/nattreid/app-manager/blob/7821d09a0b3e58ba9c6eb81d44e35aacce55de75/src/Helpers/Info.php#L420-L453
|
235,307
|
yujin1st/yii2-user
|
models/User.php
|
User.attemptConfirmation
|
public function attemptConfirmation($code) {
$token = Token::find()->where([
'userId' => $this->id,
'code' => $code,
'type' => Token::TYPE_CONFIRMATION,
])->one();
if ($token instanceof Token && !$token->isExpired) {
$token->delete();
if (($success = $this->confirm())) {
Yii::$app->user->login($this, $this->module->rememberFor);
$message = Yii::t('users', 'Thank you, registration is now complete.');
} else {
$message = Yii::t('users', 'Something went wrong and your account has not been confirmed.');
}
} else {
$success = false;
$message = Yii::t('users', 'The confirmation link is invalid or expired. Please try requesting a new one.');
}
Yii::$app->session->setFlash($success ? 'success' : 'danger', $message);
return $success;
}
|
php
|
public function attemptConfirmation($code) {
$token = Token::find()->where([
'userId' => $this->id,
'code' => $code,
'type' => Token::TYPE_CONFIRMATION,
])->one();
if ($token instanceof Token && !$token->isExpired) {
$token->delete();
if (($success = $this->confirm())) {
Yii::$app->user->login($this, $this->module->rememberFor);
$message = Yii::t('users', 'Thank you, registration is now complete.');
} else {
$message = Yii::t('users', 'Something went wrong and your account has not been confirmed.');
}
} else {
$success = false;
$message = Yii::t('users', 'The confirmation link is invalid or expired. Please try requesting a new one.');
}
Yii::$app->session->setFlash($success ? 'success' : 'danger', $message);
return $success;
}
|
[
"public",
"function",
"attemptConfirmation",
"(",
"$",
"code",
")",
"{",
"$",
"token",
"=",
"Token",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"'userId'",
"=>",
"$",
"this",
"->",
"id",
",",
"'code'",
"=>",
"$",
"code",
",",
"'type'",
"=>",
"Token",
"::",
"TYPE_CONFIRMATION",
",",
"]",
")",
"->",
"one",
"(",
")",
";",
"if",
"(",
"$",
"token",
"instanceof",
"Token",
"&&",
"!",
"$",
"token",
"->",
"isExpired",
")",
"{",
"$",
"token",
"->",
"delete",
"(",
")",
";",
"if",
"(",
"(",
"$",
"success",
"=",
"$",
"this",
"->",
"confirm",
"(",
")",
")",
")",
"{",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"login",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"module",
"->",
"rememberFor",
")",
";",
"$",
"message",
"=",
"Yii",
"::",
"t",
"(",
"'users'",
",",
"'Thank you, registration is now complete.'",
")",
";",
"}",
"else",
"{",
"$",
"message",
"=",
"Yii",
"::",
"t",
"(",
"'users'",
",",
"'Something went wrong and your account has not been confirmed.'",
")",
";",
"}",
"}",
"else",
"{",
"$",
"success",
"=",
"false",
";",
"$",
"message",
"=",
"Yii",
"::",
"t",
"(",
"'users'",
",",
"'The confirmation link is invalid or expired. Please try requesting a new one.'",
")",
";",
"}",
"Yii",
"::",
"$",
"app",
"->",
"session",
"->",
"setFlash",
"(",
"$",
"success",
"?",
"'success'",
":",
"'danger'",
",",
"$",
"message",
")",
";",
"return",
"$",
"success",
";",
"}"
] |
Attempts user confirmation.
@param string $code Confirmation code.
@return boolean
|
[
"Attempts",
"user",
"confirmation",
"."
] |
b404c77acf4a96f0cdf9bb0af5c8d62bcae3946f
|
https://github.com/yujin1st/yii2-user/blob/b404c77acf4a96f0cdf9bb0af5c8d62bcae3946f/models/User.php#L316-L339
|
235,308
|
yujin1st/yii2-user
|
models/User.php
|
User.assignRoles
|
public function assignRoles() {
$auth = Yii::$app->authManager;
$auth->assign($auth->getRole(Access::ROLE_USER), $this->id);
}
|
php
|
public function assignRoles() {
$auth = Yii::$app->authManager;
$auth->assign($auth->getRole(Access::ROLE_USER), $this->id);
}
|
[
"public",
"function",
"assignRoles",
"(",
")",
"{",
"$",
"auth",
"=",
"Yii",
"::",
"$",
"app",
"->",
"authManager",
";",
"$",
"auth",
"->",
"assign",
"(",
"$",
"auth",
"->",
"getRole",
"(",
"Access",
"::",
"ROLE_USER",
")",
",",
"$",
"this",
"->",
"id",
")",
";",
"}"
] |
Assign roles to new user
Overwrite this method for own purposes
|
[
"Assign",
"roles",
"to",
"new",
"user",
"Overwrite",
"this",
"method",
"for",
"own",
"purposes"
] |
b404c77acf4a96f0cdf9bb0af5c8d62bcae3946f
|
https://github.com/yujin1st/yii2-user/blob/b404c77acf4a96f0cdf9bb0af5c8d62bcae3946f/models/User.php#L471-L474
|
235,309
|
jitesoft/php-math
|
src/VectorMath.php
|
VectorMath.mul
|
public static function mul(Vector $vector, $value) : Vector {
$type = get_class($vector);
$out = new $type();
$count = count($out);
if ($value instanceof Vector === false) {
$value = new $type(...array_fill(0, $count , $value));
}
for ($i=$count;$i-->0;) {
$out[$i] = $vector[$i] * $value[$i];
}
return $out;
}
|
php
|
public static function mul(Vector $vector, $value) : Vector {
$type = get_class($vector);
$out = new $type();
$count = count($out);
if ($value instanceof Vector === false) {
$value = new $type(...array_fill(0, $count , $value));
}
for ($i=$count;$i-->0;) {
$out[$i] = $vector[$i] * $value[$i];
}
return $out;
}
|
[
"public",
"static",
"function",
"mul",
"(",
"Vector",
"$",
"vector",
",",
"$",
"value",
")",
":",
"Vector",
"{",
"$",
"type",
"=",
"get_class",
"(",
"$",
"vector",
")",
";",
"$",
"out",
"=",
"new",
"$",
"type",
"(",
")",
";",
"$",
"count",
"=",
"count",
"(",
"$",
"out",
")",
";",
"if",
"(",
"$",
"value",
"instanceof",
"Vector",
"===",
"false",
")",
"{",
"$",
"value",
"=",
"new",
"$",
"type",
"(",
"...",
"array_fill",
"(",
"0",
",",
"$",
"count",
",",
"$",
"value",
")",
")",
";",
"}",
"for",
"(",
"$",
"i",
"=",
"$",
"count",
";",
"$",
"i",
"--",
">",
"0",
";",
")",
"{",
"$",
"out",
"[",
"$",
"i",
"]",
"=",
"$",
"vector",
"[",
"$",
"i",
"]",
"*",
"$",
"value",
"[",
"$",
"i",
"]",
";",
"}",
"return",
"$",
"out",
";",
"}"
] |
Vector multiplication.
@param Vector $vector
@param Vector|float $value
@return Vector
|
[
"Vector",
"multiplication",
"."
] |
1775055e5a14ef30c7df0deeb1fe1ff0775bb581
|
https://github.com/jitesoft/php-math/blob/1775055e5a14ef30c7df0deeb1fe1ff0775bb581/src/VectorMath.php#L18-L32
|
235,310
|
jitesoft/php-math
|
src/VectorMath.php
|
VectorMath.cross
|
public static function cross(Vector3D $value1, Vector3D $value2) : Vector3D {
return new Vector3D(
($value1->getY() * $value2->getZ()) - ($value1->getZ() * $value2->getY()),
-(($value1->getX() * $value2->getZ()) - ($value1->getZ() * $value2->getX())),
($value1->getX() * $value2->getY()) - ($value1->getY() * $value2->getX())
);
}
|
php
|
public static function cross(Vector3D $value1, Vector3D $value2) : Vector3D {
return new Vector3D(
($value1->getY() * $value2->getZ()) - ($value1->getZ() * $value2->getY()),
-(($value1->getX() * $value2->getZ()) - ($value1->getZ() * $value2->getX())),
($value1->getX() * $value2->getY()) - ($value1->getY() * $value2->getX())
);
}
|
[
"public",
"static",
"function",
"cross",
"(",
"Vector3D",
"$",
"value1",
",",
"Vector3D",
"$",
"value2",
")",
":",
"Vector3D",
"{",
"return",
"new",
"Vector3D",
"(",
"(",
"$",
"value1",
"->",
"getY",
"(",
")",
"*",
"$",
"value2",
"->",
"getZ",
"(",
")",
")",
"-",
"(",
"$",
"value1",
"->",
"getZ",
"(",
")",
"*",
"$",
"value2",
"->",
"getY",
"(",
")",
")",
",",
"-",
"(",
"(",
"$",
"value1",
"->",
"getX",
"(",
")",
"*",
"$",
"value2",
"->",
"getZ",
"(",
")",
")",
"-",
"(",
"$",
"value1",
"->",
"getZ",
"(",
")",
"*",
"$",
"value2",
"->",
"getX",
"(",
")",
")",
")",
",",
"(",
"$",
"value1",
"->",
"getX",
"(",
")",
"*",
"$",
"value2",
"->",
"getY",
"(",
")",
")",
"-",
"(",
"$",
"value1",
"->",
"getY",
"(",
")",
"*",
"$",
"value2",
"->",
"getX",
"(",
")",
")",
")",
";",
"}"
] |
Cross product of two vectors.
@param Vector3D $value1
@param Vector3D $value2
@return Vector3D
|
[
"Cross",
"product",
"of",
"two",
"vectors",
"."
] |
1775055e5a14ef30c7df0deeb1fe1ff0775bb581
|
https://github.com/jitesoft/php-math/blob/1775055e5a14ef30c7df0deeb1fe1ff0775bb581/src/VectorMath.php#L125-L131
|
235,311
|
droid-php/droid-model
|
src/Model/Inventory/Remote/SynchroniserComposer.php
|
SynchroniserComposer.executeComposerInstall
|
private function executeComposerInstall($host)
{
$ssh = $host->getSshClient();
$ssh->exec(array(
sprintf('cd %s;', $host->getWorkingDirectory()),
'stat composer.phar'
));
if ($ssh->getExitCode()) {
$this->installComposer($host);
}
$ssh = $host->getSshClient();
$ssh->exec(
array(
sprintf('cd %s;', $host->getWorkingDirectory()),
'php composer.phar install --no-dev'
),
null,
self::TIMEOUT_MAX_RUNTIME_COMPOSER_INSTALL
);
if ($ssh->getExitCode()) {
throw new SynchronisationException($host->getName(), sprintf(
'Unable to execute composer install: "%s".',
$ssh->getErrorOutput()
));
}
}
|
php
|
private function executeComposerInstall($host)
{
$ssh = $host->getSshClient();
$ssh->exec(array(
sprintf('cd %s;', $host->getWorkingDirectory()),
'stat composer.phar'
));
if ($ssh->getExitCode()) {
$this->installComposer($host);
}
$ssh = $host->getSshClient();
$ssh->exec(
array(
sprintf('cd %s;', $host->getWorkingDirectory()),
'php composer.phar install --no-dev'
),
null,
self::TIMEOUT_MAX_RUNTIME_COMPOSER_INSTALL
);
if ($ssh->getExitCode()) {
throw new SynchronisationException($host->getName(), sprintf(
'Unable to execute composer install: "%s".',
$ssh->getErrorOutput()
));
}
}
|
[
"private",
"function",
"executeComposerInstall",
"(",
"$",
"host",
")",
"{",
"$",
"ssh",
"=",
"$",
"host",
"->",
"getSshClient",
"(",
")",
";",
"$",
"ssh",
"->",
"exec",
"(",
"array",
"(",
"sprintf",
"(",
"'cd %s;'",
",",
"$",
"host",
"->",
"getWorkingDirectory",
"(",
")",
")",
",",
"'stat composer.phar'",
")",
")",
";",
"if",
"(",
"$",
"ssh",
"->",
"getExitCode",
"(",
")",
")",
"{",
"$",
"this",
"->",
"installComposer",
"(",
"$",
"host",
")",
";",
"}",
"$",
"ssh",
"=",
"$",
"host",
"->",
"getSshClient",
"(",
")",
";",
"$",
"ssh",
"->",
"exec",
"(",
"array",
"(",
"sprintf",
"(",
"'cd %s;'",
",",
"$",
"host",
"->",
"getWorkingDirectory",
"(",
")",
")",
",",
"'php composer.phar install --no-dev'",
")",
",",
"null",
",",
"self",
"::",
"TIMEOUT_MAX_RUNTIME_COMPOSER_INSTALL",
")",
";",
"if",
"(",
"$",
"ssh",
"->",
"getExitCode",
"(",
")",
")",
"{",
"throw",
"new",
"SynchronisationException",
"(",
"$",
"host",
"->",
"getName",
"(",
")",
",",
"sprintf",
"(",
"'Unable to execute composer install: \"%s\".'",
",",
"$",
"ssh",
"->",
"getErrorOutput",
"(",
")",
")",
")",
";",
"}",
"}"
] |
Execute composer install from the host's working directory. Install
composer to the working directory if it isn't already installed there.
|
[
"Execute",
"composer",
"install",
"from",
"the",
"host",
"s",
"working",
"directory",
".",
"Install",
"composer",
"to",
"the",
"working",
"directory",
"if",
"it",
"isn",
"t",
"already",
"installed",
"there",
"."
] |
5dee2a4a6a7a77512747ac5ddf2f4b8f7018ce5a
|
https://github.com/droid-php/droid-model/blob/5dee2a4a6a7a77512747ac5ddf2f4b8f7018ce5a/src/Model/Inventory/Remote/SynchroniserComposer.php#L76-L101
|
235,312
|
weew/router-routes-invoker-container-aware
|
src/Weew/Router/Invoker/ContainerAware/RoutesInvoker.php
|
RoutesInvoker.invoke
|
public function invoke($route) {
if ($route instanceof IRoute) {
return $this->invokeRoute($route);
}
return new HttpResponse(HttpStatusCode::NOT_FOUND);
}
|
php
|
public function invoke($route) {
if ($route instanceof IRoute) {
return $this->invokeRoute($route);
}
return new HttpResponse(HttpStatusCode::NOT_FOUND);
}
|
[
"public",
"function",
"invoke",
"(",
"$",
"route",
")",
"{",
"if",
"(",
"$",
"route",
"instanceof",
"IRoute",
")",
"{",
"return",
"$",
"this",
"->",
"invokeRoute",
"(",
"$",
"route",
")",
";",
"}",
"return",
"new",
"HttpResponse",
"(",
"HttpStatusCode",
"::",
"NOT_FOUND",
")",
";",
"}"
] |
Invoke given route. If the route is null, returns a 404 response.
@param IRoute $route
@return IHttpResponse
@throws InvalidRouteValue
|
[
"Invoke",
"given",
"route",
".",
"If",
"the",
"route",
"is",
"null",
"returns",
"a",
"404",
"response",
"."
] |
96bc23f67081223031218274b7a51fff196e6039
|
https://github.com/weew/router-routes-invoker-container-aware/blob/96bc23f67081223031218274b7a51fff196e6039/src/Weew/Router/Invoker/ContainerAware/RoutesInvoker.php#L45-L51
|
235,313
|
zepi/turbo-base
|
Zepi/Api/Rest/src/Helper/RestHelper.php
|
RestHelper.sendRequest
|
public function sendRequest(ApiKey $apiKey, RestRequest $request)
{
$hmac = $this->generateHmac($apiKey->getPrivateKey(), $request->getEndpoint(), array_merge($request->getQueryData(), $request->getPostData()));
$client = new Client([
'base_uri' => $request->getHost()
]);
$args = [
'auth' => [$apiKey->getPublicKey(), $hmac],
'headers' => [
'Accept' => 'application/json'
]
];
if ($request->getRequestMethod() === 'POST') {
$args['form_params'] = $request->getPostData();
} else {
$args['query'] = $request->getQueryData();
}
try {
$responseRaw = $client->request($request->getRequestMethod(), $request->getEndpoint(), $args);
} catch (RequestException $e) {
if (!$e->hasResponse()) {
throw new Exception('Cannot send REST request.', 0, $e);
}
$responseRaw = $e->getResponse();
}
return $this->prepareResponse($responseRaw, $request);
}
|
php
|
public function sendRequest(ApiKey $apiKey, RestRequest $request)
{
$hmac = $this->generateHmac($apiKey->getPrivateKey(), $request->getEndpoint(), array_merge($request->getQueryData(), $request->getPostData()));
$client = new Client([
'base_uri' => $request->getHost()
]);
$args = [
'auth' => [$apiKey->getPublicKey(), $hmac],
'headers' => [
'Accept' => 'application/json'
]
];
if ($request->getRequestMethod() === 'POST') {
$args['form_params'] = $request->getPostData();
} else {
$args['query'] = $request->getQueryData();
}
try {
$responseRaw = $client->request($request->getRequestMethod(), $request->getEndpoint(), $args);
} catch (RequestException $e) {
if (!$e->hasResponse()) {
throw new Exception('Cannot send REST request.', 0, $e);
}
$responseRaw = $e->getResponse();
}
return $this->prepareResponse($responseRaw, $request);
}
|
[
"public",
"function",
"sendRequest",
"(",
"ApiKey",
"$",
"apiKey",
",",
"RestRequest",
"$",
"request",
")",
"{",
"$",
"hmac",
"=",
"$",
"this",
"->",
"generateHmac",
"(",
"$",
"apiKey",
"->",
"getPrivateKey",
"(",
")",
",",
"$",
"request",
"->",
"getEndpoint",
"(",
")",
",",
"array_merge",
"(",
"$",
"request",
"->",
"getQueryData",
"(",
")",
",",
"$",
"request",
"->",
"getPostData",
"(",
")",
")",
")",
";",
"$",
"client",
"=",
"new",
"Client",
"(",
"[",
"'base_uri'",
"=>",
"$",
"request",
"->",
"getHost",
"(",
")",
"]",
")",
";",
"$",
"args",
"=",
"[",
"'auth'",
"=>",
"[",
"$",
"apiKey",
"->",
"getPublicKey",
"(",
")",
",",
"$",
"hmac",
"]",
",",
"'headers'",
"=>",
"[",
"'Accept'",
"=>",
"'application/json'",
"]",
"]",
";",
"if",
"(",
"$",
"request",
"->",
"getRequestMethod",
"(",
")",
"===",
"'POST'",
")",
"{",
"$",
"args",
"[",
"'form_params'",
"]",
"=",
"$",
"request",
"->",
"getPostData",
"(",
")",
";",
"}",
"else",
"{",
"$",
"args",
"[",
"'query'",
"]",
"=",
"$",
"request",
"->",
"getQueryData",
"(",
")",
";",
"}",
"try",
"{",
"$",
"responseRaw",
"=",
"$",
"client",
"->",
"request",
"(",
"$",
"request",
"->",
"getRequestMethod",
"(",
")",
",",
"$",
"request",
"->",
"getEndpoint",
"(",
")",
",",
"$",
"args",
")",
";",
"}",
"catch",
"(",
"RequestException",
"$",
"e",
")",
"{",
"if",
"(",
"!",
"$",
"e",
"->",
"hasResponse",
"(",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Cannot send REST request.'",
",",
"0",
",",
"$",
"e",
")",
";",
"}",
"$",
"responseRaw",
"=",
"$",
"e",
"->",
"getResponse",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"prepareResponse",
"(",
"$",
"responseRaw",
",",
"$",
"request",
")",
";",
"}"
] |
Sends the RestRequest to the endpoint
@access public
@param \Zepi\Api\AccessControl\Entity\ApiKey $apiKey
@param \Zepi\Api\Rest\Entity\Request $request
@return \Zepi\Api\Rest\Entity\Response
@throws \Zepi\Api\Rest\Exception Cannot send REST request.
|
[
"Sends",
"the",
"RestRequest",
"to",
"the",
"endpoint"
] |
9a36d8c7649317f55f91b2adf386bd1f04ec02a3
|
https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/Api/Rest/src/Helper/RestHelper.php#L85-L117
|
235,314
|
zepi/turbo-base
|
Zepi/Api/Rest/src/Helper/RestHelper.php
|
RestHelper.prepareResponse
|
protected function prepareResponse($responseRaw, RestRequest $request)
{
$body = (string) $responseRaw->getBody();
$parsedResult = json_decode($body);
if ($parsedResult == false) {
$parsedResult = new \stdClass();
}
$response = new RestResponse($responseRaw->getStatusCode(), $body, $parsedResult, $request);
return $response;
}
|
php
|
protected function prepareResponse($responseRaw, RestRequest $request)
{
$body = (string) $responseRaw->getBody();
$parsedResult = json_decode($body);
if ($parsedResult == false) {
$parsedResult = new \stdClass();
}
$response = new RestResponse($responseRaw->getStatusCode(), $body, $parsedResult, $request);
return $response;
}
|
[
"protected",
"function",
"prepareResponse",
"(",
"$",
"responseRaw",
",",
"RestRequest",
"$",
"request",
")",
"{",
"$",
"body",
"=",
"(",
"string",
")",
"$",
"responseRaw",
"->",
"getBody",
"(",
")",
";",
"$",
"parsedResult",
"=",
"json_decode",
"(",
"$",
"body",
")",
";",
"if",
"(",
"$",
"parsedResult",
"==",
"false",
")",
"{",
"$",
"parsedResult",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"}",
"$",
"response",
"=",
"new",
"RestResponse",
"(",
"$",
"responseRaw",
"->",
"getStatusCode",
"(",
")",
",",
"$",
"body",
",",
"$",
"parsedResult",
",",
"$",
"request",
")",
";",
"return",
"$",
"response",
";",
"}"
] |
Prepares the response object for the given raw response object
@param mixed $responseRaw
@param \Zepi\Api\Rest\Entity\Request
@return \Zepi\Api\Rest\Entity\Response
|
[
"Prepares",
"the",
"response",
"object",
"for",
"the",
"given",
"raw",
"response",
"object"
] |
9a36d8c7649317f55f91b2adf386bd1f04ec02a3
|
https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/Api/Rest/src/Helper/RestHelper.php#L126-L138
|
235,315
|
zepi/turbo-base
|
Zepi/Api/Rest/src/Helper/RestHelper.php
|
RestHelper.fillXml
|
protected function fillXml(\SimpleXMLElement $element, $data)
{
foreach ($data as $key => $value) {
if (is_array($value) || is_object($value)) {
if (!is_numeric($key)) {
$child = $element->addChild($key);
} else {
$child = $element;
}
$this->fillXml($child, $value);
} else {
$element->addChild($key, $value);
}
}
}
|
php
|
protected function fillXml(\SimpleXMLElement $element, $data)
{
foreach ($data as $key => $value) {
if (is_array($value) || is_object($value)) {
if (!is_numeric($key)) {
$child = $element->addChild($key);
} else {
$child = $element;
}
$this->fillXml($child, $value);
} else {
$element->addChild($key, $value);
}
}
}
|
[
"protected",
"function",
"fillXml",
"(",
"\\",
"SimpleXMLElement",
"$",
"element",
",",
"$",
"data",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
"||",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"key",
")",
")",
"{",
"$",
"child",
"=",
"$",
"element",
"->",
"addChild",
"(",
"$",
"key",
")",
";",
"}",
"else",
"{",
"$",
"child",
"=",
"$",
"element",
";",
"}",
"$",
"this",
"->",
"fillXml",
"(",
"$",
"child",
",",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"element",
"->",
"addChild",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"}",
"}"
] |
Builds a xml string out of the given array
@access public
@param \SimpleXMLElement $element
@param array|object $data
|
[
"Builds",
"a",
"xml",
"string",
"out",
"of",
"the",
"given",
"array"
] |
9a36d8c7649317f55f91b2adf386bd1f04ec02a3
|
https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/Api/Rest/src/Helper/RestHelper.php#L181-L196
|
235,316
|
zepi/turbo-base
|
Zepi/Api/Rest/src/Helper/RestHelper.php
|
RestHelper.generateHmac
|
protected function generateHmac($privateKey, $requestedRoute, $data)
{
$completeString = $requestedRoute . json_encode($data);
return hash_hmac('sha256', $completeString, $privateKey);
}
|
php
|
protected function generateHmac($privateKey, $requestedRoute, $data)
{
$completeString = $requestedRoute . json_encode($data);
return hash_hmac('sha256', $completeString, $privateKey);
}
|
[
"protected",
"function",
"generateHmac",
"(",
"$",
"privateKey",
",",
"$",
"requestedRoute",
",",
"$",
"data",
")",
"{",
"$",
"completeString",
"=",
"$",
"requestedRoute",
".",
"json_encode",
"(",
"$",
"data",
")",
";",
"return",
"hash_hmac",
"(",
"'sha256'",
",",
"$",
"completeString",
",",
"$",
"privateKey",
")",
";",
"}"
] |
Generates the hmac for the given data
@access protected
@param string $privateKey
@param string $requestedRoute
@param array $data
@return string
|
[
"Generates",
"the",
"hmac",
"for",
"the",
"given",
"data"
] |
9a36d8c7649317f55f91b2adf386bd1f04ec02a3
|
https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/Api/Rest/src/Helper/RestHelper.php#L231-L236
|
235,317
|
Dhii/data-state-base
|
src/CreateTransitionerExceptionCapableTrait.php
|
CreateTransitionerExceptionCapableTrait._createTransitionerException
|
protected function _createTransitionerException(
$message = null,
$code = null,
RootException $previous = null,
$transitioner = null
) {
return new TransitionerException($message, $code, $previous, $transitioner);
}
|
php
|
protected function _createTransitionerException(
$message = null,
$code = null,
RootException $previous = null,
$transitioner = null
) {
return new TransitionerException($message, $code, $previous, $transitioner);
}
|
[
"protected",
"function",
"_createTransitionerException",
"(",
"$",
"message",
"=",
"null",
",",
"$",
"code",
"=",
"null",
",",
"RootException",
"$",
"previous",
"=",
"null",
",",
"$",
"transitioner",
"=",
"null",
")",
"{",
"return",
"new",
"TransitionerException",
"(",
"$",
"message",
",",
"$",
"code",
",",
"$",
"previous",
",",
"$",
"transitioner",
")",
";",
"}"
] |
Creates a new transitioner exception.
@since [*next-version*]
@param string|Stringable|null $message The error message, if any.
@param int|null $code The error code, if any.
@param RootException|null $previous The previous exception for chaining, if any.
@param TransitionerInterface|null $transitioner The transitioner that erred, if any.
@return TransitionerException The created transitioner exception.
|
[
"Creates",
"a",
"new",
"transitioner",
"exception",
"."
] |
762866374fc8c7cc482fd8a5d37520b14873be06
|
https://github.com/Dhii/data-state-base/blob/762866374fc8c7cc482fd8a5d37520b14873be06/src/CreateTransitionerExceptionCapableTrait.php#L28-L35
|
235,318
|
budkit/budkit-framework
|
src/Budkit/Filesystem/Directory.php
|
Directory.chmodR
|
public function chmodR($path, $filemode)
{
if (!$this->isFolder($path)) {
return $this->chmod($path, $filemode);
}
$dirh = @opendir($path);
while ($file = readdir($dirh)) {
if ($file != '.' && $file != '..') {
$fullpath = $path . '/' . $file;
if (!$this->isFolder($fullpath)) {
if (!$this->chmod($fullpath, $filemode)) {
return false;
}
} else {
if (!$this->chmodR($fullpath, $filemode)) {
return false;
}
}
}
}
closedir($dirh);
if ($this->chmod($path, $filemode)) {
return true;
} else {
return false;
}
}
|
php
|
public function chmodR($path, $filemode)
{
if (!$this->isFolder($path)) {
return $this->chmod($path, $filemode);
}
$dirh = @opendir($path);
while ($file = readdir($dirh)) {
if ($file != '.' && $file != '..') {
$fullpath = $path . '/' . $file;
if (!$this->isFolder($fullpath)) {
if (!$this->chmod($fullpath, $filemode)) {
return false;
}
} else {
if (!$this->chmodR($fullpath, $filemode)) {
return false;
}
}
}
}
closedir($dirh);
if ($this->chmod($path, $filemode)) {
return true;
} else {
return false;
}
}
|
[
"public",
"function",
"chmodR",
"(",
"$",
"path",
",",
"$",
"filemode",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isFolder",
"(",
"$",
"path",
")",
")",
"{",
"return",
"$",
"this",
"->",
"chmod",
"(",
"$",
"path",
",",
"$",
"filemode",
")",
";",
"}",
"$",
"dirh",
"=",
"@",
"opendir",
"(",
"$",
"path",
")",
";",
"while",
"(",
"$",
"file",
"=",
"readdir",
"(",
"$",
"dirh",
")",
")",
"{",
"if",
"(",
"$",
"file",
"!=",
"'.'",
"&&",
"$",
"file",
"!=",
"'..'",
")",
"{",
"$",
"fullpath",
"=",
"$",
"path",
".",
"'/'",
".",
"$",
"file",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"isFolder",
"(",
"$",
"fullpath",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"chmod",
"(",
"$",
"fullpath",
",",
"$",
"filemode",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"chmodR",
"(",
"$",
"fullpath",
",",
"$",
"filemode",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"}",
"}",
"closedir",
"(",
"$",
"dirh",
")",
";",
"if",
"(",
"$",
"this",
"->",
"chmod",
"(",
"$",
"path",
",",
"$",
"filemode",
")",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] |
Recursively sets permissions for all files in a folder
@param type $path
@param type $permission
|
[
"Recursively",
"sets",
"permissions",
"for",
"all",
"files",
"in",
"a",
"folder"
] |
0635061815fe07a8c63f9514b845d199b3c0d485
|
https://github.com/budkit/budkit-framework/blob/0635061815fe07a8c63f9514b845d199b3c0d485/src/Budkit/Filesystem/Directory.php#L31-L61
|
235,319
|
budkit/budkit-framework
|
src/Budkit/Filesystem/Directory.php
|
Directory.ls
|
final public function ls($path, $exclude = array(".DS_Store", ".git", ".svn", ".CVS"), $recursive = FALSE, $recursivelimit = 0, $showfiles = FALSE, $sort = TRUE, $long = FALSE)
{
//1. Search $name as a folder or as a file
if (!$this->is($path)) { //if in path is a directory
return array();
}
$dirh = @opendir($path); //directory handler
//$recursion = 0;
$found = [];
if ($dirh) {
while (false !== ($file = readdir($dirh))) {
// remove '.' and '..'
if ($file == '.' || $file == '..' || in_array($file, $exclude)) {
continue;
}
$recursion = 0;
$newPath = $path . $file;
if ($this->isFolder($newPath) && $recursive && ($recursion < $recursiveLimit)) {
//echo $this->is($newPath)."<br />";
//echo $newPath."<br />";
$newRecursiveLimit = ((int)$recursiveLimit > 0) ? ((int)$recursiveLimit - 1) : 0;
$items = $this->list($newPath, $exclude, $recursive, $newRecursiveLimit);
$found = array_merge($items, $found);
}
$found[] = $newPath;
}
closedir($dirh);
}
//@TODO if long, get additional info for each path;
return $found;
}
|
php
|
final public function ls($path, $exclude = array(".DS_Store", ".git", ".svn", ".CVS"), $recursive = FALSE, $recursivelimit = 0, $showfiles = FALSE, $sort = TRUE, $long = FALSE)
{
//1. Search $name as a folder or as a file
if (!$this->is($path)) { //if in path is a directory
return array();
}
$dirh = @opendir($path); //directory handler
//$recursion = 0;
$found = [];
if ($dirh) {
while (false !== ($file = readdir($dirh))) {
// remove '.' and '..'
if ($file == '.' || $file == '..' || in_array($file, $exclude)) {
continue;
}
$recursion = 0;
$newPath = $path . $file;
if ($this->isFolder($newPath) && $recursive && ($recursion < $recursiveLimit)) {
//echo $this->is($newPath)."<br />";
//echo $newPath."<br />";
$newRecursiveLimit = ((int)$recursiveLimit > 0) ? ((int)$recursiveLimit - 1) : 0;
$items = $this->list($newPath, $exclude, $recursive, $newRecursiveLimit);
$found = array_merge($items, $found);
}
$found[] = $newPath;
}
closedir($dirh);
}
//@TODO if long, get additional info for each path;
return $found;
}
|
[
"final",
"public",
"function",
"ls",
"(",
"$",
"path",
",",
"$",
"exclude",
"=",
"array",
"(",
"\".DS_Store\"",
",",
"\".git\"",
",",
"\".svn\"",
",",
"\".CVS\"",
")",
",",
"$",
"recursive",
"=",
"FALSE",
",",
"$",
"recursivelimit",
"=",
"0",
",",
"$",
"showfiles",
"=",
"FALSE",
",",
"$",
"sort",
"=",
"TRUE",
",",
"$",
"long",
"=",
"FALSE",
")",
"{",
"//1. Search $name as a folder or as a file",
"if",
"(",
"!",
"$",
"this",
"->",
"is",
"(",
"$",
"path",
")",
")",
"{",
"//if in path is a directory",
"return",
"array",
"(",
")",
";",
"}",
"$",
"dirh",
"=",
"@",
"opendir",
"(",
"$",
"path",
")",
";",
"//directory handler",
"//$recursion = 0;",
"$",
"found",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"dirh",
")",
"{",
"while",
"(",
"false",
"!==",
"(",
"$",
"file",
"=",
"readdir",
"(",
"$",
"dirh",
")",
")",
")",
"{",
"// remove '.' and '..'",
"if",
"(",
"$",
"file",
"==",
"'.'",
"||",
"$",
"file",
"==",
"'..'",
"||",
"in_array",
"(",
"$",
"file",
",",
"$",
"exclude",
")",
")",
"{",
"continue",
";",
"}",
"$",
"recursion",
"=",
"0",
";",
"$",
"newPath",
"=",
"$",
"path",
".",
"$",
"file",
";",
"if",
"(",
"$",
"this",
"->",
"isFolder",
"(",
"$",
"newPath",
")",
"&&",
"$",
"recursive",
"&&",
"(",
"$",
"recursion",
"<",
"$",
"recursiveLimit",
")",
")",
"{",
"//echo $this->is($newPath).\"<br />\";",
"//echo $newPath.\"<br />\";",
"$",
"newRecursiveLimit",
"=",
"(",
"(",
"int",
")",
"$",
"recursiveLimit",
">",
"0",
")",
"?",
"(",
"(",
"int",
")",
"$",
"recursiveLimit",
"-",
"1",
")",
":",
"0",
";",
"$",
"items",
"=",
"$",
"this",
"->",
"list",
"(",
"$",
"newPath",
",",
"$",
"exclude",
",",
"$",
"recursive",
",",
"$",
"newRecursiveLimit",
")",
";",
"$",
"found",
"=",
"array_merge",
"(",
"$",
"items",
",",
"$",
"found",
")",
";",
"}",
"$",
"found",
"[",
"]",
"=",
"$",
"newPath",
";",
"}",
"closedir",
"(",
"$",
"dirh",
")",
";",
"}",
"//@TODO if long, get additional info for each path;",
"return",
"$",
"found",
";",
"}"
] |
Lists all the files in a directory
@param string $path the compound path being searched and listed
@param array $exclude a list of folders, files or fileTypes to exclude from the list
@param boolean $recursive Determines whether to search subdirectories if found
@param interger $recursivelimit The number of deep subfolder levels to search
@param boolean $showfiles Include Files contained in each folder to the array
@param boolean $sort Sort folder/files in alphabetical order
@param boolean $long returns size, permission, datemodified in list if true, Slow!!
@return array $list = array(
"path/to/folder" => array(
"name" => '',
"parent" => '', //only in long
"size" => '', //only in long
"modified" => '', //only in long
"permission" => '',
"files" => array(
"path/to/file" => array(
"name" => '',
"size" => '', //only in long
"modified" => '', //only in long
"permission" => '',
"extension" => '',
"mimetype" => ''//only in long
)
),
"children" => array()
|
[
"Lists",
"all",
"the",
"files",
"in",
"a",
"directory"
] |
0635061815fe07a8c63f9514b845d199b3c0d485
|
https://github.com/budkit/budkit-framework/blob/0635061815fe07a8c63f9514b845d199b3c0d485/src/Budkit/Filesystem/Directory.php#L102-L140
|
235,320
|
budkit/budkit-framework
|
src/Budkit/Filesystem/Directory.php
|
Directory.deleteContents
|
final public function deleteContents($folderpath, $filterByExtension = [], $filterByName = [],
$filterExcludeMode = true, $recursive = true)
{
//1. Search $name as a folder or as a file
if (!$this->is($folderpath)) { //if in path is a directory
return false;
}
$dirh = @opendir($folderpath); //directory handler
if ($dirh) {
while (false !== ($file = readdir($dirh))) {
// remove '.' and '..'
if ($filterExcludeMode) {
//Excluding by name as in "file.ext"
if ($file == '.' || $file == '..' || in_array($file, $filterByName)) {
continue;
}
//Excluding extension
if (!empty($filterByExtension)) {
$fhandler = $this->getFile();
$extension = $fhandler->getExtension($file);
if (in_array($extension, $filterByExtension)) {
continue;
}
}
}
//The new path
$newPath = $folderpath . DS . $file;
//echo $newPath;
//If newpath is a folder and we are deleting recursively
if ($this->isFolder($newPath) && $recursive) {
$this->deleteContents($newPath, $filterByExtension, $filterByName, $filterExcludeMode, $recursive);
}
//Now unlink the file
if (!static::delete($newPath)) {
static::setError("Could not delete {$newPath}");
return false;
}
}
closedir($dirh);
}
//@TODO if long, get additional info for each path;
return true;
}
|
php
|
final public function deleteContents($folderpath, $filterByExtension = [], $filterByName = [],
$filterExcludeMode = true, $recursive = true)
{
//1. Search $name as a folder or as a file
if (!$this->is($folderpath)) { //if in path is a directory
return false;
}
$dirh = @opendir($folderpath); //directory handler
if ($dirh) {
while (false !== ($file = readdir($dirh))) {
// remove '.' and '..'
if ($filterExcludeMode) {
//Excluding by name as in "file.ext"
if ($file == '.' || $file == '..' || in_array($file, $filterByName)) {
continue;
}
//Excluding extension
if (!empty($filterByExtension)) {
$fhandler = $this->getFile();
$extension = $fhandler->getExtension($file);
if (in_array($extension, $filterByExtension)) {
continue;
}
}
}
//The new path
$newPath = $folderpath . DS . $file;
//echo $newPath;
//If newpath is a folder and we are deleting recursively
if ($this->isFolder($newPath) && $recursive) {
$this->deleteContents($newPath, $filterByExtension, $filterByName, $filterExcludeMode, $recursive);
}
//Now unlink the file
if (!static::delete($newPath)) {
static::setError("Could not delete {$newPath}");
return false;
}
}
closedir($dirh);
}
//@TODO if long, get additional info for each path;
return true;
}
|
[
"final",
"public",
"function",
"deleteContents",
"(",
"$",
"folderpath",
",",
"$",
"filterByExtension",
"=",
"[",
"]",
",",
"$",
"filterByName",
"=",
"[",
"]",
",",
"$",
"filterExcludeMode",
"=",
"true",
",",
"$",
"recursive",
"=",
"true",
")",
"{",
"//1. Search $name as a folder or as a file",
"if",
"(",
"!",
"$",
"this",
"->",
"is",
"(",
"$",
"folderpath",
")",
")",
"{",
"//if in path is a directory",
"return",
"false",
";",
"}",
"$",
"dirh",
"=",
"@",
"opendir",
"(",
"$",
"folderpath",
")",
";",
"//directory handler",
"if",
"(",
"$",
"dirh",
")",
"{",
"while",
"(",
"false",
"!==",
"(",
"$",
"file",
"=",
"readdir",
"(",
"$",
"dirh",
")",
")",
")",
"{",
"// remove '.' and '..'",
"if",
"(",
"$",
"filterExcludeMode",
")",
"{",
"//Excluding by name as in \"file.ext\"",
"if",
"(",
"$",
"file",
"==",
"'.'",
"||",
"$",
"file",
"==",
"'..'",
"||",
"in_array",
"(",
"$",
"file",
",",
"$",
"filterByName",
")",
")",
"{",
"continue",
";",
"}",
"//Excluding extension",
"if",
"(",
"!",
"empty",
"(",
"$",
"filterByExtension",
")",
")",
"{",
"$",
"fhandler",
"=",
"$",
"this",
"->",
"getFile",
"(",
")",
";",
"$",
"extension",
"=",
"$",
"fhandler",
"->",
"getExtension",
"(",
"$",
"file",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"extension",
",",
"$",
"filterByExtension",
")",
")",
"{",
"continue",
";",
"}",
"}",
"}",
"//The new path",
"$",
"newPath",
"=",
"$",
"folderpath",
".",
"DS",
".",
"$",
"file",
";",
"//echo $newPath;",
"//If newpath is a folder and we are deleting recursively",
"if",
"(",
"$",
"this",
"->",
"isFolder",
"(",
"$",
"newPath",
")",
"&&",
"$",
"recursive",
")",
"{",
"$",
"this",
"->",
"deleteContents",
"(",
"$",
"newPath",
",",
"$",
"filterByExtension",
",",
"$",
"filterByName",
",",
"$",
"filterExcludeMode",
",",
"$",
"recursive",
")",
";",
"}",
"//Now unlink the file",
"if",
"(",
"!",
"static",
"::",
"delete",
"(",
"$",
"newPath",
")",
")",
"{",
"static",
"::",
"setError",
"(",
"\"Could not delete {$newPath}\"",
")",
";",
"return",
"false",
";",
"}",
"}",
"closedir",
"(",
"$",
"dirh",
")",
";",
"}",
"//@TODO if long, get additional info for each path;",
"return",
"true",
";",
"}"
] |
Method to delete the contents of a folder
@param type $folderpath
@param type $filterByType
@param type $filterByName
@param type $filterExcludeMode
|
[
"Method",
"to",
"delete",
"the",
"contents",
"of",
"a",
"folder"
] |
0635061815fe07a8c63f9514b845d199b3c0d485
|
https://github.com/budkit/budkit-framework/blob/0635061815fe07a8c63f9514b845d199b3c0d485/src/Budkit/Filesystem/Directory.php#L208-L258
|
235,321
|
Puzzlout/FrameworkMvcLegacy
|
src/Core/Page.php
|
Page.GetOutput
|
public function GetOutput() {
$numberOfVarsExtracted = extract($this->variablesList);
if (count($this->variablesList) !== $numberOfVarsExtracted) {
$errMsg = "Number of variables extracted different from the $vars array";
throw new \Exception($errMsg, Codes\LogicErrors::UNEXPECTED_VALUE, null);
}
ob_start();
include_once $this->contentFile;
$content = ob_get_clean();
ob_start();
include_once "APP_ROOT_DIR" . \Puzzlout\Framework\Enums\FrameworkFolderName::ViewsFolderName . \Puzzlout\Framework\Enums\FileNameConst::LayoutTemplate;
return ob_get_clean();
}
|
php
|
public function GetOutput() {
$numberOfVarsExtracted = extract($this->variablesList);
if (count($this->variablesList) !== $numberOfVarsExtracted) {
$errMsg = "Number of variables extracted different from the $vars array";
throw new \Exception($errMsg, Codes\LogicErrors::UNEXPECTED_VALUE, null);
}
ob_start();
include_once $this->contentFile;
$content = ob_get_clean();
ob_start();
include_once "APP_ROOT_DIR" . \Puzzlout\Framework\Enums\FrameworkFolderName::ViewsFolderName . \Puzzlout\Framework\Enums\FileNameConst::LayoutTemplate;
return ob_get_clean();
}
|
[
"public",
"function",
"GetOutput",
"(",
")",
"{",
"$",
"numberOfVarsExtracted",
"=",
"extract",
"(",
"$",
"this",
"->",
"variablesList",
")",
";",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"variablesList",
")",
"!==",
"$",
"numberOfVarsExtracted",
")",
"{",
"$",
"errMsg",
"=",
"\"Number of variables extracted different from the $vars array\"",
";",
"throw",
"new",
"\\",
"Exception",
"(",
"$",
"errMsg",
",",
"Codes",
"\\",
"LogicErrors",
"::",
"UNEXPECTED_VALUE",
",",
"null",
")",
";",
"}",
"ob_start",
"(",
")",
";",
"include_once",
"$",
"this",
"->",
"contentFile",
";",
"$",
"content",
"=",
"ob_get_clean",
"(",
")",
";",
"ob_start",
"(",
")",
";",
"include_once",
"\"APP_ROOT_DIR\"",
".",
"\\",
"Puzzlout",
"\\",
"Framework",
"\\",
"Enums",
"\\",
"FrameworkFolderName",
"::",
"ViewsFolderName",
".",
"\\",
"Puzzlout",
"\\",
"Framework",
"\\",
"Enums",
"\\",
"FileNameConst",
"::",
"LayoutTemplate",
";",
"return",
"ob_get_clean",
"(",
")",
";",
"}"
] |
Computes the html output of send to the client. It extracts the variables
first,
@return string The output generated.
@throws \Exception Throws if the number of variables extracted if different
to the number of variables given to extract.
|
[
"Computes",
"the",
"html",
"output",
"of",
"send",
"to",
"the",
"client",
".",
"It",
"extracts",
"the",
"variables",
"first"
] |
14e0fc5b16978cbd209f552ee9c649f66a0dfc6e
|
https://github.com/Puzzlout/FrameworkMvcLegacy/blob/14e0fc5b16978cbd209f552ee9c649f66a0dfc6e/src/Core/Page.php#L67-L79
|
235,322
|
nishimura/laiz-db
|
src/Laiz/Db/Driver/Pgsql.php
|
Pgsql.getMetaTables
|
public function getMetaTables(){
$stmt = $this->query(self::META_TABLES_SQL);
if ($stmt === false){
return array();
}
$rows = array();
foreach ($stmt as $row){
$rows[] = $row[0];
}
return $rows;
}
|
php
|
public function getMetaTables(){
$stmt = $this->query(self::META_TABLES_SQL);
if ($stmt === false){
return array();
}
$rows = array();
foreach ($stmt as $row){
$rows[] = $row[0];
}
return $rows;
}
|
[
"public",
"function",
"getMetaTables",
"(",
")",
"{",
"$",
"stmt",
"=",
"$",
"this",
"->",
"query",
"(",
"self",
"::",
"META_TABLES_SQL",
")",
";",
"if",
"(",
"$",
"stmt",
"===",
"false",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"rows",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"stmt",
"as",
"$",
"row",
")",
"{",
"$",
"rows",
"[",
"]",
"=",
"$",
"row",
"[",
"0",
"]",
";",
"}",
"return",
"$",
"rows",
";",
"}"
] |
Return tables information.
@return array
@access public
|
[
"Return",
"tables",
"information",
"."
] |
9d14c99711cd2081d2f658c5253f72721a2c7337
|
https://github.com/nishimura/laiz-db/blob/9d14c99711cd2081d2f658c5253f72721a2c7337/src/Laiz/Db/Driver/Pgsql.php#L66-L78
|
235,323
|
nishimura/laiz-db
|
src/Laiz/Db/Driver/Pgsql.php
|
Pgsql.getMetaColumns
|
public function getMetaColumns($tableName){
$stmt = $this->query(self::META_COLUMNS_SQL, array($tableName));
if ($stmt === false){
return array();
}
$rows = array();
foreach ($stmt as $row){
switch($row[1]){
case 'float8':
case 'numeric':
$type = PDO::PARAM_STR; // Not exists PARAM_FLOAT by current version.
break;
case 'int4':
case 'int8':
$type = PDO::PARAM_INT;
break;
case 'bool':
$type = PDO::PARAM_BOOL;
break;
default:
$type = PDO::PARAM_STR;
break;
}
$rows[$row[0]] = $type;
}
return $rows;
}
|
php
|
public function getMetaColumns($tableName){
$stmt = $this->query(self::META_COLUMNS_SQL, array($tableName));
if ($stmt === false){
return array();
}
$rows = array();
foreach ($stmt as $row){
switch($row[1]){
case 'float8':
case 'numeric':
$type = PDO::PARAM_STR; // Not exists PARAM_FLOAT by current version.
break;
case 'int4':
case 'int8':
$type = PDO::PARAM_INT;
break;
case 'bool':
$type = PDO::PARAM_BOOL;
break;
default:
$type = PDO::PARAM_STR;
break;
}
$rows[$row[0]] = $type;
}
return $rows;
}
|
[
"public",
"function",
"getMetaColumns",
"(",
"$",
"tableName",
")",
"{",
"$",
"stmt",
"=",
"$",
"this",
"->",
"query",
"(",
"self",
"::",
"META_COLUMNS_SQL",
",",
"array",
"(",
"$",
"tableName",
")",
")",
";",
"if",
"(",
"$",
"stmt",
"===",
"false",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"rows",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"stmt",
"as",
"$",
"row",
")",
"{",
"switch",
"(",
"$",
"row",
"[",
"1",
"]",
")",
"{",
"case",
"'float8'",
":",
"case",
"'numeric'",
":",
"$",
"type",
"=",
"PDO",
"::",
"PARAM_STR",
";",
"// Not exists PARAM_FLOAT by current version.",
"break",
";",
"case",
"'int4'",
":",
"case",
"'int8'",
":",
"$",
"type",
"=",
"PDO",
"::",
"PARAM_INT",
";",
"break",
";",
"case",
"'bool'",
":",
"$",
"type",
"=",
"PDO",
"::",
"PARAM_BOOL",
";",
"break",
";",
"default",
":",
"$",
"type",
"=",
"PDO",
"::",
"PARAM_STR",
";",
"break",
";",
"}",
"$",
"rows",
"[",
"$",
"row",
"[",
"0",
"]",
"]",
"=",
"$",
"type",
";",
"}",
"return",
"$",
"rows",
";",
"}"
] |
Return columns information.
@return array
@access public
|
[
"Return",
"columns",
"information",
"."
] |
9d14c99711cd2081d2f658c5253f72721a2c7337
|
https://github.com/nishimura/laiz-db/blob/9d14c99711cd2081d2f658c5253f72721a2c7337/src/Laiz/Db/Driver/Pgsql.php#L86-L118
|
235,324
|
nishimura/laiz-db
|
src/Laiz/Db/Driver/Pgsql.php
|
Pgsql.currval
|
public function currval($table, $pkey){
$stmt = $this->query("SELECT currval('{$table}_{$pkey}_seq')");
if (!$stmt)
return false;
$ret = $stmt->fetch(PDO::FETCH_NUM);
if (!$ret){
$stmt = null;
return false;
}
$stmt = null;
return $ret[0];
}
|
php
|
public function currval($table, $pkey){
$stmt = $this->query("SELECT currval('{$table}_{$pkey}_seq')");
if (!$stmt)
return false;
$ret = $stmt->fetch(PDO::FETCH_NUM);
if (!$ret){
$stmt = null;
return false;
}
$stmt = null;
return $ret[0];
}
|
[
"public",
"function",
"currval",
"(",
"$",
"table",
",",
"$",
"pkey",
")",
"{",
"$",
"stmt",
"=",
"$",
"this",
"->",
"query",
"(",
"\"SELECT currval('{$table}_{$pkey}_seq')\"",
")",
";",
"if",
"(",
"!",
"$",
"stmt",
")",
"return",
"false",
";",
"$",
"ret",
"=",
"$",
"stmt",
"->",
"fetch",
"(",
"PDO",
"::",
"FETCH_NUM",
")",
";",
"if",
"(",
"!",
"$",
"ret",
")",
"{",
"$",
"stmt",
"=",
"null",
";",
"return",
"false",
";",
"}",
"$",
"stmt",
"=",
"null",
";",
"return",
"$",
"ret",
"[",
"0",
"]",
";",
"}"
] |
Return current sequence.
@param string $table
|
[
"Return",
"current",
"sequence",
"."
] |
9d14c99711cd2081d2f658c5253f72721a2c7337
|
https://github.com/nishimura/laiz-db/blob/9d14c99711cd2081d2f658c5253f72721a2c7337/src/Laiz/Db/Driver/Pgsql.php#L177-L191
|
235,325
|
emmanix2002/dorcas-sdk-php
|
src/Sdk.php
|
Sdk.checkCredentials
|
private function checkCredentials(array $args = []): bool
{
if (empty($args['credentials'])) {
throw new DorcasException('You did not provide the Dorcas client credentials in the configuration.', $args);
}
$id = data_get($args, 'credentials.id', null);
$secret = data_get($args, 'credentials.secret', null);
if (empty($id)) {
throw new DorcasException('The client "id" key is absent in the credentials configuration.', $args);
}
if (empty($secret)) {
throw new DorcasException('The client "secret" key is absent in the credentials configuration.', $args);
}
return true;
}
|
php
|
private function checkCredentials(array $args = []): bool
{
if (empty($args['credentials'])) {
throw new DorcasException('You did not provide the Dorcas client credentials in the configuration.', $args);
}
$id = data_get($args, 'credentials.id', null);
$secret = data_get($args, 'credentials.secret', null);
if (empty($id)) {
throw new DorcasException('The client "id" key is absent in the credentials configuration.', $args);
}
if (empty($secret)) {
throw new DorcasException('The client "secret" key is absent in the credentials configuration.', $args);
}
return true;
}
|
[
"private",
"function",
"checkCredentials",
"(",
"array",
"$",
"args",
"=",
"[",
"]",
")",
":",
"bool",
"{",
"if",
"(",
"empty",
"(",
"$",
"args",
"[",
"'credentials'",
"]",
")",
")",
"{",
"throw",
"new",
"DorcasException",
"(",
"'You did not provide the Dorcas client credentials in the configuration.'",
",",
"$",
"args",
")",
";",
"}",
"$",
"id",
"=",
"data_get",
"(",
"$",
"args",
",",
"'credentials.id'",
",",
"null",
")",
";",
"$",
"secret",
"=",
"data_get",
"(",
"$",
"args",
",",
"'credentials.secret'",
",",
"null",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"id",
")",
")",
"{",
"throw",
"new",
"DorcasException",
"(",
"'The client \"id\" key is absent in the credentials configuration.'",
",",
"$",
"args",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"secret",
")",
")",
"{",
"throw",
"new",
"DorcasException",
"(",
"'The client \"secret\" key is absent in the credentials configuration.'",
",",
"$",
"args",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Checks the credentials configuration to make sure it is valid.
@param array $args
@return bool
@throws DorcasException
|
[
"Checks",
"the",
"credentials",
"configuration",
"to",
"make",
"sure",
"it",
"is",
"valid",
"."
] |
1b68df62da1ed5f993f9e2687633402b96ab7f64
|
https://github.com/emmanix2002/dorcas-sdk-php/blob/1b68df62da1ed5f993f9e2687633402b96ab7f64/src/Sdk.php#L188-L202
|
235,326
|
emmanix2002/dorcas-sdk-php
|
src/Sdk.php
|
Sdk.createResourceClient
|
protected function createResourceClient(string $name, array $options = []): ResourceInterface
{
$entry = $this->manifest->getResource($name);
# we check for the manifest entry
if (empty($entry)) {
throw new ResourceNotFoundException('Could not find the client for the requested resource '.$name);
}
$resource = $entry['namespace'] . '\\' . $entry['client'];
return new $resource($this, ...$options);
}
|
php
|
protected function createResourceClient(string $name, array $options = []): ResourceInterface
{
$entry = $this->manifest->getResource($name);
# we check for the manifest entry
if (empty($entry)) {
throw new ResourceNotFoundException('Could not find the client for the requested resource '.$name);
}
$resource = $entry['namespace'] . '\\' . $entry['client'];
return new $resource($this, ...$options);
}
|
[
"protected",
"function",
"createResourceClient",
"(",
"string",
"$",
"name",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
":",
"ResourceInterface",
"{",
"$",
"entry",
"=",
"$",
"this",
"->",
"manifest",
"->",
"getResource",
"(",
"$",
"name",
")",
";",
"# we check for the manifest entry",
"if",
"(",
"empty",
"(",
"$",
"entry",
")",
")",
"{",
"throw",
"new",
"ResourceNotFoundException",
"(",
"'Could not find the client for the requested resource '",
".",
"$",
"name",
")",
";",
"}",
"$",
"resource",
"=",
"$",
"entry",
"[",
"'namespace'",
"]",
".",
"'\\\\'",
".",
"$",
"entry",
"[",
"'client'",
"]",
";",
"return",
"new",
"$",
"resource",
"(",
"$",
"this",
",",
"...",
"$",
"options",
")",
";",
"}"
] |
Creates a new resource client with the provided options.
@param string $name
@param array $options
@return ResourceInterface
|
[
"Creates",
"a",
"new",
"resource",
"client",
"with",
"the",
"provided",
"options",
"."
] |
1b68df62da1ed5f993f9e2687633402b96ab7f64
|
https://github.com/emmanix2002/dorcas-sdk-php/blob/1b68df62da1ed5f993f9e2687633402b96ab7f64/src/Sdk.php#L212-L222
|
235,327
|
emmanix2002/dorcas-sdk-php
|
src/Sdk.php
|
Sdk.createServiceClient
|
protected function createServiceClient(string $name, array $options = []): ServiceInterface
{
$entry = $this->manifest->getService($name);
# we check for the manifest entry
if (empty($entry)) {
throw new ResourceNotFoundException('Could not find the client for the requested service '.$name);
}
$service = $entry['namespace'] . '\\' . $entry['client'];
return new $service($this, $options);
}
|
php
|
protected function createServiceClient(string $name, array $options = []): ServiceInterface
{
$entry = $this->manifest->getService($name);
# we check for the manifest entry
if (empty($entry)) {
throw new ResourceNotFoundException('Could not find the client for the requested service '.$name);
}
$service = $entry['namespace'] . '\\' . $entry['client'];
return new $service($this, $options);
}
|
[
"protected",
"function",
"createServiceClient",
"(",
"string",
"$",
"name",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
":",
"ServiceInterface",
"{",
"$",
"entry",
"=",
"$",
"this",
"->",
"manifest",
"->",
"getService",
"(",
"$",
"name",
")",
";",
"# we check for the manifest entry",
"if",
"(",
"empty",
"(",
"$",
"entry",
")",
")",
"{",
"throw",
"new",
"ResourceNotFoundException",
"(",
"'Could not find the client for the requested service '",
".",
"$",
"name",
")",
";",
"}",
"$",
"service",
"=",
"$",
"entry",
"[",
"'namespace'",
"]",
".",
"'\\\\'",
".",
"$",
"entry",
"[",
"'client'",
"]",
";",
"return",
"new",
"$",
"service",
"(",
"$",
"this",
",",
"$",
"options",
")",
";",
"}"
] |
Creates a new service client with the provided options.
@param string $name
@param array $options
@return ServiceInterface
|
[
"Creates",
"a",
"new",
"service",
"client",
"with",
"the",
"provided",
"options",
"."
] |
1b68df62da1ed5f993f9e2687633402b96ab7f64
|
https://github.com/emmanix2002/dorcas-sdk-php/blob/1b68df62da1ed5f993f9e2687633402b96ab7f64/src/Sdk.php#L232-L241
|
235,328
|
as3io/modlr-api-jsonapiorg
|
src/Normalizer.php
|
Normalizer.extractAttributes
|
protected function extractAttributes(array $data, EntityMetadata $metadata)
{
$flattened = [];
if (!isset($data['attributes']) || !is_array($data['attributes'])) {
return $data['attributes'] = [];
}
$keyMap = array_flip(array_keys($data['attributes']));
foreach ($metadata->getProperties() as $key => $propMeta) {
if (!isset($keyMap[$key])) {
continue;
}
if (true === $metadata->hasAttribute($key) || true === $metadata->hasEmbed($key)) {
$flattened[$key] = $data['attributes'][$key];
}
}
return $flattened;
}
|
php
|
protected function extractAttributes(array $data, EntityMetadata $metadata)
{
$flattened = [];
if (!isset($data['attributes']) || !is_array($data['attributes'])) {
return $data['attributes'] = [];
}
$keyMap = array_flip(array_keys($data['attributes']));
foreach ($metadata->getProperties() as $key => $propMeta) {
if (!isset($keyMap[$key])) {
continue;
}
if (true === $metadata->hasAttribute($key) || true === $metadata->hasEmbed($key)) {
$flattened[$key] = $data['attributes'][$key];
}
}
return $flattened;
}
|
[
"protected",
"function",
"extractAttributes",
"(",
"array",
"$",
"data",
",",
"EntityMetadata",
"$",
"metadata",
")",
"{",
"$",
"flattened",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"'attributes'",
"]",
")",
"||",
"!",
"is_array",
"(",
"$",
"data",
"[",
"'attributes'",
"]",
")",
")",
"{",
"return",
"$",
"data",
"[",
"'attributes'",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"keyMap",
"=",
"array_flip",
"(",
"array_keys",
"(",
"$",
"data",
"[",
"'attributes'",
"]",
")",
")",
";",
"foreach",
"(",
"$",
"metadata",
"->",
"getProperties",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"propMeta",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"keyMap",
"[",
"$",
"key",
"]",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"true",
"===",
"$",
"metadata",
"->",
"hasAttribute",
"(",
"$",
"key",
")",
"||",
"true",
"===",
"$",
"metadata",
"->",
"hasEmbed",
"(",
"$",
"key",
")",
")",
"{",
"$",
"flattened",
"[",
"$",
"key",
"]",
"=",
"$",
"data",
"[",
"'attributes'",
"]",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"return",
"$",
"flattened",
";",
"}"
] |
Extracts the model's attributes, per JSON API spec.
@param array $data
@param EntityMetadata $metadata
@return array
|
[
"Extracts",
"the",
"model",
"s",
"attributes",
"per",
"JSON",
"API",
"spec",
"."
] |
f53163c315a6a7be09e514a4c81af24aa665634b
|
https://github.com/as3io/modlr-api-jsonapiorg/blob/f53163c315a6a7be09e514a4c81af24aa665634b/src/Normalizer.php#L57-L74
|
235,329
|
as3io/modlr-api-jsonapiorg
|
src/Normalizer.php
|
Normalizer.extractRelationships
|
protected function extractRelationships(array $data, EntityMetadata $metadata)
{
$flattened = [];
if (!isset($data['relationships']) || !is_array($data['relationships'])) {
return $flattened;
}
foreach ($metadata->getRelationships() as $key => $relMeta) {
if (!isset($data['relationships'][$key])) {
continue;
}
$rel = $data['relationships'][$key];
// Need to use array_key_exists over isset because 'null' is valid. Creating a key map for each relationship is too costly since every relationship needs the data check.
if (false === array_key_exists('data', $rel)) {
throw NormalizerException::badRequest(sprintf('The "data" member was missing from the payload for relationship "%s"', $key));
}
if (empty($rel['data'])) {
$flattened[$key] = $relMeta->isOne() ? null : [];
continue;
}
if (!is_array($rel['data'])) {
throw NormalizerException::badRequest(sprintf('The "data" member is not valid in the payload for relationship "%s"', $key));
}
if (true === $relMeta->isOne() && true === $this->isSequentialArray($rel['data'])) {
throw NormalizerException::badRequest(sprintf('The data payload for relationship "%s" is malformed. Data types of "one" must be an associative array, sequential found.', $key));
}
if (true === $relMeta->isMany() && false === $this->isSequentialArray($rel['data'])) {
throw NormalizerException::badRequest(sprintf('The data payload for relationship "%s" is malformed. Data types of "many" must be a sequential array, associative found.', $key));
}
$flattened[$key] = $rel['data'];
}
return $flattened;
}
|
php
|
protected function extractRelationships(array $data, EntityMetadata $metadata)
{
$flattened = [];
if (!isset($data['relationships']) || !is_array($data['relationships'])) {
return $flattened;
}
foreach ($metadata->getRelationships() as $key => $relMeta) {
if (!isset($data['relationships'][$key])) {
continue;
}
$rel = $data['relationships'][$key];
// Need to use array_key_exists over isset because 'null' is valid. Creating a key map for each relationship is too costly since every relationship needs the data check.
if (false === array_key_exists('data', $rel)) {
throw NormalizerException::badRequest(sprintf('The "data" member was missing from the payload for relationship "%s"', $key));
}
if (empty($rel['data'])) {
$flattened[$key] = $relMeta->isOne() ? null : [];
continue;
}
if (!is_array($rel['data'])) {
throw NormalizerException::badRequest(sprintf('The "data" member is not valid in the payload for relationship "%s"', $key));
}
if (true === $relMeta->isOne() && true === $this->isSequentialArray($rel['data'])) {
throw NormalizerException::badRequest(sprintf('The data payload for relationship "%s" is malformed. Data types of "one" must be an associative array, sequential found.', $key));
}
if (true === $relMeta->isMany() && false === $this->isSequentialArray($rel['data'])) {
throw NormalizerException::badRequest(sprintf('The data payload for relationship "%s" is malformed. Data types of "many" must be a sequential array, associative found.', $key));
}
$flattened[$key] = $rel['data'];
}
return $flattened;
}
|
[
"protected",
"function",
"extractRelationships",
"(",
"array",
"$",
"data",
",",
"EntityMetadata",
"$",
"metadata",
")",
"{",
"$",
"flattened",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"'relationships'",
"]",
")",
"||",
"!",
"is_array",
"(",
"$",
"data",
"[",
"'relationships'",
"]",
")",
")",
"{",
"return",
"$",
"flattened",
";",
"}",
"foreach",
"(",
"$",
"metadata",
"->",
"getRelationships",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"relMeta",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"'relationships'",
"]",
"[",
"$",
"key",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"rel",
"=",
"$",
"data",
"[",
"'relationships'",
"]",
"[",
"$",
"key",
"]",
";",
"// Need to use array_key_exists over isset because 'null' is valid. Creating a key map for each relationship is too costly since every relationship needs the data check.",
"if",
"(",
"false",
"===",
"array_key_exists",
"(",
"'data'",
",",
"$",
"rel",
")",
")",
"{",
"throw",
"NormalizerException",
"::",
"badRequest",
"(",
"sprintf",
"(",
"'The \"data\" member was missing from the payload for relationship \"%s\"'",
",",
"$",
"key",
")",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"rel",
"[",
"'data'",
"]",
")",
")",
"{",
"$",
"flattened",
"[",
"$",
"key",
"]",
"=",
"$",
"relMeta",
"->",
"isOne",
"(",
")",
"?",
"null",
":",
"[",
"]",
";",
"continue",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"rel",
"[",
"'data'",
"]",
")",
")",
"{",
"throw",
"NormalizerException",
"::",
"badRequest",
"(",
"sprintf",
"(",
"'The \"data\" member is not valid in the payload for relationship \"%s\"'",
",",
"$",
"key",
")",
")",
";",
"}",
"if",
"(",
"true",
"===",
"$",
"relMeta",
"->",
"isOne",
"(",
")",
"&&",
"true",
"===",
"$",
"this",
"->",
"isSequentialArray",
"(",
"$",
"rel",
"[",
"'data'",
"]",
")",
")",
"{",
"throw",
"NormalizerException",
"::",
"badRequest",
"(",
"sprintf",
"(",
"'The data payload for relationship \"%s\" is malformed. Data types of \"one\" must be an associative array, sequential found.'",
",",
"$",
"key",
")",
")",
";",
"}",
"if",
"(",
"true",
"===",
"$",
"relMeta",
"->",
"isMany",
"(",
")",
"&&",
"false",
"===",
"$",
"this",
"->",
"isSequentialArray",
"(",
"$",
"rel",
"[",
"'data'",
"]",
")",
")",
"{",
"throw",
"NormalizerException",
"::",
"badRequest",
"(",
"sprintf",
"(",
"'The data payload for relationship \"%s\" is malformed. Data types of \"many\" must be a sequential array, associative found.'",
",",
"$",
"key",
")",
")",
";",
"}",
"$",
"flattened",
"[",
"$",
"key",
"]",
"=",
"$",
"rel",
"[",
"'data'",
"]",
";",
"}",
"return",
"$",
"flattened",
";",
"}"
] |
Extracts the model's relationships, per JSON API spec.
@param array $data
@param EntityMetadata $metadata
@return array
|
[
"Extracts",
"the",
"model",
"s",
"relationships",
"per",
"JSON",
"API",
"spec",
"."
] |
f53163c315a6a7be09e514a4c81af24aa665634b
|
https://github.com/as3io/modlr-api-jsonapiorg/blob/f53163c315a6a7be09e514a4c81af24aa665634b/src/Normalizer.php#L83-L118
|
235,330
|
tasoftch/skyline-translation
|
src/TranslationManager.php
|
TranslationManager.setClientLocales
|
public function setClientLocales($clientLocales): void
{
if(!$this->clientLocales)
$this->clientLocales = new LocaleCollection();
$this->clientLocales->removeAllLocales();
foreach ($clientLocales as $locale) {
if(is_string($locale)) {
$locale = new Locale($locale);
}
if($locale instanceof Locale) {
$this->clientLocales->addLocale($locale);
}
}
}
|
php
|
public function setClientLocales($clientLocales): void
{
if(!$this->clientLocales)
$this->clientLocales = new LocaleCollection();
$this->clientLocales->removeAllLocales();
foreach ($clientLocales as $locale) {
if(is_string($locale)) {
$locale = new Locale($locale);
}
if($locale instanceof Locale) {
$this->clientLocales->addLocale($locale);
}
}
}
|
[
"public",
"function",
"setClientLocales",
"(",
"$",
"clientLocales",
")",
":",
"void",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"clientLocales",
")",
"$",
"this",
"->",
"clientLocales",
"=",
"new",
"LocaleCollection",
"(",
")",
";",
"$",
"this",
"->",
"clientLocales",
"->",
"removeAllLocales",
"(",
")",
";",
"foreach",
"(",
"$",
"clientLocales",
"as",
"$",
"locale",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"locale",
")",
")",
"{",
"$",
"locale",
"=",
"new",
"Locale",
"(",
"$",
"locale",
")",
";",
"}",
"if",
"(",
"$",
"locale",
"instanceof",
"Locale",
")",
"{",
"$",
"this",
"->",
"clientLocales",
"->",
"addLocale",
"(",
"$",
"locale",
")",
";",
"}",
"}",
"}"
] |
Sets the client locales. You may pass Locale objects or string values.
@param \Traversable|array $clientLocales
@throws BadLocaleException
|
[
"Sets",
"the",
"client",
"locales",
".",
"You",
"may",
"pass",
"Locale",
"objects",
"or",
"string",
"values",
"."
] |
fce37d7298f8bd880d11c73e7ecf145600668bc5
|
https://github.com/tasoftch/skyline-translation/blob/fce37d7298f8bd880d11c73e7ecf145600668bc5/src/TranslationManager.php#L93-L109
|
235,331
|
tasoftch/skyline-translation
|
src/TranslationManager.php
|
TranslationManager.readClientLocalesFromRequest
|
public function readClientLocalesFromRequest(Request $request) {
$locales = [];
foreach($request->getLanguages() as $client) {
try {
$locale = new Locale($client);
$locales[] = $locale;
} catch(\Exception $e) {
trigger_error($e->getMessage(), E_USER_NOTICE);
}
}
$this->setClientLocales($locales);
}
|
php
|
public function readClientLocalesFromRequest(Request $request) {
$locales = [];
foreach($request->getLanguages() as $client) {
try {
$locale = new Locale($client);
$locales[] = $locale;
} catch(\Exception $e) {
trigger_error($e->getMessage(), E_USER_NOTICE);
}
}
$this->setClientLocales($locales);
}
|
[
"public",
"function",
"readClientLocalesFromRequest",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"locales",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"request",
"->",
"getLanguages",
"(",
")",
"as",
"$",
"client",
")",
"{",
"try",
"{",
"$",
"locale",
"=",
"new",
"Locale",
"(",
"$",
"client",
")",
";",
"$",
"locales",
"[",
"]",
"=",
"$",
"locale",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"trigger_error",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"E_USER_NOTICE",
")",
";",
"}",
"}",
"$",
"this",
"->",
"setClientLocales",
"(",
"$",
"locales",
")",
";",
"}"
] |
Reads the client locales from the request
@param Request $request
@throws BadLocaleException
|
[
"Reads",
"the",
"client",
"locales",
"from",
"the",
"request"
] |
fce37d7298f8bd880d11c73e7ecf145600668bc5
|
https://github.com/tasoftch/skyline-translation/blob/fce37d7298f8bd880d11c73e7ecf145600668bc5/src/TranslationManager.php#L116-L129
|
235,332
|
tasoftch/skyline-translation
|
src/TranslationManager.php
|
TranslationManager.getServerLocales
|
public function getServerLocales() {
if(!isset($this->serverLocales)) {
$this->serverLocales = new LocaleCollection();
foreach($this->supportedLocaleStrings as $server) {
try {
$locale = new Locale($server);
$this->serverLocales->addLocale( $locale );
} catch(\Exception $e) {
trigger_error($e->getMessage(), E_USER_NOTICE);
}
}
}
return $this->serverLocales->getLocales();
}
|
php
|
public function getServerLocales() {
if(!isset($this->serverLocales)) {
$this->serverLocales = new LocaleCollection();
foreach($this->supportedLocaleStrings as $server) {
try {
$locale = new Locale($server);
$this->serverLocales->addLocale( $locale );
} catch(\Exception $e) {
trigger_error($e->getMessage(), E_USER_NOTICE);
}
}
}
return $this->serverLocales->getLocales();
}
|
[
"public",
"function",
"getServerLocales",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"serverLocales",
")",
")",
"{",
"$",
"this",
"->",
"serverLocales",
"=",
"new",
"LocaleCollection",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"supportedLocaleStrings",
"as",
"$",
"server",
")",
"{",
"try",
"{",
"$",
"locale",
"=",
"new",
"Locale",
"(",
"$",
"server",
")",
";",
"$",
"this",
"->",
"serverLocales",
"->",
"addLocale",
"(",
"$",
"locale",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"trigger_error",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"E_USER_NOTICE",
")",
";",
"}",
"}",
"}",
"return",
"$",
"this",
"->",
"serverLocales",
"->",
"getLocales",
"(",
")",
";",
"}"
] |
Returns all possible locales the server can deliver the render result
@return array
|
[
"Returns",
"all",
"possible",
"locales",
"the",
"server",
"can",
"deliver",
"the",
"render",
"result"
] |
fce37d7298f8bd880d11c73e7ecf145600668bc5
|
https://github.com/tasoftch/skyline-translation/blob/fce37d7298f8bd880d11c73e7ecf145600668bc5/src/TranslationManager.php#L135-L148
|
235,333
|
tasoftch/skyline-translation
|
src/TranslationManager.php
|
TranslationManager.getBestRenderLocales
|
public function getBestRenderLocales($ordered = self::ORDER_LANG) {
$locales = [];
$this->getServerLocales();
foreach($this->getClientLocales() as $locale) {
/** @var Locale $locale */
$loc = $this->serverLocales->getBestMatchingLocaleForLocale($locale);
if($loc && !in_array($loc, $locales)) {
$locales[] = $loc;
}
}
if(count($locales) == 0) {
if($this->defaultLocale)
$locales[] = $this->defaultLocale;
else {
$locales[] = $this->getServerLocales()[0] ?? NULL;
}
}
if($ordered & self::ORDER_STRUCT) {
$locs = [];
foreach($locales as $loc) {
/** @var Locale $loc */
$lang = $loc->getLanguage();
$locs[$lang][] = $loc;
}
if($ordered & self::ORDER_LANG) {
foreach($locs as &$ll)
usort($ll, LocaleCollection::LANG_SORT_CALLBACK);
} elseif($ordered & self::ORDER_REG) {
foreach($locs as &$ll)
usort($ll, LocaleCollection::REG_SORT_CALLBACK);
}
return $locs;
}
return $locales;
}
|
php
|
public function getBestRenderLocales($ordered = self::ORDER_LANG) {
$locales = [];
$this->getServerLocales();
foreach($this->getClientLocales() as $locale) {
/** @var Locale $locale */
$loc = $this->serverLocales->getBestMatchingLocaleForLocale($locale);
if($loc && !in_array($loc, $locales)) {
$locales[] = $loc;
}
}
if(count($locales) == 0) {
if($this->defaultLocale)
$locales[] = $this->defaultLocale;
else {
$locales[] = $this->getServerLocales()[0] ?? NULL;
}
}
if($ordered & self::ORDER_STRUCT) {
$locs = [];
foreach($locales as $loc) {
/** @var Locale $loc */
$lang = $loc->getLanguage();
$locs[$lang][] = $loc;
}
if($ordered & self::ORDER_LANG) {
foreach($locs as &$ll)
usort($ll, LocaleCollection::LANG_SORT_CALLBACK);
} elseif($ordered & self::ORDER_REG) {
foreach($locs as &$ll)
usort($ll, LocaleCollection::REG_SORT_CALLBACK);
}
return $locs;
}
return $locales;
}
|
[
"public",
"function",
"getBestRenderLocales",
"(",
"$",
"ordered",
"=",
"self",
"::",
"ORDER_LANG",
")",
"{",
"$",
"locales",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"getServerLocales",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getClientLocales",
"(",
")",
"as",
"$",
"locale",
")",
"{",
"/** @var Locale $locale */",
"$",
"loc",
"=",
"$",
"this",
"->",
"serverLocales",
"->",
"getBestMatchingLocaleForLocale",
"(",
"$",
"locale",
")",
";",
"if",
"(",
"$",
"loc",
"&&",
"!",
"in_array",
"(",
"$",
"loc",
",",
"$",
"locales",
")",
")",
"{",
"$",
"locales",
"[",
"]",
"=",
"$",
"loc",
";",
"}",
"}",
"if",
"(",
"count",
"(",
"$",
"locales",
")",
"==",
"0",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"defaultLocale",
")",
"$",
"locales",
"[",
"]",
"=",
"$",
"this",
"->",
"defaultLocale",
";",
"else",
"{",
"$",
"locales",
"[",
"]",
"=",
"$",
"this",
"->",
"getServerLocales",
"(",
")",
"[",
"0",
"]",
"??",
"NULL",
";",
"}",
"}",
"if",
"(",
"$",
"ordered",
"&",
"self",
"::",
"ORDER_STRUCT",
")",
"{",
"$",
"locs",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"locales",
"as",
"$",
"loc",
")",
"{",
"/** @var Locale $loc */",
"$",
"lang",
"=",
"$",
"loc",
"->",
"getLanguage",
"(",
")",
";",
"$",
"locs",
"[",
"$",
"lang",
"]",
"[",
"]",
"=",
"$",
"loc",
";",
"}",
"if",
"(",
"$",
"ordered",
"&",
"self",
"::",
"ORDER_LANG",
")",
"{",
"foreach",
"(",
"$",
"locs",
"as",
"&",
"$",
"ll",
")",
"usort",
"(",
"$",
"ll",
",",
"LocaleCollection",
"::",
"LANG_SORT_CALLBACK",
")",
";",
"}",
"elseif",
"(",
"$",
"ordered",
"&",
"self",
"::",
"ORDER_REG",
")",
"{",
"foreach",
"(",
"$",
"locs",
"as",
"&",
"$",
"ll",
")",
"usort",
"(",
"$",
"ll",
",",
"LocaleCollection",
"::",
"REG_SORT_CALLBACK",
")",
";",
"}",
"return",
"$",
"locs",
";",
"}",
"return",
"$",
"locales",
";",
"}"
] |
Tries to figure out which locales matching the desired language and the provided language.
If no matches can be found, the default CMS language will be served.
@param int $ordered
@return array
|
[
"Tries",
"to",
"figure",
"out",
"which",
"locales",
"matching",
"the",
"desired",
"language",
"and",
"the",
"provided",
"language",
".",
"If",
"no",
"matches",
"can",
"be",
"found",
"the",
"default",
"CMS",
"language",
"will",
"be",
"served",
"."
] |
fce37d7298f8bd880d11c73e7ecf145600668bc5
|
https://github.com/tasoftch/skyline-translation/blob/fce37d7298f8bd880d11c73e7ecf145600668bc5/src/TranslationManager.php#L156-L197
|
235,334
|
avoo/FrameworkInstallerBundle
|
Composer/ScriptHandler.php
|
ScriptHandler.installAvooDemoBundle
|
public static function installAvooDemoBundle(InputInterface $input, OutputInterface $output, QuestionHelper $helper)
{
$rootDir = getcwd();
if (file_exists($rootDir.'/src/Avoo/DemoBundle')) {
return;
}
if (!getenv('AVOO_DEMO')) {
$question = new ConfirmationQuestion('Would you like to install Avoo Demo bundle? [y/n] ', true);
if (!$helper->ask($input, $output, $question)) {
return;
}
}
$output->writeln('<info>Installing the Avoo Demo bundle.</info>');
$output->writeln('');
$kernelFile = $rootDir . '/app/AppKernel.php';
$configFile = $rootDir . '/app/config/config_dev.yml';
$fileSystem = new Filesystem();
$fileSystem->mirror(__DIR__.'/../Resources/skeleton/avoo-demo-bundle', $rootDir . '/src', null, array('override' => true));
$ref = '$bundles[] = new \Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();';
$bundleDeclaration = "\$bundles[] = new \\Avoo\\DemoBundle\\AvooDemoBundle();";
$content = file_get_contents($kernelFile);
if (false === strpos($content, $bundleDeclaration)) {
$updatedContent = str_replace($ref, $bundleDeclaration."\n ".$ref, $content);
if ($content === $updatedContent) {
throw new \RuntimeException('Unable to patch %s.', $kernelFile);
}
$fileSystem->dumpFile($kernelFile, $updatedContent);
}
$ref = '- { resource: config.yml }';
$configDeclaration = '- { resource: @AvooDemoBundle/Resources/config/config.yml }';
$content = file_get_contents($configFile);
if (false === strpos($content, $bundleDeclaration)) {
$updatedContent = str_replace($ref, $ref . "\n " . $configDeclaration, $content);
if ($content === $updatedContent) {
throw new \RuntimeException('Unable to patch %s.', $kernelFile);
}
$fileSystem->dumpFile($configFile, $updatedContent);
}
self::patchAvooDemoBundleConfiguration($rootDir, $fileSystem);
}
|
php
|
public static function installAvooDemoBundle(InputInterface $input, OutputInterface $output, QuestionHelper $helper)
{
$rootDir = getcwd();
if (file_exists($rootDir.'/src/Avoo/DemoBundle')) {
return;
}
if (!getenv('AVOO_DEMO')) {
$question = new ConfirmationQuestion('Would you like to install Avoo Demo bundle? [y/n] ', true);
if (!$helper->ask($input, $output, $question)) {
return;
}
}
$output->writeln('<info>Installing the Avoo Demo bundle.</info>');
$output->writeln('');
$kernelFile = $rootDir . '/app/AppKernel.php';
$configFile = $rootDir . '/app/config/config_dev.yml';
$fileSystem = new Filesystem();
$fileSystem->mirror(__DIR__.'/../Resources/skeleton/avoo-demo-bundle', $rootDir . '/src', null, array('override' => true));
$ref = '$bundles[] = new \Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();';
$bundleDeclaration = "\$bundles[] = new \\Avoo\\DemoBundle\\AvooDemoBundle();";
$content = file_get_contents($kernelFile);
if (false === strpos($content, $bundleDeclaration)) {
$updatedContent = str_replace($ref, $bundleDeclaration."\n ".$ref, $content);
if ($content === $updatedContent) {
throw new \RuntimeException('Unable to patch %s.', $kernelFile);
}
$fileSystem->dumpFile($kernelFile, $updatedContent);
}
$ref = '- { resource: config.yml }';
$configDeclaration = '- { resource: @AvooDemoBundle/Resources/config/config.yml }';
$content = file_get_contents($configFile);
if (false === strpos($content, $bundleDeclaration)) {
$updatedContent = str_replace($ref, $ref . "\n " . $configDeclaration, $content);
if ($content === $updatedContent) {
throw new \RuntimeException('Unable to patch %s.', $kernelFile);
}
$fileSystem->dumpFile($configFile, $updatedContent);
}
self::patchAvooDemoBundleConfiguration($rootDir, $fileSystem);
}
|
[
"public",
"static",
"function",
"installAvooDemoBundle",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
",",
"QuestionHelper",
"$",
"helper",
")",
"{",
"$",
"rootDir",
"=",
"getcwd",
"(",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"rootDir",
".",
"'/src/Avoo/DemoBundle'",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"getenv",
"(",
"'AVOO_DEMO'",
")",
")",
"{",
"$",
"question",
"=",
"new",
"ConfirmationQuestion",
"(",
"'Would you like to install Avoo Demo bundle? [y/n] '",
",",
"true",
")",
";",
"if",
"(",
"!",
"$",
"helper",
"->",
"ask",
"(",
"$",
"input",
",",
"$",
"output",
",",
"$",
"question",
")",
")",
"{",
"return",
";",
"}",
"}",
"$",
"output",
"->",
"writeln",
"(",
"'<info>Installing the Avoo Demo bundle.</info>'",
")",
";",
"$",
"output",
"->",
"writeln",
"(",
"''",
")",
";",
"$",
"kernelFile",
"=",
"$",
"rootDir",
".",
"'/app/AppKernel.php'",
";",
"$",
"configFile",
"=",
"$",
"rootDir",
".",
"'/app/config/config_dev.yml'",
";",
"$",
"fileSystem",
"=",
"new",
"Filesystem",
"(",
")",
";",
"$",
"fileSystem",
"->",
"mirror",
"(",
"__DIR__",
".",
"'/../Resources/skeleton/avoo-demo-bundle'",
",",
"$",
"rootDir",
".",
"'/src'",
",",
"null",
",",
"array",
"(",
"'override'",
"=>",
"true",
")",
")",
";",
"$",
"ref",
"=",
"'$bundles[] = new \\Symfony\\Bundle\\WebProfilerBundle\\WebProfilerBundle();'",
";",
"$",
"bundleDeclaration",
"=",
"\"\\$bundles[] = new \\\\Avoo\\\\DemoBundle\\\\AvooDemoBundle();\"",
";",
"$",
"content",
"=",
"file_get_contents",
"(",
"$",
"kernelFile",
")",
";",
"if",
"(",
"false",
"===",
"strpos",
"(",
"$",
"content",
",",
"$",
"bundleDeclaration",
")",
")",
"{",
"$",
"updatedContent",
"=",
"str_replace",
"(",
"$",
"ref",
",",
"$",
"bundleDeclaration",
".",
"\"\\n \"",
".",
"$",
"ref",
",",
"$",
"content",
")",
";",
"if",
"(",
"$",
"content",
"===",
"$",
"updatedContent",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Unable to patch %s.'",
",",
"$",
"kernelFile",
")",
";",
"}",
"$",
"fileSystem",
"->",
"dumpFile",
"(",
"$",
"kernelFile",
",",
"$",
"updatedContent",
")",
";",
"}",
"$",
"ref",
"=",
"'- { resource: config.yml }'",
";",
"$",
"configDeclaration",
"=",
"'- { resource: @AvooDemoBundle/Resources/config/config.yml }'",
";",
"$",
"content",
"=",
"file_get_contents",
"(",
"$",
"configFile",
")",
";",
"if",
"(",
"false",
"===",
"strpos",
"(",
"$",
"content",
",",
"$",
"bundleDeclaration",
")",
")",
"{",
"$",
"updatedContent",
"=",
"str_replace",
"(",
"$",
"ref",
",",
"$",
"ref",
".",
"\"\\n \"",
".",
"$",
"configDeclaration",
",",
"$",
"content",
")",
";",
"if",
"(",
"$",
"content",
"===",
"$",
"updatedContent",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Unable to patch %s.'",
",",
"$",
"kernelFile",
")",
";",
"}",
"$",
"fileSystem",
"->",
"dumpFile",
"(",
"$",
"configFile",
",",
"$",
"updatedContent",
")",
";",
"}",
"self",
"::",
"patchAvooDemoBundleConfiguration",
"(",
"$",
"rootDir",
",",
"$",
"fileSystem",
")",
";",
"}"
] |
Avoo demo bundle install
@param InputInterface $input
@param OutputInterface $output
@param QuestionHelper $helper
|
[
"Avoo",
"demo",
"bundle",
"install"
] |
402032e01467359b176de19731ebbff744cc52f5
|
https://github.com/avoo/FrameworkInstallerBundle/blob/402032e01467359b176de19731ebbff744cc52f5/Composer/ScriptHandler.php#L28-L78
|
235,335
|
avoo/FrameworkInstallerBundle
|
Composer/ScriptHandler.php
|
ScriptHandler.getApplicationName
|
private static function getApplicationName(InputInterface $input, OutputInterface $output, QuestionHelper $helper)
{
$question = new Question('Choose your application name: ');
$question->setValidator(function($answer) {
if (!preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $answer)) {
throw new \InvalidArgumentException('The application name contains invalid characters.');
}
return ucfirst(strtolower($answer));
});
return $helper->ask($input, $output, $question);
}
|
php
|
private static function getApplicationName(InputInterface $input, OutputInterface $output, QuestionHelper $helper)
{
$question = new Question('Choose your application name: ');
$question->setValidator(function($answer) {
if (!preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $answer)) {
throw new \InvalidArgumentException('The application name contains invalid characters.');
}
return ucfirst(strtolower($answer));
});
return $helper->ask($input, $output, $question);
}
|
[
"private",
"static",
"function",
"getApplicationName",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
",",
"QuestionHelper",
"$",
"helper",
")",
"{",
"$",
"question",
"=",
"new",
"Question",
"(",
"'Choose your application name: '",
")",
";",
"$",
"question",
"->",
"setValidator",
"(",
"function",
"(",
"$",
"answer",
")",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"'/^[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*$/'",
",",
"$",
"answer",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'The application name contains invalid characters.'",
")",
";",
"}",
"return",
"ucfirst",
"(",
"strtolower",
"(",
"$",
"answer",
")",
")",
";",
"}",
")",
";",
"return",
"$",
"helper",
"->",
"ask",
"(",
"$",
"input",
",",
"$",
"output",
",",
"$",
"question",
")",
";",
"}"
] |
Get application name
@param InputInterface $input
@param OutputInterface $output
@param QuestionHelper $helper
@return string
|
[
"Get",
"application",
"name"
] |
402032e01467359b176de19731ebbff744cc52f5
|
https://github.com/avoo/FrameworkInstallerBundle/blob/402032e01467359b176de19731ebbff744cc52f5/Composer/ScriptHandler.php#L248-L260
|
235,336
|
avoo/FrameworkInstallerBundle
|
Composer/ScriptHandler.php
|
ScriptHandler.buildCoreFiles
|
private static function buildCoreFiles($bundleDir, $applicationName, Filesystem $filesystem)
{
$filesystem->setParameters(array(
'namespace' => $applicationName . '\\Bundle\\CoreBundle',
'applicationName' => $applicationName,
'rename' => array(
'Bundle.php.twig' => $applicationName . 'CoreBundle.php',
'Extension.php.twig' => $applicationName . 'CoreExtension.php',
'app.yml.twig' => strtolower($applicationName) . '.yml',
)
));
$filesystem->mirror(__DIR__.'/../Resources/skeleton/avoo-core-bundle', $bundleDir, null, array('override' => true));
}
|
php
|
private static function buildCoreFiles($bundleDir, $applicationName, Filesystem $filesystem)
{
$filesystem->setParameters(array(
'namespace' => $applicationName . '\\Bundle\\CoreBundle',
'applicationName' => $applicationName,
'rename' => array(
'Bundle.php.twig' => $applicationName . 'CoreBundle.php',
'Extension.php.twig' => $applicationName . 'CoreExtension.php',
'app.yml.twig' => strtolower($applicationName) . '.yml',
)
));
$filesystem->mirror(__DIR__.'/../Resources/skeleton/avoo-core-bundle', $bundleDir, null, array('override' => true));
}
|
[
"private",
"static",
"function",
"buildCoreFiles",
"(",
"$",
"bundleDir",
",",
"$",
"applicationName",
",",
"Filesystem",
"$",
"filesystem",
")",
"{",
"$",
"filesystem",
"->",
"setParameters",
"(",
"array",
"(",
"'namespace'",
"=>",
"$",
"applicationName",
".",
"'\\\\Bundle\\\\CoreBundle'",
",",
"'applicationName'",
"=>",
"$",
"applicationName",
",",
"'rename'",
"=>",
"array",
"(",
"'Bundle.php.twig'",
"=>",
"$",
"applicationName",
".",
"'CoreBundle.php'",
",",
"'Extension.php.twig'",
"=>",
"$",
"applicationName",
".",
"'CoreExtension.php'",
",",
"'app.yml.twig'",
"=>",
"strtolower",
"(",
"$",
"applicationName",
")",
".",
"'.yml'",
",",
")",
")",
")",
";",
"$",
"filesystem",
"->",
"mirror",
"(",
"__DIR__",
".",
"'/../Resources/skeleton/avoo-core-bundle'",
",",
"$",
"bundleDir",
",",
"null",
",",
"array",
"(",
"'override'",
"=>",
"true",
")",
")",
";",
"}"
] |
Build core files
@param string $bundleDir
@param string $applicationName
@param Filesystem $filesystem
|
[
"Build",
"core",
"files"
] |
402032e01467359b176de19731ebbff744cc52f5
|
https://github.com/avoo/FrameworkInstallerBundle/blob/402032e01467359b176de19731ebbff744cc52f5/Composer/ScriptHandler.php#L269-L282
|
235,337
|
avoo/FrameworkInstallerBundle
|
Composer/ScriptHandler.php
|
ScriptHandler.buildComponentFiles
|
private static function buildComponentFiles($bundleDir, $applicationName, Filesystem $filesystem)
{
$filesystem->setParameters(array(
'namespace' => $applicationName,
'applicationName' => $applicationName,
));
$filesystem->mirror(__DIR__.'/../Resources/skeleton/avoo-component', $bundleDir, null, array('override' => true));
}
|
php
|
private static function buildComponentFiles($bundleDir, $applicationName, Filesystem $filesystem)
{
$filesystem->setParameters(array(
'namespace' => $applicationName,
'applicationName' => $applicationName,
));
$filesystem->mirror(__DIR__.'/../Resources/skeleton/avoo-component', $bundleDir, null, array('override' => true));
}
|
[
"private",
"static",
"function",
"buildComponentFiles",
"(",
"$",
"bundleDir",
",",
"$",
"applicationName",
",",
"Filesystem",
"$",
"filesystem",
")",
"{",
"$",
"filesystem",
"->",
"setParameters",
"(",
"array",
"(",
"'namespace'",
"=>",
"$",
"applicationName",
",",
"'applicationName'",
"=>",
"$",
"applicationName",
",",
")",
")",
";",
"$",
"filesystem",
"->",
"mirror",
"(",
"__DIR__",
".",
"'/../Resources/skeleton/avoo-component'",
",",
"$",
"bundleDir",
",",
"null",
",",
"array",
"(",
"'override'",
"=>",
"true",
")",
")",
";",
"}"
] |
Build component files
@param string $bundleDir
@param string $applicationName
@param Filesystem $filesystem
|
[
"Build",
"component",
"files"
] |
402032e01467359b176de19731ebbff744cc52f5
|
https://github.com/avoo/FrameworkInstallerBundle/blob/402032e01467359b176de19731ebbff744cc52f5/Composer/ScriptHandler.php#L334-L342
|
235,338
|
binsoul/net-http-message-message
|
src/Request.php
|
Request.buildHost
|
private function buildHost(UriInterface $uri): string
{
return $uri->getHost().($uri->getPort() !== null ? ':'.$uri->getPort() : '');
}
|
php
|
private function buildHost(UriInterface $uri): string
{
return $uri->getHost().($uri->getPort() !== null ? ':'.$uri->getPort() : '');
}
|
[
"private",
"function",
"buildHost",
"(",
"UriInterface",
"$",
"uri",
")",
":",
"string",
"{",
"return",
"$",
"uri",
"->",
"getHost",
"(",
")",
".",
"(",
"$",
"uri",
"->",
"getPort",
"(",
")",
"!==",
"null",
"?",
"':'",
".",
"$",
"uri",
"->",
"getPort",
"(",
")",
":",
"''",
")",
";",
"}"
] |
Returns the host header.
@param UriInterface $uri
@return string
|
[
"Returns",
"the",
"host",
"header",
"."
] |
b367ecdfda28570f849fc7e0723125a951d915a7
|
https://github.com/binsoul/net-http-message-message/blob/b367ecdfda28570f849fc7e0723125a951d915a7/src/Request.php#L121-L124
|
235,339
|
getconnect/connect-php
|
src/Security.php
|
Security.generateFilteredKey
|
public static function generateFilteredKey($definition, $masterKey) {
$cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
$ivSize = mcrypt_enc_get_iv_size($cipher);
$iv = mcrypt_create_iv($ivSize, MCRYPT_RAND);
$definitionWithPading = self::_pad(json_encode($definition),16);
if (mcrypt_generic_init($cipher, $masterKey, $iv) != -1) {
$cipherText = mcrypt_generic($cipher,$definitionWithPading);
mcrypt_generic_deinit($cipher);
$encrypted = sprintf("%s-%s",bin2hex($iv),bin2hex($cipherText));
return $encrypted;
}
}
|
php
|
public static function generateFilteredKey($definition, $masterKey) {
$cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
$ivSize = mcrypt_enc_get_iv_size($cipher);
$iv = mcrypt_create_iv($ivSize, MCRYPT_RAND);
$definitionWithPading = self::_pad(json_encode($definition),16);
if (mcrypt_generic_init($cipher, $masterKey, $iv) != -1) {
$cipherText = mcrypt_generic($cipher,$definitionWithPading);
mcrypt_generic_deinit($cipher);
$encrypted = sprintf("%s-%s",bin2hex($iv),bin2hex($cipherText));
return $encrypted;
}
}
|
[
"public",
"static",
"function",
"generateFilteredKey",
"(",
"$",
"definition",
",",
"$",
"masterKey",
")",
"{",
"$",
"cipher",
"=",
"mcrypt_module_open",
"(",
"MCRYPT_RIJNDAEL_128",
",",
"''",
",",
"MCRYPT_MODE_CBC",
",",
"''",
")",
";",
"$",
"ivSize",
"=",
"mcrypt_enc_get_iv_size",
"(",
"$",
"cipher",
")",
";",
"$",
"iv",
"=",
"mcrypt_create_iv",
"(",
"$",
"ivSize",
",",
"MCRYPT_RAND",
")",
";",
"$",
"definitionWithPading",
"=",
"self",
"::",
"_pad",
"(",
"json_encode",
"(",
"$",
"definition",
")",
",",
"16",
")",
";",
"if",
"(",
"mcrypt_generic_init",
"(",
"$",
"cipher",
",",
"$",
"masterKey",
",",
"$",
"iv",
")",
"!=",
"-",
"1",
")",
"{",
"$",
"cipherText",
"=",
"mcrypt_generic",
"(",
"$",
"cipher",
",",
"$",
"definitionWithPading",
")",
";",
"mcrypt_generic_deinit",
"(",
"$",
"cipher",
")",
";",
"$",
"encrypted",
"=",
"sprintf",
"(",
"\"%s-%s\"",
",",
"bin2hex",
"(",
"$",
"iv",
")",
",",
"bin2hex",
"(",
"$",
"cipherText",
")",
")",
";",
"return",
"$",
"encrypted",
";",
"}",
"}"
] |
Encrypt filtered key for use with the Connect API
@param array $definition The filtered key definition
@param string $masterKey The master key for the Connect project
@return String
|
[
"Encrypt",
"filtered",
"key",
"for",
"use",
"with",
"the",
"Connect",
"API"
] |
cbce3daae58eca16450df811ac6f1280fc1ef6b1
|
https://github.com/getconnect/connect-php/blob/cbce3daae58eca16450df811ac6f1280fc1ef6b1/src/Security.php#L15-L29
|
235,340
|
getconnect/connect-php
|
src/Security.php
|
Security.decryptFilteredKey
|
public static function decryptFilteredKey($encryptedKey, $masterKey){
$cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
$ivAndFilter = explode('-',$encryptedKey);
$iv = hex2bin($ivAndFilter[0]);
$filter = hex2bin($ivAndFilter[1]);
if (mcrypt_generic_init($cipher, $masterKey, $iv) != -1) {
$decrypted = mdecrypt_generic($cipher, $filter);
mcrypt_generic_deinit($cipher);
mcrypt_module_close($cipher);
$decryptedNoPadding = self::_unpad($decrypted,16);
return $decryptedNoPadding;
}
}
|
php
|
public static function decryptFilteredKey($encryptedKey, $masterKey){
$cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
$ivAndFilter = explode('-',$encryptedKey);
$iv = hex2bin($ivAndFilter[0]);
$filter = hex2bin($ivAndFilter[1]);
if (mcrypt_generic_init($cipher, $masterKey, $iv) != -1) {
$decrypted = mdecrypt_generic($cipher, $filter);
mcrypt_generic_deinit($cipher);
mcrypt_module_close($cipher);
$decryptedNoPadding = self::_unpad($decrypted,16);
return $decryptedNoPadding;
}
}
|
[
"public",
"static",
"function",
"decryptFilteredKey",
"(",
"$",
"encryptedKey",
",",
"$",
"masterKey",
")",
"{",
"$",
"cipher",
"=",
"mcrypt_module_open",
"(",
"MCRYPT_RIJNDAEL_128",
",",
"''",
",",
"MCRYPT_MODE_CBC",
",",
"''",
")",
";",
"$",
"ivAndFilter",
"=",
"explode",
"(",
"'-'",
",",
"$",
"encryptedKey",
")",
";",
"$",
"iv",
"=",
"hex2bin",
"(",
"$",
"ivAndFilter",
"[",
"0",
"]",
")",
";",
"$",
"filter",
"=",
"hex2bin",
"(",
"$",
"ivAndFilter",
"[",
"1",
"]",
")",
";",
"if",
"(",
"mcrypt_generic_init",
"(",
"$",
"cipher",
",",
"$",
"masterKey",
",",
"$",
"iv",
")",
"!=",
"-",
"1",
")",
"{",
"$",
"decrypted",
"=",
"mdecrypt_generic",
"(",
"$",
"cipher",
",",
"$",
"filter",
")",
";",
"mcrypt_generic_deinit",
"(",
"$",
"cipher",
")",
";",
"mcrypt_module_close",
"(",
"$",
"cipher",
")",
";",
"$",
"decryptedNoPadding",
"=",
"self",
"::",
"_unpad",
"(",
"$",
"decrypted",
",",
"16",
")",
";",
"return",
"$",
"decryptedNoPadding",
";",
"}",
"}"
] |
Decrypt filtered key generated via the encryptFukteredKey function
@param array $definition The filtered key definition
@param string $masterKey The master key for the Connect project
@return String
|
[
"Decrypt",
"filtered",
"key",
"generated",
"via",
"the",
"encryptFukteredKey",
"function"
] |
cbce3daae58eca16450df811ac6f1280fc1ef6b1
|
https://github.com/getconnect/connect-php/blob/cbce3daae58eca16450df811ac6f1280fc1ef6b1/src/Security.php#L37-L52
|
235,341
|
getconnect/connect-php
|
src/Security.php
|
Security._pad
|
private static function _pad($text, $blocksize) {
$pad = $blocksize - (strlen($text) % $blocksize);
$textWithPadding = $text . str_repeat(chr($pad), $pad);
return $textWithPadding;
}
|
php
|
private static function _pad($text, $blocksize) {
$pad = $blocksize - (strlen($text) % $blocksize);
$textWithPadding = $text . str_repeat(chr($pad), $pad);
return $textWithPadding;
}
|
[
"private",
"static",
"function",
"_pad",
"(",
"$",
"text",
",",
"$",
"blocksize",
")",
"{",
"$",
"pad",
"=",
"$",
"blocksize",
"-",
"(",
"strlen",
"(",
"$",
"text",
")",
"%",
"$",
"blocksize",
")",
";",
"$",
"textWithPadding",
"=",
"$",
"text",
".",
"str_repeat",
"(",
"chr",
"(",
"$",
"pad",
")",
",",
"$",
"pad",
")",
";",
"return",
"$",
"textWithPadding",
";",
"}"
] |
Pad an input string for encryption
@text string the string to add padding to
@blocksize int
|
[
"Pad",
"an",
"input",
"string",
"for",
"encryption"
] |
cbce3daae58eca16450df811ac6f1280fc1ef6b1
|
https://github.com/getconnect/connect-php/blob/cbce3daae58eca16450df811ac6f1280fc1ef6b1/src/Security.php#L59-L63
|
235,342
|
getconnect/connect-php
|
src/Security.php
|
Security._unpad
|
private static function _unpad($text, $blocksize) {
if (empty($text)) {
return '';
}
if (strlen($text) % $blocksize !== 0) {
return false;
}
$pad = ord($text{strlen($text)-1});
if ($pad > $blocksize || $pad > strlen($text) || $pad === 0) {
return false;
}
if (strspn($text, chr($pad), strlen($text) - $pad) != $pad) {
return false;
}
$textNoPadding = substr($text, 0, - $pad);
return $textNoPadding;
}
|
php
|
private static function _unpad($text, $blocksize) {
if (empty($text)) {
return '';
}
if (strlen($text) % $blocksize !== 0) {
return false;
}
$pad = ord($text{strlen($text)-1});
if ($pad > $blocksize || $pad > strlen($text) || $pad === 0) {
return false;
}
if (strspn($text, chr($pad), strlen($text) - $pad) != $pad) {
return false;
}
$textNoPadding = substr($text, 0, - $pad);
return $textNoPadding;
}
|
[
"private",
"static",
"function",
"_unpad",
"(",
"$",
"text",
",",
"$",
"blocksize",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"text",
")",
")",
"{",
"return",
"''",
";",
"}",
"if",
"(",
"strlen",
"(",
"$",
"text",
")",
"%",
"$",
"blocksize",
"!==",
"0",
")",
"{",
"return",
"false",
";",
"}",
"$",
"pad",
"=",
"ord",
"(",
"$",
"text",
"{",
"strlen",
"(",
"$",
"text",
")",
"-",
"1",
"}",
")",
";",
"if",
"(",
"$",
"pad",
">",
"$",
"blocksize",
"||",
"$",
"pad",
">",
"strlen",
"(",
"$",
"text",
")",
"||",
"$",
"pad",
"===",
"0",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"strspn",
"(",
"$",
"text",
",",
"chr",
"(",
"$",
"pad",
")",
",",
"strlen",
"(",
"$",
"text",
")",
"-",
"$",
"pad",
")",
"!=",
"$",
"pad",
")",
"{",
"return",
"false",
";",
"}",
"$",
"textNoPadding",
"=",
"substr",
"(",
"$",
"text",
",",
"0",
",",
"-",
"$",
"pad",
")",
";",
"return",
"$",
"textNoPadding",
";",
"}"
] |
Unpad an input string
@text string the string to add padding to
@blocksize int
|
[
"Unpad",
"an",
"input",
"string"
] |
cbce3daae58eca16450df811ac6f1280fc1ef6b1
|
https://github.com/getconnect/connect-php/blob/cbce3daae58eca16450df811ac6f1280fc1ef6b1/src/Security.php#L70-L86
|
235,343
|
interactivesolutions/honeycomb-acl
|
src/app/http/controllers/UserActivation.php
|
UserActivation.sendActivationMail
|
public function sendActivationMail($user)
{
if( ! $this->shouldSend($user) ) {
return trans('HCACL::users.activation.check_email');
}
\DB::beginTransaction();
try {
$token = $this->createActivation($user);
$user->sendActivationLinkNotification($token);
} catch ( \Exception $e ) {
\DB::rollback();
throw new \Exception('Activation code or mail sending failed');
}
\DB::commit();
return trans('HCACL::users.activation.resent_activation');
}
|
php
|
public function sendActivationMail($user)
{
if( ! $this->shouldSend($user) ) {
return trans('HCACL::users.activation.check_email');
}
\DB::beginTransaction();
try {
$token = $this->createActivation($user);
$user->sendActivationLinkNotification($token);
} catch ( \Exception $e ) {
\DB::rollback();
throw new \Exception('Activation code or mail sending failed');
}
\DB::commit();
return trans('HCACL::users.activation.resent_activation');
}
|
[
"public",
"function",
"sendActivationMail",
"(",
"$",
"user",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"shouldSend",
"(",
"$",
"user",
")",
")",
"{",
"return",
"trans",
"(",
"'HCACL::users.activation.check_email'",
")",
";",
"}",
"\\",
"DB",
"::",
"beginTransaction",
"(",
")",
";",
"try",
"{",
"$",
"token",
"=",
"$",
"this",
"->",
"createActivation",
"(",
"$",
"user",
")",
";",
"$",
"user",
"->",
"sendActivationLinkNotification",
"(",
"$",
"token",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"\\",
"DB",
"::",
"rollback",
"(",
")",
";",
"throw",
"new",
"\\",
"Exception",
"(",
"'Activation code or mail sending failed'",
")",
";",
"}",
"\\",
"DB",
"::",
"commit",
"(",
")",
";",
"return",
"trans",
"(",
"'HCACL::users.activation.resent_activation'",
")",
";",
"}"
] |
Send activation mail
@param $user
@return array
@throws \Exception
|
[
"Send",
"activation",
"mail"
] |
6c73d7d1c5d17ef730593e03386236a746bab12c
|
https://github.com/interactivesolutions/honeycomb-acl/blob/6c73d7d1c5d17ef730593e03386236a746bab12c/src/app/http/controllers/UserActivation.php#L40-L61
|
235,344
|
interactivesolutions/honeycomb-acl
|
src/app/http/controllers/UserActivation.php
|
UserActivation.shouldSend
|
protected function shouldSend($user)
{
$activation = $this->getActivation($user);
return $activation === null || strtotime($activation->created_at) + 60 * 60 * $this->resendAfter < time();
}
|
php
|
protected function shouldSend($user)
{
$activation = $this->getActivation($user);
return $activation === null || strtotime($activation->created_at) + 60 * 60 * $this->resendAfter < time();
}
|
[
"protected",
"function",
"shouldSend",
"(",
"$",
"user",
")",
"{",
"$",
"activation",
"=",
"$",
"this",
"->",
"getActivation",
"(",
"$",
"user",
")",
";",
"return",
"$",
"activation",
"===",
"null",
"||",
"strtotime",
"(",
"$",
"activation",
"->",
"created_at",
")",
"+",
"60",
"*",
"60",
"*",
"$",
"this",
"->",
"resendAfter",
"<",
"time",
"(",
")",
";",
"}"
] |
Check if activation mail should be resent
@param $user
@return bool
|
[
"Check",
"if",
"activation",
"mail",
"should",
"be",
"resent"
] |
6c73d7d1c5d17ef730593e03386236a746bab12c
|
https://github.com/interactivesolutions/honeycomb-acl/blob/6c73d7d1c5d17ef730593e03386236a746bab12c/src/app/http/controllers/UserActivation.php#L99-L104
|
235,345
|
jmpantoja/planb-utils
|
src/Beautifier/Parser/AttributeList.php
|
AttributeList.parseValue
|
private function parseValue(string $key, $value): string
{
if (is_array($value)) {
return $this->parseArray($key, $value);
}
return $this->parseScalar($key, $value);
}
|
php
|
private function parseValue(string $key, $value): string
{
if (is_array($value)) {
return $this->parseArray($key, $value);
}
return $this->parseScalar($key, $value);
}
|
[
"private",
"function",
"parseValue",
"(",
"string",
"$",
"key",
",",
"$",
"value",
")",
":",
"string",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"this",
"->",
"parseArray",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"this",
"->",
"parseScalar",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}"
] |
Parsea un valor
@param string $key
@param mixed $value
@return string
|
[
"Parsea",
"un",
"valor"
] |
d17fbced4a285275928f8428ee56e269eb851690
|
https://github.com/jmpantoja/planb-utils/blob/d17fbced4a285275928f8428ee56e269eb851690/src/Beautifier/Parser/AttributeList.php#L121-L129
|
235,346
|
rafflesargentina/l5-action-based-form-request
|
src/Traits/WorksWithFormRequests.php
|
WorksWithFormRequests.getRules
|
public function getRules()
{
$action = $this->getActionReplaced();
if (method_exists($this->formRequest, $action)) {
return call_user_func([$this->formRequest, $action]);
}
if (method_exists($this->formRequest, 'rules')) {
return call_user_func([$this->formRequest, 'rules']);
}
return [];
}
|
php
|
public function getRules()
{
$action = $this->getActionReplaced();
if (method_exists($this->formRequest, $action)) {
return call_user_func([$this->formRequest, $action]);
}
if (method_exists($this->formRequest, 'rules')) {
return call_user_func([$this->formRequest, 'rules']);
}
return [];
}
|
[
"public",
"function",
"getRules",
"(",
")",
"{",
"$",
"action",
"=",
"$",
"this",
"->",
"getActionReplaced",
"(",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
"->",
"formRequest",
",",
"$",
"action",
")",
")",
"{",
"return",
"call_user_func",
"(",
"[",
"$",
"this",
"->",
"formRequest",
",",
"$",
"action",
"]",
")",
";",
"}",
"if",
"(",
"method_exists",
"(",
"$",
"this",
"->",
"formRequest",
",",
"'rules'",
")",
")",
"{",
"return",
"call_user_func",
"(",
"[",
"$",
"this",
"->",
"formRequest",
",",
"'rules'",
"]",
")",
";",
"}",
"return",
"[",
"]",
";",
"}"
] |
Get rules from ActionBasedFormRequest or FormRequest instance.
@return array
|
[
"Get",
"rules",
"from",
"ActionBasedFormRequest",
"or",
"FormRequest",
"instance",
"."
] |
dc39cc93d506763fa9714754c9700862bfeca5a7
|
https://github.com/rafflesargentina/l5-action-based-form-request/blob/dc39cc93d506763fa9714754c9700862bfeca5a7/src/Traits/WorksWithFormRequests.php#L15-L27
|
235,347
|
rafflesargentina/l5-action-based-form-request
|
src/Traits/WorksWithFormRequests.php
|
WorksWithFormRequests.getRequiredFields
|
public function getRequiredFields()
{
$rules = $this->getRules();
$requiredFields = array_where(
$rules, function ($value, $key) {
if (is_array($value)) {
$value = implode('|', $value);
}
return str_contains($value, ['required', 'sometimes']);
}
);
return $requiredFields;
}
|
php
|
public function getRequiredFields()
{
$rules = $this->getRules();
$requiredFields = array_where(
$rules, function ($value, $key) {
if (is_array($value)) {
$value = implode('|', $value);
}
return str_contains($value, ['required', 'sometimes']);
}
);
return $requiredFields;
}
|
[
"public",
"function",
"getRequiredFields",
"(",
")",
"{",
"$",
"rules",
"=",
"$",
"this",
"->",
"getRules",
"(",
")",
";",
"$",
"requiredFields",
"=",
"array_where",
"(",
"$",
"rules",
",",
"function",
"(",
"$",
"value",
",",
"$",
"key",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"implode",
"(",
"'|'",
",",
"$",
"value",
")",
";",
"}",
"return",
"str_contains",
"(",
"$",
"value",
",",
"[",
"'required'",
",",
"'sometimes'",
"]",
")",
";",
"}",
")",
";",
"return",
"$",
"requiredFields",
";",
"}"
] |
Get required fields.
@return array
|
[
"Get",
"required",
"fields",
"."
] |
dc39cc93d506763fa9714754c9700862bfeca5a7
|
https://github.com/rafflesargentina/l5-action-based-form-request/blob/dc39cc93d506763fa9714754c9700862bfeca5a7/src/Traits/WorksWithFormRequests.php#L44-L59
|
235,348
|
e-commerce-passaro/produto
|
src/Produto/Repository.php
|
Repository.getTableGateway
|
private function getTableGateway()
{
return new TableGateway($this->tableName, $this->dbAdapter, null, new HydratingResultSet($this->hydrator, $this->prototipo));
}
|
php
|
private function getTableGateway()
{
return new TableGateway($this->tableName, $this->dbAdapter, null, new HydratingResultSet($this->hydrator, $this->prototipo));
}
|
[
"private",
"function",
"getTableGateway",
"(",
")",
"{",
"return",
"new",
"TableGateway",
"(",
"$",
"this",
"->",
"tableName",
",",
"$",
"this",
"->",
"dbAdapter",
",",
"null",
",",
"new",
"HydratingResultSet",
"(",
"$",
"this",
"->",
"hydrator",
",",
"$",
"this",
"->",
"prototipo",
")",
")",
";",
"}"
] |
Obtem o TableGatwey
@return \Zend\Db\TableGateway\TableGateway
|
[
"Obtem",
"o",
"TableGatwey"
] |
31cb790173485c37db8de9a2cc5cfaeb827250aa
|
https://github.com/e-commerce-passaro/produto/blob/31cb790173485c37db8de9a2cc5cfaeb827250aa/src/Produto/Repository.php#L37-L40
|
235,349
|
johanderuijter/mailer-swift-mailer-bridge
|
src/SwiftMailer.php
|
SwiftMailer.sendEmail
|
public function sendEmail(EmailType $type)
{
$builder = $this->builder;
$type->buildEmail($builder);
$email = $builder->build(new SwiftEmail());
$this->mailer->send($email->getMessage());
}
|
php
|
public function sendEmail(EmailType $type)
{
$builder = $this->builder;
$type->buildEmail($builder);
$email = $builder->build(new SwiftEmail());
$this->mailer->send($email->getMessage());
}
|
[
"public",
"function",
"sendEmail",
"(",
"EmailType",
"$",
"type",
")",
"{",
"$",
"builder",
"=",
"$",
"this",
"->",
"builder",
";",
"$",
"type",
"->",
"buildEmail",
"(",
"$",
"builder",
")",
";",
"$",
"email",
"=",
"$",
"builder",
"->",
"build",
"(",
"new",
"SwiftEmail",
"(",
")",
")",
";",
"$",
"this",
"->",
"mailer",
"->",
"send",
"(",
"$",
"email",
"->",
"getMessage",
"(",
")",
")",
";",
"}"
] |
Build and send a given type of email.
@param EmailType $type
|
[
"Build",
"and",
"send",
"a",
"given",
"type",
"of",
"email",
"."
] |
be7acf4b6f3f2e448546835038f98fdef9fc2889
|
https://github.com/johanderuijter/mailer-swift-mailer-bridge/blob/be7acf4b6f3f2e448546835038f98fdef9fc2889/src/SwiftMailer.php#L40-L47
|
235,350
|
DavidFricker/DataAbstracter
|
src/Adapter/MySQLDatabaseWrapper.php
|
MySQLDatabaseWrapper.run
|
public function run ($query, $bind=[]) {
try {
$this->handle = $this->prepare($query);
$this->handle->execute($bind);
// check what the query begins with
if (preg_match('/^(select|describe|pragma)/i', $query)) {
// return a result set
return $this->handle->fetchAll();
}
if (preg_match('/^(delete|insert|update)/i', $query)) {
// return the affected row count
return $this->rowCount();
}
// default to simply indicating success
return true;
} catch (\PDOException $e) {
$this->error = $e->getMessage();
return false;
}
}
|
php
|
public function run ($query, $bind=[]) {
try {
$this->handle = $this->prepare($query);
$this->handle->execute($bind);
// check what the query begins with
if (preg_match('/^(select|describe|pragma)/i', $query)) {
// return a result set
return $this->handle->fetchAll();
}
if (preg_match('/^(delete|insert|update)/i', $query)) {
// return the affected row count
return $this->rowCount();
}
// default to simply indicating success
return true;
} catch (\PDOException $e) {
$this->error = $e->getMessage();
return false;
}
}
|
[
"public",
"function",
"run",
"(",
"$",
"query",
",",
"$",
"bind",
"=",
"[",
"]",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"handle",
"=",
"$",
"this",
"->",
"prepare",
"(",
"$",
"query",
")",
";",
"$",
"this",
"->",
"handle",
"->",
"execute",
"(",
"$",
"bind",
")",
";",
"// check what the query begins with",
"if",
"(",
"preg_match",
"(",
"'/^(select|describe|pragma)/i'",
",",
"$",
"query",
")",
")",
"{",
"// return a result set",
"return",
"$",
"this",
"->",
"handle",
"->",
"fetchAll",
"(",
")",
";",
"}",
"if",
"(",
"preg_match",
"(",
"'/^(delete|insert|update)/i'",
",",
"$",
"query",
")",
")",
"{",
"// return the affected row count",
"return",
"$",
"this",
"->",
"rowCount",
"(",
")",
";",
"}",
"// default to simply indicating success",
"return",
"true",
";",
"}",
"catch",
"(",
"\\",
"PDOException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"error",
"=",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"return",
"false",
";",
"}",
"}"
] |
Execute any SQL query
To ensure your query is safe from first order SQL injection attacks pass all values via the $bind array
@param string $query MySQL query
@param array $bind key:value pairs where the key is a bind identifier and value is to be inserted at that location
@return mixed see example
@example depending on the type of input query the returned result can be an affected row count or a result set, the type of which is specified in the options passed to the constructor, defaulting to an assoc array
@example $query = 'SELECT * FROM table_name WHERE col_id = :BindColID'; $bind = [':BindColID' => 12];
|
[
"Execute",
"any",
"SQL",
"query"
] |
d612910cb114ddceb9f4ab1d152d5eb8019e5342
|
https://github.com/DavidFricker/DataAbstracter/blob/d612910cb114ddceb9f4ab1d152d5eb8019e5342/src/Adapter/MySQLDatabaseWrapper.php#L167-L189
|
235,351
|
padosoft/laravel-request
|
src/RequestHelper.php
|
RequestHelper.requestHasFiles
|
public static function requestHasFiles(Request $request) : bool
{
return ($request && $request->allFiles() && count($request->allFiles()) > 0);
}
|
php
|
public static function requestHasFiles(Request $request) : bool
{
return ($request && $request->allFiles() && count($request->allFiles()) > 0);
}
|
[
"public",
"static",
"function",
"requestHasFiles",
"(",
"Request",
"$",
"request",
")",
":",
"bool",
"{",
"return",
"(",
"$",
"request",
"&&",
"$",
"request",
"->",
"allFiles",
"(",
")",
"&&",
"count",
"(",
"$",
"request",
"->",
"allFiles",
"(",
")",
")",
">",
"0",
")",
";",
"}"
] |
Check if the passed request has at least one file
@param Request $request
@return bool
|
[
"Check",
"if",
"the",
"passed",
"request",
"has",
"at",
"least",
"one",
"file"
] |
8c4ea439db6ad2e7d28402b0f1e358d4df9c7768
|
https://github.com/padosoft/laravel-request/blob/8c4ea439db6ad2e7d28402b0f1e358d4df9c7768/src/RequestHelper.php#L28-L31
|
235,352
|
padosoft/laravel-request
|
src/RequestHelper.php
|
RequestHelper.isValidCurrentRequestUploadFile
|
public static function isValidCurrentRequestUploadFile(string $uploadField, array $arrMimeType = array()) : bool
{
return self::isValidUploadFile($uploadField, $arrMimeType, request());
}
|
php
|
public static function isValidCurrentRequestUploadFile(string $uploadField, array $arrMimeType = array()) : bool
{
return self::isValidUploadFile($uploadField, $arrMimeType, request());
}
|
[
"public",
"static",
"function",
"isValidCurrentRequestUploadFile",
"(",
"string",
"$",
"uploadField",
",",
"array",
"$",
"arrMimeType",
"=",
"array",
"(",
")",
")",
":",
"bool",
"{",
"return",
"self",
"::",
"isValidUploadFile",
"(",
"$",
"uploadField",
",",
"$",
"arrMimeType",
",",
"request",
"(",
")",
")",
";",
"}"
] |
Check if uploaded File in current request is valid and has a valid Mime Type.
Return true is all ok, otherwise return false.
@param string $uploadField
@param array $arrMimeType
@return bool
|
[
"Check",
"if",
"uploaded",
"File",
"in",
"current",
"request",
"is",
"valid",
"and",
"has",
"a",
"valid",
"Mime",
"Type",
".",
"Return",
"true",
"is",
"all",
"ok",
"otherwise",
"return",
"false",
"."
] |
8c4ea439db6ad2e7d28402b0f1e358d4df9c7768
|
https://github.com/padosoft/laravel-request/blob/8c4ea439db6ad2e7d28402b0f1e358d4df9c7768/src/RequestHelper.php#L40-L43
|
235,353
|
padosoft/laravel-request
|
src/RequestHelper.php
|
RequestHelper.isValidUploadFile
|
public static function isValidUploadFile(string $uploadField, array $arrMimeType = array(), Request $request) : bool
{
$uploadedFile = self::getFileSafe($uploadField, $request);
if (!is_a($uploadedFile, UploadedFile::class)) {
return false;
}
return UploadedFileHelper::isValidUploadFile($uploadedFile, $arrMimeType);
}
|
php
|
public static function isValidUploadFile(string $uploadField, array $arrMimeType = array(), Request $request) : bool
{
$uploadedFile = self::getFileSafe($uploadField, $request);
if (!is_a($uploadedFile, UploadedFile::class)) {
return false;
}
return UploadedFileHelper::isValidUploadFile($uploadedFile, $arrMimeType);
}
|
[
"public",
"static",
"function",
"isValidUploadFile",
"(",
"string",
"$",
"uploadField",
",",
"array",
"$",
"arrMimeType",
"=",
"array",
"(",
")",
",",
"Request",
"$",
"request",
")",
":",
"bool",
"{",
"$",
"uploadedFile",
"=",
"self",
"::",
"getFileSafe",
"(",
"$",
"uploadField",
",",
"$",
"request",
")",
";",
"if",
"(",
"!",
"is_a",
"(",
"$",
"uploadedFile",
",",
"UploadedFile",
"::",
"class",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"UploadedFileHelper",
"::",
"isValidUploadFile",
"(",
"$",
"uploadedFile",
",",
"$",
"arrMimeType",
")",
";",
"}"
] |
Check if uploaded File is valid and has a valid Mime Type.
Return true is all ok, otherwise return false.
@param string $uploadField
@param array $arrMimeType
@param Request $request
@return bool
|
[
"Check",
"if",
"uploaded",
"File",
"is",
"valid",
"and",
"has",
"a",
"valid",
"Mime",
"Type",
".",
"Return",
"true",
"is",
"all",
"ok",
"otherwise",
"return",
"false",
"."
] |
8c4ea439db6ad2e7d28402b0f1e358d4df9c7768
|
https://github.com/padosoft/laravel-request/blob/8c4ea439db6ad2e7d28402b0f1e358d4df9c7768/src/RequestHelper.php#L53-L62
|
235,354
|
padosoft/laravel-request
|
src/RequestHelper.php
|
RequestHelper.getFileSafe
|
public static function getFileSafe(
string $uploadField,
Request $request
) {
if (!$request) {
return null;
}
$uploadedFile = $request->file($uploadField);
//check type because request file method, may returns UploadedFile, array or null
if (!is_a($uploadedFile, UploadedFile::class)) {
return null;
}
return $uploadedFile;
}
|
php
|
public static function getFileSafe(
string $uploadField,
Request $request
) {
if (!$request) {
return null;
}
$uploadedFile = $request->file($uploadField);
//check type because request file method, may returns UploadedFile, array or null
if (!is_a($uploadedFile, UploadedFile::class)) {
return null;
}
return $uploadedFile;
}
|
[
"public",
"static",
"function",
"getFileSafe",
"(",
"string",
"$",
"uploadField",
",",
"Request",
"$",
"request",
")",
"{",
"if",
"(",
"!",
"$",
"request",
")",
"{",
"return",
"null",
";",
"}",
"$",
"uploadedFile",
"=",
"$",
"request",
"->",
"file",
"(",
"$",
"uploadField",
")",
";",
"//check type because request file method, may returns UploadedFile, array or null",
"if",
"(",
"!",
"is_a",
"(",
"$",
"uploadedFile",
",",
"UploadedFile",
"::",
"class",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"uploadedFile",
";",
"}"
] |
Return File in passed request if ok, otherwise return null
@param string $uploadField
@param Request $request
@return null|UploadedFile
|
[
"Return",
"File",
"in",
"passed",
"request",
"if",
"ok",
"otherwise",
"return",
"null"
] |
8c4ea439db6ad2e7d28402b0f1e358d4df9c7768
|
https://github.com/padosoft/laravel-request/blob/8c4ea439db6ad2e7d28402b0f1e358d4df9c7768/src/RequestHelper.php#L80-L96
|
235,355
|
lucifurious/kisma
|
src/Kisma/Core/Utility/Log.php
|
Log.error
|
public static function error( $message, $context = array(), $extra = null )
{
return static::log( $message, LoggingLevels::ERROR, $context, $extra );
}
|
php
|
public static function error( $message, $context = array(), $extra = null )
{
return static::log( $message, LoggingLevels::ERROR, $context, $extra );
}
|
[
"public",
"static",
"function",
"error",
"(",
"$",
"message",
",",
"$",
"context",
"=",
"array",
"(",
")",
",",
"$",
"extra",
"=",
"null",
")",
"{",
"return",
"static",
"::",
"log",
"(",
"$",
"message",
",",
"LoggingLevels",
"::",
"ERROR",
",",
"$",
"context",
",",
"$",
"extra",
")",
";",
"}"
] |
Creates an 'error' log entry
@param string $message The message to send to the log
@param array $context
@param mixed $extra
@return bool
|
[
"Creates",
"an",
"error",
"log",
"entry"
] |
4cc9954249da4e535b52f154e728935f07e648ae
|
https://github.com/lucifurious/kisma/blob/4cc9954249da4e535b52f154e728935f07e648ae/src/Kisma/Core/Utility/Log.php#L206-L209
|
235,356
|
lucifurious/kisma
|
src/Kisma/Core/Utility/Log.php
|
Log.warning
|
public static function warning( $message, $context = array(), $extra = null )
{
return static::log( $message, LoggingLevels::WARNING, $context, $extra );
}
|
php
|
public static function warning( $message, $context = array(), $extra = null )
{
return static::log( $message, LoggingLevels::WARNING, $context, $extra );
}
|
[
"public",
"static",
"function",
"warning",
"(",
"$",
"message",
",",
"$",
"context",
"=",
"array",
"(",
")",
",",
"$",
"extra",
"=",
"null",
")",
"{",
"return",
"static",
"::",
"log",
"(",
"$",
"message",
",",
"LoggingLevels",
"::",
"WARNING",
",",
"$",
"context",
",",
"$",
"extra",
")",
";",
"}"
] |
Creates a 'warning' log entry
@param string $message The message to send to the log
@param array $context
@param mixed $extra
@return bool
|
[
"Creates",
"a",
"warning",
"log",
"entry"
] |
4cc9954249da4e535b52f154e728935f07e648ae
|
https://github.com/lucifurious/kisma/blob/4cc9954249da4e535b52f154e728935f07e648ae/src/Kisma/Core/Utility/Log.php#L220-L223
|
235,357
|
lucifurious/kisma
|
src/Kisma/Core/Utility/Log.php
|
Log.notice
|
public static function notice( $message, $context = array(), $extra = null )
{
return static::log( $message, LoggingLevels::NOTICE, $context, $extra );
}
|
php
|
public static function notice( $message, $context = array(), $extra = null )
{
return static::log( $message, LoggingLevels::NOTICE, $context, $extra );
}
|
[
"public",
"static",
"function",
"notice",
"(",
"$",
"message",
",",
"$",
"context",
"=",
"array",
"(",
")",
",",
"$",
"extra",
"=",
"null",
")",
"{",
"return",
"static",
"::",
"log",
"(",
"$",
"message",
",",
"LoggingLevels",
"::",
"NOTICE",
",",
"$",
"context",
",",
"$",
"extra",
")",
";",
"}"
] |
Creates a 'notice' log entry
@param string $message The message to send to the log
@param array $context
@param mixed $extra
@return bool
|
[
"Creates",
"a",
"notice",
"log",
"entry"
] |
4cc9954249da4e535b52f154e728935f07e648ae
|
https://github.com/lucifurious/kisma/blob/4cc9954249da4e535b52f154e728935f07e648ae/src/Kisma/Core/Utility/Log.php#L234-L237
|
235,358
|
lucifurious/kisma
|
src/Kisma/Core/Utility/Log.php
|
Log.info
|
public static function info( $message, $context = array(), $extra = null )
{
return static::log( $message, LoggingLevels::INFO, $context, $extra );
}
|
php
|
public static function info( $message, $context = array(), $extra = null )
{
return static::log( $message, LoggingLevels::INFO, $context, $extra );
}
|
[
"public",
"static",
"function",
"info",
"(",
"$",
"message",
",",
"$",
"context",
"=",
"array",
"(",
")",
",",
"$",
"extra",
"=",
"null",
")",
"{",
"return",
"static",
"::",
"log",
"(",
"$",
"message",
",",
"LoggingLevels",
"::",
"INFO",
",",
"$",
"context",
",",
"$",
"extra",
")",
";",
"}"
] |
Creates an 'info' log entry
@param string $message The message to send to the log
@param array $context
@param mixed $extra
@return bool
|
[
"Creates",
"an",
"info",
"log",
"entry"
] |
4cc9954249da4e535b52f154e728935f07e648ae
|
https://github.com/lucifurious/kisma/blob/4cc9954249da4e535b52f154e728935f07e648ae/src/Kisma/Core/Utility/Log.php#L248-L251
|
235,359
|
lucifurious/kisma
|
src/Kisma/Core/Utility/Log.php
|
Log.debug
|
public static function debug( $message, $context = array(), $extra = null )
{
return static::log( $message, LoggingLevels::DEBUG, $context, $extra );
}
|
php
|
public static function debug( $message, $context = array(), $extra = null )
{
return static::log( $message, LoggingLevels::DEBUG, $context, $extra );
}
|
[
"public",
"static",
"function",
"debug",
"(",
"$",
"message",
",",
"$",
"context",
"=",
"array",
"(",
")",
",",
"$",
"extra",
"=",
"null",
")",
"{",
"return",
"static",
"::",
"log",
"(",
"$",
"message",
",",
"LoggingLevels",
"::",
"DEBUG",
",",
"$",
"context",
",",
"$",
"extra",
")",
";",
"}"
] |
Creates a 'debug' log entry
@param string $message The message to send to the log
@param array $context
@param mixed $extra
@return bool
|
[
"Creates",
"a",
"debug",
"log",
"entry"
] |
4cc9954249da4e535b52f154e728935f07e648ae
|
https://github.com/lucifurious/kisma/blob/4cc9954249da4e535b52f154e728935f07e648ae/src/Kisma/Core/Utility/Log.php#L262-L265
|
235,360
|
lucifurious/kisma
|
src/Kisma/Core/Utility/Log.php
|
Log._processMessage
|
protected static function _processMessage( &$message )
{
$_newIndent = 0;
foreach ( static::$_indentTokens as $_key => $_token )
{
if ( $_token == substr( $message, 0, $_length = strlen( $_token ) ) )
{
$_newIndent = ( false === $_key ? -1 : 1 );
$message = substr( $message, $_length );
}
}
return $_newIndent;
}
|
php
|
protected static function _processMessage( &$message )
{
$_newIndent = 0;
foreach ( static::$_indentTokens as $_key => $_token )
{
if ( $_token == substr( $message, 0, $_length = strlen( $_token ) ) )
{
$_newIndent = ( false === $_key ? -1 : 1 );
$message = substr( $message, $_length );
}
}
return $_newIndent;
}
|
[
"protected",
"static",
"function",
"_processMessage",
"(",
"&",
"$",
"message",
")",
"{",
"$",
"_newIndent",
"=",
"0",
";",
"foreach",
"(",
"static",
"::",
"$",
"_indentTokens",
"as",
"$",
"_key",
"=>",
"$",
"_token",
")",
"{",
"if",
"(",
"$",
"_token",
"==",
"substr",
"(",
"$",
"message",
",",
"0",
",",
"$",
"_length",
"=",
"strlen",
"(",
"$",
"_token",
")",
")",
")",
"{",
"$",
"_newIndent",
"=",
"(",
"false",
"===",
"$",
"_key",
"?",
"-",
"1",
":",
"1",
")",
";",
"$",
"message",
"=",
"substr",
"(",
"$",
"message",
",",
"$",
"_length",
")",
";",
"}",
"}",
"return",
"$",
"_newIndent",
";",
"}"
] |
Processes the indent level for the messages
@param string $message
@return integer The indent difference AFTER this message
|
[
"Processes",
"the",
"indent",
"level",
"for",
"the",
"messages"
] |
4cc9954249da4e535b52f154e728935f07e648ae
|
https://github.com/lucifurious/kisma/blob/4cc9954249da4e535b52f154e728935f07e648ae/src/Kisma/Core/Utility/Log.php#L307-L321
|
235,361
|
lucifurious/kisma
|
src/Kisma/Core/Utility/Log.php
|
Log._getCallingMethod
|
protected static function _getCallingMethod()
{
$_backTrace = debug_backtrace();
$_thisClass = get_called_class();
$_type = $_class = $_method = null;
for ( $_i = 0, $_size = sizeof( $_backTrace ); $_i < $_size; $_i++ )
{
if ( isset( $_backTrace[$_i]['class'] ) )
{
$_class = $_backTrace[$_i]['class'];
}
if ( $_class == $_thisClass )
{
continue;
}
if ( isset( $_backTrace[$_i]['method'] ) )
{
$_method = $_backTrace[$_i]['method'];
}
else if ( isset( $_backTrace[$_i]['function'] ) )
{
$_method = $_backTrace[$_i]['function'];
}
else
{
$_method = 'Unknown';
}
$_type = $_backTrace[$_i]['type'];
break;
}
if ( $_i >= 0 )
{
return str_ireplace( 'Kisma\\Core\\', 'Core\\', $_class ) . $_type . $_method;
}
return 'Unknown';
}
|
php
|
protected static function _getCallingMethod()
{
$_backTrace = debug_backtrace();
$_thisClass = get_called_class();
$_type = $_class = $_method = null;
for ( $_i = 0, $_size = sizeof( $_backTrace ); $_i < $_size; $_i++ )
{
if ( isset( $_backTrace[$_i]['class'] ) )
{
$_class = $_backTrace[$_i]['class'];
}
if ( $_class == $_thisClass )
{
continue;
}
if ( isset( $_backTrace[$_i]['method'] ) )
{
$_method = $_backTrace[$_i]['method'];
}
else if ( isset( $_backTrace[$_i]['function'] ) )
{
$_method = $_backTrace[$_i]['function'];
}
else
{
$_method = 'Unknown';
}
$_type = $_backTrace[$_i]['type'];
break;
}
if ( $_i >= 0 )
{
return str_ireplace( 'Kisma\\Core\\', 'Core\\', $_class ) . $_type . $_method;
}
return 'Unknown';
}
|
[
"protected",
"static",
"function",
"_getCallingMethod",
"(",
")",
"{",
"$",
"_backTrace",
"=",
"debug_backtrace",
"(",
")",
";",
"$",
"_thisClass",
"=",
"get_called_class",
"(",
")",
";",
"$",
"_type",
"=",
"$",
"_class",
"=",
"$",
"_method",
"=",
"null",
";",
"for",
"(",
"$",
"_i",
"=",
"0",
",",
"$",
"_size",
"=",
"sizeof",
"(",
"$",
"_backTrace",
")",
";",
"$",
"_i",
"<",
"$",
"_size",
";",
"$",
"_i",
"++",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_backTrace",
"[",
"$",
"_i",
"]",
"[",
"'class'",
"]",
")",
")",
"{",
"$",
"_class",
"=",
"$",
"_backTrace",
"[",
"$",
"_i",
"]",
"[",
"'class'",
"]",
";",
"}",
"if",
"(",
"$",
"_class",
"==",
"$",
"_thisClass",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"_backTrace",
"[",
"$",
"_i",
"]",
"[",
"'method'",
"]",
")",
")",
"{",
"$",
"_method",
"=",
"$",
"_backTrace",
"[",
"$",
"_i",
"]",
"[",
"'method'",
"]",
";",
"}",
"else",
"if",
"(",
"isset",
"(",
"$",
"_backTrace",
"[",
"$",
"_i",
"]",
"[",
"'function'",
"]",
")",
")",
"{",
"$",
"_method",
"=",
"$",
"_backTrace",
"[",
"$",
"_i",
"]",
"[",
"'function'",
"]",
";",
"}",
"else",
"{",
"$",
"_method",
"=",
"'Unknown'",
";",
"}",
"$",
"_type",
"=",
"$",
"_backTrace",
"[",
"$",
"_i",
"]",
"[",
"'type'",
"]",
";",
"break",
";",
"}",
"if",
"(",
"$",
"_i",
">=",
"0",
")",
"{",
"return",
"str_ireplace",
"(",
"'Kisma\\\\Core\\\\'",
",",
"'Core\\\\'",
",",
"$",
"_class",
")",
".",
"$",
"_type",
".",
"$",
"_method",
";",
"}",
"return",
"'Unknown'",
";",
"}"
] |
Returns the name of the method that made the call
@return string
@deprecated in v0.2.20. To be removed in v0.3.0. Replaced by Monolog
|
[
"Returns",
"the",
"name",
"of",
"the",
"method",
"that",
"made",
"the",
"call"
] |
4cc9954249da4e535b52f154e728935f07e648ae
|
https://github.com/lucifurious/kisma/blob/4cc9954249da4e535b52f154e728935f07e648ae/src/Kisma/Core/Utility/Log.php#L497-L539
|
235,362
|
lucifurious/kisma
|
src/Kisma/Core/Utility/Log.php
|
Log.formatLogEntry
|
public static function formatLogEntry( array $entry, $newline = true )
{
$_level = Option::get( $entry, 'level' );
$_levelName = static::_getLogLevel( $_level );
$_timestamp = Option::get( $entry, 'timestamp' );
$_message = preg_replace( '/\033\[[\d;]+m/', null, Option::get( $entry, 'message' ) );
$_context = Option::get( $entry, 'context' );
$_extra = Option::get( $entry, 'extra' );
$_blob = new \stdClass();
if ( static::$_includeProcessInfo )
{
$_blob->pid = getmypid();
$_blob->uid = getmyuid();
$_blob->hostname = gethostname();
}
if ( !empty( $_context ) )
{
$_blob->context = $_context;
}
if ( !empty( $_extra ) )
{
$_context->extra = $_extra;
}
$_blob = json_encode( $_blob );
if ( false === $_blob || '{}' == $_blob )
{
$_blob = null;
}
$_replacements = array(
0 => $_levelName,
1 => date( 'M d', $_timestamp ),
2 => date( 'H:i:s', $_timestamp ),
3 => $_message,
4 => $_blob,
);
return str_ireplace(
array(
'%%level%%',
'%%date%%',
'%%time%%',
'%%message%%',
'%%extra%%',
),
$_replacements,
static::$_logFormat
) . ( $newline ? PHP_EOL : null );
}
|
php
|
public static function formatLogEntry( array $entry, $newline = true )
{
$_level = Option::get( $entry, 'level' );
$_levelName = static::_getLogLevel( $_level );
$_timestamp = Option::get( $entry, 'timestamp' );
$_message = preg_replace( '/\033\[[\d;]+m/', null, Option::get( $entry, 'message' ) );
$_context = Option::get( $entry, 'context' );
$_extra = Option::get( $entry, 'extra' );
$_blob = new \stdClass();
if ( static::$_includeProcessInfo )
{
$_blob->pid = getmypid();
$_blob->uid = getmyuid();
$_blob->hostname = gethostname();
}
if ( !empty( $_context ) )
{
$_blob->context = $_context;
}
if ( !empty( $_extra ) )
{
$_context->extra = $_extra;
}
$_blob = json_encode( $_blob );
if ( false === $_blob || '{}' == $_blob )
{
$_blob = null;
}
$_replacements = array(
0 => $_levelName,
1 => date( 'M d', $_timestamp ),
2 => date( 'H:i:s', $_timestamp ),
3 => $_message,
4 => $_blob,
);
return str_ireplace(
array(
'%%level%%',
'%%date%%',
'%%time%%',
'%%message%%',
'%%extra%%',
),
$_replacements,
static::$_logFormat
) . ( $newline ? PHP_EOL : null );
}
|
[
"public",
"static",
"function",
"formatLogEntry",
"(",
"array",
"$",
"entry",
",",
"$",
"newline",
"=",
"true",
")",
"{",
"$",
"_level",
"=",
"Option",
"::",
"get",
"(",
"$",
"entry",
",",
"'level'",
")",
";",
"$",
"_levelName",
"=",
"static",
"::",
"_getLogLevel",
"(",
"$",
"_level",
")",
";",
"$",
"_timestamp",
"=",
"Option",
"::",
"get",
"(",
"$",
"entry",
",",
"'timestamp'",
")",
";",
"$",
"_message",
"=",
"preg_replace",
"(",
"'/\\033\\[[\\d;]+m/'",
",",
"null",
",",
"Option",
"::",
"get",
"(",
"$",
"entry",
",",
"'message'",
")",
")",
";",
"$",
"_context",
"=",
"Option",
"::",
"get",
"(",
"$",
"entry",
",",
"'context'",
")",
";",
"$",
"_extra",
"=",
"Option",
"::",
"get",
"(",
"$",
"entry",
",",
"'extra'",
")",
";",
"$",
"_blob",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"if",
"(",
"static",
"::",
"$",
"_includeProcessInfo",
")",
"{",
"$",
"_blob",
"->",
"pid",
"=",
"getmypid",
"(",
")",
";",
"$",
"_blob",
"->",
"uid",
"=",
"getmyuid",
"(",
")",
";",
"$",
"_blob",
"->",
"hostname",
"=",
"gethostname",
"(",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"_context",
")",
")",
"{",
"$",
"_blob",
"->",
"context",
"=",
"$",
"_context",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"_extra",
")",
")",
"{",
"$",
"_context",
"->",
"extra",
"=",
"$",
"_extra",
";",
"}",
"$",
"_blob",
"=",
"json_encode",
"(",
"$",
"_blob",
")",
";",
"if",
"(",
"false",
"===",
"$",
"_blob",
"||",
"'{}'",
"==",
"$",
"_blob",
")",
"{",
"$",
"_blob",
"=",
"null",
";",
"}",
"$",
"_replacements",
"=",
"array",
"(",
"0",
"=>",
"$",
"_levelName",
",",
"1",
"=>",
"date",
"(",
"'M d'",
",",
"$",
"_timestamp",
")",
",",
"2",
"=>",
"date",
"(",
"'H:i:s'",
",",
"$",
"_timestamp",
")",
",",
"3",
"=>",
"$",
"_message",
",",
"4",
"=>",
"$",
"_blob",
",",
")",
";",
"return",
"str_ireplace",
"(",
"array",
"(",
"'%%level%%'",
",",
"'%%date%%'",
",",
"'%%time%%'",
",",
"'%%message%%'",
",",
"'%%extra%%'",
",",
")",
",",
"$",
"_replacements",
",",
"static",
"::",
"$",
"_logFormat",
")",
".",
"(",
"$",
"newline",
"?",
"PHP_EOL",
":",
"null",
")",
";",
"}"
] |
Formats the log entry. You can override this method to provide you own formatting.
It will strip out any console escape sequences as well
@param array $entry Read the code, data in the array
@param bool $newline
@return string
@deprecated in v0.2.20. To be removed in v0.3.0. Replaced by Monolog formatter
|
[
"Formats",
"the",
"log",
"entry",
".",
"You",
"can",
"override",
"this",
"method",
"to",
"provide",
"you",
"own",
"formatting",
".",
"It",
"will",
"strip",
"out",
"any",
"console",
"escape",
"sequences",
"as",
"well"
] |
4cc9954249da4e535b52f154e728935f07e648ae
|
https://github.com/lucifurious/kisma/blob/4cc9954249da4e535b52f154e728935f07e648ae/src/Kisma/Core/Utility/Log.php#L551-L605
|
235,363
|
lucifurious/kisma
|
src/Kisma/Core/Utility/Log.php
|
Log._checkLogFile
|
protected static function _checkLogFile()
{
if ( null !== static::$_logger )
{
return static::$_logFileValid = true;
}
if ( empty( static::$_logFilePath ) )
{
// Try and figure out a good place to log...
static::$_logFilePath = ( \Kisma::get( 'app.log_path', \Kisma::get( 'app.base_path' ) ) ?: dirname( getcwd() ) ) . '/log';
}
if ( !is_dir( static::$_logFilePath ) )
{
if ( false === @mkdir( static::$_logFilePath, 0777, true ) )
{
error_log( 'Unable to create default log directory: ' . static::$_logFilePath );
return static::$_logFileValid = false;
}
}
if ( empty( static::$_logFileName ) )
{
\Kisma::set( 'app.log_file_name', static::$_logFileName = static::DEFAULT_LOG_FILE_NAME );
}
static::$_defaultLog = static::$_logFilePath . '/' . trim( static::$_logFileName, '/' );
static::$_logger = static::createLogger( static::DEFAULT_CHANNEL_NAME );
// If we're in debug mode and these haven't been disabled, enable...
if ( \Kisma::get( CoreSettings::DEBUG ) )
{
static::$_enableChromePhp = static::$_enableChromePhp ?: true;
static::$_enableFirePhp = static::$_enableFirePhp ?: true;
}
// Enable conditional handlers
if ( static::$_enableFirePhp )
{
static::$_logger->pushHandler( new FirePHPHandler() );
}
if ( static::$_enableChromePhp )
{
static::$_logger->pushHandler( new ChromePHPHandler() );
}
return static::$_logFileValid = true;
}
|
php
|
protected static function _checkLogFile()
{
if ( null !== static::$_logger )
{
return static::$_logFileValid = true;
}
if ( empty( static::$_logFilePath ) )
{
// Try and figure out a good place to log...
static::$_logFilePath = ( \Kisma::get( 'app.log_path', \Kisma::get( 'app.base_path' ) ) ?: dirname( getcwd() ) ) . '/log';
}
if ( !is_dir( static::$_logFilePath ) )
{
if ( false === @mkdir( static::$_logFilePath, 0777, true ) )
{
error_log( 'Unable to create default log directory: ' . static::$_logFilePath );
return static::$_logFileValid = false;
}
}
if ( empty( static::$_logFileName ) )
{
\Kisma::set( 'app.log_file_name', static::$_logFileName = static::DEFAULT_LOG_FILE_NAME );
}
static::$_defaultLog = static::$_logFilePath . '/' . trim( static::$_logFileName, '/' );
static::$_logger = static::createLogger( static::DEFAULT_CHANNEL_NAME );
// If we're in debug mode and these haven't been disabled, enable...
if ( \Kisma::get( CoreSettings::DEBUG ) )
{
static::$_enableChromePhp = static::$_enableChromePhp ?: true;
static::$_enableFirePhp = static::$_enableFirePhp ?: true;
}
// Enable conditional handlers
if ( static::$_enableFirePhp )
{
static::$_logger->pushHandler( new FirePHPHandler() );
}
if ( static::$_enableChromePhp )
{
static::$_logger->pushHandler( new ChromePHPHandler() );
}
return static::$_logFileValid = true;
}
|
[
"protected",
"static",
"function",
"_checkLogFile",
"(",
")",
"{",
"if",
"(",
"null",
"!==",
"static",
"::",
"$",
"_logger",
")",
"{",
"return",
"static",
"::",
"$",
"_logFileValid",
"=",
"true",
";",
"}",
"if",
"(",
"empty",
"(",
"static",
"::",
"$",
"_logFilePath",
")",
")",
"{",
"//\tTry and figure out a good place to log...",
"static",
"::",
"$",
"_logFilePath",
"=",
"(",
"\\",
"Kisma",
"::",
"get",
"(",
"'app.log_path'",
",",
"\\",
"Kisma",
"::",
"get",
"(",
"'app.base_path'",
")",
")",
"?",
":",
"dirname",
"(",
"getcwd",
"(",
")",
")",
")",
".",
"'/log'",
";",
"}",
"if",
"(",
"!",
"is_dir",
"(",
"static",
"::",
"$",
"_logFilePath",
")",
")",
"{",
"if",
"(",
"false",
"===",
"@",
"mkdir",
"(",
"static",
"::",
"$",
"_logFilePath",
",",
"0777",
",",
"true",
")",
")",
"{",
"error_log",
"(",
"'Unable to create default log directory: '",
".",
"static",
"::",
"$",
"_logFilePath",
")",
";",
"return",
"static",
"::",
"$",
"_logFileValid",
"=",
"false",
";",
"}",
"}",
"if",
"(",
"empty",
"(",
"static",
"::",
"$",
"_logFileName",
")",
")",
"{",
"\\",
"Kisma",
"::",
"set",
"(",
"'app.log_file_name'",
",",
"static",
"::",
"$",
"_logFileName",
"=",
"static",
"::",
"DEFAULT_LOG_FILE_NAME",
")",
";",
"}",
"static",
"::",
"$",
"_defaultLog",
"=",
"static",
"::",
"$",
"_logFilePath",
".",
"'/'",
".",
"trim",
"(",
"static",
"::",
"$",
"_logFileName",
",",
"'/'",
")",
";",
"static",
"::",
"$",
"_logger",
"=",
"static",
"::",
"createLogger",
"(",
"static",
"::",
"DEFAULT_CHANNEL_NAME",
")",
";",
"//\tIf we're in debug mode and these haven't been disabled, enable...",
"if",
"(",
"\\",
"Kisma",
"::",
"get",
"(",
"CoreSettings",
"::",
"DEBUG",
")",
")",
"{",
"static",
"::",
"$",
"_enableChromePhp",
"=",
"static",
"::",
"$",
"_enableChromePhp",
"?",
":",
"true",
";",
"static",
"::",
"$",
"_enableFirePhp",
"=",
"static",
"::",
"$",
"_enableFirePhp",
"?",
":",
"true",
";",
"}",
"//\tEnable conditional handlers",
"if",
"(",
"static",
"::",
"$",
"_enableFirePhp",
")",
"{",
"static",
"::",
"$",
"_logger",
"->",
"pushHandler",
"(",
"new",
"FirePHPHandler",
"(",
")",
")",
";",
"}",
"if",
"(",
"static",
"::",
"$",
"_enableChromePhp",
")",
"{",
"static",
"::",
"$",
"_logger",
"->",
"pushHandler",
"(",
"new",
"ChromePHPHandler",
"(",
")",
")",
";",
"}",
"return",
"static",
"::",
"$",
"_logFileValid",
"=",
"true",
";",
"}"
] |
Makes sure we have a log file name and path
@deprecated in v0.2.20. To be removed in v0.3.0. Replaced by Monolog
|
[
"Makes",
"sure",
"we",
"have",
"a",
"log",
"file",
"name",
"and",
"path"
] |
4cc9954249da4e535b52f154e728935f07e648ae
|
https://github.com/lucifurious/kisma/blob/4cc9954249da4e535b52f154e728935f07e648ae/src/Kisma/Core/Utility/Log.php#L612-L663
|
235,364
|
ekyna/Characteristics
|
Entity/NumberCharacteristic.php
|
NumberCharacteristic.setNumber
|
public function setNumber($number = null)
{
$this->number = null !== $number ? floatval($number) : null;
return $this;
}
|
php
|
public function setNumber($number = null)
{
$this->number = null !== $number ? floatval($number) : null;
return $this;
}
|
[
"public",
"function",
"setNumber",
"(",
"$",
"number",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"number",
"=",
"null",
"!==",
"$",
"number",
"?",
"floatval",
"(",
"$",
"number",
")",
":",
"null",
";",
"return",
"$",
"this",
";",
"}"
] |
Sets the number.
@param float $number
@return NumberCharacteristic
|
[
"Sets",
"the",
"number",
"."
] |
118a349fd98a7c28721d3cbaba67ce79d1cffada
|
https://github.com/ekyna/Characteristics/blob/118a349fd98a7c28721d3cbaba67ce79d1cffada/Entity/NumberCharacteristic.php#L26-L31
|
235,365
|
MASNathan/Curl
|
src/MASNathan/Curl/Ch.php
|
Ch.curl
|
static private function curl($method, $url, $data, $special_options = null)
{
$curl = \curl_init();
if ($method == 'GET') {
if (!empty($data)) {
$url .= '?' . \http_build_query($data);
}
} elseif (!is_null($special_options)) {
\curl_setopt_array($curl, $special_options);
\curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
\curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
} else {
\curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
\curl_setopt($curl, CURLOPT_POSTFIELDS, \http_build_query($data));
}
\curl_setopt($curl, CURLOPT_URL, $url);
\curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
\curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
\curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
\curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$content = \curl_exec($curl);
\curl_close($curl);
return $content;
}
|
php
|
static private function curl($method, $url, $data, $special_options = null)
{
$curl = \curl_init();
if ($method == 'GET') {
if (!empty($data)) {
$url .= '?' . \http_build_query($data);
}
} elseif (!is_null($special_options)) {
\curl_setopt_array($curl, $special_options);
\curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
\curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
} else {
\curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
\curl_setopt($curl, CURLOPT_POSTFIELDS, \http_build_query($data));
}
\curl_setopt($curl, CURLOPT_URL, $url);
\curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
\curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
\curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
\curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$content = \curl_exec($curl);
\curl_close($curl);
return $content;
}
|
[
"static",
"private",
"function",
"curl",
"(",
"$",
"method",
",",
"$",
"url",
",",
"$",
"data",
",",
"$",
"special_options",
"=",
"null",
")",
"{",
"$",
"curl",
"=",
"\\",
"curl_init",
"(",
")",
";",
"if",
"(",
"$",
"method",
"==",
"'GET'",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"$",
"url",
".=",
"'?'",
".",
"\\",
"http_build_query",
"(",
"$",
"data",
")",
";",
"}",
"}",
"elseif",
"(",
"!",
"is_null",
"(",
"$",
"special_options",
")",
")",
"{",
"\\",
"curl_setopt_array",
"(",
"$",
"curl",
",",
"$",
"special_options",
")",
";",
"\\",
"curl_setopt",
"(",
"$",
"curl",
",",
"CURLOPT_CUSTOMREQUEST",
",",
"$",
"method",
")",
";",
"\\",
"curl_setopt",
"(",
"$",
"curl",
",",
"CURLOPT_POSTFIELDS",
",",
"$",
"data",
")",
";",
"}",
"else",
"{",
"\\",
"curl_setopt",
"(",
"$",
"curl",
",",
"CURLOPT_CUSTOMREQUEST",
",",
"$",
"method",
")",
";",
"\\",
"curl_setopt",
"(",
"$",
"curl",
",",
"CURLOPT_POSTFIELDS",
",",
"\\",
"http_build_query",
"(",
"$",
"data",
")",
")",
";",
"}",
"\\",
"curl_setopt",
"(",
"$",
"curl",
",",
"CURLOPT_URL",
",",
"$",
"url",
")",
";",
"\\",
"curl_setopt",
"(",
"$",
"curl",
",",
"CURLOPT_SSL_VERIFYHOST",
",",
"0",
")",
";",
"\\",
"curl_setopt",
"(",
"$",
"curl",
",",
"CURLOPT_SSL_VERIFYPEER",
",",
"false",
")",
";",
"\\",
"curl_setopt",
"(",
"$",
"curl",
",",
"CURLOPT_CONNECTTIMEOUT",
",",
"10",
")",
";",
"\\",
"curl_setopt",
"(",
"$",
"curl",
",",
"CURLOPT_RETURNTRANSFER",
",",
"true",
")",
";",
"$",
"content",
"=",
"\\",
"curl_exec",
"(",
"$",
"curl",
")",
";",
"\\",
"curl_close",
"(",
"$",
"curl",
")",
";",
"return",
"$",
"content",
";",
"}"
] |
Requests a specified url using the specified method
@param string $methof
@param string $url
@param array $data
@param array $special_options Adicional CURL options
@return string
|
[
"Requests",
"a",
"specified",
"url",
"using",
"the",
"specified",
"method"
] |
f03d33d45d583723dcfde8005c13ae3dd16d4d97
|
https://github.com/MASNathan/Curl/blob/f03d33d45d583723dcfde8005c13ae3dd16d4d97/src/MASNathan/Curl/Ch.php#L145-L173
|
235,366
|
MASNathan/Curl
|
src/MASNathan/Curl/Ch.php
|
Ch.call
|
public static function call($method, $args, $content_type = null)
{
if (count($args) == 0) {
throw new Exception\InvalidArgsException("You need specify at least the URL to call");
}
$method = strtoupper($method);
$url = null;
$params = null;
$callback = null;
$data_type = '';
if (!is_string($args[0]) || !filter_var($args[0], FILTER_VALIDATE_URL)) {
throw new Exception\InvalidArgsException("The URL you specified is not valid.");
} else {
$url = \array_shift($args);
}
//Is there any parameters to add?
if (count($args) > 0 && is_array($args[0])) {
$params = \array_shift($args);
}
//Is there any callback function to call?
if (count($args) > 0 && is_callable($args[0])) {
$callback = \array_shift($args);
}
//Is there any data type?
if (count($args) > 0 && is_string($args[0])) {
$data_type = \array_shift($args);
}
//END of arguments treatment
if ($method == 'POST' && $content_type == 'json') {
$data = self::curl($method, $url, \reset($params), array(
CURLOPT_HTTPHEADER => array('Content-Type: application/json'),
CURLOPT_POSTFIELDS => $params,
));
} else if ($method == 'POST' && $content_type == 'xml') {
$data = self::curl($method, $url, \reset($params), array(
CURLOPT_HTTPHEADER => array('Content-Type: text/xml'),
CURLOPT_POSTFIELDS => $params,
));
} else {
$data = self::curl($method, $url, $params);
}
$data = StringParser::parse($data, $data_type);
if (!is_null($callback)) {
$data = $callback($data);
}
return $data;
}
|
php
|
public static function call($method, $args, $content_type = null)
{
if (count($args) == 0) {
throw new Exception\InvalidArgsException("You need specify at least the URL to call");
}
$method = strtoupper($method);
$url = null;
$params = null;
$callback = null;
$data_type = '';
if (!is_string($args[0]) || !filter_var($args[0], FILTER_VALIDATE_URL)) {
throw new Exception\InvalidArgsException("The URL you specified is not valid.");
} else {
$url = \array_shift($args);
}
//Is there any parameters to add?
if (count($args) > 0 && is_array($args[0])) {
$params = \array_shift($args);
}
//Is there any callback function to call?
if (count($args) > 0 && is_callable($args[0])) {
$callback = \array_shift($args);
}
//Is there any data type?
if (count($args) > 0 && is_string($args[0])) {
$data_type = \array_shift($args);
}
//END of arguments treatment
if ($method == 'POST' && $content_type == 'json') {
$data = self::curl($method, $url, \reset($params), array(
CURLOPT_HTTPHEADER => array('Content-Type: application/json'),
CURLOPT_POSTFIELDS => $params,
));
} else if ($method == 'POST' && $content_type == 'xml') {
$data = self::curl($method, $url, \reset($params), array(
CURLOPT_HTTPHEADER => array('Content-Type: text/xml'),
CURLOPT_POSTFIELDS => $params,
));
} else {
$data = self::curl($method, $url, $params);
}
$data = StringParser::parse($data, $data_type);
if (!is_null($callback)) {
$data = $callback($data);
}
return $data;
}
|
[
"public",
"static",
"function",
"call",
"(",
"$",
"method",
",",
"$",
"args",
",",
"$",
"content_type",
"=",
"null",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"args",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"InvalidArgsException",
"(",
"\"You need specify at least the URL to call\"",
")",
";",
"}",
"$",
"method",
"=",
"strtoupper",
"(",
"$",
"method",
")",
";",
"$",
"url",
"=",
"null",
";",
"$",
"params",
"=",
"null",
";",
"$",
"callback",
"=",
"null",
";",
"$",
"data_type",
"=",
"''",
";",
"if",
"(",
"!",
"is_string",
"(",
"$",
"args",
"[",
"0",
"]",
")",
"||",
"!",
"filter_var",
"(",
"$",
"args",
"[",
"0",
"]",
",",
"FILTER_VALIDATE_URL",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"InvalidArgsException",
"(",
"\"The URL you specified is not valid.\"",
")",
";",
"}",
"else",
"{",
"$",
"url",
"=",
"\\",
"array_shift",
"(",
"$",
"args",
")",
";",
"}",
"//Is there any parameters to add?",
"if",
"(",
"count",
"(",
"$",
"args",
")",
">",
"0",
"&&",
"is_array",
"(",
"$",
"args",
"[",
"0",
"]",
")",
")",
"{",
"$",
"params",
"=",
"\\",
"array_shift",
"(",
"$",
"args",
")",
";",
"}",
"//Is there any callback function to call?",
"if",
"(",
"count",
"(",
"$",
"args",
")",
">",
"0",
"&&",
"is_callable",
"(",
"$",
"args",
"[",
"0",
"]",
")",
")",
"{",
"$",
"callback",
"=",
"\\",
"array_shift",
"(",
"$",
"args",
")",
";",
"}",
"//Is there any data type?",
"if",
"(",
"count",
"(",
"$",
"args",
")",
">",
"0",
"&&",
"is_string",
"(",
"$",
"args",
"[",
"0",
"]",
")",
")",
"{",
"$",
"data_type",
"=",
"\\",
"array_shift",
"(",
"$",
"args",
")",
";",
"}",
"//END of arguments treatment",
"if",
"(",
"$",
"method",
"==",
"'POST'",
"&&",
"$",
"content_type",
"==",
"'json'",
")",
"{",
"$",
"data",
"=",
"self",
"::",
"curl",
"(",
"$",
"method",
",",
"$",
"url",
",",
"\\",
"reset",
"(",
"$",
"params",
")",
",",
"array",
"(",
"CURLOPT_HTTPHEADER",
"=>",
"array",
"(",
"'Content-Type: application/json'",
")",
",",
"CURLOPT_POSTFIELDS",
"=>",
"$",
"params",
",",
")",
")",
";",
"}",
"else",
"if",
"(",
"$",
"method",
"==",
"'POST'",
"&&",
"$",
"content_type",
"==",
"'xml'",
")",
"{",
"$",
"data",
"=",
"self",
"::",
"curl",
"(",
"$",
"method",
",",
"$",
"url",
",",
"\\",
"reset",
"(",
"$",
"params",
")",
",",
"array",
"(",
"CURLOPT_HTTPHEADER",
"=>",
"array",
"(",
"'Content-Type: text/xml'",
")",
",",
"CURLOPT_POSTFIELDS",
"=>",
"$",
"params",
",",
")",
")",
";",
"}",
"else",
"{",
"$",
"data",
"=",
"self",
"::",
"curl",
"(",
"$",
"method",
",",
"$",
"url",
",",
"$",
"params",
")",
";",
"}",
"$",
"data",
"=",
"StringParser",
"::",
"parse",
"(",
"$",
"data",
",",
"$",
"data_type",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"callback",
")",
")",
"{",
"$",
"data",
"=",
"$",
"callback",
"(",
"$",
"data",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] |
Deals with the arguments "detection" and sets the rigth configs for the method you specify
@param string $method You can use the following: GET, POST, PUT, DELETE
@param array $args
@param string $content_type Should be json or xml, if not, just leave it empty
@return string|array
|
[
"Deals",
"with",
"the",
"arguments",
"detection",
"and",
"sets",
"the",
"rigth",
"configs",
"for",
"the",
"method",
"you",
"specify"
] |
f03d33d45d583723dcfde8005c13ae3dd16d4d97
|
https://github.com/MASNathan/Curl/blob/f03d33d45d583723dcfde8005c13ae3dd16d4d97/src/MASNathan/Curl/Ch.php#L182-L239
|
235,367
|
minecraftphp/rcon
|
src/ConnectionFactory.php
|
ConnectionFactory.createConnection
|
public function createConnection($host, $port, $password = null)
{
$socket = $this->socketFactory->createClient(sprintf('%s:%s', $host, $port));
$conn = new Connection($socket);
if (!empty($password)) {
$conn->authenticate($password);
}
return $conn;
}
|
php
|
public function createConnection($host, $port, $password = null)
{
$socket = $this->socketFactory->createClient(sprintf('%s:%s', $host, $port));
$conn = new Connection($socket);
if (!empty($password)) {
$conn->authenticate($password);
}
return $conn;
}
|
[
"public",
"function",
"createConnection",
"(",
"$",
"host",
",",
"$",
"port",
",",
"$",
"password",
"=",
"null",
")",
"{",
"$",
"socket",
"=",
"$",
"this",
"->",
"socketFactory",
"->",
"createClient",
"(",
"sprintf",
"(",
"'%s:%s'",
",",
"$",
"host",
",",
"$",
"port",
")",
")",
";",
"$",
"conn",
"=",
"new",
"Connection",
"(",
"$",
"socket",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"password",
")",
")",
"{",
"$",
"conn",
"->",
"authenticate",
"(",
"$",
"password",
")",
";",
"}",
"return",
"$",
"conn",
";",
"}"
] |
Creates a new Connection
@param string $host
@param integer $port
@param string|null $password
@return Connection
|
[
"Creates",
"a",
"new",
"Connection"
] |
15c2a523b58f4326633192717800db62da2bbde3
|
https://github.com/minecraftphp/rcon/blob/15c2a523b58f4326633192717800db62da2bbde3/src/ConnectionFactory.php#L43-L54
|
235,368
|
indigophp/fuelphp-dbal
|
src/Providers/FuelServiceProvider.php
|
FuelServiceProvider.parseFuelConfig
|
public function parseFuelConfig(array $config)
{
$params = array();
$params['driver'] = $config['type'];
if ($params['driver'] === 'pdo')
{
list($type, $dsn) = explode(':', $config['connection']['dsn'], 2);
$params['driver'] .= '_' . $type;
$dsn = explode(';', $dsn);
foreach ($dsn as $d)
{
list($k, $v) = explode('=', $d);
$params[$k] = $v;
}
}
else
{
$params['dbname'] = $config['connection']['database'];
$params['host'] = $config['connection']['hostname'];
$params['port'] = Arr::get($config, 'connection.port');
}
$params['user'] = Arr::get($config, 'connection.username');
$params['password'] = Arr::get($config, 'connection.password');
$params['charset'] = Arr::get($config, 'charset');
return $params;
}
|
php
|
public function parseFuelConfig(array $config)
{
$params = array();
$params['driver'] = $config['type'];
if ($params['driver'] === 'pdo')
{
list($type, $dsn) = explode(':', $config['connection']['dsn'], 2);
$params['driver'] .= '_' . $type;
$dsn = explode(';', $dsn);
foreach ($dsn as $d)
{
list($k, $v) = explode('=', $d);
$params[$k] = $v;
}
}
else
{
$params['dbname'] = $config['connection']['database'];
$params['host'] = $config['connection']['hostname'];
$params['port'] = Arr::get($config, 'connection.port');
}
$params['user'] = Arr::get($config, 'connection.username');
$params['password'] = Arr::get($config, 'connection.password');
$params['charset'] = Arr::get($config, 'charset');
return $params;
}
|
[
"public",
"function",
"parseFuelConfig",
"(",
"array",
"$",
"config",
")",
"{",
"$",
"params",
"=",
"array",
"(",
")",
";",
"$",
"params",
"[",
"'driver'",
"]",
"=",
"$",
"config",
"[",
"'type'",
"]",
";",
"if",
"(",
"$",
"params",
"[",
"'driver'",
"]",
"===",
"'pdo'",
")",
"{",
"list",
"(",
"$",
"type",
",",
"$",
"dsn",
")",
"=",
"explode",
"(",
"':'",
",",
"$",
"config",
"[",
"'connection'",
"]",
"[",
"'dsn'",
"]",
",",
"2",
")",
";",
"$",
"params",
"[",
"'driver'",
"]",
".=",
"'_'",
".",
"$",
"type",
";",
"$",
"dsn",
"=",
"explode",
"(",
"';'",
",",
"$",
"dsn",
")",
";",
"foreach",
"(",
"$",
"dsn",
"as",
"$",
"d",
")",
"{",
"list",
"(",
"$",
"k",
",",
"$",
"v",
")",
"=",
"explode",
"(",
"'='",
",",
"$",
"d",
")",
";",
"$",
"params",
"[",
"$",
"k",
"]",
"=",
"$",
"v",
";",
"}",
"}",
"else",
"{",
"$",
"params",
"[",
"'dbname'",
"]",
"=",
"$",
"config",
"[",
"'connection'",
"]",
"[",
"'database'",
"]",
";",
"$",
"params",
"[",
"'host'",
"]",
"=",
"$",
"config",
"[",
"'connection'",
"]",
"[",
"'hostname'",
"]",
";",
"$",
"params",
"[",
"'port'",
"]",
"=",
"Arr",
"::",
"get",
"(",
"$",
"config",
",",
"'connection.port'",
")",
";",
"}",
"$",
"params",
"[",
"'user'",
"]",
"=",
"Arr",
"::",
"get",
"(",
"$",
"config",
",",
"'connection.username'",
")",
";",
"$",
"params",
"[",
"'password'",
"]",
"=",
"Arr",
"::",
"get",
"(",
"$",
"config",
",",
"'connection.password'",
")",
";",
"$",
"params",
"[",
"'charset'",
"]",
"=",
"Arr",
"::",
"get",
"(",
"$",
"config",
",",
"'charset'",
")",
";",
"return",
"$",
"params",
";",
"}"
] |
Parses Fuel db config to DBAL compatible configuration
@param array $config
@return array
|
[
"Parses",
"Fuel",
"db",
"config",
"to",
"DBAL",
"compatible",
"configuration"
] |
2c98a3ea8bf4b1dab1bb6b578bb2af3a7ad1ee49
|
https://github.com/indigophp/fuelphp-dbal/blob/2c98a3ea8bf4b1dab1bb6b578bb2af3a7ad1ee49/src/Providers/FuelServiceProvider.php#L114-L147
|
235,369
|
indigophp/fuelphp-dbal
|
src/Providers/FuelServiceProvider.php
|
FuelServiceProvider.getApp
|
private function getApp()
{
$stack = $this->resolve('requeststack');
if ($request = $stack->top())
{
$app = $request->getApplication();
}
else
{
$app = $this->resolve('application::__main');
}
return $app;
}
|
php
|
private function getApp()
{
$stack = $this->resolve('requeststack');
if ($request = $stack->top())
{
$app = $request->getApplication();
}
else
{
$app = $this->resolve('application::__main');
}
return $app;
}
|
[
"private",
"function",
"getApp",
"(",
")",
"{",
"$",
"stack",
"=",
"$",
"this",
"->",
"resolve",
"(",
"'requeststack'",
")",
";",
"if",
"(",
"$",
"request",
"=",
"$",
"stack",
"->",
"top",
"(",
")",
")",
"{",
"$",
"app",
"=",
"$",
"request",
"->",
"getApplication",
"(",
")",
";",
"}",
"else",
"{",
"$",
"app",
"=",
"$",
"this",
"->",
"resolve",
"(",
"'application::__main'",
")",
";",
"}",
"return",
"$",
"app",
";",
"}"
] |
Returns the current application
@return \Fuel\Foundation\Application
|
[
"Returns",
"the",
"current",
"application"
] |
2c98a3ea8bf4b1dab1bb6b578bb2af3a7ad1ee49
|
https://github.com/indigophp/fuelphp-dbal/blob/2c98a3ea8bf4b1dab1bb6b578bb2af3a7ad1ee49/src/Providers/FuelServiceProvider.php#L154-L168
|
235,370
|
EarthlingInteractive/PHPProjectUtils
|
lib/EarthIT/ProjectUtil/DB/DatabaseUpgrader.php
|
EarthIT_ProjectUtil_DB_DatabaseUpgrader.semicolonTerminate
|
protected static function semicolonTerminate( $sql ) {
$lines = explode("\n", $sql);
$lastLineK = null;
foreach( $lines as $k=>$line ) {
$line = trim($line);
if( !preg_match('/^$|^--$|^--\s+/', $line) ) $lastLineK = $k;
}
if( $lastLineK !== null and !preg_match('/;$/', $lines[$lastLineK]) ) {
$lines[$lastLineK] .= ";";
return implode("\n", $lines);
} else {
return $sql;
}
}
|
php
|
protected static function semicolonTerminate( $sql ) {
$lines = explode("\n", $sql);
$lastLineK = null;
foreach( $lines as $k=>$line ) {
$line = trim($line);
if( !preg_match('/^$|^--$|^--\s+/', $line) ) $lastLineK = $k;
}
if( $lastLineK !== null and !preg_match('/;$/', $lines[$lastLineK]) ) {
$lines[$lastLineK] .= ";";
return implode("\n", $lines);
} else {
return $sql;
}
}
|
[
"protected",
"static",
"function",
"semicolonTerminate",
"(",
"$",
"sql",
")",
"{",
"$",
"lines",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"sql",
")",
";",
"$",
"lastLineK",
"=",
"null",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"k",
"=>",
"$",
"line",
")",
"{",
"$",
"line",
"=",
"trim",
"(",
"$",
"line",
")",
";",
"if",
"(",
"!",
"preg_match",
"(",
"'/^$|^--$|^--\\s+/'",
",",
"$",
"line",
")",
")",
"$",
"lastLineK",
"=",
"$",
"k",
";",
"}",
"if",
"(",
"$",
"lastLineK",
"!==",
"null",
"and",
"!",
"preg_match",
"(",
"'/;$/'",
",",
"$",
"lines",
"[",
"$",
"lastLineK",
"]",
")",
")",
"{",
"$",
"lines",
"[",
"$",
"lastLineK",
"]",
".=",
"\";\"",
";",
"return",
"implode",
"(",
"\"\\n\"",
",",
"$",
"lines",
")",
";",
"}",
"else",
"{",
"return",
"$",
"sql",
";",
"}",
"}"
] |
Make sure the last non-comment line ends with a semicolon.
|
[
"Make",
"sure",
"the",
"last",
"non",
"-",
"comment",
"line",
"ends",
"with",
"a",
"semicolon",
"."
] |
1a1cb341b877130604650b4e5b19e4bc78f0cfca
|
https://github.com/EarthlingInteractive/PHPProjectUtils/blob/1a1cb341b877130604650b4e5b19e4bc78f0cfca/lib/EarthIT/ProjectUtil/DB/DatabaseUpgrader.php#L145-L158
|
235,371
|
EarthlingInteractive/PHPProjectUtils
|
lib/EarthIT/ProjectUtil/DB/DatabaseUpgrader.php
|
EarthIT_ProjectUtil_DB_DatabaseUpgrader.isEntirelyCommented
|
protected function isEntirelyCommented( $sql ) {
$lines = explode("\n", $sql);
foreach( $lines as $line ) {
if( preg_match(self::COMMENT_LINE_REGEX,$line) ) continue;
// Otherwise this line's not a comment!
return false;
}
// If we get here, there were no non-comment, non-blank lines, so yes.
return true;
}
|
php
|
protected function isEntirelyCommented( $sql ) {
$lines = explode("\n", $sql);
foreach( $lines as $line ) {
if( preg_match(self::COMMENT_LINE_REGEX,$line) ) continue;
// Otherwise this line's not a comment!
return false;
}
// If we get here, there were no non-comment, non-blank lines, so yes.
return true;
}
|
[
"protected",
"function",
"isEntirelyCommented",
"(",
"$",
"sql",
")",
"{",
"$",
"lines",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"sql",
")",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"line",
")",
"{",
"if",
"(",
"preg_match",
"(",
"self",
"::",
"COMMENT_LINE_REGEX",
",",
"$",
"line",
")",
")",
"continue",
";",
"// Otherwise this line's not a comment!",
"return",
"false",
";",
"}",
"// If we get here, there were no non-comment, non-blank lines, so yes.",
"return",
"true",
";",
"}"
] |
Commented or empty
|
[
"Commented",
"or",
"empty"
] |
1a1cb341b877130604650b4e5b19e4bc78f0cfca
|
https://github.com/EarthlingInteractive/PHPProjectUtils/blob/1a1cb341b877130604650b4e5b19e4bc78f0cfca/lib/EarthIT/ProjectUtil/DB/DatabaseUpgrader.php#L162-L172
|
235,372
|
EarthlingInteractive/PHPProjectUtils
|
lib/EarthIT/ProjectUtil/DB/DatabaseUpgrader.php
|
EarthIT_ProjectUtil_DB_DatabaseUpgrader.getUpgradeLogColumnNames
|
protected function getUpgradeLogColumnNames() {
$colNames = array();
foreach( array('time','script filename','script file hash') as $attrib ) {
$colNames[self::toLowerCamelCase($attrib)] = $this->toDbObjectName($attrib);
}
return $colNames;
}
|
php
|
protected function getUpgradeLogColumnNames() {
$colNames = array();
foreach( array('time','script filename','script file hash') as $attrib ) {
$colNames[self::toLowerCamelCase($attrib)] = $this->toDbObjectName($attrib);
}
return $colNames;
}
|
[
"protected",
"function",
"getUpgradeLogColumnNames",
"(",
")",
"{",
"$",
"colNames",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"array",
"(",
"'time'",
",",
"'script filename'",
",",
"'script file hash'",
")",
"as",
"$",
"attrib",
")",
"{",
"$",
"colNames",
"[",
"self",
"::",
"toLowerCamelCase",
"(",
"$",
"attrib",
")",
"]",
"=",
"$",
"this",
"->",
"toDbObjectName",
"(",
"$",
"attrib",
")",
";",
"}",
"return",
"$",
"colNames",
";",
"}"
] |
Returns a map of camelCase => however the column is spelled in the database
of our upgrade table columns
|
[
"Returns",
"a",
"map",
"of",
"camelCase",
"=",
">",
"however",
"the",
"column",
"is",
"spelled",
"in",
"the",
"database",
"of",
"our",
"upgrade",
"table",
"columns"
] |
1a1cb341b877130604650b4e5b19e4bc78f0cfca
|
https://github.com/EarthlingInteractive/PHPProjectUtils/blob/1a1cb341b877130604650b4e5b19e4bc78f0cfca/lib/EarthIT/ProjectUtil/DB/DatabaseUpgrader.php#L270-L276
|
235,373
|
bishopb/vanilla
|
applications/dashboard/models/class.activitymodel.php
|
ActivityModel.ActivityQuery
|
public function ActivityQuery($Join = TRUE) {
$this->SQL
->Select('a.*')
->Select('t.FullHeadline, t.ProfileHeadline, t.AllowComments, t.ShowIcon, t.RouteCode')
->Select('t.Name', '', 'ActivityType')
->From('Activity a')
->Join('ActivityType t', 'a.ActivityTypeID = t.ActivityTypeID');
if ($Join) {
$this->SQL
->Select('au.Name', '', 'ActivityName')
->Select('au.Gender', '', 'ActivityGender')
->Select('au.Photo', '', 'ActivityPhoto')
->Select('au.Email', '', 'ActivityEmail')
->Select('ru.Name', '', 'RegardingName')
->Select('ru.Gender', '', 'RegardingGender')
->Select('ru.Email', '', 'RegardingEmail')
->Select('ru.Photo', '', 'RegardingPhoto')
->Join('User au', 'a.ActivityUserID = au.UserID')
->Join('User ru', 'a.RegardingUserID = ru.UserID', 'left');
}
$this->FireEvent('AfterActivityQuery');
}
|
php
|
public function ActivityQuery($Join = TRUE) {
$this->SQL
->Select('a.*')
->Select('t.FullHeadline, t.ProfileHeadline, t.AllowComments, t.ShowIcon, t.RouteCode')
->Select('t.Name', '', 'ActivityType')
->From('Activity a')
->Join('ActivityType t', 'a.ActivityTypeID = t.ActivityTypeID');
if ($Join) {
$this->SQL
->Select('au.Name', '', 'ActivityName')
->Select('au.Gender', '', 'ActivityGender')
->Select('au.Photo', '', 'ActivityPhoto')
->Select('au.Email', '', 'ActivityEmail')
->Select('ru.Name', '', 'RegardingName')
->Select('ru.Gender', '', 'RegardingGender')
->Select('ru.Email', '', 'RegardingEmail')
->Select('ru.Photo', '', 'RegardingPhoto')
->Join('User au', 'a.ActivityUserID = au.UserID')
->Join('User ru', 'a.RegardingUserID = ru.UserID', 'left');
}
$this->FireEvent('AfterActivityQuery');
}
|
[
"public",
"function",
"ActivityQuery",
"(",
"$",
"Join",
"=",
"TRUE",
")",
"{",
"$",
"this",
"->",
"SQL",
"->",
"Select",
"(",
"'a.*'",
")",
"->",
"Select",
"(",
"'t.FullHeadline, t.ProfileHeadline, t.AllowComments, t.ShowIcon, t.RouteCode'",
")",
"->",
"Select",
"(",
"'t.Name'",
",",
"''",
",",
"'ActivityType'",
")",
"->",
"From",
"(",
"'Activity a'",
")",
"->",
"Join",
"(",
"'ActivityType t'",
",",
"'a.ActivityTypeID = t.ActivityTypeID'",
")",
";",
"if",
"(",
"$",
"Join",
")",
"{",
"$",
"this",
"->",
"SQL",
"->",
"Select",
"(",
"'au.Name'",
",",
"''",
",",
"'ActivityName'",
")",
"->",
"Select",
"(",
"'au.Gender'",
",",
"''",
",",
"'ActivityGender'",
")",
"->",
"Select",
"(",
"'au.Photo'",
",",
"''",
",",
"'ActivityPhoto'",
")",
"->",
"Select",
"(",
"'au.Email'",
",",
"''",
",",
"'ActivityEmail'",
")",
"->",
"Select",
"(",
"'ru.Name'",
",",
"''",
",",
"'RegardingName'",
")",
"->",
"Select",
"(",
"'ru.Gender'",
",",
"''",
",",
"'RegardingGender'",
")",
"->",
"Select",
"(",
"'ru.Email'",
",",
"''",
",",
"'RegardingEmail'",
")",
"->",
"Select",
"(",
"'ru.Photo'",
",",
"''",
",",
"'RegardingPhoto'",
")",
"->",
"Join",
"(",
"'User au'",
",",
"'a.ActivityUserID = au.UserID'",
")",
"->",
"Join",
"(",
"'User ru'",
",",
"'a.RegardingUserID = ru.UserID'",
",",
"'left'",
")",
";",
"}",
"$",
"this",
"->",
"FireEvent",
"(",
"'AfterActivityQuery'",
")",
";",
"}"
] |
Build basis of common activity SQL query.
@since 2.0.0
@access public
|
[
"Build",
"basis",
"of",
"common",
"activity",
"SQL",
"query",
"."
] |
8494eb4a4ad61603479015a8054d23ff488364e8
|
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/models/class.activitymodel.php#L50-L73
|
235,374
|
bishopb/vanilla
|
applications/dashboard/models/class.activitymodel.php
|
ActivityModel.Delete
|
public function Delete($ActivityID, $Options = array()) {
// Get the activity first.
$Activity = $this->GetID($ActivityID);
if ($Activity) {
// Log the deletion.
$Log = GetValue('Log', $Options);
if ($Log) {
LogModel::Insert($Log, 'Activity', $Activity);
}
// Delete comments on the activity item
$this->SQL->Delete('ActivityComment', array('ActivityID' => $ActivityID));
// Delete the activity item
parent::Delete(array('ActivityID' => $ActivityID));
}
}
|
php
|
public function Delete($ActivityID, $Options = array()) {
// Get the activity first.
$Activity = $this->GetID($ActivityID);
if ($Activity) {
// Log the deletion.
$Log = GetValue('Log', $Options);
if ($Log) {
LogModel::Insert($Log, 'Activity', $Activity);
}
// Delete comments on the activity item
$this->SQL->Delete('ActivityComment', array('ActivityID' => $ActivityID));
// Delete the activity item
parent::Delete(array('ActivityID' => $ActivityID));
}
}
|
[
"public",
"function",
"Delete",
"(",
"$",
"ActivityID",
",",
"$",
"Options",
"=",
"array",
"(",
")",
")",
"{",
"// Get the activity first.",
"$",
"Activity",
"=",
"$",
"this",
"->",
"GetID",
"(",
"$",
"ActivityID",
")",
";",
"if",
"(",
"$",
"Activity",
")",
"{",
"// Log the deletion.",
"$",
"Log",
"=",
"GetValue",
"(",
"'Log'",
",",
"$",
"Options",
")",
";",
"if",
"(",
"$",
"Log",
")",
"{",
"LogModel",
"::",
"Insert",
"(",
"$",
"Log",
",",
"'Activity'",
",",
"$",
"Activity",
")",
";",
"}",
"// Delete comments on the activity item",
"$",
"this",
"->",
"SQL",
"->",
"Delete",
"(",
"'ActivityComment'",
",",
"array",
"(",
"'ActivityID'",
"=>",
"$",
"ActivityID",
")",
")",
";",
"// Delete the activity item",
"parent",
"::",
"Delete",
"(",
"array",
"(",
"'ActivityID'",
"=>",
"$",
"ActivityID",
")",
")",
";",
"}",
"}"
] |
Delete a particular activity item.
@since 2.0.0
@access public
@param int $ActivityID Unique ID of acitivity to be deleted.
|
[
"Delete",
"a",
"particular",
"activity",
"item",
"."
] |
8494eb4a4ad61603479015a8054d23ff488364e8
|
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/models/class.activitymodel.php#L139-L155
|
235,375
|
bishopb/vanilla
|
applications/dashboard/models/class.activitymodel.php
|
ActivityModel.GetWhere
|
public function GetWhere($Where, $Offset = 0, $Limit = 30) {
if (is_string($Where)) {
$Where = array($Where => $Offset);
$Offset = 0;
}
// Add the basic activity query.
$this->SQL
->Select('a2.*')
->Select('t.FullHeadline, t.ProfileHeadline, t.AllowComments, t.ShowIcon, t.RouteCode')
->Select('t.Name', '', 'ActivityType')
->From('Activity a')
->Join('Activity a2', 'a.ActivityID = a2.ActivityID') // self-join for index speed.
->Join('ActivityType t', 'a2.ActivityTypeID = t.ActivityTypeID');
// Add prefixes to the where.
foreach ($Where as $Key => $Value) {
if (strpos($Key, '.') === FALSE) {
$Where['a.'.$Key] = $Value;
unset($Where[$Key]);
}
}
$Result = $this->SQL
->Where($Where)
->OrderBy('a.DateUpdated', 'desc')
->Limit($Limit, $Offset)
->Get();
self::GetUsers($Result->ResultArray());
Gdn::UserModel()->JoinUsers($Result->ResultArray(), array('ActivityUserID', 'RegardingUserID'), array('Join' => array('Name', 'Email', 'Gender', 'Photo')));
$this->CalculateData($Result->ResultArray());
$this->EventArguments['Data'] =& $Result;
$this->FireEvent('AfterGet');
return $Result;
}
|
php
|
public function GetWhere($Where, $Offset = 0, $Limit = 30) {
if (is_string($Where)) {
$Where = array($Where => $Offset);
$Offset = 0;
}
// Add the basic activity query.
$this->SQL
->Select('a2.*')
->Select('t.FullHeadline, t.ProfileHeadline, t.AllowComments, t.ShowIcon, t.RouteCode')
->Select('t.Name', '', 'ActivityType')
->From('Activity a')
->Join('Activity a2', 'a.ActivityID = a2.ActivityID') // self-join for index speed.
->Join('ActivityType t', 'a2.ActivityTypeID = t.ActivityTypeID');
// Add prefixes to the where.
foreach ($Where as $Key => $Value) {
if (strpos($Key, '.') === FALSE) {
$Where['a.'.$Key] = $Value;
unset($Where[$Key]);
}
}
$Result = $this->SQL
->Where($Where)
->OrderBy('a.DateUpdated', 'desc')
->Limit($Limit, $Offset)
->Get();
self::GetUsers($Result->ResultArray());
Gdn::UserModel()->JoinUsers($Result->ResultArray(), array('ActivityUserID', 'RegardingUserID'), array('Join' => array('Name', 'Email', 'Gender', 'Photo')));
$this->CalculateData($Result->ResultArray());
$this->EventArguments['Data'] =& $Result;
$this->FireEvent('AfterGet');
return $Result;
}
|
[
"public",
"function",
"GetWhere",
"(",
"$",
"Where",
",",
"$",
"Offset",
"=",
"0",
",",
"$",
"Limit",
"=",
"30",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"Where",
")",
")",
"{",
"$",
"Where",
"=",
"array",
"(",
"$",
"Where",
"=>",
"$",
"Offset",
")",
";",
"$",
"Offset",
"=",
"0",
";",
"}",
"// Add the basic activity query.",
"$",
"this",
"->",
"SQL",
"->",
"Select",
"(",
"'a2.*'",
")",
"->",
"Select",
"(",
"'t.FullHeadline, t.ProfileHeadline, t.AllowComments, t.ShowIcon, t.RouteCode'",
")",
"->",
"Select",
"(",
"'t.Name'",
",",
"''",
",",
"'ActivityType'",
")",
"->",
"From",
"(",
"'Activity a'",
")",
"->",
"Join",
"(",
"'Activity a2'",
",",
"'a.ActivityID = a2.ActivityID'",
")",
"// self-join for index speed.",
"->",
"Join",
"(",
"'ActivityType t'",
",",
"'a2.ActivityTypeID = t.ActivityTypeID'",
")",
";",
"// Add prefixes to the where.",
"foreach",
"(",
"$",
"Where",
"as",
"$",
"Key",
"=>",
"$",
"Value",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"Key",
",",
"'.'",
")",
"===",
"FALSE",
")",
"{",
"$",
"Where",
"[",
"'a.'",
".",
"$",
"Key",
"]",
"=",
"$",
"Value",
";",
"unset",
"(",
"$",
"Where",
"[",
"$",
"Key",
"]",
")",
";",
"}",
"}",
"$",
"Result",
"=",
"$",
"this",
"->",
"SQL",
"->",
"Where",
"(",
"$",
"Where",
")",
"->",
"OrderBy",
"(",
"'a.DateUpdated'",
",",
"'desc'",
")",
"->",
"Limit",
"(",
"$",
"Limit",
",",
"$",
"Offset",
")",
"->",
"Get",
"(",
")",
";",
"self",
"::",
"GetUsers",
"(",
"$",
"Result",
"->",
"ResultArray",
"(",
")",
")",
";",
"Gdn",
"::",
"UserModel",
"(",
")",
"->",
"JoinUsers",
"(",
"$",
"Result",
"->",
"ResultArray",
"(",
")",
",",
"array",
"(",
"'ActivityUserID'",
",",
"'RegardingUserID'",
")",
",",
"array",
"(",
"'Join'",
"=>",
"array",
"(",
"'Name'",
",",
"'Email'",
",",
"'Gender'",
",",
"'Photo'",
")",
")",
")",
";",
"$",
"this",
"->",
"CalculateData",
"(",
"$",
"Result",
"->",
"ResultArray",
"(",
")",
")",
";",
"$",
"this",
"->",
"EventArguments",
"[",
"'Data'",
"]",
"=",
"&",
"$",
"Result",
";",
"$",
"this",
"->",
"FireEvent",
"(",
"'AfterGet'",
")",
";",
"return",
"$",
"Result",
";",
"}"
] |
Modifies standard Gdn_Model->GetWhere to use AcitivityQuery.
Events: AfterGet.
@since 2.0.0
@access public
@param array $Where The where condition.
@param int $Offset The offset of the query.
@param int $Limit the limit of the query.
@return DataSet SQL results.
|
[
"Modifies",
"standard",
"Gdn_Model",
"-",
">",
"GetWhere",
"to",
"use",
"AcitivityQuery",
"."
] |
8494eb4a4ad61603479015a8054d23ff488364e8
|
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/models/class.activitymodel.php#L178-L215
|
235,376
|
bishopb/vanilla
|
applications/dashboard/models/class.activitymodel.php
|
ActivityModel.Get
|
public function Get($NotifyUserID = FALSE, $Offset = 0, $Limit = 30) {
$Offset = is_numeric($Offset) ? $Offset : 0;
if ($Offset < 0)
$Offset = 0;
$Limit = is_numeric($Limit) ? $Limit : 0;
if ($Limit < 0)
$Limit = 30;
$this->ActivityQuery(FALSE);
if (!$NotifyUserID) {
$NotifyUserID = self::NOTIFY_PUBLIC;
}
$this->SQL->WhereIn('NotifyUserID', (array)$NotifyUserID);
$this->FireEvent('BeforeGet');
$Result = $this->SQL
->OrderBy('a.ActivityID', 'desc')
->Limit($Limit, $Offset)
->Get();
Gdn::UserModel()->JoinUsers($Result, array('ActivityUserID', 'RegardingUserID'), array('Join' => array('Name', 'Photo', 'Email', 'Gender')));
$this->EventArguments['Data'] =& $Result;
$this->FireEvent('AfterGet');
return $Result;
}
|
php
|
public function Get($NotifyUserID = FALSE, $Offset = 0, $Limit = 30) {
$Offset = is_numeric($Offset) ? $Offset : 0;
if ($Offset < 0)
$Offset = 0;
$Limit = is_numeric($Limit) ? $Limit : 0;
if ($Limit < 0)
$Limit = 30;
$this->ActivityQuery(FALSE);
if (!$NotifyUserID) {
$NotifyUserID = self::NOTIFY_PUBLIC;
}
$this->SQL->WhereIn('NotifyUserID', (array)$NotifyUserID);
$this->FireEvent('BeforeGet');
$Result = $this->SQL
->OrderBy('a.ActivityID', 'desc')
->Limit($Limit, $Offset)
->Get();
Gdn::UserModel()->JoinUsers($Result, array('ActivityUserID', 'RegardingUserID'), array('Join' => array('Name', 'Photo', 'Email', 'Gender')));
$this->EventArguments['Data'] =& $Result;
$this->FireEvent('AfterGet');
return $Result;
}
|
[
"public",
"function",
"Get",
"(",
"$",
"NotifyUserID",
"=",
"FALSE",
",",
"$",
"Offset",
"=",
"0",
",",
"$",
"Limit",
"=",
"30",
")",
"{",
"$",
"Offset",
"=",
"is_numeric",
"(",
"$",
"Offset",
")",
"?",
"$",
"Offset",
":",
"0",
";",
"if",
"(",
"$",
"Offset",
"<",
"0",
")",
"$",
"Offset",
"=",
"0",
";",
"$",
"Limit",
"=",
"is_numeric",
"(",
"$",
"Limit",
")",
"?",
"$",
"Limit",
":",
"0",
";",
"if",
"(",
"$",
"Limit",
"<",
"0",
")",
"$",
"Limit",
"=",
"30",
";",
"$",
"this",
"->",
"ActivityQuery",
"(",
"FALSE",
")",
";",
"if",
"(",
"!",
"$",
"NotifyUserID",
")",
"{",
"$",
"NotifyUserID",
"=",
"self",
"::",
"NOTIFY_PUBLIC",
";",
"}",
"$",
"this",
"->",
"SQL",
"->",
"WhereIn",
"(",
"'NotifyUserID'",
",",
"(",
"array",
")",
"$",
"NotifyUserID",
")",
";",
"$",
"this",
"->",
"FireEvent",
"(",
"'BeforeGet'",
")",
";",
"$",
"Result",
"=",
"$",
"this",
"->",
"SQL",
"->",
"OrderBy",
"(",
"'a.ActivityID'",
",",
"'desc'",
")",
"->",
"Limit",
"(",
"$",
"Limit",
",",
"$",
"Offset",
")",
"->",
"Get",
"(",
")",
";",
"Gdn",
"::",
"UserModel",
"(",
")",
"->",
"JoinUsers",
"(",
"$",
"Result",
",",
"array",
"(",
"'ActivityUserID'",
",",
"'RegardingUserID'",
")",
",",
"array",
"(",
"'Join'",
"=>",
"array",
"(",
"'Name'",
",",
"'Photo'",
",",
"'Email'",
",",
"'Gender'",
")",
")",
")",
";",
"$",
"this",
"->",
"EventArguments",
"[",
"'Data'",
"]",
"=",
"&",
"$",
"Result",
";",
"$",
"this",
"->",
"FireEvent",
"(",
"'AfterGet'",
")",
";",
"return",
"$",
"Result",
";",
"}"
] |
Modifies standard Gdn_Model->Get to use AcitivityQuery.
Events: BeforeGet, AfterGet.
@since 2.0.0
@access public
@param int $NotifyUserID Unique ID of user to gather activity for or one of the NOTIFY_* constants in this class.
@param int $Offset Number to skip.
@param int $Limit How many to return.
@return DataSet SQL results.
|
[
"Modifies",
"standard",
"Gdn_Model",
"-",
">",
"Get",
"to",
"use",
"AcitivityQuery",
"."
] |
8494eb4a4ad61603479015a8054d23ff488364e8
|
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/models/class.activitymodel.php#L261-L289
|
235,377
|
bishopb/vanilla
|
applications/dashboard/models/class.activitymodel.php
|
ActivityModel.GetCount
|
public function GetCount($UserID = '') {
$this->SQL
->Select('a.ActivityID', 'count', 'ActivityCount')
->From('Activity a')
->Join('ActivityType t', 'a.ActivityTypeID = t.ActivityTypeID');
if ($UserID != '') {
$this->SQL
->BeginWhereGroup()
->Where('a.ActivityUserID', $UserID)
->OrWhere('a.RegardingUserID', $UserID)
->EndWhereGroup();
}
$Session = Gdn::Session();
if (!$Session->IsValid() || $Session->UserID != $UserID)
$this->SQL->Where('t.Public', '1');
$this->FireEvent('BeforeGetCount');
return $this->SQL
->Get()
->FirstRow()
->ActivityCount;
}
|
php
|
public function GetCount($UserID = '') {
$this->SQL
->Select('a.ActivityID', 'count', 'ActivityCount')
->From('Activity a')
->Join('ActivityType t', 'a.ActivityTypeID = t.ActivityTypeID');
if ($UserID != '') {
$this->SQL
->BeginWhereGroup()
->Where('a.ActivityUserID', $UserID)
->OrWhere('a.RegardingUserID', $UserID)
->EndWhereGroup();
}
$Session = Gdn::Session();
if (!$Session->IsValid() || $Session->UserID != $UserID)
$this->SQL->Where('t.Public', '1');
$this->FireEvent('BeforeGetCount');
return $this->SQL
->Get()
->FirstRow()
->ActivityCount;
}
|
[
"public",
"function",
"GetCount",
"(",
"$",
"UserID",
"=",
"''",
")",
"{",
"$",
"this",
"->",
"SQL",
"->",
"Select",
"(",
"'a.ActivityID'",
",",
"'count'",
",",
"'ActivityCount'",
")",
"->",
"From",
"(",
"'Activity a'",
")",
"->",
"Join",
"(",
"'ActivityType t'",
",",
"'a.ActivityTypeID = t.ActivityTypeID'",
")",
";",
"if",
"(",
"$",
"UserID",
"!=",
"''",
")",
"{",
"$",
"this",
"->",
"SQL",
"->",
"BeginWhereGroup",
"(",
")",
"->",
"Where",
"(",
"'a.ActivityUserID'",
",",
"$",
"UserID",
")",
"->",
"OrWhere",
"(",
"'a.RegardingUserID'",
",",
"$",
"UserID",
")",
"->",
"EndWhereGroup",
"(",
")",
";",
"}",
"$",
"Session",
"=",
"Gdn",
"::",
"Session",
"(",
")",
";",
"if",
"(",
"!",
"$",
"Session",
"->",
"IsValid",
"(",
")",
"||",
"$",
"Session",
"->",
"UserID",
"!=",
"$",
"UserID",
")",
"$",
"this",
"->",
"SQL",
"->",
"Where",
"(",
"'t.Public'",
",",
"'1'",
")",
";",
"$",
"this",
"->",
"FireEvent",
"(",
"'BeforeGetCount'",
")",
";",
"return",
"$",
"this",
"->",
"SQL",
"->",
"Get",
"(",
")",
"->",
"FirstRow",
"(",
")",
"->",
"ActivityCount",
";",
"}"
] |
Get number of activity related to a user.
Events: BeforeGetCount.
@since 2.0.0
@access public
@param string $UserID Unique ID of user.
@return int Number of activity items found.
|
[
"Get",
"number",
"of",
"activity",
"related",
"to",
"a",
"user",
"."
] |
8494eb4a4ad61603479015a8054d23ff488364e8
|
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/models/class.activitymodel.php#L340-L363
|
235,378
|
bishopb/vanilla
|
applications/dashboard/models/class.activitymodel.php
|
ActivityModel.GetForRole
|
public function GetForRole($RoleID = '', $Offset = '0', $Limit = '50') {
if (!is_array($RoleID))
$RoleID = array($RoleID);
$Offset = is_numeric($Offset) ? $Offset : 0;
if ($Offset < 0)
$Offset = 0;
$Limit = is_numeric($Limit) ? $Limit : 0;
if ($Limit < 0)
$Limit = 0;
$this->ActivityQuery();
$Result = $this->SQL
->Join('UserRole ur', 'a.ActivityUserID = ur.UserID')
->WhereIn('ur.RoleID', $RoleID)
->Where('t.Public', '1')
->OrderBy('a.DateInserted', 'desc')
->Limit($Limit, $Offset)
->Get();
$this->EventArguments['Data'] =& $Result;
$this->FireEvent('AfterGet');
return $Result;
}
|
php
|
public function GetForRole($RoleID = '', $Offset = '0', $Limit = '50') {
if (!is_array($RoleID))
$RoleID = array($RoleID);
$Offset = is_numeric($Offset) ? $Offset : 0;
if ($Offset < 0)
$Offset = 0;
$Limit = is_numeric($Limit) ? $Limit : 0;
if ($Limit < 0)
$Limit = 0;
$this->ActivityQuery();
$Result = $this->SQL
->Join('UserRole ur', 'a.ActivityUserID = ur.UserID')
->WhereIn('ur.RoleID', $RoleID)
->Where('t.Public', '1')
->OrderBy('a.DateInserted', 'desc')
->Limit($Limit, $Offset)
->Get();
$this->EventArguments['Data'] =& $Result;
$this->FireEvent('AfterGet');
return $Result;
}
|
[
"public",
"function",
"GetForRole",
"(",
"$",
"RoleID",
"=",
"''",
",",
"$",
"Offset",
"=",
"'0'",
",",
"$",
"Limit",
"=",
"'50'",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"RoleID",
")",
")",
"$",
"RoleID",
"=",
"array",
"(",
"$",
"RoleID",
")",
";",
"$",
"Offset",
"=",
"is_numeric",
"(",
"$",
"Offset",
")",
"?",
"$",
"Offset",
":",
"0",
";",
"if",
"(",
"$",
"Offset",
"<",
"0",
")",
"$",
"Offset",
"=",
"0",
";",
"$",
"Limit",
"=",
"is_numeric",
"(",
"$",
"Limit",
")",
"?",
"$",
"Limit",
":",
"0",
";",
"if",
"(",
"$",
"Limit",
"<",
"0",
")",
"$",
"Limit",
"=",
"0",
";",
"$",
"this",
"->",
"ActivityQuery",
"(",
")",
";",
"$",
"Result",
"=",
"$",
"this",
"->",
"SQL",
"->",
"Join",
"(",
"'UserRole ur'",
",",
"'a.ActivityUserID = ur.UserID'",
")",
"->",
"WhereIn",
"(",
"'ur.RoleID'",
",",
"$",
"RoleID",
")",
"->",
"Where",
"(",
"'t.Public'",
",",
"'1'",
")",
"->",
"OrderBy",
"(",
"'a.DateInserted'",
",",
"'desc'",
")",
"->",
"Limit",
"(",
"$",
"Limit",
",",
"$",
"Offset",
")",
"->",
"Get",
"(",
")",
";",
"$",
"this",
"->",
"EventArguments",
"[",
"'Data'",
"]",
"=",
"&",
"$",
"Result",
";",
"$",
"this",
"->",
"FireEvent",
"(",
"'AfterGet'",
")",
";",
"return",
"$",
"Result",
";",
"}"
] |
Get activity related to a particular role.
Events: AfterGet.
@since 2.0.18
@access public
@param string $RoleID Unique ID of role.
@param int $Offset Number to skip.
@param int $Limit Max number to return.
@return DataSet SQL results.
|
[
"Get",
"activity",
"related",
"to",
"a",
"particular",
"role",
"."
] |
8494eb4a4ad61603479015a8054d23ff488364e8
|
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/models/class.activitymodel.php#L377-L402
|
235,379
|
bishopb/vanilla
|
applications/dashboard/models/class.activitymodel.php
|
ActivityModel.GetCountForRole
|
public function GetCountForRole($RoleID = '') {
if (!is_array($RoleID))
$RoleID = array($RoleID);
return $this->SQL
->Select('a.ActivityID', 'count', 'ActivityCount')
->From('Activity a')
->Join('ActivityType t', 'a.ActivityTypeID = t.ActivityTypeID')
->Join('UserRole ur', 'a.ActivityUserID = ur.UserID')
->WhereIn('ur.RoleID', $RoleID)
->Where('t.Public', '1')
->Get()
->FirstRow()
->ActivityCount;
}
|
php
|
public function GetCountForRole($RoleID = '') {
if (!is_array($RoleID))
$RoleID = array($RoleID);
return $this->SQL
->Select('a.ActivityID', 'count', 'ActivityCount')
->From('Activity a')
->Join('ActivityType t', 'a.ActivityTypeID = t.ActivityTypeID')
->Join('UserRole ur', 'a.ActivityUserID = ur.UserID')
->WhereIn('ur.RoleID', $RoleID)
->Where('t.Public', '1')
->Get()
->FirstRow()
->ActivityCount;
}
|
[
"public",
"function",
"GetCountForRole",
"(",
"$",
"RoleID",
"=",
"''",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"RoleID",
")",
")",
"$",
"RoleID",
"=",
"array",
"(",
"$",
"RoleID",
")",
";",
"return",
"$",
"this",
"->",
"SQL",
"->",
"Select",
"(",
"'a.ActivityID'",
",",
"'count'",
",",
"'ActivityCount'",
")",
"->",
"From",
"(",
"'Activity a'",
")",
"->",
"Join",
"(",
"'ActivityType t'",
",",
"'a.ActivityTypeID = t.ActivityTypeID'",
")",
"->",
"Join",
"(",
"'UserRole ur'",
",",
"'a.ActivityUserID = ur.UserID'",
")",
"->",
"WhereIn",
"(",
"'ur.RoleID'",
",",
"$",
"RoleID",
")",
"->",
"Where",
"(",
"'t.Public'",
",",
"'1'",
")",
"->",
"Get",
"(",
")",
"->",
"FirstRow",
"(",
")",
"->",
"ActivityCount",
";",
"}"
] |
Get number of activity related to a particular role.
@since 2.0.18
@access public
@param int $RoleID Unique ID of role.
@return int Number of activity items.
|
[
"Get",
"number",
"of",
"activity",
"related",
"to",
"a",
"particular",
"role",
"."
] |
8494eb4a4ad61603479015a8054d23ff488364e8
|
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/models/class.activitymodel.php#L412-L426
|
235,380
|
bishopb/vanilla
|
applications/dashboard/models/class.activitymodel.php
|
ActivityModel.GetID
|
public function GetID($ActivityID, $DataType = FALSE) {
$Activity = parent::GetID($ActivityID, $DataType);
if ($Activity) {
$this->CalculateRow($Activity);
$Activities = array($Activity);
self::JoinUsers($Activities);
$Activity = array_pop($Activities);
}
return $Activity;
}
|
php
|
public function GetID($ActivityID, $DataType = FALSE) {
$Activity = parent::GetID($ActivityID, $DataType);
if ($Activity) {
$this->CalculateRow($Activity);
$Activities = array($Activity);
self::JoinUsers($Activities);
$Activity = array_pop($Activities);
}
return $Activity;
}
|
[
"public",
"function",
"GetID",
"(",
"$",
"ActivityID",
",",
"$",
"DataType",
"=",
"FALSE",
")",
"{",
"$",
"Activity",
"=",
"parent",
"::",
"GetID",
"(",
"$",
"ActivityID",
",",
"$",
"DataType",
")",
";",
"if",
"(",
"$",
"Activity",
")",
"{",
"$",
"this",
"->",
"CalculateRow",
"(",
"$",
"Activity",
")",
";",
"$",
"Activities",
"=",
"array",
"(",
"$",
"Activity",
")",
";",
"self",
"::",
"JoinUsers",
"(",
"$",
"Activities",
")",
";",
"$",
"Activity",
"=",
"array_pop",
"(",
"$",
"Activities",
")",
";",
"}",
"return",
"$",
"Activity",
";",
"}"
] |
Get a particular activity record.
@since 2.0.0
@access public
@param int $ActivityID Unique ID of activity item.
@return array|object A single SQL result.
|
[
"Get",
"a",
"particular",
"activity",
"record",
"."
] |
8494eb4a4ad61603479015a8054d23ff488364e8
|
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/models/class.activitymodel.php#L436-L446
|
235,381
|
bishopb/vanilla
|
applications/dashboard/models/class.activitymodel.php
|
ActivityModel.GetNotifications
|
public function GetNotifications($NotifyUserID, $Offset = '0', $Limit = '30') {
$this->ActivityQuery(FALSE);
$this->FireEvent('BeforeGetNotifications');
$Result = $this->SQL
->Where('NotifyUserID', $NotifyUserID)
->Limit($Limit, $Offset)
->OrderBy('a.ActivityID', 'desc')
->Get();
$Result->DatasetType(DATASET_TYPE_ARRAY);
self::GetUsers($Result->ResultArray());
Gdn::UserModel()->JoinUsers($Result->ResultArray(), array('ActivityUserID', 'RegardingUserID'), array('Join' => array('Name', 'Photo', 'Email', 'Gender')));
$this->CalculateData($Result->ResultArray());
return $Result;
}
|
php
|
public function GetNotifications($NotifyUserID, $Offset = '0', $Limit = '30') {
$this->ActivityQuery(FALSE);
$this->FireEvent('BeforeGetNotifications');
$Result = $this->SQL
->Where('NotifyUserID', $NotifyUserID)
->Limit($Limit, $Offset)
->OrderBy('a.ActivityID', 'desc')
->Get();
$Result->DatasetType(DATASET_TYPE_ARRAY);
self::GetUsers($Result->ResultArray());
Gdn::UserModel()->JoinUsers($Result->ResultArray(), array('ActivityUserID', 'RegardingUserID'), array('Join' => array('Name', 'Photo', 'Email', 'Gender')));
$this->CalculateData($Result->ResultArray());
return $Result;
}
|
[
"public",
"function",
"GetNotifications",
"(",
"$",
"NotifyUserID",
",",
"$",
"Offset",
"=",
"'0'",
",",
"$",
"Limit",
"=",
"'30'",
")",
"{",
"$",
"this",
"->",
"ActivityQuery",
"(",
"FALSE",
")",
";",
"$",
"this",
"->",
"FireEvent",
"(",
"'BeforeGetNotifications'",
")",
";",
"$",
"Result",
"=",
"$",
"this",
"->",
"SQL",
"->",
"Where",
"(",
"'NotifyUserID'",
",",
"$",
"NotifyUserID",
")",
"->",
"Limit",
"(",
"$",
"Limit",
",",
"$",
"Offset",
")",
"->",
"OrderBy",
"(",
"'a.ActivityID'",
",",
"'desc'",
")",
"->",
"Get",
"(",
")",
";",
"$",
"Result",
"->",
"DatasetType",
"(",
"DATASET_TYPE_ARRAY",
")",
";",
"self",
"::",
"GetUsers",
"(",
"$",
"Result",
"->",
"ResultArray",
"(",
")",
")",
";",
"Gdn",
"::",
"UserModel",
"(",
")",
"->",
"JoinUsers",
"(",
"$",
"Result",
"->",
"ResultArray",
"(",
")",
",",
"array",
"(",
"'ActivityUserID'",
",",
"'RegardingUserID'",
")",
",",
"array",
"(",
"'Join'",
"=>",
"array",
"(",
"'Name'",
",",
"'Photo'",
",",
"'Email'",
",",
"'Gender'",
")",
")",
")",
";",
"$",
"this",
"->",
"CalculateData",
"(",
"$",
"Result",
"->",
"ResultArray",
"(",
")",
")",
";",
"return",
"$",
"Result",
";",
"}"
] |
Get notifications for a user.
Events: BeforeGetNotifications.
@since 2.0.0
@access public
@param int $NotifyUserID Unique ID of user.
@param int $Offset Number to skip.
@param int $Limit Max number to return.
@return DataSet SQL results.
|
[
"Get",
"notifications",
"for",
"a",
"user",
"."
] |
8494eb4a4ad61603479015a8054d23ff488364e8
|
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/models/class.activitymodel.php#L460-L475
|
235,382
|
bishopb/vanilla
|
applications/dashboard/models/class.activitymodel.php
|
ActivityModel.GetNotificationsSince
|
public function GetNotificationsSince($UserID, $LastActivityID, $FilterToActivityTypeIDs = '', $Limit = '5') {
$this->ActivityQuery();
$this->FireEvent('BeforeGetNotificationsSince');
if (is_array($FilterToActivityTypeIDs))
$this->SQL->WhereIn('a.ActivityTypeID', $FilterToActivityTypeIDs);
else
$this->SQL->Where('t.Notify', '1');
$Result = $this->SQL
->Where('RegardingUserID', $UserID)
->Where('a.ActivityID >', $LastActivityID)
->Limit($Limit, 0)
->OrderBy('a.ActivityID', 'desc')
->Get();
return $Result;
}
|
php
|
public function GetNotificationsSince($UserID, $LastActivityID, $FilterToActivityTypeIDs = '', $Limit = '5') {
$this->ActivityQuery();
$this->FireEvent('BeforeGetNotificationsSince');
if (is_array($FilterToActivityTypeIDs))
$this->SQL->WhereIn('a.ActivityTypeID', $FilterToActivityTypeIDs);
else
$this->SQL->Where('t.Notify', '1');
$Result = $this->SQL
->Where('RegardingUserID', $UserID)
->Where('a.ActivityID >', $LastActivityID)
->Limit($Limit, 0)
->OrderBy('a.ActivityID', 'desc')
->Get();
return $Result;
}
|
[
"public",
"function",
"GetNotificationsSince",
"(",
"$",
"UserID",
",",
"$",
"LastActivityID",
",",
"$",
"FilterToActivityTypeIDs",
"=",
"''",
",",
"$",
"Limit",
"=",
"'5'",
")",
"{",
"$",
"this",
"->",
"ActivityQuery",
"(",
")",
";",
"$",
"this",
"->",
"FireEvent",
"(",
"'BeforeGetNotificationsSince'",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"FilterToActivityTypeIDs",
")",
")",
"$",
"this",
"->",
"SQL",
"->",
"WhereIn",
"(",
"'a.ActivityTypeID'",
",",
"$",
"FilterToActivityTypeIDs",
")",
";",
"else",
"$",
"this",
"->",
"SQL",
"->",
"Where",
"(",
"'t.Notify'",
",",
"'1'",
")",
";",
"$",
"Result",
"=",
"$",
"this",
"->",
"SQL",
"->",
"Where",
"(",
"'RegardingUserID'",
",",
"$",
"UserID",
")",
"->",
"Where",
"(",
"'a.ActivityID >'",
",",
"$",
"LastActivityID",
")",
"->",
"Limit",
"(",
"$",
"Limit",
",",
"0",
")",
"->",
"OrderBy",
"(",
"'a.ActivityID'",
",",
"'desc'",
")",
"->",
"Get",
"(",
")",
";",
"return",
"$",
"Result",
";",
"}"
] |
Get notifications for a user since designated ActivityID.
Events: BeforeGetNotificationsSince.
@since 2.0.18
@access public
@param int $UserID Unique ID of user.
@param int $LastActivityID ID of activity to start at.
@param array $FilterToActivityTypeIDs Limits returned activity to particular types.
@param int $Limit Max number to return.
@return DataSet SQL results.
|
[
"Get",
"notifications",
"for",
"a",
"user",
"since",
"designated",
"ActivityID",
"."
] |
8494eb4a4ad61603479015a8054d23ff488364e8
|
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/models/class.activitymodel.php#L490-L506
|
235,383
|
bishopb/vanilla
|
applications/dashboard/models/class.activitymodel.php
|
ActivityModel.GetComments
|
public function GetComments($ActivityIDs) {
$Result = $this->SQL
->Select('c.*')
->From('ActivityComment c')
->WhereIn('c.ActivityID', $ActivityIDs)
->OrderBy('c.ActivityID, c.DateInserted')
->Get()->ResultArray();
Gdn::UserModel()->JoinUsers($Result, array('InsertUserID'), array('Join' => array('Name', 'Photo', 'Email')));
return $Result;
}
|
php
|
public function GetComments($ActivityIDs) {
$Result = $this->SQL
->Select('c.*')
->From('ActivityComment c')
->WhereIn('c.ActivityID', $ActivityIDs)
->OrderBy('c.ActivityID, c.DateInserted')
->Get()->ResultArray();
Gdn::UserModel()->JoinUsers($Result, array('InsertUserID'), array('Join' => array('Name', 'Photo', 'Email')));
return $Result;
}
|
[
"public",
"function",
"GetComments",
"(",
"$",
"ActivityIDs",
")",
"{",
"$",
"Result",
"=",
"$",
"this",
"->",
"SQL",
"->",
"Select",
"(",
"'c.*'",
")",
"->",
"From",
"(",
"'ActivityComment c'",
")",
"->",
"WhereIn",
"(",
"'c.ActivityID'",
",",
"$",
"ActivityIDs",
")",
"->",
"OrderBy",
"(",
"'c.ActivityID, c.DateInserted'",
")",
"->",
"Get",
"(",
")",
"->",
"ResultArray",
"(",
")",
";",
"Gdn",
"::",
"UserModel",
"(",
")",
"->",
"JoinUsers",
"(",
"$",
"Result",
",",
"array",
"(",
"'InsertUserID'",
")",
",",
"array",
"(",
"'Join'",
"=>",
"array",
"(",
"'Name'",
",",
"'Photo'",
",",
"'Email'",
")",
")",
")",
";",
"return",
"$",
"Result",
";",
"}"
] |
Get comments related to designated activity items.
Events: BeforeGetComments.
@since 2.0.0
@access public
@param array $ActivityIDs IDs of activity items.
@return DataSet SQL results.
|
[
"Get",
"comments",
"related",
"to",
"designated",
"activity",
"items",
"."
] |
8494eb4a4ad61603479015a8054d23ff488364e8
|
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/models/class.activitymodel.php#L552-L561
|
235,384
|
bishopb/vanilla
|
applications/dashboard/models/class.activitymodel.php
|
ActivityModel.Add
|
public function Add($ActivityUserID, $ActivityType, $Story = NULL, $RegardingUserID = NULL, $CommentActivityID = NULL, $Route = NULL, $SendEmail = '') {
static $ActivityTypes = array();
// Get the ActivityTypeID & see if this is a notification.
$ActivityTypeRow = self::GetActivityType($ActivityType);
if ($ActivityTypeRow !== FALSE) {
$ActivityTypeID = $ActivityTypeRow['ActivityTypeID'];
$Notify = (bool)$ActivityTypeRow['Notify'];
} else {
trigger_error(ErrorMessage(sprintf('Activity type could not be found: %s', $ActivityType), 'ActivityModel', 'Add'), E_USER_ERROR);
}
$Activity = array(
'ActivityUserID' => $ActivityUserID,
'ActivityType' => $ActivityType,
'Story' => $Story,
'RegardingUserID' => $RegardingUserID,
'Route' => $Route
);
// Massage $SendEmail to allow for only sending an email.
$QueueEmail = FALSE;
if ($SendEmail === 'Only') {
$SendEmail = '';
$AddActivity = FALSE;
} else if ($SendEmail === 'QueueOnly') {
$SendEmail = '';
$QueueEmail = TRUE;
$AddActivity = TRUE;
$Notify = TRUE;
} else {
$AddActivity = TRUE;
}
// If $SendEmail was FALSE or TRUE, let it override the $Notify setting.
if ($SendEmail === FALSE || $SendEmail === TRUE)
$Notify = $SendEmail;
$Preference = FALSE;
if (($ActivityTypeRow['Notify'] || !$ActivityTypeRow['Public']) && $RegardingUserID) {
$Activity['NotifyUserID'] = $Activity['RegardingUserID'];
$Preference = $ActivityType;
} else {
$Activity['NotifyUserID'] = self::NOTIFY_PUBLIC;
}
// Otherwise let the decision to email lie with the $Notify setting.
if ($SendEmail == 'Force' || $Notify) {
$Activity['Emailed'] = self::SENT_PENDING;
} elseif ($Notify) {
$Activity['Emailed'] = self::SENT_PENDING;
} elseif ($SendEmail === FALSE) {
$Activity['Emailed'] = self::SENT_ARCHIVE;
}
$Activity = $this->Save($Activity, $Preference);
return GetValue('ActivityID', $Activity);
}
|
php
|
public function Add($ActivityUserID, $ActivityType, $Story = NULL, $RegardingUserID = NULL, $CommentActivityID = NULL, $Route = NULL, $SendEmail = '') {
static $ActivityTypes = array();
// Get the ActivityTypeID & see if this is a notification.
$ActivityTypeRow = self::GetActivityType($ActivityType);
if ($ActivityTypeRow !== FALSE) {
$ActivityTypeID = $ActivityTypeRow['ActivityTypeID'];
$Notify = (bool)$ActivityTypeRow['Notify'];
} else {
trigger_error(ErrorMessage(sprintf('Activity type could not be found: %s', $ActivityType), 'ActivityModel', 'Add'), E_USER_ERROR);
}
$Activity = array(
'ActivityUserID' => $ActivityUserID,
'ActivityType' => $ActivityType,
'Story' => $Story,
'RegardingUserID' => $RegardingUserID,
'Route' => $Route
);
// Massage $SendEmail to allow for only sending an email.
$QueueEmail = FALSE;
if ($SendEmail === 'Only') {
$SendEmail = '';
$AddActivity = FALSE;
} else if ($SendEmail === 'QueueOnly') {
$SendEmail = '';
$QueueEmail = TRUE;
$AddActivity = TRUE;
$Notify = TRUE;
} else {
$AddActivity = TRUE;
}
// If $SendEmail was FALSE or TRUE, let it override the $Notify setting.
if ($SendEmail === FALSE || $SendEmail === TRUE)
$Notify = $SendEmail;
$Preference = FALSE;
if (($ActivityTypeRow['Notify'] || !$ActivityTypeRow['Public']) && $RegardingUserID) {
$Activity['NotifyUserID'] = $Activity['RegardingUserID'];
$Preference = $ActivityType;
} else {
$Activity['NotifyUserID'] = self::NOTIFY_PUBLIC;
}
// Otherwise let the decision to email lie with the $Notify setting.
if ($SendEmail == 'Force' || $Notify) {
$Activity['Emailed'] = self::SENT_PENDING;
} elseif ($Notify) {
$Activity['Emailed'] = self::SENT_PENDING;
} elseif ($SendEmail === FALSE) {
$Activity['Emailed'] = self::SENT_ARCHIVE;
}
$Activity = $this->Save($Activity, $Preference);
return GetValue('ActivityID', $Activity);
}
|
[
"public",
"function",
"Add",
"(",
"$",
"ActivityUserID",
",",
"$",
"ActivityType",
",",
"$",
"Story",
"=",
"NULL",
",",
"$",
"RegardingUserID",
"=",
"NULL",
",",
"$",
"CommentActivityID",
"=",
"NULL",
",",
"$",
"Route",
"=",
"NULL",
",",
"$",
"SendEmail",
"=",
"''",
")",
"{",
"static",
"$",
"ActivityTypes",
"=",
"array",
"(",
")",
";",
"// Get the ActivityTypeID & see if this is a notification.",
"$",
"ActivityTypeRow",
"=",
"self",
"::",
"GetActivityType",
"(",
"$",
"ActivityType",
")",
";",
"if",
"(",
"$",
"ActivityTypeRow",
"!==",
"FALSE",
")",
"{",
"$",
"ActivityTypeID",
"=",
"$",
"ActivityTypeRow",
"[",
"'ActivityTypeID'",
"]",
";",
"$",
"Notify",
"=",
"(",
"bool",
")",
"$",
"ActivityTypeRow",
"[",
"'Notify'",
"]",
";",
"}",
"else",
"{",
"trigger_error",
"(",
"ErrorMessage",
"(",
"sprintf",
"(",
"'Activity type could not be found: %s'",
",",
"$",
"ActivityType",
")",
",",
"'ActivityModel'",
",",
"'Add'",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"Activity",
"=",
"array",
"(",
"'ActivityUserID'",
"=>",
"$",
"ActivityUserID",
",",
"'ActivityType'",
"=>",
"$",
"ActivityType",
",",
"'Story'",
"=>",
"$",
"Story",
",",
"'RegardingUserID'",
"=>",
"$",
"RegardingUserID",
",",
"'Route'",
"=>",
"$",
"Route",
")",
";",
"// Massage $SendEmail to allow for only sending an email.",
"$",
"QueueEmail",
"=",
"FALSE",
";",
"if",
"(",
"$",
"SendEmail",
"===",
"'Only'",
")",
"{",
"$",
"SendEmail",
"=",
"''",
";",
"$",
"AddActivity",
"=",
"FALSE",
";",
"}",
"else",
"if",
"(",
"$",
"SendEmail",
"===",
"'QueueOnly'",
")",
"{",
"$",
"SendEmail",
"=",
"''",
";",
"$",
"QueueEmail",
"=",
"TRUE",
";",
"$",
"AddActivity",
"=",
"TRUE",
";",
"$",
"Notify",
"=",
"TRUE",
";",
"}",
"else",
"{",
"$",
"AddActivity",
"=",
"TRUE",
";",
"}",
"// If $SendEmail was FALSE or TRUE, let it override the $Notify setting.",
"if",
"(",
"$",
"SendEmail",
"===",
"FALSE",
"||",
"$",
"SendEmail",
"===",
"TRUE",
")",
"$",
"Notify",
"=",
"$",
"SendEmail",
";",
"$",
"Preference",
"=",
"FALSE",
";",
"if",
"(",
"(",
"$",
"ActivityTypeRow",
"[",
"'Notify'",
"]",
"||",
"!",
"$",
"ActivityTypeRow",
"[",
"'Public'",
"]",
")",
"&&",
"$",
"RegardingUserID",
")",
"{",
"$",
"Activity",
"[",
"'NotifyUserID'",
"]",
"=",
"$",
"Activity",
"[",
"'RegardingUserID'",
"]",
";",
"$",
"Preference",
"=",
"$",
"ActivityType",
";",
"}",
"else",
"{",
"$",
"Activity",
"[",
"'NotifyUserID'",
"]",
"=",
"self",
"::",
"NOTIFY_PUBLIC",
";",
"}",
"// Otherwise let the decision to email lie with the $Notify setting.",
"if",
"(",
"$",
"SendEmail",
"==",
"'Force'",
"||",
"$",
"Notify",
")",
"{",
"$",
"Activity",
"[",
"'Emailed'",
"]",
"=",
"self",
"::",
"SENT_PENDING",
";",
"}",
"elseif",
"(",
"$",
"Notify",
")",
"{",
"$",
"Activity",
"[",
"'Emailed'",
"]",
"=",
"self",
"::",
"SENT_PENDING",
";",
"}",
"elseif",
"(",
"$",
"SendEmail",
"===",
"FALSE",
")",
"{",
"$",
"Activity",
"[",
"'Emailed'",
"]",
"=",
"self",
"::",
"SENT_ARCHIVE",
";",
"}",
"$",
"Activity",
"=",
"$",
"this",
"->",
"Save",
"(",
"$",
"Activity",
",",
"$",
"Preference",
")",
";",
"return",
"GetValue",
"(",
"'ActivityID'",
",",
"$",
"Activity",
")",
";",
"}"
] |
Add a new activity item.
Getting reworked for 2.1 so I'm cheating and skipping params for now. -mlr
@since 2.0.0
@access public
@param int $ActivityUserID
@param string $ActivityType
@param string $Story
@param int $RegardingUserID
@param int $CommentActivityID
@param string $Route
@param mixed $SendEmail
@return int ActivityID of item created.
|
[
"Add",
"a",
"new",
"activity",
"item",
"."
] |
8494eb4a4ad61603479015a8054d23ff488364e8
|
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/models/class.activitymodel.php#L579-L639
|
235,385
|
bishopb/vanilla
|
applications/dashboard/models/class.activitymodel.php
|
ActivityModel.NotificationPreference
|
public static function NotificationPreference($ActivityType, $Preferences, $Type = NULL) {
if (is_numeric($Preferences)) {
$User = Gdn::UserModel()->GetID($Preferences);
if (!$User)
return $Type == 'both' ? array(FALSE, FALSE) : FALSE;
$Preferences = GetValue('Preferences', $User);
}
if ($Type === NULL) {
$Result = self::NotificationPreference($ActivityType, $Preferences, 'Email')
|| self::NotificationPreference($ActivityType, $Preferences, 'Popup');
return $Result;
} elseif ($Type === 'both') {
$Result = array(
self::NotificationPreference($ActivityType, $Preferences, 'Popup'),
self::NotificationPreference($ActivityType, $Preferences, 'Email')
);
return $Result;
}
$ConfigPreference = C("Preferences.$Type.$ActivityType", '0');
if ((int)$ConfigPreference === 2)
$Preference = TRUE; // This preference is forced on.
if ($ConfigPreference !== FALSE)
$Preference = ArrayValue($Type.'.'.$ActivityType, $Preferences, $ConfigPreference);
else
$Preference = FALSE;
return $Preference;
}
|
php
|
public static function NotificationPreference($ActivityType, $Preferences, $Type = NULL) {
if (is_numeric($Preferences)) {
$User = Gdn::UserModel()->GetID($Preferences);
if (!$User)
return $Type == 'both' ? array(FALSE, FALSE) : FALSE;
$Preferences = GetValue('Preferences', $User);
}
if ($Type === NULL) {
$Result = self::NotificationPreference($ActivityType, $Preferences, 'Email')
|| self::NotificationPreference($ActivityType, $Preferences, 'Popup');
return $Result;
} elseif ($Type === 'both') {
$Result = array(
self::NotificationPreference($ActivityType, $Preferences, 'Popup'),
self::NotificationPreference($ActivityType, $Preferences, 'Email')
);
return $Result;
}
$ConfigPreference = C("Preferences.$Type.$ActivityType", '0');
if ((int)$ConfigPreference === 2)
$Preference = TRUE; // This preference is forced on.
if ($ConfigPreference !== FALSE)
$Preference = ArrayValue($Type.'.'.$ActivityType, $Preferences, $ConfigPreference);
else
$Preference = FALSE;
return $Preference;
}
|
[
"public",
"static",
"function",
"NotificationPreference",
"(",
"$",
"ActivityType",
",",
"$",
"Preferences",
",",
"$",
"Type",
"=",
"NULL",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"Preferences",
")",
")",
"{",
"$",
"User",
"=",
"Gdn",
"::",
"UserModel",
"(",
")",
"->",
"GetID",
"(",
"$",
"Preferences",
")",
";",
"if",
"(",
"!",
"$",
"User",
")",
"return",
"$",
"Type",
"==",
"'both'",
"?",
"array",
"(",
"FALSE",
",",
"FALSE",
")",
":",
"FALSE",
";",
"$",
"Preferences",
"=",
"GetValue",
"(",
"'Preferences'",
",",
"$",
"User",
")",
";",
"}",
"if",
"(",
"$",
"Type",
"===",
"NULL",
")",
"{",
"$",
"Result",
"=",
"self",
"::",
"NotificationPreference",
"(",
"$",
"ActivityType",
",",
"$",
"Preferences",
",",
"'Email'",
")",
"||",
"self",
"::",
"NotificationPreference",
"(",
"$",
"ActivityType",
",",
"$",
"Preferences",
",",
"'Popup'",
")",
";",
"return",
"$",
"Result",
";",
"}",
"elseif",
"(",
"$",
"Type",
"===",
"'both'",
")",
"{",
"$",
"Result",
"=",
"array",
"(",
"self",
"::",
"NotificationPreference",
"(",
"$",
"ActivityType",
",",
"$",
"Preferences",
",",
"'Popup'",
")",
",",
"self",
"::",
"NotificationPreference",
"(",
"$",
"ActivityType",
",",
"$",
"Preferences",
",",
"'Email'",
")",
")",
";",
"return",
"$",
"Result",
";",
"}",
"$",
"ConfigPreference",
"=",
"C",
"(",
"\"Preferences.$Type.$ActivityType\"",
",",
"'0'",
")",
";",
"if",
"(",
"(",
"int",
")",
"$",
"ConfigPreference",
"===",
"2",
")",
"$",
"Preference",
"=",
"TRUE",
";",
"// This preference is forced on.",
"if",
"(",
"$",
"ConfigPreference",
"!==",
"FALSE",
")",
"$",
"Preference",
"=",
"ArrayValue",
"(",
"$",
"Type",
".",
"'.'",
".",
"$",
"ActivityType",
",",
"$",
"Preferences",
",",
"$",
"ConfigPreference",
")",
";",
"else",
"$",
"Preference",
"=",
"FALSE",
";",
"return",
"$",
"Preference",
";",
"}"
] |
Get default notification preference for an activity type.
@since 2.0.0
@access public
@param string $ActivityType
@param array $Preferences
@param string $Type One of the following:
- Popup: Popup a notification.
- Email: Email the notification.
- NULL: True if either notification is true.
- both: Return an array of (Popup, Email).
@return bool
|
[
"Get",
"default",
"notification",
"preference",
"for",
"an",
"activity",
"type",
"."
] |
8494eb4a4ad61603479015a8054d23ff488364e8
|
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/models/class.activitymodel.php#L659-L689
|
235,386
|
bishopb/vanilla
|
applications/dashboard/models/class.activitymodel.php
|
ActivityModel.SendNotification
|
public function SendNotification($ActivityID, $Story = '', $Force = FALSE) {
$Activity = $this->GetID($ActivityID);
if (!$Activity)
return;
$Activity = (object)$Activity;
$Story = Gdn_Format::Text($Story == '' ? $Activity->Story : $Story, FALSE);
// If this is a comment on another activity, fudge the activity a bit so that everything appears properly.
if (is_null($Activity->RegardingUserID) && $Activity->CommentActivityID > 0) {
$CommentActivity = $this->GetID($Activity->CommentActivityID);
$Activity->RegardingUserID = $CommentActivity->RegardingUserID;
$Activity->Route = '/activity/item/'.$Activity->CommentActivityID;
}
$User = Gdn::UserModel()->GetID($Activity->RegardingUserID, DATASET_TYPE_OBJECT);
if ($User) {
if ($Force)
$Preference = $Force;
else {
$Preferences = $User->Preferences;
$Preference = ArrayValue('Email.'.$Activity->ActivityType, $Preferences, Gdn::Config('Preferences.Email.'.$Activity->ActivityType));
}
if ($Preference) {
$ActivityHeadline = Gdn_Format::Text(Gdn_Format::ActivityHeadline($Activity, $Activity->ActivityUserID, $Activity->RegardingUserID), FALSE);
$Email = new Gdn_Email();
$Email->Subject(sprintf(T('[%1$s] %2$s'), Gdn::Config('Garden.Title'), $ActivityHeadline));
$Email->To($User);
//$Email->From(Gdn::Config('Garden.SupportEmail'), Gdn::Config('Garden.SupportName'));
$Message = sprintf(
$Story == '' ? T('EmailNotification', "%1\$s\n\n%2\$s") : T('EmailStoryNotification', "%3\$s\n\n%2\$s"),
$ActivityHeadline,
ExternalUrl($Activity->Route == '' ? '/' : $Activity->Route),
$Story
);
$Email->Message($Message);
$Notification = array('ActivityID' => $ActivityID, 'User' => $User, 'Email' => $Email, 'Route' => $Activity->Route, 'Story' => $Story, 'Headline' => $ActivityHeadline, 'Activity' => $Activity);
$this->EventArguments = $Notification;
$this->FireEvent('BeforeSendNotification');
try {
// Only send if the user is not banned
if (!GetValue('Banned', $User))
$Email->Send();
$Emailed = self::SENT_OK;
} catch (phpmailerException $pex) {
if ($pex->getCode() == PHPMailer::STOP_CRITICAL)
$Emailed = self::SENT_FAIL;
else
$Emailed = self::SENT_ERROR;
} catch (Exception $ex) {
$Emailed = self::SENT_FAIL; // similar to http 5xx
}
try {
$this->SQL->Put('Activity', array('Emailed' => $Emailed), array('ActivityID' => $ActivityID));
} catch (Exception $Ex) {
}
}
}
}
|
php
|
public function SendNotification($ActivityID, $Story = '', $Force = FALSE) {
$Activity = $this->GetID($ActivityID);
if (!$Activity)
return;
$Activity = (object)$Activity;
$Story = Gdn_Format::Text($Story == '' ? $Activity->Story : $Story, FALSE);
// If this is a comment on another activity, fudge the activity a bit so that everything appears properly.
if (is_null($Activity->RegardingUserID) && $Activity->CommentActivityID > 0) {
$CommentActivity = $this->GetID($Activity->CommentActivityID);
$Activity->RegardingUserID = $CommentActivity->RegardingUserID;
$Activity->Route = '/activity/item/'.$Activity->CommentActivityID;
}
$User = Gdn::UserModel()->GetID($Activity->RegardingUserID, DATASET_TYPE_OBJECT);
if ($User) {
if ($Force)
$Preference = $Force;
else {
$Preferences = $User->Preferences;
$Preference = ArrayValue('Email.'.$Activity->ActivityType, $Preferences, Gdn::Config('Preferences.Email.'.$Activity->ActivityType));
}
if ($Preference) {
$ActivityHeadline = Gdn_Format::Text(Gdn_Format::ActivityHeadline($Activity, $Activity->ActivityUserID, $Activity->RegardingUserID), FALSE);
$Email = new Gdn_Email();
$Email->Subject(sprintf(T('[%1$s] %2$s'), Gdn::Config('Garden.Title'), $ActivityHeadline));
$Email->To($User);
//$Email->From(Gdn::Config('Garden.SupportEmail'), Gdn::Config('Garden.SupportName'));
$Message = sprintf(
$Story == '' ? T('EmailNotification', "%1\$s\n\n%2\$s") : T('EmailStoryNotification', "%3\$s\n\n%2\$s"),
$ActivityHeadline,
ExternalUrl($Activity->Route == '' ? '/' : $Activity->Route),
$Story
);
$Email->Message($Message);
$Notification = array('ActivityID' => $ActivityID, 'User' => $User, 'Email' => $Email, 'Route' => $Activity->Route, 'Story' => $Story, 'Headline' => $ActivityHeadline, 'Activity' => $Activity);
$this->EventArguments = $Notification;
$this->FireEvent('BeforeSendNotification');
try {
// Only send if the user is not banned
if (!GetValue('Banned', $User))
$Email->Send();
$Emailed = self::SENT_OK;
} catch (phpmailerException $pex) {
if ($pex->getCode() == PHPMailer::STOP_CRITICAL)
$Emailed = self::SENT_FAIL;
else
$Emailed = self::SENT_ERROR;
} catch (Exception $ex) {
$Emailed = self::SENT_FAIL; // similar to http 5xx
}
try {
$this->SQL->Put('Activity', array('Emailed' => $Emailed), array('ActivityID' => $ActivityID));
} catch (Exception $Ex) {
}
}
}
}
|
[
"public",
"function",
"SendNotification",
"(",
"$",
"ActivityID",
",",
"$",
"Story",
"=",
"''",
",",
"$",
"Force",
"=",
"FALSE",
")",
"{",
"$",
"Activity",
"=",
"$",
"this",
"->",
"GetID",
"(",
"$",
"ActivityID",
")",
";",
"if",
"(",
"!",
"$",
"Activity",
")",
"return",
";",
"$",
"Activity",
"=",
"(",
"object",
")",
"$",
"Activity",
";",
"$",
"Story",
"=",
"Gdn_Format",
"::",
"Text",
"(",
"$",
"Story",
"==",
"''",
"?",
"$",
"Activity",
"->",
"Story",
":",
"$",
"Story",
",",
"FALSE",
")",
";",
"// If this is a comment on another activity, fudge the activity a bit so that everything appears properly.",
"if",
"(",
"is_null",
"(",
"$",
"Activity",
"->",
"RegardingUserID",
")",
"&&",
"$",
"Activity",
"->",
"CommentActivityID",
">",
"0",
")",
"{",
"$",
"CommentActivity",
"=",
"$",
"this",
"->",
"GetID",
"(",
"$",
"Activity",
"->",
"CommentActivityID",
")",
";",
"$",
"Activity",
"->",
"RegardingUserID",
"=",
"$",
"CommentActivity",
"->",
"RegardingUserID",
";",
"$",
"Activity",
"->",
"Route",
"=",
"'/activity/item/'",
".",
"$",
"Activity",
"->",
"CommentActivityID",
";",
"}",
"$",
"User",
"=",
"Gdn",
"::",
"UserModel",
"(",
")",
"->",
"GetID",
"(",
"$",
"Activity",
"->",
"RegardingUserID",
",",
"DATASET_TYPE_OBJECT",
")",
";",
"if",
"(",
"$",
"User",
")",
"{",
"if",
"(",
"$",
"Force",
")",
"$",
"Preference",
"=",
"$",
"Force",
";",
"else",
"{",
"$",
"Preferences",
"=",
"$",
"User",
"->",
"Preferences",
";",
"$",
"Preference",
"=",
"ArrayValue",
"(",
"'Email.'",
".",
"$",
"Activity",
"->",
"ActivityType",
",",
"$",
"Preferences",
",",
"Gdn",
"::",
"Config",
"(",
"'Preferences.Email.'",
".",
"$",
"Activity",
"->",
"ActivityType",
")",
")",
";",
"}",
"if",
"(",
"$",
"Preference",
")",
"{",
"$",
"ActivityHeadline",
"=",
"Gdn_Format",
"::",
"Text",
"(",
"Gdn_Format",
"::",
"ActivityHeadline",
"(",
"$",
"Activity",
",",
"$",
"Activity",
"->",
"ActivityUserID",
",",
"$",
"Activity",
"->",
"RegardingUserID",
")",
",",
"FALSE",
")",
";",
"$",
"Email",
"=",
"new",
"Gdn_Email",
"(",
")",
";",
"$",
"Email",
"->",
"Subject",
"(",
"sprintf",
"(",
"T",
"(",
"'[%1$s] %2$s'",
")",
",",
"Gdn",
"::",
"Config",
"(",
"'Garden.Title'",
")",
",",
"$",
"ActivityHeadline",
")",
")",
";",
"$",
"Email",
"->",
"To",
"(",
"$",
"User",
")",
";",
"//$Email->From(Gdn::Config('Garden.SupportEmail'), Gdn::Config('Garden.SupportName'));",
"$",
"Message",
"=",
"sprintf",
"(",
"$",
"Story",
"==",
"''",
"?",
"T",
"(",
"'EmailNotification'",
",",
"\"%1\\$s\\n\\n%2\\$s\"",
")",
":",
"T",
"(",
"'EmailStoryNotification'",
",",
"\"%3\\$s\\n\\n%2\\$s\"",
")",
",",
"$",
"ActivityHeadline",
",",
"ExternalUrl",
"(",
"$",
"Activity",
"->",
"Route",
"==",
"''",
"?",
"'/'",
":",
"$",
"Activity",
"->",
"Route",
")",
",",
"$",
"Story",
")",
";",
"$",
"Email",
"->",
"Message",
"(",
"$",
"Message",
")",
";",
"$",
"Notification",
"=",
"array",
"(",
"'ActivityID'",
"=>",
"$",
"ActivityID",
",",
"'User'",
"=>",
"$",
"User",
",",
"'Email'",
"=>",
"$",
"Email",
",",
"'Route'",
"=>",
"$",
"Activity",
"->",
"Route",
",",
"'Story'",
"=>",
"$",
"Story",
",",
"'Headline'",
"=>",
"$",
"ActivityHeadline",
",",
"'Activity'",
"=>",
"$",
"Activity",
")",
";",
"$",
"this",
"->",
"EventArguments",
"=",
"$",
"Notification",
";",
"$",
"this",
"->",
"FireEvent",
"(",
"'BeforeSendNotification'",
")",
";",
"try",
"{",
"// Only send if the user is not banned",
"if",
"(",
"!",
"GetValue",
"(",
"'Banned'",
",",
"$",
"User",
")",
")",
"$",
"Email",
"->",
"Send",
"(",
")",
";",
"$",
"Emailed",
"=",
"self",
"::",
"SENT_OK",
";",
"}",
"catch",
"(",
"phpmailerException",
"$",
"pex",
")",
"{",
"if",
"(",
"$",
"pex",
"->",
"getCode",
"(",
")",
"==",
"PHPMailer",
"::",
"STOP_CRITICAL",
")",
"$",
"Emailed",
"=",
"self",
"::",
"SENT_FAIL",
";",
"else",
"$",
"Emailed",
"=",
"self",
"::",
"SENT_ERROR",
";",
"}",
"catch",
"(",
"Exception",
"$",
"ex",
")",
"{",
"$",
"Emailed",
"=",
"self",
"::",
"SENT_FAIL",
";",
"// similar to http 5xx",
"}",
"try",
"{",
"$",
"this",
"->",
"SQL",
"->",
"Put",
"(",
"'Activity'",
",",
"array",
"(",
"'Emailed'",
"=>",
"$",
"Emailed",
")",
",",
"array",
"(",
"'ActivityID'",
"=>",
"$",
"ActivityID",
")",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"Ex",
")",
"{",
"}",
"}",
"}",
"}"
] |
Send notification.
@since 2.0.17
@access public
@param int $ActivityID
@param array $Story
@param string $Force
|
[
"Send",
"notification",
"."
] |
8494eb4a4ad61603479015a8054d23ff488364e8
|
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/models/class.activitymodel.php#L700-L762
|
235,387
|
bishopb/vanilla
|
applications/dashboard/models/class.activitymodel.php
|
ActivityModel.Comment
|
public function Comment($Comment) {
$Comment['InsertUserID'] = Gdn::Session()->UserID;
$Comment['DateInserted'] = Gdn_Format::ToDateTime();
$Comment['InsertIPAddress'] = Gdn::Request()->IpAddress();
$this->Validation->ApplyRule('ActivityID', 'Required');
$this->Validation->ApplyRule('Body', 'Required');
$this->Validation->ApplyRule('DateInserted', 'Required');
$this->Validation->ApplyRule('InsertUserID', 'Required');
$this->EventArguments['Comment'] = $Comment;
$this->FireEvent('BeforeSaveComment');
if ($this->Validate($Comment)) {
$Activity = $this->GetID($Comment['ActivityID'], DATASET_TYPE_ARRAY);
Gdn::Controller()->Json('Activity', $CommentActivityID);
$_ActivityID = $Comment['ActivityID'];
// Check to see if this is a shared activity/notification.
if ($CommentActivityID = GetValue('CommentActivityID', $Activity['Data'])) {
Gdn::Controller()->Json('CommentActivityID', $CommentActivityID);
$Comment['ActivityID'] = $CommentActivityID;
}
// Check for spam.
$Spam = SpamModel::IsSpam('ActivityComment', $Comment);
if ($Spam)
return SPAM;
// Check for approval
$ApprovalRequired = CheckRestriction('Vanilla.Approval.Require');
if ($ApprovalRequired && !GetValue('Verified', Gdn::Session()->User)) {
LogModel::Insert('Pending', 'ActivityComment', $Comment);
return UNAPPROVED;
}
$ID = $this->SQL->Insert('ActivityComment', $Comment);
if ($ID) {
// Check to see if this comment bumps the activity.
if ($Activity && GetValue('Bump', $Activity['Data'])) {
$this->SQL->Put('Activity', array('DateUpdated' => $Comment['DateInserted']), array('ActivityID' => $Activity['ActivityID']));
if ($_ActivityID != $Comment['ActivityID']) {
$this->SQL->Put('Activity', array('DateUpdated' => $Comment['DateInserted']), array('ActivityID' => $_ActivityID));
}
}
}
return $ID;
}
return FALSE;
}
|
php
|
public function Comment($Comment) {
$Comment['InsertUserID'] = Gdn::Session()->UserID;
$Comment['DateInserted'] = Gdn_Format::ToDateTime();
$Comment['InsertIPAddress'] = Gdn::Request()->IpAddress();
$this->Validation->ApplyRule('ActivityID', 'Required');
$this->Validation->ApplyRule('Body', 'Required');
$this->Validation->ApplyRule('DateInserted', 'Required');
$this->Validation->ApplyRule('InsertUserID', 'Required');
$this->EventArguments['Comment'] = $Comment;
$this->FireEvent('BeforeSaveComment');
if ($this->Validate($Comment)) {
$Activity = $this->GetID($Comment['ActivityID'], DATASET_TYPE_ARRAY);
Gdn::Controller()->Json('Activity', $CommentActivityID);
$_ActivityID = $Comment['ActivityID'];
// Check to see if this is a shared activity/notification.
if ($CommentActivityID = GetValue('CommentActivityID', $Activity['Data'])) {
Gdn::Controller()->Json('CommentActivityID', $CommentActivityID);
$Comment['ActivityID'] = $CommentActivityID;
}
// Check for spam.
$Spam = SpamModel::IsSpam('ActivityComment', $Comment);
if ($Spam)
return SPAM;
// Check for approval
$ApprovalRequired = CheckRestriction('Vanilla.Approval.Require');
if ($ApprovalRequired && !GetValue('Verified', Gdn::Session()->User)) {
LogModel::Insert('Pending', 'ActivityComment', $Comment);
return UNAPPROVED;
}
$ID = $this->SQL->Insert('ActivityComment', $Comment);
if ($ID) {
// Check to see if this comment bumps the activity.
if ($Activity && GetValue('Bump', $Activity['Data'])) {
$this->SQL->Put('Activity', array('DateUpdated' => $Comment['DateInserted']), array('ActivityID' => $Activity['ActivityID']));
if ($_ActivityID != $Comment['ActivityID']) {
$this->SQL->Put('Activity', array('DateUpdated' => $Comment['DateInserted']), array('ActivityID' => $_ActivityID));
}
}
}
return $ID;
}
return FALSE;
}
|
[
"public",
"function",
"Comment",
"(",
"$",
"Comment",
")",
"{",
"$",
"Comment",
"[",
"'InsertUserID'",
"]",
"=",
"Gdn",
"::",
"Session",
"(",
")",
"->",
"UserID",
";",
"$",
"Comment",
"[",
"'DateInserted'",
"]",
"=",
"Gdn_Format",
"::",
"ToDateTime",
"(",
")",
";",
"$",
"Comment",
"[",
"'InsertIPAddress'",
"]",
"=",
"Gdn",
"::",
"Request",
"(",
")",
"->",
"IpAddress",
"(",
")",
";",
"$",
"this",
"->",
"Validation",
"->",
"ApplyRule",
"(",
"'ActivityID'",
",",
"'Required'",
")",
";",
"$",
"this",
"->",
"Validation",
"->",
"ApplyRule",
"(",
"'Body'",
",",
"'Required'",
")",
";",
"$",
"this",
"->",
"Validation",
"->",
"ApplyRule",
"(",
"'DateInserted'",
",",
"'Required'",
")",
";",
"$",
"this",
"->",
"Validation",
"->",
"ApplyRule",
"(",
"'InsertUserID'",
",",
"'Required'",
")",
";",
"$",
"this",
"->",
"EventArguments",
"[",
"'Comment'",
"]",
"=",
"$",
"Comment",
";",
"$",
"this",
"->",
"FireEvent",
"(",
"'BeforeSaveComment'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"Validate",
"(",
"$",
"Comment",
")",
")",
"{",
"$",
"Activity",
"=",
"$",
"this",
"->",
"GetID",
"(",
"$",
"Comment",
"[",
"'ActivityID'",
"]",
",",
"DATASET_TYPE_ARRAY",
")",
";",
"Gdn",
"::",
"Controller",
"(",
")",
"->",
"Json",
"(",
"'Activity'",
",",
"$",
"CommentActivityID",
")",
";",
"$",
"_ActivityID",
"=",
"$",
"Comment",
"[",
"'ActivityID'",
"]",
";",
"// Check to see if this is a shared activity/notification.",
"if",
"(",
"$",
"CommentActivityID",
"=",
"GetValue",
"(",
"'CommentActivityID'",
",",
"$",
"Activity",
"[",
"'Data'",
"]",
")",
")",
"{",
"Gdn",
"::",
"Controller",
"(",
")",
"->",
"Json",
"(",
"'CommentActivityID'",
",",
"$",
"CommentActivityID",
")",
";",
"$",
"Comment",
"[",
"'ActivityID'",
"]",
"=",
"$",
"CommentActivityID",
";",
"}",
"// Check for spam.",
"$",
"Spam",
"=",
"SpamModel",
"::",
"IsSpam",
"(",
"'ActivityComment'",
",",
"$",
"Comment",
")",
";",
"if",
"(",
"$",
"Spam",
")",
"return",
"SPAM",
";",
"// Check for approval",
"$",
"ApprovalRequired",
"=",
"CheckRestriction",
"(",
"'Vanilla.Approval.Require'",
")",
";",
"if",
"(",
"$",
"ApprovalRequired",
"&&",
"!",
"GetValue",
"(",
"'Verified'",
",",
"Gdn",
"::",
"Session",
"(",
")",
"->",
"User",
")",
")",
"{",
"LogModel",
"::",
"Insert",
"(",
"'Pending'",
",",
"'ActivityComment'",
",",
"$",
"Comment",
")",
";",
"return",
"UNAPPROVED",
";",
"}",
"$",
"ID",
"=",
"$",
"this",
"->",
"SQL",
"->",
"Insert",
"(",
"'ActivityComment'",
",",
"$",
"Comment",
")",
";",
"if",
"(",
"$",
"ID",
")",
"{",
"// Check to see if this comment bumps the activity.",
"if",
"(",
"$",
"Activity",
"&&",
"GetValue",
"(",
"'Bump'",
",",
"$",
"Activity",
"[",
"'Data'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"SQL",
"->",
"Put",
"(",
"'Activity'",
",",
"array",
"(",
"'DateUpdated'",
"=>",
"$",
"Comment",
"[",
"'DateInserted'",
"]",
")",
",",
"array",
"(",
"'ActivityID'",
"=>",
"$",
"Activity",
"[",
"'ActivityID'",
"]",
")",
")",
";",
"if",
"(",
"$",
"_ActivityID",
"!=",
"$",
"Comment",
"[",
"'ActivityID'",
"]",
")",
"{",
"$",
"this",
"->",
"SQL",
"->",
"Put",
"(",
"'Activity'",
",",
"array",
"(",
"'DateUpdated'",
"=>",
"$",
"Comment",
"[",
"'DateInserted'",
"]",
")",
",",
"array",
"(",
"'ActivityID'",
"=>",
"$",
"_ActivityID",
")",
")",
";",
"}",
"}",
"}",
"return",
"$",
"ID",
";",
"}",
"return",
"FALSE",
";",
"}"
] |
Save a comment on an activity.
@param array $Comment
@return int|bool
@since 2.1
|
[
"Save",
"a",
"comment",
"on",
"an",
"activity",
"."
] |
8494eb4a4ad61603479015a8054d23ff488364e8
|
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/models/class.activitymodel.php#L886-L937
|
235,388
|
bishopb/vanilla
|
applications/dashboard/models/class.activitymodel.php
|
ActivityModel.SendNotificationQueue
|
public function SendNotificationQueue() {
foreach ($this->_NotificationQueue as $UserID => $Notifications) {
if (is_array($Notifications)) {
// Only send out one notification per user.
$Notification = $Notifications[0];
$Email = $Notification['Email'];
if (is_object($Email)) {
$this->EventArguments = $Notification;
$this->FireEvent('BeforeSendNotification');
try {
// Only send if the user is not banned
$User = Gdn::UserModel()->GetID($UserID);
if (!GetValue('Banned', $User))
$Email->Send();
$Emailed = self::SENT_OK;
} catch (phpmailerException $pex) {
if ($pex->getCode() == PHPMailer::STOP_CRITICAL)
$Emailed = self::SENT_FAIL;
else
$Emailed = self::SENT_ERROR;
} catch(Exception $Ex) {
$Emailed = self::SENT_FAIL;
}
try {
$this->SQL->Put('Activity', array('Emailed' => $Emailed), array('ActivityID' => $Notification['ActivityID']));
} catch (Exception $Ex) {
}
}
}
}
// Clear out the queue
unset($this->_NotificationQueue);
$this->_NotificationQueue = array();
}
|
php
|
public function SendNotificationQueue() {
foreach ($this->_NotificationQueue as $UserID => $Notifications) {
if (is_array($Notifications)) {
// Only send out one notification per user.
$Notification = $Notifications[0];
$Email = $Notification['Email'];
if (is_object($Email)) {
$this->EventArguments = $Notification;
$this->FireEvent('BeforeSendNotification');
try {
// Only send if the user is not banned
$User = Gdn::UserModel()->GetID($UserID);
if (!GetValue('Banned', $User))
$Email->Send();
$Emailed = self::SENT_OK;
} catch (phpmailerException $pex) {
if ($pex->getCode() == PHPMailer::STOP_CRITICAL)
$Emailed = self::SENT_FAIL;
else
$Emailed = self::SENT_ERROR;
} catch(Exception $Ex) {
$Emailed = self::SENT_FAIL;
}
try {
$this->SQL->Put('Activity', array('Emailed' => $Emailed), array('ActivityID' => $Notification['ActivityID']));
} catch (Exception $Ex) {
}
}
}
}
// Clear out the queue
unset($this->_NotificationQueue);
$this->_NotificationQueue = array();
}
|
[
"public",
"function",
"SendNotificationQueue",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"_NotificationQueue",
"as",
"$",
"UserID",
"=>",
"$",
"Notifications",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"Notifications",
")",
")",
"{",
"// Only send out one notification per user.",
"$",
"Notification",
"=",
"$",
"Notifications",
"[",
"0",
"]",
";",
"$",
"Email",
"=",
"$",
"Notification",
"[",
"'Email'",
"]",
";",
"if",
"(",
"is_object",
"(",
"$",
"Email",
")",
")",
"{",
"$",
"this",
"->",
"EventArguments",
"=",
"$",
"Notification",
";",
"$",
"this",
"->",
"FireEvent",
"(",
"'BeforeSendNotification'",
")",
";",
"try",
"{",
"// Only send if the user is not banned",
"$",
"User",
"=",
"Gdn",
"::",
"UserModel",
"(",
")",
"->",
"GetID",
"(",
"$",
"UserID",
")",
";",
"if",
"(",
"!",
"GetValue",
"(",
"'Banned'",
",",
"$",
"User",
")",
")",
"$",
"Email",
"->",
"Send",
"(",
")",
";",
"$",
"Emailed",
"=",
"self",
"::",
"SENT_OK",
";",
"}",
"catch",
"(",
"phpmailerException",
"$",
"pex",
")",
"{",
"if",
"(",
"$",
"pex",
"->",
"getCode",
"(",
")",
"==",
"PHPMailer",
"::",
"STOP_CRITICAL",
")",
"$",
"Emailed",
"=",
"self",
"::",
"SENT_FAIL",
";",
"else",
"$",
"Emailed",
"=",
"self",
"::",
"SENT_ERROR",
";",
"}",
"catch",
"(",
"Exception",
"$",
"Ex",
")",
"{",
"$",
"Emailed",
"=",
"self",
"::",
"SENT_FAIL",
";",
"}",
"try",
"{",
"$",
"this",
"->",
"SQL",
"->",
"Put",
"(",
"'Activity'",
",",
"array",
"(",
"'Emailed'",
"=>",
"$",
"Emailed",
")",
",",
"array",
"(",
"'ActivityID'",
"=>",
"$",
"Notification",
"[",
"'ActivityID'",
"]",
")",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"Ex",
")",
"{",
"}",
"}",
"}",
"}",
"// Clear out the queue",
"unset",
"(",
"$",
"this",
"->",
"_NotificationQueue",
")",
";",
"$",
"this",
"->",
"_NotificationQueue",
"=",
"array",
"(",
")",
";",
"}"
] |
Send all notifications in the queue.
@since 2.0.17
@access public
|
[
"Send",
"all",
"notifications",
"in",
"the",
"queue",
"."
] |
8494eb4a4ad61603479015a8054d23ff488364e8
|
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/models/class.activitymodel.php#L945-L984
|
235,389
|
bishopb/vanilla
|
applications/dashboard/models/class.activitymodel.php
|
ActivityModel.QueueNotification
|
public function QueueNotification($ActivityID, $Story = '', $Position = 'last', $Force = FALSE) {
$Activity = $this->GetID($ActivityID);
if (!is_object($Activity))
return;
$Story = Gdn_Format::Text($Story == '' ? $Activity->Story : $Story, FALSE);
// If this is a comment on another activity, fudge the activity a bit so that everything appears properly.
if (is_null($Activity->RegardingUserID) && $Activity->CommentActivityID > 0) {
$CommentActivity = $this->GetID($Activity->CommentActivityID);
$Activity->RegardingUserID = $CommentActivity->RegardingUserID;
$Activity->Route = '/activity/item/'.$Activity->CommentActivityID;
}
$User = Gdn::UserModel()->GetID($Activity->RegardingUserID, DATASET_TYPE_OBJECT); //$this->SQL->Select('UserID, Name, Email, Preferences')->From('User')->Where('UserID', $Activity->RegardingUserID)->Get()->FirstRow();
if ($User) {
if ($Force)
$Preference = $Force;
else {
// $Preferences = Gdn_Format::Unserialize($User->Preferences);
$ConfigPreference = C('Preferences.Email.'.$Activity->ActivityType, '0');
if ($ConfigPreference !== FALSE)
$Preference = GetValue('Email.'.$Activity->ActivityType, $User->Preferences, $ConfigPreference);
else
$Preference = FALSE;
}
if ($Preference) {
$ActivityHeadline = Gdn_Format::Text(Gdn_Format::ActivityHeadline($Activity, $Activity->ActivityUserID, $Activity->RegardingUserID), FALSE);
$Email = new Gdn_Email();
$Email->Subject(sprintf(T('[%1$s] %2$s'), Gdn::Config('Garden.Title'), $ActivityHeadline));
$Email->To($User);
$Message = sprintf(
$Story == '' ? T('EmailNotification', "%1\$s\n\n%2\$s") : T('EmailStoryNotification', "%3\$s\n\n%2\$s"),
$ActivityHeadline,
ExternalUrl($Activity->Route == '' ? '/' : $Activity->Route),
$Story
);
$Email->Message($Message);
if (!array_key_exists($User->UserID, $this->_NotificationQueue))
$this->_NotificationQueue[$User->UserID] = array();
$Notification = array('ActivityID' => $ActivityID, 'User' => $User, 'Email' => $Email, 'Route' => $Activity->Route, 'Story' => $Story, 'Headline' => $ActivityHeadline, 'Activity' => $Activity);
if ($Position == 'first')
$this->_NotificationQueue[$User->UserID] = array_merge(array($Notification), $this->_NotificationQueue[$User->UserID]);
else
$this->_NotificationQueue[$User->UserID][] = $Notification;
}
}
}
|
php
|
public function QueueNotification($ActivityID, $Story = '', $Position = 'last', $Force = FALSE) {
$Activity = $this->GetID($ActivityID);
if (!is_object($Activity))
return;
$Story = Gdn_Format::Text($Story == '' ? $Activity->Story : $Story, FALSE);
// If this is a comment on another activity, fudge the activity a bit so that everything appears properly.
if (is_null($Activity->RegardingUserID) && $Activity->CommentActivityID > 0) {
$CommentActivity = $this->GetID($Activity->CommentActivityID);
$Activity->RegardingUserID = $CommentActivity->RegardingUserID;
$Activity->Route = '/activity/item/'.$Activity->CommentActivityID;
}
$User = Gdn::UserModel()->GetID($Activity->RegardingUserID, DATASET_TYPE_OBJECT); //$this->SQL->Select('UserID, Name, Email, Preferences')->From('User')->Where('UserID', $Activity->RegardingUserID)->Get()->FirstRow();
if ($User) {
if ($Force)
$Preference = $Force;
else {
// $Preferences = Gdn_Format::Unserialize($User->Preferences);
$ConfigPreference = C('Preferences.Email.'.$Activity->ActivityType, '0');
if ($ConfigPreference !== FALSE)
$Preference = GetValue('Email.'.$Activity->ActivityType, $User->Preferences, $ConfigPreference);
else
$Preference = FALSE;
}
if ($Preference) {
$ActivityHeadline = Gdn_Format::Text(Gdn_Format::ActivityHeadline($Activity, $Activity->ActivityUserID, $Activity->RegardingUserID), FALSE);
$Email = new Gdn_Email();
$Email->Subject(sprintf(T('[%1$s] %2$s'), Gdn::Config('Garden.Title'), $ActivityHeadline));
$Email->To($User);
$Message = sprintf(
$Story == '' ? T('EmailNotification', "%1\$s\n\n%2\$s") : T('EmailStoryNotification', "%3\$s\n\n%2\$s"),
$ActivityHeadline,
ExternalUrl($Activity->Route == '' ? '/' : $Activity->Route),
$Story
);
$Email->Message($Message);
if (!array_key_exists($User->UserID, $this->_NotificationQueue))
$this->_NotificationQueue[$User->UserID] = array();
$Notification = array('ActivityID' => $ActivityID, 'User' => $User, 'Email' => $Email, 'Route' => $Activity->Route, 'Story' => $Story, 'Headline' => $ActivityHeadline, 'Activity' => $Activity);
if ($Position == 'first')
$this->_NotificationQueue[$User->UserID] = array_merge(array($Notification), $this->_NotificationQueue[$User->UserID]);
else
$this->_NotificationQueue[$User->UserID][] = $Notification;
}
}
}
|
[
"public",
"function",
"QueueNotification",
"(",
"$",
"ActivityID",
",",
"$",
"Story",
"=",
"''",
",",
"$",
"Position",
"=",
"'last'",
",",
"$",
"Force",
"=",
"FALSE",
")",
"{",
"$",
"Activity",
"=",
"$",
"this",
"->",
"GetID",
"(",
"$",
"ActivityID",
")",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"Activity",
")",
")",
"return",
";",
"$",
"Story",
"=",
"Gdn_Format",
"::",
"Text",
"(",
"$",
"Story",
"==",
"''",
"?",
"$",
"Activity",
"->",
"Story",
":",
"$",
"Story",
",",
"FALSE",
")",
";",
"// If this is a comment on another activity, fudge the activity a bit so that everything appears properly.",
"if",
"(",
"is_null",
"(",
"$",
"Activity",
"->",
"RegardingUserID",
")",
"&&",
"$",
"Activity",
"->",
"CommentActivityID",
">",
"0",
")",
"{",
"$",
"CommentActivity",
"=",
"$",
"this",
"->",
"GetID",
"(",
"$",
"Activity",
"->",
"CommentActivityID",
")",
";",
"$",
"Activity",
"->",
"RegardingUserID",
"=",
"$",
"CommentActivity",
"->",
"RegardingUserID",
";",
"$",
"Activity",
"->",
"Route",
"=",
"'/activity/item/'",
".",
"$",
"Activity",
"->",
"CommentActivityID",
";",
"}",
"$",
"User",
"=",
"Gdn",
"::",
"UserModel",
"(",
")",
"->",
"GetID",
"(",
"$",
"Activity",
"->",
"RegardingUserID",
",",
"DATASET_TYPE_OBJECT",
")",
";",
"//$this->SQL->Select('UserID, Name, Email, Preferences')->From('User')->Where('UserID', $Activity->RegardingUserID)->Get()->FirstRow();",
"if",
"(",
"$",
"User",
")",
"{",
"if",
"(",
"$",
"Force",
")",
"$",
"Preference",
"=",
"$",
"Force",
";",
"else",
"{",
"// $Preferences = Gdn_Format::Unserialize($User->Preferences);",
"$",
"ConfigPreference",
"=",
"C",
"(",
"'Preferences.Email.'",
".",
"$",
"Activity",
"->",
"ActivityType",
",",
"'0'",
")",
";",
"if",
"(",
"$",
"ConfigPreference",
"!==",
"FALSE",
")",
"$",
"Preference",
"=",
"GetValue",
"(",
"'Email.'",
".",
"$",
"Activity",
"->",
"ActivityType",
",",
"$",
"User",
"->",
"Preferences",
",",
"$",
"ConfigPreference",
")",
";",
"else",
"$",
"Preference",
"=",
"FALSE",
";",
"}",
"if",
"(",
"$",
"Preference",
")",
"{",
"$",
"ActivityHeadline",
"=",
"Gdn_Format",
"::",
"Text",
"(",
"Gdn_Format",
"::",
"ActivityHeadline",
"(",
"$",
"Activity",
",",
"$",
"Activity",
"->",
"ActivityUserID",
",",
"$",
"Activity",
"->",
"RegardingUserID",
")",
",",
"FALSE",
")",
";",
"$",
"Email",
"=",
"new",
"Gdn_Email",
"(",
")",
";",
"$",
"Email",
"->",
"Subject",
"(",
"sprintf",
"(",
"T",
"(",
"'[%1$s] %2$s'",
")",
",",
"Gdn",
"::",
"Config",
"(",
"'Garden.Title'",
")",
",",
"$",
"ActivityHeadline",
")",
")",
";",
"$",
"Email",
"->",
"To",
"(",
"$",
"User",
")",
";",
"$",
"Message",
"=",
"sprintf",
"(",
"$",
"Story",
"==",
"''",
"?",
"T",
"(",
"'EmailNotification'",
",",
"\"%1\\$s\\n\\n%2\\$s\"",
")",
":",
"T",
"(",
"'EmailStoryNotification'",
",",
"\"%3\\$s\\n\\n%2\\$s\"",
")",
",",
"$",
"ActivityHeadline",
",",
"ExternalUrl",
"(",
"$",
"Activity",
"->",
"Route",
"==",
"''",
"?",
"'/'",
":",
"$",
"Activity",
"->",
"Route",
")",
",",
"$",
"Story",
")",
";",
"$",
"Email",
"->",
"Message",
"(",
"$",
"Message",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"User",
"->",
"UserID",
",",
"$",
"this",
"->",
"_NotificationQueue",
")",
")",
"$",
"this",
"->",
"_NotificationQueue",
"[",
"$",
"User",
"->",
"UserID",
"]",
"=",
"array",
"(",
")",
";",
"$",
"Notification",
"=",
"array",
"(",
"'ActivityID'",
"=>",
"$",
"ActivityID",
",",
"'User'",
"=>",
"$",
"User",
",",
"'Email'",
"=>",
"$",
"Email",
",",
"'Route'",
"=>",
"$",
"Activity",
"->",
"Route",
",",
"'Story'",
"=>",
"$",
"Story",
",",
"'Headline'",
"=>",
"$",
"ActivityHeadline",
",",
"'Activity'",
"=>",
"$",
"Activity",
")",
";",
"if",
"(",
"$",
"Position",
"==",
"'first'",
")",
"$",
"this",
"->",
"_NotificationQueue",
"[",
"$",
"User",
"->",
"UserID",
"]",
"=",
"array_merge",
"(",
"array",
"(",
"$",
"Notification",
")",
",",
"$",
"this",
"->",
"_NotificationQueue",
"[",
"$",
"User",
"->",
"UserID",
"]",
")",
";",
"else",
"$",
"this",
"->",
"_NotificationQueue",
"[",
"$",
"User",
"->",
"UserID",
"]",
"[",
"]",
"=",
"$",
"Notification",
";",
"}",
"}",
"}"
] |
Queue a notification for sending.
@since 2.0.17
@access public
@param int $ActivityID
@param string $Story
@param string $Position
@param bool $Force
|
[
"Queue",
"a",
"notification",
"for",
"sending",
"."
] |
8494eb4a4ad61603479015a8054d23ff488364e8
|
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/models/class.activitymodel.php#L1014-L1062
|
235,390
|
bishopb/vanilla
|
applications/dashboard/models/class.activitymodel.php
|
ActivityModel.Queue
|
public function Queue($Data, $Preference = FALSE, $Options = array()) {
$this->_Touch($Data);
if (!isset($Data['NotifyUserID']) || !isset($Data['ActivityType']))
throw new Exception('Data missing NotifyUserID and/or ActivityType', 400);
if ($Data['ActivityUserID'] == $Data['NotifyUserID'] && !GetValue('Force', $Options))
return; // don't notify users of something they did.
$Notified = $Data['Notified'];
$Emailed = $Data['Emailed'];
if (isset(self::$Queue[$Data['NotifyUserID']][$Data['ActivityType']])) {
list($CurrentData, $CurrentOptions) = self::$Queue[$Data['NotifyUserID']][$Data['ActivityType']];
$Notified = $Notified ? $Notified : $CurrentData['Notified'];
$Emailed = $Emailed ? $Emailed : $CurrentData['Emailed'];
$Data = array_merge($CurrentData, $Data);
$Options = array_merge($CurrentOptions, $Options);
}
if ($Preference) {
list($Popup, $Email) = self::NotificationPreference($Preference, $Data['NotifyUserID'], 'both');
if (!$Popup && !$Email)
return; // don't queue if user doesn't want to be notified at all.
if ($Popup)
$Notified = self::SENT_PENDING;
if ($Email)
$Emailed = self::SENT_PENDING;
}
$Data['Notified'] = $Notified;
$Data['Emailed'] = $Emailed;
self::$Queue[$Data['NotifyUserID']][$Data['ActivityType']] = array($Data, $Options);
}
|
php
|
public function Queue($Data, $Preference = FALSE, $Options = array()) {
$this->_Touch($Data);
if (!isset($Data['NotifyUserID']) || !isset($Data['ActivityType']))
throw new Exception('Data missing NotifyUserID and/or ActivityType', 400);
if ($Data['ActivityUserID'] == $Data['NotifyUserID'] && !GetValue('Force', $Options))
return; // don't notify users of something they did.
$Notified = $Data['Notified'];
$Emailed = $Data['Emailed'];
if (isset(self::$Queue[$Data['NotifyUserID']][$Data['ActivityType']])) {
list($CurrentData, $CurrentOptions) = self::$Queue[$Data['NotifyUserID']][$Data['ActivityType']];
$Notified = $Notified ? $Notified : $CurrentData['Notified'];
$Emailed = $Emailed ? $Emailed : $CurrentData['Emailed'];
$Data = array_merge($CurrentData, $Data);
$Options = array_merge($CurrentOptions, $Options);
}
if ($Preference) {
list($Popup, $Email) = self::NotificationPreference($Preference, $Data['NotifyUserID'], 'both');
if (!$Popup && !$Email)
return; // don't queue if user doesn't want to be notified at all.
if ($Popup)
$Notified = self::SENT_PENDING;
if ($Email)
$Emailed = self::SENT_PENDING;
}
$Data['Notified'] = $Notified;
$Data['Emailed'] = $Emailed;
self::$Queue[$Data['NotifyUserID']][$Data['ActivityType']] = array($Data, $Options);
}
|
[
"public",
"function",
"Queue",
"(",
"$",
"Data",
",",
"$",
"Preference",
"=",
"FALSE",
",",
"$",
"Options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"this",
"->",
"_Touch",
"(",
"$",
"Data",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"Data",
"[",
"'NotifyUserID'",
"]",
")",
"||",
"!",
"isset",
"(",
"$",
"Data",
"[",
"'ActivityType'",
"]",
")",
")",
"throw",
"new",
"Exception",
"(",
"'Data missing NotifyUserID and/or ActivityType'",
",",
"400",
")",
";",
"if",
"(",
"$",
"Data",
"[",
"'ActivityUserID'",
"]",
"==",
"$",
"Data",
"[",
"'NotifyUserID'",
"]",
"&&",
"!",
"GetValue",
"(",
"'Force'",
",",
"$",
"Options",
")",
")",
"return",
";",
"// don't notify users of something they did.",
"$",
"Notified",
"=",
"$",
"Data",
"[",
"'Notified'",
"]",
";",
"$",
"Emailed",
"=",
"$",
"Data",
"[",
"'Emailed'",
"]",
";",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"Queue",
"[",
"$",
"Data",
"[",
"'NotifyUserID'",
"]",
"]",
"[",
"$",
"Data",
"[",
"'ActivityType'",
"]",
"]",
")",
")",
"{",
"list",
"(",
"$",
"CurrentData",
",",
"$",
"CurrentOptions",
")",
"=",
"self",
"::",
"$",
"Queue",
"[",
"$",
"Data",
"[",
"'NotifyUserID'",
"]",
"]",
"[",
"$",
"Data",
"[",
"'ActivityType'",
"]",
"]",
";",
"$",
"Notified",
"=",
"$",
"Notified",
"?",
"$",
"Notified",
":",
"$",
"CurrentData",
"[",
"'Notified'",
"]",
";",
"$",
"Emailed",
"=",
"$",
"Emailed",
"?",
"$",
"Emailed",
":",
"$",
"CurrentData",
"[",
"'Emailed'",
"]",
";",
"$",
"Data",
"=",
"array_merge",
"(",
"$",
"CurrentData",
",",
"$",
"Data",
")",
";",
"$",
"Options",
"=",
"array_merge",
"(",
"$",
"CurrentOptions",
",",
"$",
"Options",
")",
";",
"}",
"if",
"(",
"$",
"Preference",
")",
"{",
"list",
"(",
"$",
"Popup",
",",
"$",
"Email",
")",
"=",
"self",
"::",
"NotificationPreference",
"(",
"$",
"Preference",
",",
"$",
"Data",
"[",
"'NotifyUserID'",
"]",
",",
"'both'",
")",
";",
"if",
"(",
"!",
"$",
"Popup",
"&&",
"!",
"$",
"Email",
")",
"return",
";",
"// don't queue if user doesn't want to be notified at all.",
"if",
"(",
"$",
"Popup",
")",
"$",
"Notified",
"=",
"self",
"::",
"SENT_PENDING",
";",
"if",
"(",
"$",
"Email",
")",
"$",
"Emailed",
"=",
"self",
"::",
"SENT_PENDING",
";",
"}",
"$",
"Data",
"[",
"'Notified'",
"]",
"=",
"$",
"Notified",
";",
"$",
"Data",
"[",
"'Emailed'",
"]",
"=",
"$",
"Emailed",
";",
"self",
"::",
"$",
"Queue",
"[",
"$",
"Data",
"[",
"'NotifyUserID'",
"]",
"]",
"[",
"$",
"Data",
"[",
"'ActivityType'",
"]",
"]",
"=",
"array",
"(",
"$",
"Data",
",",
"$",
"Options",
")",
";",
"}"
] |
Queue an activity for saving later.
@param array $Data The data in the activity.
@param string|FALSE $Preference The name of the preference governing the activity.
@param array $Options Additional options for saving.
@return type
|
[
"Queue",
"an",
"activity",
"for",
"saving",
"later",
"."
] |
8494eb4a4ad61603479015a8054d23ff488364e8
|
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/models/class.activitymodel.php#L1071-L1105
|
235,391
|
CakeCMS/Community
|
src/Model/Entity/User.php
|
User.getEditUrl
|
public function getEditUrl($backend = false)
{
$url = [
'action' => 'edit',
'controller' => 'Users',
'plugin' => 'Community'
];
if ($backend) {
$url['prefix'] = 'admin';
$url[] = $this->id;
}
return Router::url($url);
}
|
php
|
public function getEditUrl($backend = false)
{
$url = [
'action' => 'edit',
'controller' => 'Users',
'plugin' => 'Community'
];
if ($backend) {
$url['prefix'] = 'admin';
$url[] = $this->id;
}
return Router::url($url);
}
|
[
"public",
"function",
"getEditUrl",
"(",
"$",
"backend",
"=",
"false",
")",
"{",
"$",
"url",
"=",
"[",
"'action'",
"=>",
"'edit'",
",",
"'controller'",
"=>",
"'Users'",
",",
"'plugin'",
"=>",
"'Community'",
"]",
";",
"if",
"(",
"$",
"backend",
")",
"{",
"$",
"url",
"[",
"'prefix'",
"]",
"=",
"'admin'",
";",
"$",
"url",
"[",
"]",
"=",
"$",
"this",
"->",
"id",
";",
"}",
"return",
"Router",
"::",
"url",
"(",
"$",
"url",
")",
";",
"}"
] |
Get current user edit profile url.
@param bool $backend Backend or frontend point.
@return string
|
[
"Get",
"current",
"user",
"edit",
"profile",
"url",
"."
] |
cc2bdb596dd9617d42fd81f59e981024caa062e8
|
https://github.com/CakeCMS/Community/blob/cc2bdb596dd9617d42fd81f59e981024caa062e8/src/Model/Entity/User.php#L65-L79
|
235,392
|
open-orchestra/open-orchestra-media-admin-bundle
|
MediaAdminBundle/Manager/SaveMediaManager.php
|
SaveMediaManager.getFileFromChunks
|
public function getFileFromChunks(UploadedFile $uploadedFile)
{
$filename = time() . '-' . $uploadedFile->getClientOriginalName();
$path = $this->tmpDir . DIRECTORY_SEPARATOR . $filename;
if (FlowBasic::save($path, $this->tmpDir)) {
return new UploadedFile($path, $uploadedFile->getClientOriginalName(), $uploadedFile->getClientMimeType());
}
return null;
}
|
php
|
public function getFileFromChunks(UploadedFile $uploadedFile)
{
$filename = time() . '-' . $uploadedFile->getClientOriginalName();
$path = $this->tmpDir . DIRECTORY_SEPARATOR . $filename;
if (FlowBasic::save($path, $this->tmpDir)) {
return new UploadedFile($path, $uploadedFile->getClientOriginalName(), $uploadedFile->getClientMimeType());
}
return null;
}
|
[
"public",
"function",
"getFileFromChunks",
"(",
"UploadedFile",
"$",
"uploadedFile",
")",
"{",
"$",
"filename",
"=",
"time",
"(",
")",
".",
"'-'",
".",
"$",
"uploadedFile",
"->",
"getClientOriginalName",
"(",
")",
";",
"$",
"path",
"=",
"$",
"this",
"->",
"tmpDir",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"filename",
";",
"if",
"(",
"FlowBasic",
"::",
"save",
"(",
"$",
"path",
",",
"$",
"this",
"->",
"tmpDir",
")",
")",
"{",
"return",
"new",
"UploadedFile",
"(",
"$",
"path",
",",
"$",
"uploadedFile",
"->",
"getClientOriginalName",
"(",
")",
",",
"$",
"uploadedFile",
"->",
"getClientMimeType",
"(",
")",
")",
";",
"}",
"return",
"null",
";",
"}"
] |
Check if all chunks of a file being uploaded have been received
If yes, return the name of the reassembled temporary file
@param UploadedFile $uploadedFile
@return UploadedFile|null
|
[
"Check",
"if",
"all",
"chunks",
"of",
"a",
"file",
"being",
"uploaded",
"have",
"been",
"received",
"If",
"yes",
"return",
"the",
"name",
"of",
"the",
"reassembled",
"temporary",
"file"
] |
743fa00a6491b84d67221e215a806d8b210bf773
|
https://github.com/open-orchestra/open-orchestra-media-admin-bundle/blob/743fa00a6491b84d67221e215a806d8b210bf773/MediaAdminBundle/Manager/SaveMediaManager.php#L67-L77
|
235,393
|
open-orchestra/open-orchestra-media-admin-bundle
|
MediaAdminBundle/Manager/SaveMediaManager.php
|
SaveMediaManager.initializeMediaFromUploadedFile
|
public function initializeMediaFromUploadedFile(UploadedFile $uploadedFile, $folderId, $siteId, $title = null)
{
/** @var MediaInterface $media */
$media = new $this->mediaClass();
$media->setSiteId($siteId);
$media->setFile($uploadedFile);
$media->setFilesystemName($uploadedFile->getFilename());
$media->setMediaFolder($this->folderRepository->find($folderId));
$media->setName($uploadedFile->getClientOriginalName());
$media->setMimeType($uploadedFile->getMimeType());
if (null === $title) {
$title = $uploadedFile->getFilename();
}
foreach ($this->frontLanguages as $language) {
$media->addTitle($language, $title);
}
return $media;
}
|
php
|
public function initializeMediaFromUploadedFile(UploadedFile $uploadedFile, $folderId, $siteId, $title = null)
{
/** @var MediaInterface $media */
$media = new $this->mediaClass();
$media->setSiteId($siteId);
$media->setFile($uploadedFile);
$media->setFilesystemName($uploadedFile->getFilename());
$media->setMediaFolder($this->folderRepository->find($folderId));
$media->setName($uploadedFile->getClientOriginalName());
$media->setMimeType($uploadedFile->getMimeType());
if (null === $title) {
$title = $uploadedFile->getFilename();
}
foreach ($this->frontLanguages as $language) {
$media->addTitle($language, $title);
}
return $media;
}
|
[
"public",
"function",
"initializeMediaFromUploadedFile",
"(",
"UploadedFile",
"$",
"uploadedFile",
",",
"$",
"folderId",
",",
"$",
"siteId",
",",
"$",
"title",
"=",
"null",
")",
"{",
"/** @var MediaInterface $media */",
"$",
"media",
"=",
"new",
"$",
"this",
"->",
"mediaClass",
"(",
")",
";",
"$",
"media",
"->",
"setSiteId",
"(",
"$",
"siteId",
")",
";",
"$",
"media",
"->",
"setFile",
"(",
"$",
"uploadedFile",
")",
";",
"$",
"media",
"->",
"setFilesystemName",
"(",
"$",
"uploadedFile",
"->",
"getFilename",
"(",
")",
")",
";",
"$",
"media",
"->",
"setMediaFolder",
"(",
"$",
"this",
"->",
"folderRepository",
"->",
"find",
"(",
"$",
"folderId",
")",
")",
";",
"$",
"media",
"->",
"setName",
"(",
"$",
"uploadedFile",
"->",
"getClientOriginalName",
"(",
")",
")",
";",
"$",
"media",
"->",
"setMimeType",
"(",
"$",
"uploadedFile",
"->",
"getMimeType",
"(",
")",
")",
";",
"if",
"(",
"null",
"===",
"$",
"title",
")",
"{",
"$",
"title",
"=",
"$",
"uploadedFile",
"->",
"getFilename",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"frontLanguages",
"as",
"$",
"language",
")",
"{",
"$",
"media",
"->",
"addTitle",
"(",
"$",
"language",
",",
"$",
"title",
")",
";",
"}",
"return",
"$",
"media",
";",
"}"
] |
initialize a media to fit an uploaded file
@param UploadedFile $uploadedFile
@param string $folderId
@param string $siteId
@param string|null $title
@return MediaInterface
|
[
"initialize",
"a",
"media",
"to",
"fit",
"an",
"uploaded",
"file"
] |
743fa00a6491b84d67221e215a806d8b210bf773
|
https://github.com/open-orchestra/open-orchestra-media-admin-bundle/blob/743fa00a6491b84d67221e215a806d8b210bf773/MediaAdminBundle/Manager/SaveMediaManager.php#L89-L107
|
235,394
|
open-orchestra/open-orchestra-media-admin-bundle
|
MediaAdminBundle/Manager/SaveMediaManager.php
|
SaveMediaManager.saveMedia
|
public function saveMedia($media)
{
$file = $media->getFile();
$this->mediaStorageManager->uploadFile($file->getFilename(), $file->getRealPath(), false);
$this->objectManager->persist($media);
$this->objectManager->flush();
$event = new MediaEvent($media);
$this->dispatcher->dispatch(MediaEvents::MEDIA_ADD, $event);
}
|
php
|
public function saveMedia($media)
{
$file = $media->getFile();
$this->mediaStorageManager->uploadFile($file->getFilename(), $file->getRealPath(), false);
$this->objectManager->persist($media);
$this->objectManager->flush();
$event = new MediaEvent($media);
$this->dispatcher->dispatch(MediaEvents::MEDIA_ADD, $event);
}
|
[
"public",
"function",
"saveMedia",
"(",
"$",
"media",
")",
"{",
"$",
"file",
"=",
"$",
"media",
"->",
"getFile",
"(",
")",
";",
"$",
"this",
"->",
"mediaStorageManager",
"->",
"uploadFile",
"(",
"$",
"file",
"->",
"getFilename",
"(",
")",
",",
"$",
"file",
"->",
"getRealPath",
"(",
")",
",",
"false",
")",
";",
"$",
"this",
"->",
"objectManager",
"->",
"persist",
"(",
"$",
"media",
")",
";",
"$",
"this",
"->",
"objectManager",
"->",
"flush",
"(",
")",
";",
"$",
"event",
"=",
"new",
"MediaEvent",
"(",
"$",
"media",
")",
";",
"$",
"this",
"->",
"dispatcher",
"->",
"dispatch",
"(",
"MediaEvents",
"::",
"MEDIA_ADD",
",",
"$",
"event",
")",
";",
"}"
] |
Save a media in database
@param MediaInterface $media
|
[
"Save",
"a",
"media",
"in",
"database"
] |
743fa00a6491b84d67221e215a806d8b210bf773
|
https://github.com/open-orchestra/open-orchestra-media-admin-bundle/blob/743fa00a6491b84d67221e215a806d8b210bf773/MediaAdminBundle/Manager/SaveMediaManager.php#L114-L124
|
235,395
|
Puzzlout/FrameworkMvcLegacy
|
src/ViewModels/ErrorVm.php
|
ErrorVm.FillInstance
|
protected function FillInstance($errorId, $errorMessage, $exception) {
$this->errorId = $errorId;
$this->errorMessage = $errorMessage;
$this->exceptionObj = $exception;
}
|
php
|
protected function FillInstance($errorId, $errorMessage, $exception) {
$this->errorId = $errorId;
$this->errorMessage = $errorMessage;
$this->exceptionObj = $exception;
}
|
[
"protected",
"function",
"FillInstance",
"(",
"$",
"errorId",
",",
"$",
"errorMessage",
",",
"$",
"exception",
")",
"{",
"$",
"this",
"->",
"errorId",
"=",
"$",
"errorId",
";",
"$",
"this",
"->",
"errorMessage",
"=",
"$",
"errorMessage",
";",
"$",
"this",
"->",
"exceptionObj",
"=",
"$",
"exception",
";",
"}"
] |
Sets the properties of the object
@param int $errorId
@param string $errorMessage
@param \Exception $exception
|
[
"Sets",
"the",
"properties",
"of",
"the",
"object"
] |
14e0fc5b16978cbd209f552ee9c649f66a0dfc6e
|
https://github.com/Puzzlout/FrameworkMvcLegacy/blob/14e0fc5b16978cbd209f552ee9c649f66a0dfc6e/src/ViewModels/ErrorVm.php#L69-L73
|
235,396
|
stefanotorresi/thorr-persistence
|
src/Entity/SluggableTrait.php
|
SluggableTrait.setSlug
|
public function setSlug($slug)
{
if ($slug !== null) {
$slug = (string) $slug;
}
$this->slug = $slug;
}
|
php
|
public function setSlug($slug)
{
if ($slug !== null) {
$slug = (string) $slug;
}
$this->slug = $slug;
}
|
[
"public",
"function",
"setSlug",
"(",
"$",
"slug",
")",
"{",
"if",
"(",
"$",
"slug",
"!==",
"null",
")",
"{",
"$",
"slug",
"=",
"(",
"string",
")",
"$",
"slug",
";",
"}",
"$",
"this",
"->",
"slug",
"=",
"$",
"slug",
";",
"}"
] |
Setting to null should regenerate the slug
@param string|null $slug
|
[
"Setting",
"to",
"null",
"should",
"regenerate",
"the",
"slug"
] |
c29e204e6a7b0db0cc11992c0ee2dc82b67e2fec
|
https://github.com/stefanotorresi/thorr-persistence/blob/c29e204e6a7b0db0cc11992c0ee2dc82b67e2fec/src/Entity/SluggableTrait.php#L30-L37
|
235,397
|
Archi-Strasbourg/archi-wiki
|
modules/archi/includes/archiAccueil.class.php
|
ArchiAccueil.getDernieresActualites
|
public function getDernieresActualites($params = array())
{
$sqlLimit = "";
if (isset($params['sqlLimit']) && $params['sqlLimit']!='') {
$sqlLimit = $params['sqlLimit'];
}
$sqlFields = "idActualite, titre, date, ".
"photoIllustration, texte, urlFichier";
if (isset($params['sqlFields']) && $params['sqlFields']!='') {
$sqlFields = $params['sqlFields'];
}
$sqlWhere = "";
if (isset($params['sqlWhere']) && $params['sqlWhere']!='') {
$sqlWhere = $params['sqlWhere'];
}
$req = "SELECT $sqlFields FROM actualites ".
"WHERE 1=1 $sqlWhere ORDER BY date DESC $sqlLimit";
$res = $this->connexionBdd->requete($req);
$i=0;
if (!isset($params['returnAsMysqlRes'])
|| $params['returnAsMysqlRes']!=true
) {
$retour = array();
while ($fetch = mysql_fetch_assoc($res)) {
$retour[$i] = $fetch;
$i++;
}
} else {
$retour = $res;
}
return $retour;
}
|
php
|
public function getDernieresActualites($params = array())
{
$sqlLimit = "";
if (isset($params['sqlLimit']) && $params['sqlLimit']!='') {
$sqlLimit = $params['sqlLimit'];
}
$sqlFields = "idActualite, titre, date, ".
"photoIllustration, texte, urlFichier";
if (isset($params['sqlFields']) && $params['sqlFields']!='') {
$sqlFields = $params['sqlFields'];
}
$sqlWhere = "";
if (isset($params['sqlWhere']) && $params['sqlWhere']!='') {
$sqlWhere = $params['sqlWhere'];
}
$req = "SELECT $sqlFields FROM actualites ".
"WHERE 1=1 $sqlWhere ORDER BY date DESC $sqlLimit";
$res = $this->connexionBdd->requete($req);
$i=0;
if (!isset($params['returnAsMysqlRes'])
|| $params['returnAsMysqlRes']!=true
) {
$retour = array();
while ($fetch = mysql_fetch_assoc($res)) {
$retour[$i] = $fetch;
$i++;
}
} else {
$retour = $res;
}
return $retour;
}
|
[
"public",
"function",
"getDernieresActualites",
"(",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"$",
"sqlLimit",
"=",
"\"\"",
";",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"'sqlLimit'",
"]",
")",
"&&",
"$",
"params",
"[",
"'sqlLimit'",
"]",
"!=",
"''",
")",
"{",
"$",
"sqlLimit",
"=",
"$",
"params",
"[",
"'sqlLimit'",
"]",
";",
"}",
"$",
"sqlFields",
"=",
"\"idActualite, titre, date, \"",
".",
"\"photoIllustration, texte, urlFichier\"",
";",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"'sqlFields'",
"]",
")",
"&&",
"$",
"params",
"[",
"'sqlFields'",
"]",
"!=",
"''",
")",
"{",
"$",
"sqlFields",
"=",
"$",
"params",
"[",
"'sqlFields'",
"]",
";",
"}",
"$",
"sqlWhere",
"=",
"\"\"",
";",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"'sqlWhere'",
"]",
")",
"&&",
"$",
"params",
"[",
"'sqlWhere'",
"]",
"!=",
"''",
")",
"{",
"$",
"sqlWhere",
"=",
"$",
"params",
"[",
"'sqlWhere'",
"]",
";",
"}",
"$",
"req",
"=",
"\"SELECT $sqlFields FROM actualites \"",
".",
"\"WHERE 1=1 $sqlWhere ORDER BY date DESC $sqlLimit\"",
";",
"$",
"res",
"=",
"$",
"this",
"->",
"connexionBdd",
"->",
"requete",
"(",
"$",
"req",
")",
";",
"$",
"i",
"=",
"0",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"params",
"[",
"'returnAsMysqlRes'",
"]",
")",
"||",
"$",
"params",
"[",
"'returnAsMysqlRes'",
"]",
"!=",
"true",
")",
"{",
"$",
"retour",
"=",
"array",
"(",
")",
";",
"while",
"(",
"$",
"fetch",
"=",
"mysql_fetch_assoc",
"(",
"$",
"res",
")",
")",
"{",
"$",
"retour",
"[",
"$",
"i",
"]",
"=",
"$",
"fetch",
";",
"$",
"i",
"++",
";",
"}",
"}",
"else",
"{",
"$",
"retour",
"=",
"$",
"res",
";",
"}",
"return",
"$",
"retour",
";",
"}"
] |
Renvoi les dernieres actualites pour la page d'accueil
sous forme de resultat mysql ou de tableau
@param array $params Paramètres
@return Resource
|
[
"Renvoi",
"les",
"dernieres",
"actualites",
"pour",
"la",
"page",
"d",
"accueil",
"sous",
"forme",
"de",
"resultat",
"mysql",
"ou",
"de",
"tableau"
] |
b9fb39f43a78409890a7de96426c1f6c49d5c323
|
https://github.com/Archi-Strasbourg/archi-wiki/blob/b9fb39f43a78409890a7de96426c1f6c49d5c323/modules/archi/includes/archiAccueil.class.php#L1923-L1960
|
235,398
|
mainio/c5pkg_controller_extensions
|
src/Mainio/C5/ControllerExtensions/Controller/Extension/DoctrineEntitiesExtension.php
|
DoctrineEntitiesExtension.getEntityManager
|
public function getEntityManager()
{
if (isset($this->entityManager) && is_object($this->entityManager)) {
// 5.8 ->
return $this->entityManager;
}
$pkgID = $this->c->getPackageID();
if ($pkgID > 0) {
return Package::getByID($pkgID)->getEntityManager();
} else {
return ORM::entityManager('app');
}
}
|
php
|
public function getEntityManager()
{
if (isset($this->entityManager) && is_object($this->entityManager)) {
// 5.8 ->
return $this->entityManager;
}
$pkgID = $this->c->getPackageID();
if ($pkgID > 0) {
return Package::getByID($pkgID)->getEntityManager();
} else {
return ORM::entityManager('app');
}
}
|
[
"public",
"function",
"getEntityManager",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"entityManager",
")",
"&&",
"is_object",
"(",
"$",
"this",
"->",
"entityManager",
")",
")",
"{",
"// 5.8 ->",
"return",
"$",
"this",
"->",
"entityManager",
";",
"}",
"$",
"pkgID",
"=",
"$",
"this",
"->",
"c",
"->",
"getPackageID",
"(",
")",
";",
"if",
"(",
"$",
"pkgID",
">",
"0",
")",
"{",
"return",
"Package",
"::",
"getByID",
"(",
"$",
"pkgID",
")",
"->",
"getEntityManager",
"(",
")",
";",
"}",
"else",
"{",
"return",
"ORM",
"::",
"entityManager",
"(",
"'app'",
")",
";",
"}",
"}"
] |
Gets the controller specific entity manager. If the controller belongs
to a package, returns the package's entity manager. Otherwise returns
the application specific entity manager.
|
[
"Gets",
"the",
"controller",
"specific",
"entity",
"manager",
".",
"If",
"the",
"controller",
"belongs",
"to",
"a",
"package",
"returns",
"the",
"package",
"s",
"entity",
"manager",
".",
"Otherwise",
"returns",
"the",
"application",
"specific",
"entity",
"manager",
"."
] |
b3775bb6a79dcc91ce8b71be4bf5c9dd5fa66446
|
https://github.com/mainio/c5pkg_controller_extensions/blob/b3775bb6a79dcc91ce8b71be4bf5c9dd5fa66446/src/Mainio/C5/ControllerExtensions/Controller/Extension/DoctrineEntitiesExtension.php#L20-L32
|
235,399
|
leedave/html
|
src/Html5.php
|
Html5.br
|
public static function br(int $amount = 1) : string
{
$output = "";
for ($i = 0; $i < $amount; $i++) {
$output .= self::tag("br");
}
return $output;
}
|
php
|
public static function br(int $amount = 1) : string
{
$output = "";
for ($i = 0; $i < $amount; $i++) {
$output .= self::tag("br");
}
return $output;
}
|
[
"public",
"static",
"function",
"br",
"(",
"int",
"$",
"amount",
"=",
"1",
")",
":",
"string",
"{",
"$",
"output",
"=",
"\"\"",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"amount",
";",
"$",
"i",
"++",
")",
"{",
"$",
"output",
".=",
"self",
"::",
"tag",
"(",
"\"br\"",
")",
";",
"}",
"return",
"$",
"output",
";",
"}"
] |
Create a BR Tag
@param int $amount Number of how many BR Tags
@return string HTML Code
|
[
"Create",
"a",
"BR",
"Tag"
] |
f0780b37c34defbbd92d29f4e1a41ce875b4d300
|
https://github.com/leedave/html/blob/f0780b37c34defbbd92d29f4e1a41ce875b4d300/src/Html5.php#L190-L197
|
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.