repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
cohesion/cohesion-core
src/Config/Config.php
Config.get
public function get($name = null) { $data = $this->data; if ($name) { $names = explode('.', $name); if ($names) { foreach ($names as $name) { if (is_array($data) && array_key_exists($name, $data)) { $data = $data[$name]; } else { return null; } } } } return $data; }
php
public function get($name = null) { $data = $this->data; if ($name) { $names = explode('.', $name); if ($names) { foreach ($names as $name) { if (is_array($data) && array_key_exists($name, $data)) { $data = $data[$name]; } else { return null; } } } } return $data; }
[ "public", "function", "get", "(", "$", "name", "=", "null", ")", "{", "$", "data", "=", "$", "this", "->", "data", ";", "if", "(", "$", "name", ")", "{", "$", "names", "=", "explode", "(", "'.'", ",", "$", "name", ")", ";", "if", "(", "$", "names", ")", "{", "foreach", "(", "$", "names", "as", "$", "name", ")", "{", "if", "(", "is_array", "(", "$", "data", ")", "&&", "array_key_exists", "(", "$", "name", ",", "$", "data", ")", ")", "{", "$", "data", "=", "$", "data", "[", "$", "name", "]", ";", "}", "else", "{", "return", "null", ";", "}", "}", "}", "}", "return", "$", "data", ";", "}" ]
Get the value for a key with the given name Can use dot notation for acessing nested keys Example: $config->get('database') will return an associative array of all the database values $config->get('database.host') will return the value for 'host' within the array stored at key 'database'
[ "Get", "the", "value", "for", "a", "key", "with", "the", "given", "name", "Can", "use", "dot", "notation", "for", "acessing", "nested", "keys" ]
train
https://github.com/cohesion/cohesion-core/blob/c6352aef7336e06285f0943da68235dc45523998/src/Config/Config.php#L100-L115
cohesion/cohesion-core
src/Config/Config.php
Config.getConfig
public function getConfig($name) { $data = $this->get($name); if ($data === null) { return null; } if (isset($this->data['global'])) { $data['global'] = $this->data['global']; } $config = new self(); $config->load($data); return $config; }
php
public function getConfig($name) { $data = $this->get($name); if ($data === null) { return null; } if (isset($this->data['global'])) { $data['global'] = $this->data['global']; } $config = new self(); $config->load($data); return $config; }
[ "public", "function", "getConfig", "(", "$", "name", ")", "{", "$", "data", "=", "$", "this", "->", "get", "(", "$", "name", ")", ";", "if", "(", "$", "data", "===", "null", ")", "{", "return", "null", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "data", "[", "'global'", "]", ")", ")", "{", "$", "data", "[", "'global'", "]", "=", "$", "this", "->", "data", "[", "'global'", "]", ";", "}", "$", "config", "=", "new", "self", "(", ")", ";", "$", "config", "->", "load", "(", "$", "data", ")", ";", "return", "$", "config", ";", "}" ]
Get the value at the given key and return it as a config object
[ "Get", "the", "value", "at", "the", "given", "key", "and", "return", "it", "as", "a", "config", "object" ]
train
https://github.com/cohesion/cohesion-core/blob/c6352aef7336e06285f0943da68235dc45523998/src/Config/Config.php#L120-L131
cohesion/cohesion-core
src/Config/Config.php
Config.set
public function set($name, $value) { $data = array(); $dataPointer = &$data; $parents = explode('.', $name); $name = array_pop($parents); foreach ($parents as $parent) { $dataPointer[$parent] = array(); $dataPointer = &$dataPointer[$parent]; } $dataPointer[$name] = $value; $this->load($data); }
php
public function set($name, $value) { $data = array(); $dataPointer = &$data; $parents = explode('.', $name); $name = array_pop($parents); foreach ($parents as $parent) { $dataPointer[$parent] = array(); $dataPointer = &$dataPointer[$parent]; } $dataPointer[$name] = $value; $this->load($data); }
[ "public", "function", "set", "(", "$", "name", ",", "$", "value", ")", "{", "$", "data", "=", "array", "(", ")", ";", "$", "dataPointer", "=", "&", "$", "data", ";", "$", "parents", "=", "explode", "(", "'.'", ",", "$", "name", ")", ";", "$", "name", "=", "array_pop", "(", "$", "parents", ")", ";", "foreach", "(", "$", "parents", "as", "$", "parent", ")", "{", "$", "dataPointer", "[", "$", "parent", "]", "=", "array", "(", ")", ";", "$", "dataPointer", "=", "&", "$", "dataPointer", "[", "$", "parent", "]", ";", "}", "$", "dataPointer", "[", "$", "name", "]", "=", "$", "value", ";", "$", "this", "->", "load", "(", "$", "data", ")", ";", "}" ]
Set a value in the config. If the value doesn't exist it will be created.
[ "Set", "a", "value", "in", "the", "config", ".", "If", "the", "value", "doesn", "t", "exist", "it", "will", "be", "created", "." ]
train
https://github.com/cohesion/cohesion-core/blob/c6352aef7336e06285f0943da68235dc45523998/src/Config/Config.php#L136-L147
nguyenanhung/td-send-sms
src/SendSMS/SendSmsToVnmSDP.php
SendSmsToVnmSDP.createSOAPRequest
public function createSOAPRequest() { $this->soapRequest = new SoapRequest(); if (isset($this->options['debugStatus']) && $this->options['debugStatus'] === TRUE) { $this->soapRequest->debugStatus = TRUE; if (isset($this->options['debugLevel']) && !empty($this->options['debugLevel'])) { $this->soapRequest->debugLevel = $this->options['debugLevel']; } if (isset($this->options['loggerPath']) && !empty($this->options['loggerPath'])) { $this->soapRequest->debugLoggerPath = $this->options['loggerPath']; } $this->soapRequest->debugLoggerFilename = 'Log-' . date('Y-m-d') . '.log'; $this->soapRequest->__construct(); } return $this->soapRequest; }
php
public function createSOAPRequest() { $this->soapRequest = new SoapRequest(); if (isset($this->options['debugStatus']) && $this->options['debugStatus'] === TRUE) { $this->soapRequest->debugStatus = TRUE; if (isset($this->options['debugLevel']) && !empty($this->options['debugLevel'])) { $this->soapRequest->debugLevel = $this->options['debugLevel']; } if (isset($this->options['loggerPath']) && !empty($this->options['loggerPath'])) { $this->soapRequest->debugLoggerPath = $this->options['loggerPath']; } $this->soapRequest->debugLoggerFilename = 'Log-' . date('Y-m-d') . '.log'; $this->soapRequest->__construct(); } return $this->soapRequest; }
[ "public", "function", "createSOAPRequest", "(", ")", "{", "$", "this", "->", "soapRequest", "=", "new", "SoapRequest", "(", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "options", "[", "'debugStatus'", "]", ")", "&&", "$", "this", "->", "options", "[", "'debugStatus'", "]", "===", "TRUE", ")", "{", "$", "this", "->", "soapRequest", "->", "debugStatus", "=", "TRUE", ";", "if", "(", "isset", "(", "$", "this", "->", "options", "[", "'debugLevel'", "]", ")", "&&", "!", "empty", "(", "$", "this", "->", "options", "[", "'debugLevel'", "]", ")", ")", "{", "$", "this", "->", "soapRequest", "->", "debugLevel", "=", "$", "this", "->", "options", "[", "'debugLevel'", "]", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "options", "[", "'loggerPath'", "]", ")", "&&", "!", "empty", "(", "$", "this", "->", "options", "[", "'loggerPath'", "]", ")", ")", "{", "$", "this", "->", "soapRequest", "->", "debugLoggerPath", "=", "$", "this", "->", "options", "[", "'loggerPath'", "]", ";", "}", "$", "this", "->", "soapRequest", "->", "debugLoggerFilename", "=", "'Log-'", ".", "date", "(", "'Y-m-d'", ")", ".", "'.log'", ";", "$", "this", "->", "soapRequest", "->", "__construct", "(", ")", ";", "}", "return", "$", "this", "->", "soapRequest", ";", "}" ]
Function createSOAPRequest @author: 713uk13m <[email protected]> @time : 11/10/18 11:36 @return \nguyenanhung\MyRequests\SoapRequest|object
[ "Function", "createSOAPRequest" ]
train
https://github.com/nguyenanhung/td-send-sms/blob/ed7b413aa09918e0dab3354cbc1d0c4565d39463/src/SendSMS/SendSmsToVnmSDP.php#L147-L163
nguyenanhung/td-send-sms
src/SendSMS/SendSmsToVnmSDP.php
SendSmsToVnmSDP.setSdkConfig
public function setSdkConfig($sdkConfig = NULL) { $this->sdkConfig = $sdkConfig; $this->logger->debug(__FUNCTION__, 'Config Data: ' . json_encode($this->sdkConfig)); if (empty($this->sdkConfig) || !is_array($this->sdkConfig)) { $this->error = TRUE; $this->logger->error(__FUNCTION__, 'Config Data is Empty!'); } return $this; }
php
public function setSdkConfig($sdkConfig = NULL) { $this->sdkConfig = $sdkConfig; $this->logger->debug(__FUNCTION__, 'Config Data: ' . json_encode($this->sdkConfig)); if (empty($this->sdkConfig) || !is_array($this->sdkConfig)) { $this->error = TRUE; $this->logger->error(__FUNCTION__, 'Config Data is Empty!'); } return $this; }
[ "public", "function", "setSdkConfig", "(", "$", "sdkConfig", "=", "NULL", ")", "{", "$", "this", "->", "sdkConfig", "=", "$", "sdkConfig", ";", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'Config Data: '", ".", "json_encode", "(", "$", "this", "->", "sdkConfig", ")", ")", ";", "if", "(", "empty", "(", "$", "this", "->", "sdkConfig", ")", "||", "!", "is_array", "(", "$", "this", "->", "sdkConfig", ")", ")", "{", "$", "this", "->", "error", "=", "TRUE", ";", "$", "this", "->", "logger", "->", "error", "(", "__FUNCTION__", ",", "'Config Data is Empty!'", ")", ";", "}", "return", "$", "this", ";", "}" ]
Cấu hình Config Data @author: 713uk13m <[email protected]> @time : 11/9/18 15:33 @param array|null $sdkConfig @return $this
[ "Cấu", "hình", "Config", "Data" ]
train
https://github.com/nguyenanhung/td-send-sms/blob/ed7b413aa09918e0dab3354cbc1d0c4565d39463/src/SendSMS/SendSmsToVnmSDP.php#L175-L185
nguyenanhung/td-send-sms
src/SendSMS/SendSmsToVnmSDP.php
SendSmsToVnmSDP.setResponseIsObject
public function setResponseIsObject($responseIsObject = FALSE) { $this->responseIsObject = $responseIsObject; $this->logger->error(__FUNCTION__, 'Response Is Object: ' . $this->responseIsObject); return $this; }
php
public function setResponseIsObject($responseIsObject = FALSE) { $this->responseIsObject = $responseIsObject; $this->logger->error(__FUNCTION__, 'Response Is Object: ' . $this->responseIsObject); return $this; }
[ "public", "function", "setResponseIsObject", "(", "$", "responseIsObject", "=", "FALSE", ")", "{", "$", "this", "->", "responseIsObject", "=", "$", "responseIsObject", ";", "$", "this", "->", "logger", "->", "error", "(", "__FUNCTION__", ",", "'Response Is Object: '", ".", "$", "this", "->", "responseIsObject", ")", ";", "return", "$", "this", ";", "}" ]
Function setResponseIsObject @author: 713uk13m <[email protected]> @time : 11/9/18 16:35 @param bool $responseIsObject @return $this
[ "Function", "setResponseIsObject" ]
train
https://github.com/nguyenanhung/td-send-sms/blob/ed7b413aa09918e0dab3354cbc1d0c4565d39463/src/SendSMS/SendSmsToVnmSDP.php#L210-L216
nguyenanhung/td-send-sms
src/SendSMS/SendSmsToVnmSDP.php
SendSmsToVnmSDP.startTransaction
public function startTransaction($transactionId = '') { $this->logger->debug(__FUNCTION__, 'Input Transaction ID: ' . json_encode($transactionId)); if (empty($transactionId)) { $transactionId = date('YmdHis') . rand(100000, 999999); } $this->transactionId = $transactionId; $this->logger->debug(__FUNCTION__, 'Output Transaction ID: ' . json_encode($this->transactionId)); return $this; }
php
public function startTransaction($transactionId = '') { $this->logger->debug(__FUNCTION__, 'Input Transaction ID: ' . json_encode($transactionId)); if (empty($transactionId)) { $transactionId = date('YmdHis') . rand(100000, 999999); } $this->transactionId = $transactionId; $this->logger->debug(__FUNCTION__, 'Output Transaction ID: ' . json_encode($this->transactionId)); return $this; }
[ "public", "function", "startTransaction", "(", "$", "transactionId", "=", "''", ")", "{", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'Input Transaction ID: '", ".", "json_encode", "(", "$", "transactionId", ")", ")", ";", "if", "(", "empty", "(", "$", "transactionId", ")", ")", "{", "$", "transactionId", "=", "date", "(", "'YmdHis'", ")", ".", "rand", "(", "100000", ",", "999999", ")", ";", "}", "$", "this", "->", "transactionId", "=", "$", "transactionId", ";", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'Output Transaction ID: '", ".", "json_encode", "(", "$", "this", "->", "transactionId", ")", ")", ";", "return", "$", "this", ";", "}" ]
Function startTransaction @author: 713uk13m <[email protected]> @time : 11/9/18 15:50 @param string $transactionId @return $this
[ "Function", "startTransaction" ]
train
https://github.com/nguyenanhung/td-send-sms/blob/ed7b413aa09918e0dab3354cbc1d0c4565d39463/src/SendSMS/SendSmsToVnmSDP.php#L258-L268
nguyenanhung/td-send-sms
src/SendSMS/SendSmsToVnmSDP.php
SendSmsToVnmSDP.setSendMtStatus
public function setSendMtStatus($sendMtStatus = TRUE) { $this->sendMtStatus = $sendMtStatus; $this->logger->debug(__FUNCTION__, 'Send MT Status: ' . json_encode($this->sendMtStatus)); return $this; }
php
public function setSendMtStatus($sendMtStatus = TRUE) { $this->sendMtStatus = $sendMtStatus; $this->logger->debug(__FUNCTION__, 'Send MT Status: ' . json_encode($this->sendMtStatus)); return $this; }
[ "public", "function", "setSendMtStatus", "(", "$", "sendMtStatus", "=", "TRUE", ")", "{", "$", "this", "->", "sendMtStatus", "=", "$", "sendMtStatus", ";", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'Send MT Status: '", ".", "json_encode", "(", "$", "this", "->", "sendMtStatus", ")", ")", ";", "return", "$", "this", ";", "}" ]
Function setSendMtStatus @author: 713uk13m <[email protected]> @time : 11/18/18 03:11 @param bool $sendMtStatus @return $this
[ "Function", "setSendMtStatus" ]
train
https://github.com/nguyenanhung/td-send-sms/blob/ed7b413aa09918e0dab3354cbc1d0c4565d39463/src/SendSMS/SendSmsToVnmSDP.php#L293-L299
nguyenanhung/td-send-sms
src/SendSMS/SendSmsToVnmSDP.php
SendSmsToVnmSDP.getMtResult
public function getMtResult() { $this->logger->info(__FUNCTION__, 'Mt Result: ' . json_encode($this->mtResult)); return $this->mtResult; }
php
public function getMtResult() { $this->logger->info(__FUNCTION__, 'Mt Result: ' . json_encode($this->mtResult)); return $this->mtResult; }
[ "public", "function", "getMtResult", "(", ")", "{", "$", "this", "->", "logger", "->", "info", "(", "__FUNCTION__", ",", "'Mt Result: '", ".", "json_encode", "(", "$", "this", "->", "mtResult", ")", ")", ";", "return", "$", "this", "->", "mtResult", ";", "}" ]
Trả về kết quả của quá trình trả MT @author: 713uk13m <[email protected]> @time : 11/10/18 09:19 @return array|null|object Mảng dữ liệu trạng thái gửi MT, biến status == 0 là thành công
[ "Trả", "về", "kết", "quả", "của", "quá", "trình", "trả", "MT" ]
train
https://github.com/nguyenanhung/td-send-sms/blob/ed7b413aa09918e0dab3354cbc1d0c4565d39463/src/SendSMS/SendSmsToVnmSDP.php#L389-L394
nguyenanhung/td-send-sms
src/SendSMS/SendSmsToVnmSDP.php
SendSmsToVnmSDP.generateMtDataToDb
public function generateMtDataToDb() { if ($this->sendMtStatus === TRUE) { $this->mtDataToDb = array( 'shortcode' => $this->sdkConfig[self::SDP_CONFIG_KEY]['short_code'], 'msisdn' => $this->transactionMsisdn, 'mo' => $this->mtOptions['mo'], 'mt' => $this->mtMsg, 'status' => $this->mtTransactionStatus, 'response' => json_encode($this->mtRequestResponse), 'note' => $this->mtOptions['note'], 'subCode' => $this->mtOptions['subCode'], 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s') ); $this->logger->debug(__FUNCTION__, 'Send MT is TRUE, Gọi đến Web Service nhà mạng Send SMS'); } else { $mtRequestResponse = array( "transId" => $this->transactionId, "username" => $this->sdkConfig[self::SDP_CONFIG_KEY]['username'], "description" => "Save to DB, don't send SMS", "status" => 0 ); $mtRequestResponse = json_encode($mtRequestResponse); $this->mtDataToDb = array( 'shortcode' => $this->sdkConfig[self::SDP_CONFIG_KEY]['short_code'], 'msisdn' => $this->transactionMsisdn, 'mo' => $this->mtOptions['mo'], 'mt' => $this->mtMsg, 'status' => self::EXIT_SUCCESS, 'response' => $mtRequestResponse, 'note' => $this->mtOptions['note'], 'subCode' => $this->mtOptions['subCode'], 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s') ); $this->logger->debug(__FUNCTION__, 'Send MT !== TRUE, Chỉ lưu log DB, không gọi Web Service'); } $this->logger->debug(__FUNCTION__, 'MT Data Into DB: ' . json_encode($this->mtDataToDb)); return $this; }
php
public function generateMtDataToDb() { if ($this->sendMtStatus === TRUE) { $this->mtDataToDb = array( 'shortcode' => $this->sdkConfig[self::SDP_CONFIG_KEY]['short_code'], 'msisdn' => $this->transactionMsisdn, 'mo' => $this->mtOptions['mo'], 'mt' => $this->mtMsg, 'status' => $this->mtTransactionStatus, 'response' => json_encode($this->mtRequestResponse), 'note' => $this->mtOptions['note'], 'subCode' => $this->mtOptions['subCode'], 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s') ); $this->logger->debug(__FUNCTION__, 'Send MT is TRUE, Gọi đến Web Service nhà mạng Send SMS'); } else { $mtRequestResponse = array( "transId" => $this->transactionId, "username" => $this->sdkConfig[self::SDP_CONFIG_KEY]['username'], "description" => "Save to DB, don't send SMS", "status" => 0 ); $mtRequestResponse = json_encode($mtRequestResponse); $this->mtDataToDb = array( 'shortcode' => $this->sdkConfig[self::SDP_CONFIG_KEY]['short_code'], 'msisdn' => $this->transactionMsisdn, 'mo' => $this->mtOptions['mo'], 'mt' => $this->mtMsg, 'status' => self::EXIT_SUCCESS, 'response' => $mtRequestResponse, 'note' => $this->mtOptions['note'], 'subCode' => $this->mtOptions['subCode'], 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s') ); $this->logger->debug(__FUNCTION__, 'Send MT !== TRUE, Chỉ lưu log DB, không gọi Web Service'); } $this->logger->debug(__FUNCTION__, 'MT Data Into DB: ' . json_encode($this->mtDataToDb)); return $this; }
[ "public", "function", "generateMtDataToDb", "(", ")", "{", "if", "(", "$", "this", "->", "sendMtStatus", "===", "TRUE", ")", "{", "$", "this", "->", "mtDataToDb", "=", "array", "(", "'shortcode'", "=>", "$", "this", "->", "sdkConfig", "[", "self", "::", "SDP_CONFIG_KEY", "]", "[", "'short_code'", "]", ",", "'msisdn'", "=>", "$", "this", "->", "transactionMsisdn", ",", "'mo'", "=>", "$", "this", "->", "mtOptions", "[", "'mo'", "]", ",", "'mt'", "=>", "$", "this", "->", "mtMsg", ",", "'status'", "=>", "$", "this", "->", "mtTransactionStatus", ",", "'response'", "=>", "json_encode", "(", "$", "this", "->", "mtRequestResponse", ")", ",", "'note'", "=>", "$", "this", "->", "mtOptions", "[", "'note'", "]", ",", "'subCode'", "=>", "$", "this", "->", "mtOptions", "[", "'subCode'", "]", ",", "'created_at'", "=>", "date", "(", "'Y-m-d H:i:s'", ")", ",", "'updated_at'", "=>", "date", "(", "'Y-m-d H:i:s'", ")", ")", ";", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'Send MT is TRUE, Gọi đến Web Service nhà mạng Send SMS');", "", "", "}", "else", "{", "$", "mtRequestResponse", "=", "array", "(", "\"transId\"", "=>", "$", "this", "->", "transactionId", ",", "\"username\"", "=>", "$", "this", "->", "sdkConfig", "[", "self", "::", "SDP_CONFIG_KEY", "]", "[", "'username'", "]", ",", "\"description\"", "=>", "\"Save to DB, don't send SMS\"", ",", "\"status\"", "=>", "0", ")", ";", "$", "mtRequestResponse", "=", "json_encode", "(", "$", "mtRequestResponse", ")", ";", "$", "this", "->", "mtDataToDb", "=", "array", "(", "'shortcode'", "=>", "$", "this", "->", "sdkConfig", "[", "self", "::", "SDP_CONFIG_KEY", "]", "[", "'short_code'", "]", ",", "'msisdn'", "=>", "$", "this", "->", "transactionMsisdn", ",", "'mo'", "=>", "$", "this", "->", "mtOptions", "[", "'mo'", "]", ",", "'mt'", "=>", "$", "this", "->", "mtMsg", ",", "'status'", "=>", "self", "::", "EXIT_SUCCESS", ",", "'response'", "=>", "$", "mtRequestResponse", ",", "'note'", "=>", "$", "this", "->", "mtOptions", "[", "'note'", "]", ",", "'subCode'", "=>", "$", "this", "->", "mtOptions", "[", "'subCode'", "]", ",", "'created_at'", "=>", "date", "(", "'Y-m-d H:i:s'", ")", ",", "'updated_at'", "=>", "date", "(", "'Y-m-d H:i:s'", ")", ")", ";", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'Send MT !== TRUE, Chỉ lưu log DB, không gọi Web Service');", "", "", "}", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'MT Data Into DB: '", ".", "json_encode", "(", "$", "this", "->", "mtDataToDb", ")", ")", ";", "return", "$", "this", ";", "}" ]
Hàm tạo dữ liệu Insert DB sau khi gửi MT @author: 713uk13m <[email protected]> @time : 11/9/18 16:52 @return $this
[ "Hàm", "tạo", "dữ", "liệu", "Insert", "DB", "sau", "khi", "gửi", "MT" ]
train
https://github.com/nguyenanhung/td-send-sms/blob/ed7b413aa09918e0dab3354cbc1d0c4565d39463/src/SendSMS/SendSmsToVnmSDP.php#L418-L459
nguyenanhung/td-send-sms
src/SendSMS/SendSmsToVnmSDP.php
SendSmsToVnmSDP.insertMtIntoDb
public function insertMtIntoDb() { $this->getMtDataToDb(); $db = $this->connectDatabase($this->sdkConfig[self::SDP_DATABASE_CONFIG_KEY]); $insertId = $db ->setTable(self::TABLE_SMS_LOG . date(self::TABLE_SMS_LOG_SUFFIX)) ->add($this->mtDataToDb); $this->logger->debug(__FUNCTION__, 'Insert MT Into DB Data: ' . json_encode($this->mtDataToDb)); $this->logger->debug(__FUNCTION__, 'Insert MT Into DB InsertID: ' . json_encode($insertId)); return $insertId; }
php
public function insertMtIntoDb() { $this->getMtDataToDb(); $db = $this->connectDatabase($this->sdkConfig[self::SDP_DATABASE_CONFIG_KEY]); $insertId = $db ->setTable(self::TABLE_SMS_LOG . date(self::TABLE_SMS_LOG_SUFFIX)) ->add($this->mtDataToDb); $this->logger->debug(__FUNCTION__, 'Insert MT Into DB Data: ' . json_encode($this->mtDataToDb)); $this->logger->debug(__FUNCTION__, 'Insert MT Into DB InsertID: ' . json_encode($insertId)); return $insertId; }
[ "public", "function", "insertMtIntoDb", "(", ")", "{", "$", "this", "->", "getMtDataToDb", "(", ")", ";", "$", "db", "=", "$", "this", "->", "connectDatabase", "(", "$", "this", "->", "sdkConfig", "[", "self", "::", "SDP_DATABASE_CONFIG_KEY", "]", ")", ";", "$", "insertId", "=", "$", "db", "->", "setTable", "(", "self", "::", "TABLE_SMS_LOG", ".", "date", "(", "self", "::", "TABLE_SMS_LOG_SUFFIX", ")", ")", "->", "add", "(", "$", "this", "->", "mtDataToDb", ")", ";", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'Insert MT Into DB Data: '", ".", "json_encode", "(", "$", "this", "->", "mtDataToDb", ")", ")", ";", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'Insert MT Into DB InsertID: '", ".", "json_encode", "(", "$", "insertId", ")", ")", ";", "return", "$", "insertId", ";", "}" ]
Function insertMtIntoDb @author: 713uk13m <[email protected]> @time : 11/18/18 02:58 @return int
[ "Function", "insertMtIntoDb" ]
train
https://github.com/nguyenanhung/td-send-sms/blob/ed7b413aa09918e0dab3354cbc1d0c4565d39463/src/SendSMS/SendSmsToVnmSDP.php#L469-L480
nguyenanhung/td-send-sms
src/SendSMS/SendSmsToVnmSDP.php
SendSmsToVnmSDP.setDataSendMt
public function setDataSendMt($phone_number = '', $message = '', $options = array()) { if (empty($phone_number) || empty($message)) { $this->error = TRUE; $this->mtData = NULL; $this->logger->error(__FUNCTION__, 'Empty Phone Number or MT Message -> ', ['phone_number' => $phone_number, 'message' => $message]); } if (empty($this->sdkConfig)) { $this->error = TRUE; $this->mtData = NULL; $this->logger->error(__FUNCTION__, 'Config Data is Empty!'); } $this->moId = isset($options['moId']) && !empty($options['moId']) && is_numeric($options['moId']) ? $options['moId'] : 0; $this->transactionMsisdn = $phone_number; $this->mtMsg = $message; $this->mtIsUnicode = isset($options['unicode']) ? $options['unicode'] : $this->sdkConfig[self::SDP_CONFIG_KEY]['unicode']; $this->mtIsFlash = isset($options['flash']) ? $options['flash'] : $this->sdkConfig[self::SDP_CONFIG_KEY]['flash']; $this->mtHref = isset($options['href']) ? $options['href'] : $this->sdkConfig[self::SDP_CONFIG_KEY]['href']; $this->logger->debug(__FUNCTION__, 'Transaction MoID: ' . json_encode($this->moId)); $this->logger->debug(__FUNCTION__, 'Transaction MT Message: ' . json_encode($this->mtMsg)); $this->logger->debug(__FUNCTION__, 'Transaction MSISDN: ' . json_encode($this->transactionMsisdn)); $this->logger->debug(__FUNCTION__, 'Transaction MT is Unicode: ' . json_encode($this->mtIsUnicode)); $this->logger->debug(__FUNCTION__, 'Transaction MT is Flash: ' . json_encode($this->mtIsFlash)); $this->logger->debug(__FUNCTION__, 'Transaction MT is Wap Push: ' . json_encode($this->mtHref)); $this->mtData = array( 'transId' => $this->transactionId, 'time' => date('YmdHis'), 'username' => $this->sdkConfig[self::SDP_CONFIG_KEY]['username'], 'password' => $this->sdkConfig[self::SDP_CONFIG_KEY]['password'], 'isdn' => $this->transactionMsisdn, 'serviceAddress' => $this->sdkConfig[self::SDP_CONFIG_KEY]['short_code'], 'categoryId' => $this->sdkConfig[self::SDP_CONFIG_KEY]['categoryId'], 'productId' => $this->sdkConfig[self::SDP_CONFIG_KEY]['productId'], 'moId' => $this->moId, 'message' => $this->mtMsg, 'unicode' => $this->mtIsUnicode, 'flash' => $this->mtIsFlash, 'href' => $this->mtHref ); $this->mtOptions = array( 'mo' => isset($options['mo']) ? $options['mo'] : '', 'note' => isset($options['note']) ? $options['note'] : '', 'subCode' => isset($options['subCode']) ? $options['subCode'] : '' ); $this->logger->debug(__FUNCTION__, 'MT Data Output: ' . json_encode($this->mtData)); $this->logger->debug(__FUNCTION__, 'MT Data save to DB: ' . json_encode($this->mtOptions)); return $this; }
php
public function setDataSendMt($phone_number = '', $message = '', $options = array()) { if (empty($phone_number) || empty($message)) { $this->error = TRUE; $this->mtData = NULL; $this->logger->error(__FUNCTION__, 'Empty Phone Number or MT Message -> ', ['phone_number' => $phone_number, 'message' => $message]); } if (empty($this->sdkConfig)) { $this->error = TRUE; $this->mtData = NULL; $this->logger->error(__FUNCTION__, 'Config Data is Empty!'); } $this->moId = isset($options['moId']) && !empty($options['moId']) && is_numeric($options['moId']) ? $options['moId'] : 0; $this->transactionMsisdn = $phone_number; $this->mtMsg = $message; $this->mtIsUnicode = isset($options['unicode']) ? $options['unicode'] : $this->sdkConfig[self::SDP_CONFIG_KEY]['unicode']; $this->mtIsFlash = isset($options['flash']) ? $options['flash'] : $this->sdkConfig[self::SDP_CONFIG_KEY]['flash']; $this->mtHref = isset($options['href']) ? $options['href'] : $this->sdkConfig[self::SDP_CONFIG_KEY]['href']; $this->logger->debug(__FUNCTION__, 'Transaction MoID: ' . json_encode($this->moId)); $this->logger->debug(__FUNCTION__, 'Transaction MT Message: ' . json_encode($this->mtMsg)); $this->logger->debug(__FUNCTION__, 'Transaction MSISDN: ' . json_encode($this->transactionMsisdn)); $this->logger->debug(__FUNCTION__, 'Transaction MT is Unicode: ' . json_encode($this->mtIsUnicode)); $this->logger->debug(__FUNCTION__, 'Transaction MT is Flash: ' . json_encode($this->mtIsFlash)); $this->logger->debug(__FUNCTION__, 'Transaction MT is Wap Push: ' . json_encode($this->mtHref)); $this->mtData = array( 'transId' => $this->transactionId, 'time' => date('YmdHis'), 'username' => $this->sdkConfig[self::SDP_CONFIG_KEY]['username'], 'password' => $this->sdkConfig[self::SDP_CONFIG_KEY]['password'], 'isdn' => $this->transactionMsisdn, 'serviceAddress' => $this->sdkConfig[self::SDP_CONFIG_KEY]['short_code'], 'categoryId' => $this->sdkConfig[self::SDP_CONFIG_KEY]['categoryId'], 'productId' => $this->sdkConfig[self::SDP_CONFIG_KEY]['productId'], 'moId' => $this->moId, 'message' => $this->mtMsg, 'unicode' => $this->mtIsUnicode, 'flash' => $this->mtIsFlash, 'href' => $this->mtHref ); $this->mtOptions = array( 'mo' => isset($options['mo']) ? $options['mo'] : '', 'note' => isset($options['note']) ? $options['note'] : '', 'subCode' => isset($options['subCode']) ? $options['subCode'] : '' ); $this->logger->debug(__FUNCTION__, 'MT Data Output: ' . json_encode($this->mtData)); $this->logger->debug(__FUNCTION__, 'MT Data save to DB: ' . json_encode($this->mtOptions)); return $this; }
[ "public", "function", "setDataSendMt", "(", "$", "phone_number", "=", "''", ",", "$", "message", "=", "''", ",", "$", "options", "=", "array", "(", ")", ")", "{", "if", "(", "empty", "(", "$", "phone_number", ")", "||", "empty", "(", "$", "message", ")", ")", "{", "$", "this", "->", "error", "=", "TRUE", ";", "$", "this", "->", "mtData", "=", "NULL", ";", "$", "this", "->", "logger", "->", "error", "(", "__FUNCTION__", ",", "'Empty Phone Number or MT Message -> '", ",", "[", "'phone_number'", "=>", "$", "phone_number", ",", "'message'", "=>", "$", "message", "]", ")", ";", "}", "if", "(", "empty", "(", "$", "this", "->", "sdkConfig", ")", ")", "{", "$", "this", "->", "error", "=", "TRUE", ";", "$", "this", "->", "mtData", "=", "NULL", ";", "$", "this", "->", "logger", "->", "error", "(", "__FUNCTION__", ",", "'Config Data is Empty!'", ")", ";", "}", "$", "this", "->", "moId", "=", "isset", "(", "$", "options", "[", "'moId'", "]", ")", "&&", "!", "empty", "(", "$", "options", "[", "'moId'", "]", ")", "&&", "is_numeric", "(", "$", "options", "[", "'moId'", "]", ")", "?", "$", "options", "[", "'moId'", "]", ":", "0", ";", "$", "this", "->", "transactionMsisdn", "=", "$", "phone_number", ";", "$", "this", "->", "mtMsg", "=", "$", "message", ";", "$", "this", "->", "mtIsUnicode", "=", "isset", "(", "$", "options", "[", "'unicode'", "]", ")", "?", "$", "options", "[", "'unicode'", "]", ":", "$", "this", "->", "sdkConfig", "[", "self", "::", "SDP_CONFIG_KEY", "]", "[", "'unicode'", "]", ";", "$", "this", "->", "mtIsFlash", "=", "isset", "(", "$", "options", "[", "'flash'", "]", ")", "?", "$", "options", "[", "'flash'", "]", ":", "$", "this", "->", "sdkConfig", "[", "self", "::", "SDP_CONFIG_KEY", "]", "[", "'flash'", "]", ";", "$", "this", "->", "mtHref", "=", "isset", "(", "$", "options", "[", "'href'", "]", ")", "?", "$", "options", "[", "'href'", "]", ":", "$", "this", "->", "sdkConfig", "[", "self", "::", "SDP_CONFIG_KEY", "]", "[", "'href'", "]", ";", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'Transaction MoID: '", ".", "json_encode", "(", "$", "this", "->", "moId", ")", ")", ";", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'Transaction MT Message: '", ".", "json_encode", "(", "$", "this", "->", "mtMsg", ")", ")", ";", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'Transaction MSISDN: '", ".", "json_encode", "(", "$", "this", "->", "transactionMsisdn", ")", ")", ";", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'Transaction MT is Unicode: '", ".", "json_encode", "(", "$", "this", "->", "mtIsUnicode", ")", ")", ";", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'Transaction MT is Flash: '", ".", "json_encode", "(", "$", "this", "->", "mtIsFlash", ")", ")", ";", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'Transaction MT is Wap Push: '", ".", "json_encode", "(", "$", "this", "->", "mtHref", ")", ")", ";", "$", "this", "->", "mtData", "=", "array", "(", "'transId'", "=>", "$", "this", "->", "transactionId", ",", "'time'", "=>", "date", "(", "'YmdHis'", ")", ",", "'username'", "=>", "$", "this", "->", "sdkConfig", "[", "self", "::", "SDP_CONFIG_KEY", "]", "[", "'username'", "]", ",", "'password'", "=>", "$", "this", "->", "sdkConfig", "[", "self", "::", "SDP_CONFIG_KEY", "]", "[", "'password'", "]", ",", "'isdn'", "=>", "$", "this", "->", "transactionMsisdn", ",", "'serviceAddress'", "=>", "$", "this", "->", "sdkConfig", "[", "self", "::", "SDP_CONFIG_KEY", "]", "[", "'short_code'", "]", ",", "'categoryId'", "=>", "$", "this", "->", "sdkConfig", "[", "self", "::", "SDP_CONFIG_KEY", "]", "[", "'categoryId'", "]", ",", "'productId'", "=>", "$", "this", "->", "sdkConfig", "[", "self", "::", "SDP_CONFIG_KEY", "]", "[", "'productId'", "]", ",", "'moId'", "=>", "$", "this", "->", "moId", ",", "'message'", "=>", "$", "this", "->", "mtMsg", ",", "'unicode'", "=>", "$", "this", "->", "mtIsUnicode", ",", "'flash'", "=>", "$", "this", "->", "mtIsFlash", ",", "'href'", "=>", "$", "this", "->", "mtHref", ")", ";", "$", "this", "->", "mtOptions", "=", "array", "(", "'mo'", "=>", "isset", "(", "$", "options", "[", "'mo'", "]", ")", "?", "$", "options", "[", "'mo'", "]", ":", "''", ",", "'note'", "=>", "isset", "(", "$", "options", "[", "'note'", "]", ")", "?", "$", "options", "[", "'note'", "]", ":", "''", ",", "'subCode'", "=>", "isset", "(", "$", "options", "[", "'subCode'", "]", ")", "?", "$", "options", "[", "'subCode'", "]", ":", "''", ")", ";", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'MT Data Output: '", ".", "json_encode", "(", "$", "this", "->", "mtData", ")", ")", ";", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'MT Data save to DB: '", ".", "json_encode", "(", "$", "this", "->", "mtOptions", ")", ")", ";", "return", "$", "this", ";", "}" ]
Hàm cấu hình Data Send MT @author: 713uk13m <[email protected]> @time : 11/9/18 15:57 @param string $phone_number SDT người nhận @param string $message Nội dung MT gửi đi @param null|array $options Các cấu hình thêm về MO @return $this
[ "Hàm", "cấu", "hình", "Data", "Send", "MT" ]
train
https://github.com/nguyenanhung/td-send-sms/blob/ed7b413aa09918e0dab3354cbc1d0c4565d39463/src/SendSMS/SendSmsToVnmSDP.php#L495-L544
nguyenanhung/td-send-sms
src/SendSMS/SendSmsToVnmSDP.php
SendSmsToVnmSDP.sendMtUseRestful
public function sendMtUseRestful($timeout = NULL) { if (empty($timeout)) { $timeout = self::REQUEST_TIMEOUT; } if (empty($this->mtData)) { $this->error = TRUE; $result = array( 'status' => self::EXIT_CONFIG, 'case' => 'MT_DATA_IS_EMPTY', 'desc' => 'MT Data is Empty' ); $this->logger->error(__FUNCTION__, 'MT Data is Empty', $result); } else { if ($this->isTest === TRUE) { // Test Service $this->logger->debug(__FUNCTION__, 'Test Send MT, giả lập quá trình gọi Request, chỉ test mã trả về'); $resp = array( 'transId' => $this->transactionId, 'username' => $this->sdkConfig[self::SDP_CONFIG_KEY]['username'], 'description' => 'Test Services', 'status' => self::SEND_MT_RESPONSE_STATUS_IS_SUCCESS ); $request = json_encode($resp); } else { // Send Request to VNM Gateway $request = $this->requests->jsonRequest(self::SEND_MT_RESTFUL_ENDPOINT, $this->mtData, $timeout); $this->logger->debug(__FUNCTION__, 'URL Endpoint to Request: ' . json_encode(self::SEND_MT_RESTFUL_ENDPOINT)); $this->logger->debug(__FUNCTION__, 'Data Content to Request: ' . json_encode($this->mtData)); $this->logger->debug(__FUNCTION__, 'Timeout to Request: ' . json_encode($timeout)); } $this->logger->debug(__FUNCTION__, 'Data Response from Request: ' . json_encode($request)); $data = json_decode(trim($request)); if (json_last_error() != JSON_ERROR_NONE) { // có lỗi $errorMsg = function_exists('json_last_error_msg') ? 'Json Decode is Error: ' . json_last_error_msg() : 'Json Decode is Error'; $this->logger->error(__FUNCTION__, $errorMsg); $result = array( 'status' => self::EXIT_ERROR, 'case' => 'JSON_DECODE_ERROR', 'desc' => 'Json Decode Error from Response of Request' ); $this->logger->debug(__FUNCTION__, 'Json Decode is Error ', $result); } else { if (!isset($data->status)) { $result = array( 'status' => self::EXIT_DATABASE, 'case' => 'MISSING_STATUS_FROM_REQUEST', 'desc' => 'Error: Missing Status from Response of Request' ); $this->logger->debug(__FUNCTION__, 'MT Data is Empty', $result); } else { if ($data->status == self::SEND_MT_RESPONSE_STATUS_IS_SUCCESS) { // Send MT thành công $result = array( 'status' => self::EXIT_SUCCESS, 'case' => 'SUCCESS', 'desc' => 'Send MT is Success!', 'response' => array( // Main Data 'transactionId' => $this->transactionId, 'moId' => $this->moId, 'phone_number' => $this->transactionMsisdn, 'mt_message' => $this->mtMsg ), 'request_response' => array( // Response from Request 'status' => isset($data->status) ? $data->status : NULL, 'description' => isset($data->description) ? $data->description : NULL, 'transactionId' => isset($data->transId) ? $data->transId : NULL, 'username' => isset($data->username) ? $data->username : NULL ) ); $this->logger->debug(__FUNCTION__, 'Send MT is Success => ', $result); } else { // Send MT thất bại $result = array( 'status' => self::EXIT_ERROR, 'case' => 'FALSE', 'desc' => 'Send MT is Error!', 'response' => array( // Main Data 'transactionId' => $this->transactionId, 'moId' => $this->moId, 'phone_number' => $this->transactionMsisdn, 'mt_message' => $this->mtMsg ), 'request_response' => array( // Response from Request 'status' => isset($data->status) ? $data->status : NULL, 'description' => isset($data->description) ? $data->description : NULL, 'transactionId' => isset($data->transId) ? $data->transId : NULL, 'username' => isset($data->username) ? $data->username : NULL ) ); $this->logger->error(__FUNCTION__, 'Send MT is Error => ', $result['request_response']); $this->logger->debug(__FUNCTION__, 'Send MT is Error => ', $result); } } } $this->mtRequestResponse = $request; $this->mtTransactionStatus = $result['status']; } if ($this->responseIsObject === TRUE) { $result = Utils::arrayToObject($result); } $this->mtResult = $result; return $this; }
php
public function sendMtUseRestful($timeout = NULL) { if (empty($timeout)) { $timeout = self::REQUEST_TIMEOUT; } if (empty($this->mtData)) { $this->error = TRUE; $result = array( 'status' => self::EXIT_CONFIG, 'case' => 'MT_DATA_IS_EMPTY', 'desc' => 'MT Data is Empty' ); $this->logger->error(__FUNCTION__, 'MT Data is Empty', $result); } else { if ($this->isTest === TRUE) { // Test Service $this->logger->debug(__FUNCTION__, 'Test Send MT, giả lập quá trình gọi Request, chỉ test mã trả về'); $resp = array( 'transId' => $this->transactionId, 'username' => $this->sdkConfig[self::SDP_CONFIG_KEY]['username'], 'description' => 'Test Services', 'status' => self::SEND_MT_RESPONSE_STATUS_IS_SUCCESS ); $request = json_encode($resp); } else { // Send Request to VNM Gateway $request = $this->requests->jsonRequest(self::SEND_MT_RESTFUL_ENDPOINT, $this->mtData, $timeout); $this->logger->debug(__FUNCTION__, 'URL Endpoint to Request: ' . json_encode(self::SEND_MT_RESTFUL_ENDPOINT)); $this->logger->debug(__FUNCTION__, 'Data Content to Request: ' . json_encode($this->mtData)); $this->logger->debug(__FUNCTION__, 'Timeout to Request: ' . json_encode($timeout)); } $this->logger->debug(__FUNCTION__, 'Data Response from Request: ' . json_encode($request)); $data = json_decode(trim($request)); if (json_last_error() != JSON_ERROR_NONE) { // có lỗi $errorMsg = function_exists('json_last_error_msg') ? 'Json Decode is Error: ' . json_last_error_msg() : 'Json Decode is Error'; $this->logger->error(__FUNCTION__, $errorMsg); $result = array( 'status' => self::EXIT_ERROR, 'case' => 'JSON_DECODE_ERROR', 'desc' => 'Json Decode Error from Response of Request' ); $this->logger->debug(__FUNCTION__, 'Json Decode is Error ', $result); } else { if (!isset($data->status)) { $result = array( 'status' => self::EXIT_DATABASE, 'case' => 'MISSING_STATUS_FROM_REQUEST', 'desc' => 'Error: Missing Status from Response of Request' ); $this->logger->debug(__FUNCTION__, 'MT Data is Empty', $result); } else { if ($data->status == self::SEND_MT_RESPONSE_STATUS_IS_SUCCESS) { // Send MT thành công $result = array( 'status' => self::EXIT_SUCCESS, 'case' => 'SUCCESS', 'desc' => 'Send MT is Success!', 'response' => array( // Main Data 'transactionId' => $this->transactionId, 'moId' => $this->moId, 'phone_number' => $this->transactionMsisdn, 'mt_message' => $this->mtMsg ), 'request_response' => array( // Response from Request 'status' => isset($data->status) ? $data->status : NULL, 'description' => isset($data->description) ? $data->description : NULL, 'transactionId' => isset($data->transId) ? $data->transId : NULL, 'username' => isset($data->username) ? $data->username : NULL ) ); $this->logger->debug(__FUNCTION__, 'Send MT is Success => ', $result); } else { // Send MT thất bại $result = array( 'status' => self::EXIT_ERROR, 'case' => 'FALSE', 'desc' => 'Send MT is Error!', 'response' => array( // Main Data 'transactionId' => $this->transactionId, 'moId' => $this->moId, 'phone_number' => $this->transactionMsisdn, 'mt_message' => $this->mtMsg ), 'request_response' => array( // Response from Request 'status' => isset($data->status) ? $data->status : NULL, 'description' => isset($data->description) ? $data->description : NULL, 'transactionId' => isset($data->transId) ? $data->transId : NULL, 'username' => isset($data->username) ? $data->username : NULL ) ); $this->logger->error(__FUNCTION__, 'Send MT is Error => ', $result['request_response']); $this->logger->debug(__FUNCTION__, 'Send MT is Error => ', $result); } } } $this->mtRequestResponse = $request; $this->mtTransactionStatus = $result['status']; } if ($this->responseIsObject === TRUE) { $result = Utils::arrayToObject($result); } $this->mtResult = $result; return $this; }
[ "public", "function", "sendMtUseRestful", "(", "$", "timeout", "=", "NULL", ")", "{", "if", "(", "empty", "(", "$", "timeout", ")", ")", "{", "$", "timeout", "=", "self", "::", "REQUEST_TIMEOUT", ";", "}", "if", "(", "empty", "(", "$", "this", "->", "mtData", ")", ")", "{", "$", "this", "->", "error", "=", "TRUE", ";", "$", "result", "=", "array", "(", "'status'", "=>", "self", "::", "EXIT_CONFIG", ",", "'case'", "=>", "'MT_DATA_IS_EMPTY'", ",", "'desc'", "=>", "'MT Data is Empty'", ")", ";", "$", "this", "->", "logger", "->", "error", "(", "__FUNCTION__", ",", "'MT Data is Empty'", ",", "$", "result", ")", ";", "}", "else", "{", "if", "(", "$", "this", "->", "isTest", "===", "TRUE", ")", "{", "// Test Service", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'Test Send MT, giả lập quá trình gọi Request, chỉ test mã trả về');", "", "", "$", "resp", "=", "array", "(", "'transId'", "=>", "$", "this", "->", "transactionId", ",", "'username'", "=>", "$", "this", "->", "sdkConfig", "[", "self", "::", "SDP_CONFIG_KEY", "]", "[", "'username'", "]", ",", "'description'", "=>", "'Test Services'", ",", "'status'", "=>", "self", "::", "SEND_MT_RESPONSE_STATUS_IS_SUCCESS", ")", ";", "$", "request", "=", "json_encode", "(", "$", "resp", ")", ";", "}", "else", "{", "// Send Request to VNM Gateway", "$", "request", "=", "$", "this", "->", "requests", "->", "jsonRequest", "(", "self", "::", "SEND_MT_RESTFUL_ENDPOINT", ",", "$", "this", "->", "mtData", ",", "$", "timeout", ")", ";", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'URL Endpoint to Request: '", ".", "json_encode", "(", "self", "::", "SEND_MT_RESTFUL_ENDPOINT", ")", ")", ";", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'Data Content to Request: '", ".", "json_encode", "(", "$", "this", "->", "mtData", ")", ")", ";", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'Timeout to Request: '", ".", "json_encode", "(", "$", "timeout", ")", ")", ";", "}", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'Data Response from Request: '", ".", "json_encode", "(", "$", "request", ")", ")", ";", "$", "data", "=", "json_decode", "(", "trim", "(", "$", "request", ")", ")", ";", "if", "(", "json_last_error", "(", ")", "!=", "JSON_ERROR_NONE", ")", "{", "// có lỗi", "$", "errorMsg", "=", "function_exists", "(", "'json_last_error_msg'", ")", "?", "'Json Decode is Error: '", ".", "json_last_error_msg", "(", ")", ":", "'Json Decode is Error'", ";", "$", "this", "->", "logger", "->", "error", "(", "__FUNCTION__", ",", "$", "errorMsg", ")", ";", "$", "result", "=", "array", "(", "'status'", "=>", "self", "::", "EXIT_ERROR", ",", "'case'", "=>", "'JSON_DECODE_ERROR'", ",", "'desc'", "=>", "'Json Decode Error from Response of Request'", ")", ";", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'Json Decode is Error '", ",", "$", "result", ")", ";", "}", "else", "{", "if", "(", "!", "isset", "(", "$", "data", "->", "status", ")", ")", "{", "$", "result", "=", "array", "(", "'status'", "=>", "self", "::", "EXIT_DATABASE", ",", "'case'", "=>", "'MISSING_STATUS_FROM_REQUEST'", ",", "'desc'", "=>", "'Error: Missing Status from Response of Request'", ")", ";", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'MT Data is Empty'", ",", "$", "result", ")", ";", "}", "else", "{", "if", "(", "$", "data", "->", "status", "==", "self", "::", "SEND_MT_RESPONSE_STATUS_IS_SUCCESS", ")", "{", "// Send MT thành công", "$", "result", "=", "array", "(", "'status'", "=>", "self", "::", "EXIT_SUCCESS", ",", "'case'", "=>", "'SUCCESS'", ",", "'desc'", "=>", "'Send MT is Success!'", ",", "'response'", "=>", "array", "(", "// Main Data", "'transactionId'", "=>", "$", "this", "->", "transactionId", ",", "'moId'", "=>", "$", "this", "->", "moId", ",", "'phone_number'", "=>", "$", "this", "->", "transactionMsisdn", ",", "'mt_message'", "=>", "$", "this", "->", "mtMsg", ")", ",", "'request_response'", "=>", "array", "(", "// Response from Request", "'status'", "=>", "isset", "(", "$", "data", "->", "status", ")", "?", "$", "data", "->", "status", ":", "NULL", ",", "'description'", "=>", "isset", "(", "$", "data", "->", "description", ")", "?", "$", "data", "->", "description", ":", "NULL", ",", "'transactionId'", "=>", "isset", "(", "$", "data", "->", "transId", ")", "?", "$", "data", "->", "transId", ":", "NULL", ",", "'username'", "=>", "isset", "(", "$", "data", "->", "username", ")", "?", "$", "data", "->", "username", ":", "NULL", ")", ")", ";", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'Send MT is Success => '", ",", "$", "result", ")", ";", "}", "else", "{", "// Send MT thất bại", "$", "result", "=", "array", "(", "'status'", "=>", "self", "::", "EXIT_ERROR", ",", "'case'", "=>", "'FALSE'", ",", "'desc'", "=>", "'Send MT is Error!'", ",", "'response'", "=>", "array", "(", "// Main Data", "'transactionId'", "=>", "$", "this", "->", "transactionId", ",", "'moId'", "=>", "$", "this", "->", "moId", ",", "'phone_number'", "=>", "$", "this", "->", "transactionMsisdn", ",", "'mt_message'", "=>", "$", "this", "->", "mtMsg", ")", ",", "'request_response'", "=>", "array", "(", "// Response from Request", "'status'", "=>", "isset", "(", "$", "data", "->", "status", ")", "?", "$", "data", "->", "status", ":", "NULL", ",", "'description'", "=>", "isset", "(", "$", "data", "->", "description", ")", "?", "$", "data", "->", "description", ":", "NULL", ",", "'transactionId'", "=>", "isset", "(", "$", "data", "->", "transId", ")", "?", "$", "data", "->", "transId", ":", "NULL", ",", "'username'", "=>", "isset", "(", "$", "data", "->", "username", ")", "?", "$", "data", "->", "username", ":", "NULL", ")", ")", ";", "$", "this", "->", "logger", "->", "error", "(", "__FUNCTION__", ",", "'Send MT is Error => '", ",", "$", "result", "[", "'request_response'", "]", ")", ";", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'Send MT is Error => '", ",", "$", "result", ")", ";", "}", "}", "}", "$", "this", "->", "mtRequestResponse", "=", "$", "request", ";", "$", "this", "->", "mtTransactionStatus", "=", "$", "result", "[", "'status'", "]", ";", "}", "if", "(", "$", "this", "->", "responseIsObject", "===", "TRUE", ")", "{", "$", "result", "=", "Utils", "::", "arrayToObject", "(", "$", "result", ")", ";", "}", "$", "this", "->", "mtResult", "=", "$", "result", ";", "return", "$", "this", ";", "}" ]
Hàm Request Send MT Sử dụng HTTP RESTful Web Service @author: 713uk13m <[email protected]> @time : 11/9/18 16:57 @param null $timeout Thời gian Timeout của Request @return $this Mảng dữ liệu $this->mtResult trạng thái gửi MT, biến status == 0 là thành công
[ "Hàm", "Request", "Send", "MT", "Sử", "dụng", "HTTP", "RESTful", "Web", "Service" ]
train
https://github.com/nguyenanhung/td-send-sms/blob/ed7b413aa09918e0dab3354cbc1d0c4565d39463/src/SendSMS/SendSmsToVnmSDP.php#L556-L665
nguyenanhung/td-send-sms
src/SendSMS/SendSmsToVnmSDP.php
SendSmsToVnmSDP.sendMtUseWsdl
public function sendMtUseWsdl() { if (empty($this->mtData)) { $this->error = TRUE; $result = array( 'status' => self::EXIT_CONFIG, 'case' => 'MT_DATA_IS_EMPTY', 'desc' => 'MT Data is Empty' ); $this->logger->error(__FUNCTION__, 'MT Data is Empty', $result); } else { if ($this->isTest === TRUE) { // Test Service $this->logger->debug(__FUNCTION__, 'Test Send MT, giả lập quá trình gọi Request, chỉ test mã trả về'); $request = array( 'status' => 0, 'code' => 0, 'data' => array( 'transId' => $this->transactionId, 'username' => $this->sdkConfig[self::SDP_CONFIG_KEY]['username'], 'description' => 'Test WSDL Services', 'status' => self::SEND_MT_RESPONSE_STATUS_IS_SUCCESS ) ); } else { // Create SOAP Object $soapRequest = self::createSOAPRequest(); // WSDL Send Request $request = $soapRequest->setEndpoint(self::SEND_MT_WSDL_ENDPOINT)->setData($this->mtData)->setCallFunction(self::SEND_MT_WSDL_CALL_METHOD)->setFieldResult(self::SEND_MT_WSDL_FIELD_RESULT)->clientRequestWsdl(); $this->logger->debug(__FUNCTION__, 'URL Endpoint => ' . json_encode(self::SEND_MT_WSDL_ENDPOINT)); $this->logger->debug(__FUNCTION__, 'Data to request => ' . json_encode($this->mtData)); $this->logger->debug(__FUNCTION__, 'Call Method => ' . json_encode(self::SEND_MT_WSDL_CALL_METHOD)); $this->logger->debug(__FUNCTION__, 'Field Result => ' . json_encode(self::SEND_MT_WSDL_FIELD_RESULT)); $this->logger->debug(__FUNCTION__, 'Response from Request => ' . json_encode($request)); } // filter Request if (is_array($request) && isset($request['status'])) { $request_response = array( 'status' => isset($request['data']['status']) ? $request['data']['status'] : NULL, 'description' => isset($request['data']['description']) ? $request['data']['description'] : NULL, 'transactionId' => isset($request['data']['transId']) ? $request['data']['transId'] : NULL, 'username' => isset($request['data']['username']) ? $request['data']['username'] : NULL ); if (($request['status'] == self::SEND_MT_RESPONSE_STATUS_IS_SUCCESS) && (isset($request['code']) && $request['code'] == self::SEND_MT_RESPONSE_STATUS_IS_SUCCESS)) { // Send MT thành công $result = array( 'status' => self::EXIT_SUCCESS, 'case' => 'SUCCESS', 'desc' => 'Send MT is Success!', 'response' => array( // Main Data 'transactionId' => $this->transactionId, 'moId' => $this->moId, 'phone_number' => $this->transactionMsisdn, 'mt_message' => $this->mtMsg ), 'request_response' => $request_response ); $this->logger->debug(__FUNCTION__, 'Send MT is Success => ', $result); } else { // Send MT thất bại $result = array( 'status' => self::EXIT_ERROR, 'case' => 'FALSE', 'desc' => 'Send MT is Error!', 'response' => array( // Main Data 'transactionId' => $this->transactionId, 'moId' => $this->moId, 'phone_number' => $this->transactionMsisdn, 'mt_message' => $this->mtMsg ), 'request_response' => $request_response ); $this->logger->error(__FUNCTION__, 'Send MT is Error => ', $request_response); $this->logger->debug(__FUNCTION__, 'Send MT is Success => ', $result); } } else { // Request Lỗi $result = array( 'status' => self::EXIT_ERROR, 'case' => 'CLIENT_WSDL_ERROR', 'desc' => 'Missing Result from WSDL' ); $this->logger->debug(__FUNCTION__, 'Missing Result from WSDL ', $result); } $this->mtRequestResponse = $request; $this->mtTransactionStatus = $result['status']; } if ($this->responseIsObject === TRUE) { $result = Utils::arrayToObject($result); } $this->mtResult = $result; return $this; }
php
public function sendMtUseWsdl() { if (empty($this->mtData)) { $this->error = TRUE; $result = array( 'status' => self::EXIT_CONFIG, 'case' => 'MT_DATA_IS_EMPTY', 'desc' => 'MT Data is Empty' ); $this->logger->error(__FUNCTION__, 'MT Data is Empty', $result); } else { if ($this->isTest === TRUE) { // Test Service $this->logger->debug(__FUNCTION__, 'Test Send MT, giả lập quá trình gọi Request, chỉ test mã trả về'); $request = array( 'status' => 0, 'code' => 0, 'data' => array( 'transId' => $this->transactionId, 'username' => $this->sdkConfig[self::SDP_CONFIG_KEY]['username'], 'description' => 'Test WSDL Services', 'status' => self::SEND_MT_RESPONSE_STATUS_IS_SUCCESS ) ); } else { // Create SOAP Object $soapRequest = self::createSOAPRequest(); // WSDL Send Request $request = $soapRequest->setEndpoint(self::SEND_MT_WSDL_ENDPOINT)->setData($this->mtData)->setCallFunction(self::SEND_MT_WSDL_CALL_METHOD)->setFieldResult(self::SEND_MT_WSDL_FIELD_RESULT)->clientRequestWsdl(); $this->logger->debug(__FUNCTION__, 'URL Endpoint => ' . json_encode(self::SEND_MT_WSDL_ENDPOINT)); $this->logger->debug(__FUNCTION__, 'Data to request => ' . json_encode($this->mtData)); $this->logger->debug(__FUNCTION__, 'Call Method => ' . json_encode(self::SEND_MT_WSDL_CALL_METHOD)); $this->logger->debug(__FUNCTION__, 'Field Result => ' . json_encode(self::SEND_MT_WSDL_FIELD_RESULT)); $this->logger->debug(__FUNCTION__, 'Response from Request => ' . json_encode($request)); } // filter Request if (is_array($request) && isset($request['status'])) { $request_response = array( 'status' => isset($request['data']['status']) ? $request['data']['status'] : NULL, 'description' => isset($request['data']['description']) ? $request['data']['description'] : NULL, 'transactionId' => isset($request['data']['transId']) ? $request['data']['transId'] : NULL, 'username' => isset($request['data']['username']) ? $request['data']['username'] : NULL ); if (($request['status'] == self::SEND_MT_RESPONSE_STATUS_IS_SUCCESS) && (isset($request['code']) && $request['code'] == self::SEND_MT_RESPONSE_STATUS_IS_SUCCESS)) { // Send MT thành công $result = array( 'status' => self::EXIT_SUCCESS, 'case' => 'SUCCESS', 'desc' => 'Send MT is Success!', 'response' => array( // Main Data 'transactionId' => $this->transactionId, 'moId' => $this->moId, 'phone_number' => $this->transactionMsisdn, 'mt_message' => $this->mtMsg ), 'request_response' => $request_response ); $this->logger->debug(__FUNCTION__, 'Send MT is Success => ', $result); } else { // Send MT thất bại $result = array( 'status' => self::EXIT_ERROR, 'case' => 'FALSE', 'desc' => 'Send MT is Error!', 'response' => array( // Main Data 'transactionId' => $this->transactionId, 'moId' => $this->moId, 'phone_number' => $this->transactionMsisdn, 'mt_message' => $this->mtMsg ), 'request_response' => $request_response ); $this->logger->error(__FUNCTION__, 'Send MT is Error => ', $request_response); $this->logger->debug(__FUNCTION__, 'Send MT is Success => ', $result); } } else { // Request Lỗi $result = array( 'status' => self::EXIT_ERROR, 'case' => 'CLIENT_WSDL_ERROR', 'desc' => 'Missing Result from WSDL' ); $this->logger->debug(__FUNCTION__, 'Missing Result from WSDL ', $result); } $this->mtRequestResponse = $request; $this->mtTransactionStatus = $result['status']; } if ($this->responseIsObject === TRUE) { $result = Utils::arrayToObject($result); } $this->mtResult = $result; return $this; }
[ "public", "function", "sendMtUseWsdl", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "mtData", ")", ")", "{", "$", "this", "->", "error", "=", "TRUE", ";", "$", "result", "=", "array", "(", "'status'", "=>", "self", "::", "EXIT_CONFIG", ",", "'case'", "=>", "'MT_DATA_IS_EMPTY'", ",", "'desc'", "=>", "'MT Data is Empty'", ")", ";", "$", "this", "->", "logger", "->", "error", "(", "__FUNCTION__", ",", "'MT Data is Empty'", ",", "$", "result", ")", ";", "}", "else", "{", "if", "(", "$", "this", "->", "isTest", "===", "TRUE", ")", "{", "// Test Service", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'Test Send MT, giả lập quá trình gọi Request, chỉ test mã trả về');", "", "", "$", "request", "=", "array", "(", "'status'", "=>", "0", ",", "'code'", "=>", "0", ",", "'data'", "=>", "array", "(", "'transId'", "=>", "$", "this", "->", "transactionId", ",", "'username'", "=>", "$", "this", "->", "sdkConfig", "[", "self", "::", "SDP_CONFIG_KEY", "]", "[", "'username'", "]", ",", "'description'", "=>", "'Test WSDL Services'", ",", "'status'", "=>", "self", "::", "SEND_MT_RESPONSE_STATUS_IS_SUCCESS", ")", ")", ";", "}", "else", "{", "// Create SOAP Object", "$", "soapRequest", "=", "self", "::", "createSOAPRequest", "(", ")", ";", "// WSDL Send Request", "$", "request", "=", "$", "soapRequest", "->", "setEndpoint", "(", "self", "::", "SEND_MT_WSDL_ENDPOINT", ")", "->", "setData", "(", "$", "this", "->", "mtData", ")", "->", "setCallFunction", "(", "self", "::", "SEND_MT_WSDL_CALL_METHOD", ")", "->", "setFieldResult", "(", "self", "::", "SEND_MT_WSDL_FIELD_RESULT", ")", "->", "clientRequestWsdl", "(", ")", ";", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'URL Endpoint => '", ".", "json_encode", "(", "self", "::", "SEND_MT_WSDL_ENDPOINT", ")", ")", ";", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'Data to request => '", ".", "json_encode", "(", "$", "this", "->", "mtData", ")", ")", ";", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'Call Method => '", ".", "json_encode", "(", "self", "::", "SEND_MT_WSDL_CALL_METHOD", ")", ")", ";", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'Field Result => '", ".", "json_encode", "(", "self", "::", "SEND_MT_WSDL_FIELD_RESULT", ")", ")", ";", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'Response from Request => '", ".", "json_encode", "(", "$", "request", ")", ")", ";", "}", "// filter Request", "if", "(", "is_array", "(", "$", "request", ")", "&&", "isset", "(", "$", "request", "[", "'status'", "]", ")", ")", "{", "$", "request_response", "=", "array", "(", "'status'", "=>", "isset", "(", "$", "request", "[", "'data'", "]", "[", "'status'", "]", ")", "?", "$", "request", "[", "'data'", "]", "[", "'status'", "]", ":", "NULL", ",", "'description'", "=>", "isset", "(", "$", "request", "[", "'data'", "]", "[", "'description'", "]", ")", "?", "$", "request", "[", "'data'", "]", "[", "'description'", "]", ":", "NULL", ",", "'transactionId'", "=>", "isset", "(", "$", "request", "[", "'data'", "]", "[", "'transId'", "]", ")", "?", "$", "request", "[", "'data'", "]", "[", "'transId'", "]", ":", "NULL", ",", "'username'", "=>", "isset", "(", "$", "request", "[", "'data'", "]", "[", "'username'", "]", ")", "?", "$", "request", "[", "'data'", "]", "[", "'username'", "]", ":", "NULL", ")", ";", "if", "(", "(", "$", "request", "[", "'status'", "]", "==", "self", "::", "SEND_MT_RESPONSE_STATUS_IS_SUCCESS", ")", "&&", "(", "isset", "(", "$", "request", "[", "'code'", "]", ")", "&&", "$", "request", "[", "'code'", "]", "==", "self", "::", "SEND_MT_RESPONSE_STATUS_IS_SUCCESS", ")", ")", "{", "// Send MT thành công", "$", "result", "=", "array", "(", "'status'", "=>", "self", "::", "EXIT_SUCCESS", ",", "'case'", "=>", "'SUCCESS'", ",", "'desc'", "=>", "'Send MT is Success!'", ",", "'response'", "=>", "array", "(", "// Main Data", "'transactionId'", "=>", "$", "this", "->", "transactionId", ",", "'moId'", "=>", "$", "this", "->", "moId", ",", "'phone_number'", "=>", "$", "this", "->", "transactionMsisdn", ",", "'mt_message'", "=>", "$", "this", "->", "mtMsg", ")", ",", "'request_response'", "=>", "$", "request_response", ")", ";", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'Send MT is Success => '", ",", "$", "result", ")", ";", "}", "else", "{", "// Send MT thất bại", "$", "result", "=", "array", "(", "'status'", "=>", "self", "::", "EXIT_ERROR", ",", "'case'", "=>", "'FALSE'", ",", "'desc'", "=>", "'Send MT is Error!'", ",", "'response'", "=>", "array", "(", "// Main Data", "'transactionId'", "=>", "$", "this", "->", "transactionId", ",", "'moId'", "=>", "$", "this", "->", "moId", ",", "'phone_number'", "=>", "$", "this", "->", "transactionMsisdn", ",", "'mt_message'", "=>", "$", "this", "->", "mtMsg", ")", ",", "'request_response'", "=>", "$", "request_response", ")", ";", "$", "this", "->", "logger", "->", "error", "(", "__FUNCTION__", ",", "'Send MT is Error => '", ",", "$", "request_response", ")", ";", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'Send MT is Success => '", ",", "$", "result", ")", ";", "}", "}", "else", "{", "// Request Lỗi", "$", "result", "=", "array", "(", "'status'", "=>", "self", "::", "EXIT_ERROR", ",", "'case'", "=>", "'CLIENT_WSDL_ERROR'", ",", "'desc'", "=>", "'Missing Result from WSDL'", ")", ";", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'Missing Result from WSDL '", ",", "$", "result", ")", ";", "}", "$", "this", "->", "mtRequestResponse", "=", "$", "request", ";", "$", "this", "->", "mtTransactionStatus", "=", "$", "result", "[", "'status'", "]", ";", "}", "if", "(", "$", "this", "->", "responseIsObject", "===", "TRUE", ")", "{", "$", "result", "=", "Utils", "::", "arrayToObject", "(", "$", "result", ")", ";", "}", "$", "this", "->", "mtResult", "=", "$", "result", ";", "return", "$", "this", ";", "}" ]
Hàm Request Send MT Sử dụng WSDL Web Service @author: 713uk13m <[email protected]> @time : 11/10/18 11:57 @return $this Mảng dữ liệu $this->mtResult trạng thái gửi MT, biến status == 0 là thành công
[ "Hàm", "Request", "Send", "MT", "Sử", "dụng", "WSDL", "Web", "Service" ]
train
https://github.com/nguyenanhung/td-send-sms/blob/ed7b413aa09918e0dab3354cbc1d0c4565d39463/src/SendSMS/SendSmsToVnmSDP.php#L675-L770
nguyenanhung/td-send-sms
src/SendSMS/SendSmsToVnmSDP.php
SendSmsToVnmSDP.sendMtUseSOAP
public function sendMtUseSOAP() { if (empty($this->mtData)) { $this->error = TRUE; $result = array( 'status' => self::EXIT_CONFIG, 'case' => 'MT_DATA_IS_EMPTY', 'desc' => 'MT Data is Empty' ); $this->logger->error(__FUNCTION__, 'MT Data is Empty', $result); } else { if ($this->isTest === TRUE) { // Test Service $this->logger->debug(__FUNCTION__, 'Test Send MT, giả lập quá trình gọi Request, chỉ test mã trả về'); $request = array( 'status' => 0, 'code' => 0, 'data' => array( 'transId' => $this->transactionId, 'username' => $this->sdkConfig[self::SDP_CONFIG_KEY]['username'], 'description' => 'Test SOAP Services', 'status' => self::SEND_MT_RESPONSE_STATUS_IS_SUCCESS ) ); } else { // Create SOAP Object $soapRequest = self::createSOAPRequest(); // WSDL Send Request $request = $soapRequest->setEndpoint(self::SEND_MT_SOAP_ENDPOINT)->setData($this->mtData)->setCallFunction(self::SEND_MT_SOAP_CALL_METHOD)->setFieldResult(self::SEND_MT_SOAP_FIELD_RESULT)->clientRequestSOAP(); $this->logger->debug(__FUNCTION__, 'URL Endpoint => ' . json_encode(self::SEND_MT_SOAP_ENDPOINT)); $this->logger->debug(__FUNCTION__, 'Data to request => ' . json_encode($this->mtData)); $this->logger->debug(__FUNCTION__, 'Call Method => ' . json_encode(self::SEND_MT_SOAP_CALL_METHOD)); $this->logger->debug(__FUNCTION__, 'Field Result => ' . json_encode(self::SEND_MT_SOAP_FIELD_RESULT)); $this->logger->debug(__FUNCTION__, 'Response from Request => ' . json_encode($request)); } // filter Request if (is_array($request) && isset($request['status'])) { $request_response = array( 'status' => isset($request['data']['status']) ? $request['data']['status'] : NULL, 'description' => isset($request['data']['description']) ? $request['data']['description'] : NULL, 'transactionId' => isset($request['data']['transId']) ? $request['data']['transId'] : NULL, 'username' => isset($request['data']['username']) ? $request['data']['username'] : NULL ); if (($request['status'] == self::SEND_MT_RESPONSE_STATUS_IS_SUCCESS) && (isset($request['code']) && $request['code'] == self::SEND_MT_RESPONSE_STATUS_IS_SUCCESS)) { // Send MT thành công $result = array( 'status' => self::EXIT_SUCCESS, 'case' => 'SUCCESS', 'desc' => 'Send MT is Success!', 'response' => array( // Main Data 'transactionId' => $this->transactionId, 'moId' => $this->moId, 'phone_number' => $this->transactionMsisdn, 'mt_message' => $this->mtMsg ), 'request_response' => $request_response ); $this->logger->debug(__FUNCTION__, 'Send MT is Success => ', $result); } else { // Send MT thất bại $result = array( 'status' => self::EXIT_ERROR, 'case' => 'FALSE', 'desc' => 'Send MT is Error!', 'response' => array( // Main Data 'transactionId' => $this->transactionId, 'moId' => $this->moId, 'phone_number' => $this->transactionMsisdn, 'mt_message' => $this->mtMsg ), 'request_response' => $request_response ); $this->logger->error(__FUNCTION__, 'Send MT is Error => ', $request_response); $this->logger->debug(__FUNCTION__, 'Send MT is Success => ', $result); } } else { // Request Lỗi $result = array( 'status' => self::EXIT_ERROR, 'case' => 'CLIENT_SOAP_ERROR', 'desc' => 'Missing Result from WSDL' ); $this->logger->debug(__FUNCTION__, 'Missing Result from SOAP ', $result); } $this->mtRequestResponse = $request; $this->mtTransactionStatus = $result['status']; } if ($this->responseIsObject === TRUE) { $result = Utils::arrayToObject($result); } $this->mtResult = $result; return $this; }
php
public function sendMtUseSOAP() { if (empty($this->mtData)) { $this->error = TRUE; $result = array( 'status' => self::EXIT_CONFIG, 'case' => 'MT_DATA_IS_EMPTY', 'desc' => 'MT Data is Empty' ); $this->logger->error(__FUNCTION__, 'MT Data is Empty', $result); } else { if ($this->isTest === TRUE) { // Test Service $this->logger->debug(__FUNCTION__, 'Test Send MT, giả lập quá trình gọi Request, chỉ test mã trả về'); $request = array( 'status' => 0, 'code' => 0, 'data' => array( 'transId' => $this->transactionId, 'username' => $this->sdkConfig[self::SDP_CONFIG_KEY]['username'], 'description' => 'Test SOAP Services', 'status' => self::SEND_MT_RESPONSE_STATUS_IS_SUCCESS ) ); } else { // Create SOAP Object $soapRequest = self::createSOAPRequest(); // WSDL Send Request $request = $soapRequest->setEndpoint(self::SEND_MT_SOAP_ENDPOINT)->setData($this->mtData)->setCallFunction(self::SEND_MT_SOAP_CALL_METHOD)->setFieldResult(self::SEND_MT_SOAP_FIELD_RESULT)->clientRequestSOAP(); $this->logger->debug(__FUNCTION__, 'URL Endpoint => ' . json_encode(self::SEND_MT_SOAP_ENDPOINT)); $this->logger->debug(__FUNCTION__, 'Data to request => ' . json_encode($this->mtData)); $this->logger->debug(__FUNCTION__, 'Call Method => ' . json_encode(self::SEND_MT_SOAP_CALL_METHOD)); $this->logger->debug(__FUNCTION__, 'Field Result => ' . json_encode(self::SEND_MT_SOAP_FIELD_RESULT)); $this->logger->debug(__FUNCTION__, 'Response from Request => ' . json_encode($request)); } // filter Request if (is_array($request) && isset($request['status'])) { $request_response = array( 'status' => isset($request['data']['status']) ? $request['data']['status'] : NULL, 'description' => isset($request['data']['description']) ? $request['data']['description'] : NULL, 'transactionId' => isset($request['data']['transId']) ? $request['data']['transId'] : NULL, 'username' => isset($request['data']['username']) ? $request['data']['username'] : NULL ); if (($request['status'] == self::SEND_MT_RESPONSE_STATUS_IS_SUCCESS) && (isset($request['code']) && $request['code'] == self::SEND_MT_RESPONSE_STATUS_IS_SUCCESS)) { // Send MT thành công $result = array( 'status' => self::EXIT_SUCCESS, 'case' => 'SUCCESS', 'desc' => 'Send MT is Success!', 'response' => array( // Main Data 'transactionId' => $this->transactionId, 'moId' => $this->moId, 'phone_number' => $this->transactionMsisdn, 'mt_message' => $this->mtMsg ), 'request_response' => $request_response ); $this->logger->debug(__FUNCTION__, 'Send MT is Success => ', $result); } else { // Send MT thất bại $result = array( 'status' => self::EXIT_ERROR, 'case' => 'FALSE', 'desc' => 'Send MT is Error!', 'response' => array( // Main Data 'transactionId' => $this->transactionId, 'moId' => $this->moId, 'phone_number' => $this->transactionMsisdn, 'mt_message' => $this->mtMsg ), 'request_response' => $request_response ); $this->logger->error(__FUNCTION__, 'Send MT is Error => ', $request_response); $this->logger->debug(__FUNCTION__, 'Send MT is Success => ', $result); } } else { // Request Lỗi $result = array( 'status' => self::EXIT_ERROR, 'case' => 'CLIENT_SOAP_ERROR', 'desc' => 'Missing Result from WSDL' ); $this->logger->debug(__FUNCTION__, 'Missing Result from SOAP ', $result); } $this->mtRequestResponse = $request; $this->mtTransactionStatus = $result['status']; } if ($this->responseIsObject === TRUE) { $result = Utils::arrayToObject($result); } $this->mtResult = $result; return $this; }
[ "public", "function", "sendMtUseSOAP", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "mtData", ")", ")", "{", "$", "this", "->", "error", "=", "TRUE", ";", "$", "result", "=", "array", "(", "'status'", "=>", "self", "::", "EXIT_CONFIG", ",", "'case'", "=>", "'MT_DATA_IS_EMPTY'", ",", "'desc'", "=>", "'MT Data is Empty'", ")", ";", "$", "this", "->", "logger", "->", "error", "(", "__FUNCTION__", ",", "'MT Data is Empty'", ",", "$", "result", ")", ";", "}", "else", "{", "if", "(", "$", "this", "->", "isTest", "===", "TRUE", ")", "{", "// Test Service", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'Test Send MT, giả lập quá trình gọi Request, chỉ test mã trả về');", "", "", "$", "request", "=", "array", "(", "'status'", "=>", "0", ",", "'code'", "=>", "0", ",", "'data'", "=>", "array", "(", "'transId'", "=>", "$", "this", "->", "transactionId", ",", "'username'", "=>", "$", "this", "->", "sdkConfig", "[", "self", "::", "SDP_CONFIG_KEY", "]", "[", "'username'", "]", ",", "'description'", "=>", "'Test SOAP Services'", ",", "'status'", "=>", "self", "::", "SEND_MT_RESPONSE_STATUS_IS_SUCCESS", ")", ")", ";", "}", "else", "{", "// Create SOAP Object", "$", "soapRequest", "=", "self", "::", "createSOAPRequest", "(", ")", ";", "// WSDL Send Request", "$", "request", "=", "$", "soapRequest", "->", "setEndpoint", "(", "self", "::", "SEND_MT_SOAP_ENDPOINT", ")", "->", "setData", "(", "$", "this", "->", "mtData", ")", "->", "setCallFunction", "(", "self", "::", "SEND_MT_SOAP_CALL_METHOD", ")", "->", "setFieldResult", "(", "self", "::", "SEND_MT_SOAP_FIELD_RESULT", ")", "->", "clientRequestSOAP", "(", ")", ";", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'URL Endpoint => '", ".", "json_encode", "(", "self", "::", "SEND_MT_SOAP_ENDPOINT", ")", ")", ";", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'Data to request => '", ".", "json_encode", "(", "$", "this", "->", "mtData", ")", ")", ";", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'Call Method => '", ".", "json_encode", "(", "self", "::", "SEND_MT_SOAP_CALL_METHOD", ")", ")", ";", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'Field Result => '", ".", "json_encode", "(", "self", "::", "SEND_MT_SOAP_FIELD_RESULT", ")", ")", ";", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'Response from Request => '", ".", "json_encode", "(", "$", "request", ")", ")", ";", "}", "// filter Request", "if", "(", "is_array", "(", "$", "request", ")", "&&", "isset", "(", "$", "request", "[", "'status'", "]", ")", ")", "{", "$", "request_response", "=", "array", "(", "'status'", "=>", "isset", "(", "$", "request", "[", "'data'", "]", "[", "'status'", "]", ")", "?", "$", "request", "[", "'data'", "]", "[", "'status'", "]", ":", "NULL", ",", "'description'", "=>", "isset", "(", "$", "request", "[", "'data'", "]", "[", "'description'", "]", ")", "?", "$", "request", "[", "'data'", "]", "[", "'description'", "]", ":", "NULL", ",", "'transactionId'", "=>", "isset", "(", "$", "request", "[", "'data'", "]", "[", "'transId'", "]", ")", "?", "$", "request", "[", "'data'", "]", "[", "'transId'", "]", ":", "NULL", ",", "'username'", "=>", "isset", "(", "$", "request", "[", "'data'", "]", "[", "'username'", "]", ")", "?", "$", "request", "[", "'data'", "]", "[", "'username'", "]", ":", "NULL", ")", ";", "if", "(", "(", "$", "request", "[", "'status'", "]", "==", "self", "::", "SEND_MT_RESPONSE_STATUS_IS_SUCCESS", ")", "&&", "(", "isset", "(", "$", "request", "[", "'code'", "]", ")", "&&", "$", "request", "[", "'code'", "]", "==", "self", "::", "SEND_MT_RESPONSE_STATUS_IS_SUCCESS", ")", ")", "{", "// Send MT thành công", "$", "result", "=", "array", "(", "'status'", "=>", "self", "::", "EXIT_SUCCESS", ",", "'case'", "=>", "'SUCCESS'", ",", "'desc'", "=>", "'Send MT is Success!'", ",", "'response'", "=>", "array", "(", "// Main Data", "'transactionId'", "=>", "$", "this", "->", "transactionId", ",", "'moId'", "=>", "$", "this", "->", "moId", ",", "'phone_number'", "=>", "$", "this", "->", "transactionMsisdn", ",", "'mt_message'", "=>", "$", "this", "->", "mtMsg", ")", ",", "'request_response'", "=>", "$", "request_response", ")", ";", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'Send MT is Success => '", ",", "$", "result", ")", ";", "}", "else", "{", "// Send MT thất bại", "$", "result", "=", "array", "(", "'status'", "=>", "self", "::", "EXIT_ERROR", ",", "'case'", "=>", "'FALSE'", ",", "'desc'", "=>", "'Send MT is Error!'", ",", "'response'", "=>", "array", "(", "// Main Data", "'transactionId'", "=>", "$", "this", "->", "transactionId", ",", "'moId'", "=>", "$", "this", "->", "moId", ",", "'phone_number'", "=>", "$", "this", "->", "transactionMsisdn", ",", "'mt_message'", "=>", "$", "this", "->", "mtMsg", ")", ",", "'request_response'", "=>", "$", "request_response", ")", ";", "$", "this", "->", "logger", "->", "error", "(", "__FUNCTION__", ",", "'Send MT is Error => '", ",", "$", "request_response", ")", ";", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'Send MT is Success => '", ",", "$", "result", ")", ";", "}", "}", "else", "{", "// Request Lỗi", "$", "result", "=", "array", "(", "'status'", "=>", "self", "::", "EXIT_ERROR", ",", "'case'", "=>", "'CLIENT_SOAP_ERROR'", ",", "'desc'", "=>", "'Missing Result from WSDL'", ")", ";", "$", "this", "->", "logger", "->", "debug", "(", "__FUNCTION__", ",", "'Missing Result from SOAP '", ",", "$", "result", ")", ";", "}", "$", "this", "->", "mtRequestResponse", "=", "$", "request", ";", "$", "this", "->", "mtTransactionStatus", "=", "$", "result", "[", "'status'", "]", ";", "}", "if", "(", "$", "this", "->", "responseIsObject", "===", "TRUE", ")", "{", "$", "result", "=", "Utils", "::", "arrayToObject", "(", "$", "result", ")", ";", "}", "$", "this", "->", "mtResult", "=", "$", "result", ";", "return", "$", "this", ";", "}" ]
Hàm Request Send MT Sử dụng SOAP Web Service @author: 713uk13m <[email protected]> @time : 11/10/18 11:56 @return $this Mảng dữ liệu $this->mtResult trạng thái gửi MT, biến status == 0 là thành công
[ "Hàm", "Request", "Send", "MT", "Sử", "dụng", "SOAP", "Web", "Service" ]
train
https://github.com/nguyenanhung/td-send-sms/blob/ed7b413aa09918e0dab3354cbc1d0c4565d39463/src/SendSMS/SendSmsToVnmSDP.php#L780-L875
jfusion/org.jfusion.framework
src/Plugin/Plugin.php
Plugin.getName
final public function getName() { if (!$this->name) { $this->name = get_class($this); list ($jfusion, $plugins, $name) = explode('\\', get_class($this)); $this->name = $name; } return $this->name; }
php
final public function getName() { if (!$this->name) { $this->name = get_class($this); list ($jfusion, $plugins, $name) = explode('\\', get_class($this)); $this->name = $name; } return $this->name; }
[ "final", "public", "function", "getName", "(", ")", "{", "if", "(", "!", "$", "this", "->", "name", ")", "{", "$", "this", "->", "name", "=", "get_class", "(", "$", "this", ")", ";", "list", "(", "$", "jfusion", ",", "$", "plugins", ",", "$", "name", ")", "=", "explode", "(", "'\\\\'", ",", "get_class", "(", "$", "this", ")", ")", ";", "$", "this", "->", "name", "=", "$", "name", ";", "}", "return", "$", "this", "->", "name", ";", "}" ]
returns the name of this JFusion plugin, using the "namespace" part of the plugin class @return string name of current JFusion plugin
[ "returns", "the", "name", "of", "this", "JFusion", "plugin", "using", "the", "namespace", "part", "of", "the", "plugin", "class" ]
train
https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Plugin/Plugin.php#L134-L144
jfusion/org.jfusion.framework
src/Plugin/Plugin.php
Plugin.methodDefined
final public function methodDefined($method) { $name = get_class($this); /** * TODO: FIX ISSUE DETERMINE IF A FUNCTION EXISTS OR NOT for Platform_XXX_Platform */ //if the class name is the abstract class then return false $abstractClassNames = array('JFusion\Plugin\Admin', 'JFusion\Plugin\Auth', 'JFusion\Plugin\Front', 'JFusion\Plugin\User', 'JFusion\Plugin\Plugin'); $return = false; if (!in_array($name, $abstractClassNames)) { try { $m = new ReflectionMethod($this, $method); $classname = $m->getDeclaringClass()->getName(); if ($classname == $name || !in_array($classname, $abstractClassNames)) { $return = true; } } catch (Exception $e) { $return = false; } } return $return; }
php
final public function methodDefined($method) { $name = get_class($this); /** * TODO: FIX ISSUE DETERMINE IF A FUNCTION EXISTS OR NOT for Platform_XXX_Platform */ //if the class name is the abstract class then return false $abstractClassNames = array('JFusion\Plugin\Admin', 'JFusion\Plugin\Auth', 'JFusion\Plugin\Front', 'JFusion\Plugin\User', 'JFusion\Plugin\Plugin'); $return = false; if (!in_array($name, $abstractClassNames)) { try { $m = new ReflectionMethod($this, $method); $classname = $m->getDeclaringClass()->getName(); if ($classname == $name || !in_array($classname, $abstractClassNames)) { $return = true; } } catch (Exception $e) { $return = false; } } return $return; }
[ "final", "public", "function", "methodDefined", "(", "$", "method", ")", "{", "$", "name", "=", "get_class", "(", "$", "this", ")", ";", "/**\n\t\t * TODO: FIX ISSUE DETERMINE IF A FUNCTION EXISTS OR NOT for Platform_XXX_Platform\n\t\t */", "//if the class name is the abstract class then return false", "$", "abstractClassNames", "=", "array", "(", "'JFusion\\Plugin\\Admin'", ",", "'JFusion\\Plugin\\Auth'", ",", "'JFusion\\Plugin\\Front'", ",", "'JFusion\\Plugin\\User'", ",", "'JFusion\\Plugin\\Plugin'", ")", ";", "$", "return", "=", "false", ";", "if", "(", "!", "in_array", "(", "$", "name", ",", "$", "abstractClassNames", ")", ")", "{", "try", "{", "$", "m", "=", "new", "ReflectionMethod", "(", "$", "this", ",", "$", "method", ")", ";", "$", "classname", "=", "$", "m", "->", "getDeclaringClass", "(", ")", "->", "getName", "(", ")", ";", "if", "(", "$", "classname", "==", "$", "name", "||", "!", "in_array", "(", "$", "classname", ",", "$", "abstractClassNames", ")", ")", "{", "$", "return", "=", "true", ";", "}", "}", "catch", "(", "Exception", "$", "e", ")", "{", "$", "return", "=", "false", ";", "}", "}", "return", "$", "return", ";", "}" ]
Function to check if a method has been defined inside a plugin like: setupFromPath @param $method @return bool
[ "Function", "to", "check", "if", "a", "method", "has", "been", "defined", "inside", "a", "plugin", "like", ":", "setupFromPath" ]
train
https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Plugin/Plugin.php#L153-L178
jfusion/org.jfusion.framework
src/Plugin/Plugin.php
Plugin.isConfigured
final public function isConfigured() { $jname = $this->getJname(); $result = false; if (!empty($jname)) { if (!isset(static::$status[$jname])) { $db = Factory::getDBO(); $query = $db->getQuery(true) ->select('status') ->from('#__jfusion') ->where('name = ' . $db->quote($jname)); $db->setQuery($query); $result = $db->loadResult(); if ($result >= 1) { $result = true; } else { $result = false; } static::$status[$jname] = $result; } else { $result = static::$status[$jname]; } } return $result; }
php
final public function isConfigured() { $jname = $this->getJname(); $result = false; if (!empty($jname)) { if (!isset(static::$status[$jname])) { $db = Factory::getDBO(); $query = $db->getQuery(true) ->select('status') ->from('#__jfusion') ->where('name = ' . $db->quote($jname)); $db->setQuery($query); $result = $db->loadResult(); if ($result >= 1) { $result = true; } else { $result = false; } static::$status[$jname] = $result; } else { $result = static::$status[$jname]; } } return $result; }
[ "final", "public", "function", "isConfigured", "(", ")", "{", "$", "jname", "=", "$", "this", "->", "getJname", "(", ")", ";", "$", "result", "=", "false", ";", "if", "(", "!", "empty", "(", "$", "jname", ")", ")", "{", "if", "(", "!", "isset", "(", "static", "::", "$", "status", "[", "$", "jname", "]", ")", ")", "{", "$", "db", "=", "Factory", "::", "getDBO", "(", ")", ";", "$", "query", "=", "$", "db", "->", "getQuery", "(", "true", ")", "->", "select", "(", "'status'", ")", "->", "from", "(", "'#__jfusion'", ")", "->", "where", "(", "'name = '", ".", "$", "db", "->", "quote", "(", "$", "jname", ")", ")", ";", "$", "db", "->", "setQuery", "(", "$", "query", ")", ";", "$", "result", "=", "$", "db", "->", "loadResult", "(", ")", ";", "if", "(", "$", "result", ">=", "1", ")", "{", "$", "result", "=", "true", ";", "}", "else", "{", "$", "result", "=", "false", ";", "}", "static", "::", "$", "status", "[", "$", "jname", "]", "=", "$", "result", ";", "}", "else", "{", "$", "result", "=", "static", "::", "$", "status", "[", "$", "jname", "]", ";", "}", "}", "return", "$", "result", ";", "}" ]
Checks to see if the JFusion plugin is properly configured @return boolean returns true if plugin is correctly configured
[ "Checks", "to", "see", "if", "the", "JFusion", "plugin", "is", "properly", "configured" ]
train
https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Plugin/Plugin.php#L185-L211
jfusion/org.jfusion.framework
src/Plugin/Plugin.php
Plugin.getPluginFile
function getPluginFile($filename, &$error, &$reason) { //check to see if a path is defined $path = $this->params->get('source_path'); if (empty($path)) { $error = 1; $reason = Text::_('SET_PATH_FIRST'); } $mod_file = $path . $filename; //see if the file exists if (!file_exists($mod_file) && $error == 0) { $error = 1; $reason = Text::_('NO_FILE_FOUND'); } return $mod_file; }
php
function getPluginFile($filename, &$error, &$reason) { //check to see if a path is defined $path = $this->params->get('source_path'); if (empty($path)) { $error = 1; $reason = Text::_('SET_PATH_FIRST'); } $mod_file = $path . $filename; //see if the file exists if (!file_exists($mod_file) && $error == 0) { $error = 1; $reason = Text::_('NO_FILE_FOUND'); } return $mod_file; }
[ "function", "getPluginFile", "(", "$", "filename", ",", "&", "$", "error", ",", "&", "$", "reason", ")", "{", "//check to see if a path is defined", "$", "path", "=", "$", "this", "->", "params", "->", "get", "(", "'source_path'", ")", ";", "if", "(", "empty", "(", "$", "path", ")", ")", "{", "$", "error", "=", "1", ";", "$", "reason", "=", "Text", "::", "_", "(", "'SET_PATH_FIRST'", ")", ";", "}", "$", "mod_file", "=", "$", "path", ".", "$", "filename", ";", "//see if the file exists", "if", "(", "!", "file_exists", "(", "$", "mod_file", ")", "&&", "$", "error", "==", "0", ")", "{", "$", "error", "=", "1", ";", "$", "reason", "=", "Text", "::", "_", "(", "'NO_FILE_FOUND'", ")", ";", "}", "return", "$", "mod_file", ";", "}" ]
Function returns the path to the modfile @param string $filename file name @param int &$error error number @param string &$reason error reason @return string $mod_file path and file of the modfile.
[ "Function", "returns", "the", "path", "to", "the", "modfile" ]
train
https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Plugin/Plugin.php#L222-L239
leedavis81/altr-ego
library/AltrEgo/AltrEgo.php
AltrEgo.callStatic
public static function callStatic($object, $name, $arguments) { $className = self::getAdapterClassName(); return $className::_callStatic($object, $name, $arguments); }
php
public static function callStatic($object, $name, $arguments) { $className = self::getAdapterClassName(); return $className::_callStatic($object, $name, $arguments); }
[ "public", "static", "function", "callStatic", "(", "$", "object", ",", "$", "name", ",", "$", "arguments", ")", "{", "$", "className", "=", "self", "::", "getAdapterClassName", "(", ")", ";", "return", "$", "className", "::", "_callStatic", "(", "$", "object", ",", "$", "name", ",", "$", "arguments", ")", ";", "}" ]
Allows exposure to privately defined static calls @param mixed $object - Either a AltrEgo object, you own object or the class name the static function resides @param string $name - the static function name you want to call @param mixed $arguments - Can be a single argument, or an array of them that you wish to pass to the function call @throws \Exception
[ "Allows", "exposure", "to", "privately", "defined", "static", "calls" ]
train
https://github.com/leedavis81/altr-ego/blob/1556556a33c2b6caddef94444522c5bbffc217c7/library/AltrEgo/AltrEgo.php#L139-L143
aedart/laravel-helpers
src/Traits/Session/SessionManagerTrait.php
SessionManagerTrait.getSessionManager
public function getSessionManager(): ?SessionManager { if (!$this->hasSessionManager()) { $this->setSessionManager($this->getDefaultSessionManager()); } return $this->sessionManager; }
php
public function getSessionManager(): ?SessionManager { if (!$this->hasSessionManager()) { $this->setSessionManager($this->getDefaultSessionManager()); } return $this->sessionManager; }
[ "public", "function", "getSessionManager", "(", ")", ":", "?", "SessionManager", "{", "if", "(", "!", "$", "this", "->", "hasSessionManager", "(", ")", ")", "{", "$", "this", "->", "setSessionManager", "(", "$", "this", "->", "getDefaultSessionManager", "(", ")", ")", ";", "}", "return", "$", "this", "->", "sessionManager", ";", "}" ]
Get session manager If no session manager has been set, this method will set and return a default session manager, if any such value is available @see getDefaultSessionManager() @return SessionManager|null session manager or null if none session manager has been set
[ "Get", "session", "manager" ]
train
https://github.com/aedart/laravel-helpers/blob/8b81a2d6658f3f8cb62b6be2c34773aaa2df219a/src/Traits/Session/SessionManagerTrait.php#L53-L59
PortaText/php-sdk
src/PortaText/Command/Api/Services.php
Services.getEndpoint
protected function getEndpoint($method) { $endpoint = "sms_services"; $serviceId = $this->getArgument("id"); if (!is_null($serviceId)) { $endpoint .= "/$serviceId"; $this->delArgument("id"); } $saveTo = $this->getArgument("accept_file"); if (!is_null($saveTo)) { $endpoint .= "/subscribers"; } $page = $this->getArgument("page"); $this->delArgument("page"); if (!is_null($page)) { $endpoint .= "/subscribers?page=$page"; } return $endpoint; }
php
protected function getEndpoint($method) { $endpoint = "sms_services"; $serviceId = $this->getArgument("id"); if (!is_null($serviceId)) { $endpoint .= "/$serviceId"; $this->delArgument("id"); } $saveTo = $this->getArgument("accept_file"); if (!is_null($saveTo)) { $endpoint .= "/subscribers"; } $page = $this->getArgument("page"); $this->delArgument("page"); if (!is_null($page)) { $endpoint .= "/subscribers?page=$page"; } return $endpoint; }
[ "protected", "function", "getEndpoint", "(", "$", "method", ")", "{", "$", "endpoint", "=", "\"sms_services\"", ";", "$", "serviceId", "=", "$", "this", "->", "getArgument", "(", "\"id\"", ")", ";", "if", "(", "!", "is_null", "(", "$", "serviceId", ")", ")", "{", "$", "endpoint", ".=", "\"/$serviceId\"", ";", "$", "this", "->", "delArgument", "(", "\"id\"", ")", ";", "}", "$", "saveTo", "=", "$", "this", "->", "getArgument", "(", "\"accept_file\"", ")", ";", "if", "(", "!", "is_null", "(", "$", "saveTo", ")", ")", "{", "$", "endpoint", ".=", "\"/subscribers\"", ";", "}", "$", "page", "=", "$", "this", "->", "getArgument", "(", "\"page\"", ")", ";", "$", "this", "->", "delArgument", "(", "\"page\"", ")", ";", "if", "(", "!", "is_null", "(", "$", "page", ")", ")", "{", "$", "endpoint", ".=", "\"/subscribers?page=$page\"", ";", "}", "return", "$", "endpoint", ";", "}" ]
Returns a string with the endpoint for the given command. @param string $method Method for this command. @return string
[ "Returns", "a", "string", "with", "the", "endpoint", "for", "the", "given", "command", "." ]
train
https://github.com/PortaText/php-sdk/blob/dbe04ef043db5b251953f9de57aa4d0f1785dfcc/src/PortaText/Command/Api/Services.php#L63-L81
parsnick/steak
src/Build/Publishers/Skip.php
Skip.handle
public function handle(Source $source, Closure $next, ...$excluded) { foreach ($excluded as $pattern) { $value = str_contains($pattern, DIRECTORY_SEPARATOR) ? $source->getPathname() : $source->getFilename(); if (str_is($pattern, $value)) { return; } } $next($source); }
php
public function handle(Source $source, Closure $next, ...$excluded) { foreach ($excluded as $pattern) { $value = str_contains($pattern, DIRECTORY_SEPARATOR) ? $source->getPathname() : $source->getFilename(); if (str_is($pattern, $value)) { return; } } $next($source); }
[ "public", "function", "handle", "(", "Source", "$", "source", ",", "Closure", "$", "next", ",", "...", "$", "excluded", ")", "{", "foreach", "(", "$", "excluded", "as", "$", "pattern", ")", "{", "$", "value", "=", "str_contains", "(", "$", "pattern", ",", "DIRECTORY_SEPARATOR", ")", "?", "$", "source", "->", "getPathname", "(", ")", ":", "$", "source", "->", "getFilename", "(", ")", ";", "if", "(", "str_is", "(", "$", "pattern", ",", "$", "value", ")", ")", "{", "return", ";", "}", "}", "$", "next", "(", "$", "source", ")", ";", "}" ]
Publish a source file and/or pass to $next. @param Source $source @param Closure $next @param array $excluded @return mixed
[ "Publish", "a", "source", "file", "and", "/", "or", "pass", "to", "$next", "." ]
train
https://github.com/parsnick/steak/blob/461869189a640938438187330f6c50aca97c5ccc/src/Build/Publishers/Skip.php#L18-L32
inc2734/wp-share-buttons
src/App/Shortcode/Feedly.php
Feedly._shortcode
public function _shortcode( $attributes ) { if ( ! isset( $attributes['post_id'] ) ) { return; } $attributes = shortcode_atts( [ 'type' => 'balloon', 'post_id' => '', ], $attributes ); if ( 'official' === $attributes['type'] ) { $file = 'official'; } else { $file = 'feedly'; } if ( function_exists( 'scc_get_follow_feedly' ) ) { $has_cache = true; $expiration = null; $count = scc_get_follow_feedly(); } else { $count_cache = new Count_Cache( $attributes['post_id'], 'feedly' ); $has_cache = $count_cache->is_enabled(); $expiration = $count_cache->get_cache_expiration(); $cache = $count_cache->get(); $count = ( ! is_null( $cache ) ) ? $cache : '-'; } return $this->render( 'feedly/' . $file, [ 'type' => $attributes['type'], 'post_id' => $attributes['post_id'], 'has_cache' => $has_cache, 'expiration' => $expiration, 'count' => $count, ] ); }
php
public function _shortcode( $attributes ) { if ( ! isset( $attributes['post_id'] ) ) { return; } $attributes = shortcode_atts( [ 'type' => 'balloon', 'post_id' => '', ], $attributes ); if ( 'official' === $attributes['type'] ) { $file = 'official'; } else { $file = 'feedly'; } if ( function_exists( 'scc_get_follow_feedly' ) ) { $has_cache = true; $expiration = null; $count = scc_get_follow_feedly(); } else { $count_cache = new Count_Cache( $attributes['post_id'], 'feedly' ); $has_cache = $count_cache->is_enabled(); $expiration = $count_cache->get_cache_expiration(); $cache = $count_cache->get(); $count = ( ! is_null( $cache ) ) ? $cache : '-'; } return $this->render( 'feedly/' . $file, [ 'type' => $attributes['type'], 'post_id' => $attributes['post_id'], 'has_cache' => $has_cache, 'expiration' => $expiration, 'count' => $count, ] ); }
[ "public", "function", "_shortcode", "(", "$", "attributes", ")", "{", "if", "(", "!", "isset", "(", "$", "attributes", "[", "'post_id'", "]", ")", ")", "{", "return", ";", "}", "$", "attributes", "=", "shortcode_atts", "(", "[", "'type'", "=>", "'balloon'", ",", "'post_id'", "=>", "''", ",", "]", ",", "$", "attributes", ")", ";", "if", "(", "'official'", "===", "$", "attributes", "[", "'type'", "]", ")", "{", "$", "file", "=", "'official'", ";", "}", "else", "{", "$", "file", "=", "'feedly'", ";", "}", "if", "(", "function_exists", "(", "'scc_get_follow_feedly'", ")", ")", "{", "$", "has_cache", "=", "true", ";", "$", "expiration", "=", "null", ";", "$", "count", "=", "scc_get_follow_feedly", "(", ")", ";", "}", "else", "{", "$", "count_cache", "=", "new", "Count_Cache", "(", "$", "attributes", "[", "'post_id'", "]", ",", "'feedly'", ")", ";", "$", "has_cache", "=", "$", "count_cache", "->", "is_enabled", "(", ")", ";", "$", "expiration", "=", "$", "count_cache", "->", "get_cache_expiration", "(", ")", ";", "$", "cache", "=", "$", "count_cache", "->", "get", "(", ")", ";", "$", "count", "=", "(", "!", "is_null", "(", "$", "cache", ")", ")", "?", "$", "cache", ":", "'-'", ";", "}", "return", "$", "this", "->", "render", "(", "'feedly/'", ".", "$", "file", ",", "[", "'type'", "=>", "$", "attributes", "[", "'type'", "]", ",", "'post_id'", "=>", "$", "attributes", "[", "'post_id'", "]", ",", "'has_cache'", "=>", "$", "has_cache", ",", "'expiration'", "=>", "$", "expiration", ",", "'count'", "=>", "$", "count", ",", "]", ")", ";", "}" ]
Register shortcode @param array $attributes @return void
[ "Register", "shortcode" ]
train
https://github.com/inc2734/wp-share-buttons/blob/cd032893ca083a343f5871e855cce68f4ede3a17/src/App/Shortcode/Feedly.php#L24-L65
preprocess/pre-class-accessors
source/ClassAccessorsTrait.php
ClassAccessorsTrait.handleSetClassAccessors
protected function handleSetClassAccessors($property, $value) { $property = $this->studly($property); if (method_exists($this, "set{$property}")) { return $this->{"set{$property}"}($value); } }
php
protected function handleSetClassAccessors($property, $value) { $property = $this->studly($property); if (method_exists($this, "set{$property}")) { return $this->{"set{$property}"}($value); } }
[ "protected", "function", "handleSetClassAccessors", "(", "$", "property", ",", "$", "value", ")", "{", "$", "property", "=", "$", "this", "->", "studly", "(", "$", "property", ")", ";", "if", "(", "method_exists", "(", "$", "this", ",", "\"set{$property}\"", ")", ")", "{", "return", "$", "this", "->", "{", "\"set{$property}\"", "}", "(", "$", "value", ")", ";", "}", "}" ]
Finds and invokes setters. @param string $property @param mixed $value
[ "Finds", "and", "invokes", "setters", "." ]
train
https://github.com/preprocess/pre-class-accessors/blob/1723028ee756824ab0bc1dab931da065497cd8fd/source/ClassAccessorsTrait.php#L60-L67
spiral-modules/auth
source/Auth/Operators/Bridges/HeaderBridge.php
HeaderBridge.writeToken
public function writeToken( Request $request, Response $response, int $lifetime, string $token = null ): Response { if (empty($token)) { return $response; } return $response->withAddedHeader($this->header, $token); }
php
public function writeToken( Request $request, Response $response, int $lifetime, string $token = null ): Response { if (empty($token)) { return $response; } return $response->withAddedHeader($this->header, $token); }
[ "public", "function", "writeToken", "(", "Request", "$", "request", ",", "Response", "$", "response", ",", "int", "$", "lifetime", ",", "string", "$", "token", "=", "null", ")", ":", "Response", "{", "if", "(", "empty", "(", "$", "token", ")", ")", "{", "return", "$", "response", ";", "}", "return", "$", "response", "->", "withAddedHeader", "(", "$", "this", "->", "header", ",", "$", "token", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/spiral-modules/auth/blob/24e2070028f7257e8192914556963a4794428a99/source/Auth/Operators/Bridges/HeaderBridge.php#L52-L63
flipboxstudio/orm-manager
src/Flipbox/OrmManager/Relations/HasOne.php
HasOne.setDefaultOptions
protected function setDefaultOptions(array $options=[]) { $this->defaultOptions = [ 'foreign_key' => $this->model->getForeignKey(), 'primary_key' => $this->model->getKeyName() ]; }
php
protected function setDefaultOptions(array $options=[]) { $this->defaultOptions = [ 'foreign_key' => $this->model->getForeignKey(), 'primary_key' => $this->model->getKeyName() ]; }
[ "protected", "function", "setDefaultOptions", "(", "array", "$", "options", "=", "[", "]", ")", "{", "$", "this", "->", "defaultOptions", "=", "[", "'foreign_key'", "=>", "$", "this", "->", "model", "->", "getForeignKey", "(", ")", ",", "'primary_key'", "=>", "$", "this", "->", "model", "->", "getKeyName", "(", ")", "]", ";", "}" ]
set default options @param array $options @return void
[ "set", "default", "options" ]
train
https://github.com/flipboxstudio/orm-manager/blob/4288426517f53d05177b8729c4ba94c5beca9a98/src/Flipbox/OrmManager/Relations/HasOne.php#L13-L19
flipboxstudio/orm-manager
src/Flipbox/OrmManager/Relations/HasOne.php
HasOne.setConnectedRelationOptions
protected function setConnectedRelationOptions() { $modelTable = $table = $this->model->getTable(); $toModelTable = $table = $this->toModel->getTable(); $foreignKey = $this->defaultOptions['foreign_key']; $primaryKey = $this->defaultOptions['primary_key']; if (! $this->db->isFieldExists($toModelTable, $foreignKey)) { $question = "Can't find field {$this->text['foreign_key']} in the table {$this->text['to_table']} as {$this->text['foreign_text']} of table {$this->text['table']}, choice one!"; $this->options['foreign_key'] = $this->command->choice($question, $this->getFields($toModelTable)); } if (! $this->db->isFieldExists($modelTable, $primaryKey)) { $question = "Can't find field {$this->text['primary_key']} in the table {$this->text['table']} as {$this->text['primary_text']} of table {$this->text['table']}, choice one!"; $this->options['primary_key'] = $this->command->choice($question, $this->getFields($modelTable)); } }
php
protected function setConnectedRelationOptions() { $modelTable = $table = $this->model->getTable(); $toModelTable = $table = $this->toModel->getTable(); $foreignKey = $this->defaultOptions['foreign_key']; $primaryKey = $this->defaultOptions['primary_key']; if (! $this->db->isFieldExists($toModelTable, $foreignKey)) { $question = "Can't find field {$this->text['foreign_key']} in the table {$this->text['to_table']} as {$this->text['foreign_text']} of table {$this->text['table']}, choice one!"; $this->options['foreign_key'] = $this->command->choice($question, $this->getFields($toModelTable)); } if (! $this->db->isFieldExists($modelTable, $primaryKey)) { $question = "Can't find field {$this->text['primary_key']} in the table {$this->text['table']} as {$this->text['primary_text']} of table {$this->text['table']}, choice one!"; $this->options['primary_key'] = $this->command->choice($question, $this->getFields($modelTable)); } }
[ "protected", "function", "setConnectedRelationOptions", "(", ")", "{", "$", "modelTable", "=", "$", "table", "=", "$", "this", "->", "model", "->", "getTable", "(", ")", ";", "$", "toModelTable", "=", "$", "table", "=", "$", "this", "->", "toModel", "->", "getTable", "(", ")", ";", "$", "foreignKey", "=", "$", "this", "->", "defaultOptions", "[", "'foreign_key'", "]", ";", "$", "primaryKey", "=", "$", "this", "->", "defaultOptions", "[", "'primary_key'", "]", ";", "if", "(", "!", "$", "this", "->", "db", "->", "isFieldExists", "(", "$", "toModelTable", ",", "$", "foreignKey", ")", ")", "{", "$", "question", "=", "\"Can't find field {$this->text['foreign_key']} in the table {$this->text['to_table']} as {$this->text['foreign_text']} of table {$this->text['table']}, choice one!\"", ";", "$", "this", "->", "options", "[", "'foreign_key'", "]", "=", "$", "this", "->", "command", "->", "choice", "(", "$", "question", ",", "$", "this", "->", "getFields", "(", "$", "toModelTable", ")", ")", ";", "}", "if", "(", "!", "$", "this", "->", "db", "->", "isFieldExists", "(", "$", "modelTable", ",", "$", "primaryKey", ")", ")", "{", "$", "question", "=", "\"Can't find field {$this->text['primary_key']} in the table {$this->text['table']} as {$this->text['primary_text']} of table {$this->text['table']}, choice one!\"", ";", "$", "this", "->", "options", "[", "'primary_key'", "]", "=", "$", "this", "->", "command", "->", "choice", "(", "$", "question", ",", "$", "this", "->", "getFields", "(", "$", "modelTable", ")", ")", ";", "}", "}" ]
set connected db relation options @return void
[ "set", "connected", "db", "relation", "options" ]
train
https://github.com/flipboxstudio/orm-manager/blob/4288426517f53d05177b8729c4ba94c5beca9a98/src/Flipbox/OrmManager/Relations/HasOne.php#L48-L64
flipboxstudio/orm-manager
src/Flipbox/OrmManager/Relations/HasOne.php
HasOne.askToUseCustomeOptions
protected function askToUseCustomeOptions() { $question = "The {$this->text['foreign_text']} of table {$this->text['table']} in the table {$this->text['to_table']}, will be?"; $this->options['foreign_key'] = $this->command->ask($question, $this->defaultOptions['foreign_key']); $question = "The {$this->text['primary_text']} of the table {$this->text['table']}, will be?"; $this->options['primary_key'] = $this->command->ask($question, $this->defaultOptions['primary_key']); }
php
protected function askToUseCustomeOptions() { $question = "The {$this->text['foreign_text']} of table {$this->text['table']} in the table {$this->text['to_table']}, will be?"; $this->options['foreign_key'] = $this->command->ask($question, $this->defaultOptions['foreign_key']); $question = "The {$this->text['primary_text']} of the table {$this->text['table']}, will be?"; $this->options['primary_key'] = $this->command->ask($question, $this->defaultOptions['primary_key']); }
[ "protected", "function", "askToUseCustomeOptions", "(", ")", "{", "$", "question", "=", "\"The {$this->text['foreign_text']} of table {$this->text['table']} in the table {$this->text['to_table']}, will be?\"", ";", "$", "this", "->", "options", "[", "'foreign_key'", "]", "=", "$", "this", "->", "command", "->", "ask", "(", "$", "question", ",", "$", "this", "->", "defaultOptions", "[", "'foreign_key'", "]", ")", ";", "$", "question", "=", "\"The {$this->text['primary_text']} of the table {$this->text['table']}, will be?\"", ";", "$", "this", "->", "options", "[", "'primary_key'", "]", "=", "$", "this", "->", "command", "->", "ask", "(", "$", "question", ",", "$", "this", "->", "defaultOptions", "[", "'primary_key'", "]", ")", ";", "}" ]
ask to use custome options @return void
[ "ask", "to", "use", "custome", "options" ]
train
https://github.com/flipboxstudio/orm-manager/blob/4288426517f53d05177b8729c4ba94c5beca9a98/src/Flipbox/OrmManager/Relations/HasOne.php#L84-L91
ClanCats/Core
src/classes/CCResponse.php
CCResponse.json
public static function json( $data = array(), $status = 200, $beautify = true ) { if ( !is_array( $data ) ) { throw new CCException( "CCResponse::json - first argument has to be an array." ); } $response = new static( CCJson::encode( $data, $beautify ), $status ); $response->header( 'Content-Type', 'text/json' ); return $response; }
php
public static function json( $data = array(), $status = 200, $beautify = true ) { if ( !is_array( $data ) ) { throw new CCException( "CCResponse::json - first argument has to be an array." ); } $response = new static( CCJson::encode( $data, $beautify ), $status ); $response->header( 'Content-Type', 'text/json' ); return $response; }
[ "public", "static", "function", "json", "(", "$", "data", "=", "array", "(", ")", ",", "$", "status", "=", "200", ",", "$", "beautify", "=", "true", ")", "{", "if", "(", "!", "is_array", "(", "$", "data", ")", ")", "{", "throw", "new", "CCException", "(", "\"CCResponse::json - first argument has to be an array.\"", ")", ";", "}", "$", "response", "=", "new", "static", "(", "CCJson", "::", "encode", "(", "$", "data", ",", "$", "beautify", ")", ",", "$", "status", ")", ";", "$", "response", "->", "header", "(", "'Content-Type'", ",", "'text/json'", ")", ";", "return", "$", "response", ";", "}" ]
json response you can pass an array of data wich will be converted to json @param array $data @param int $status @param bool $beautify should the json output be formatted? @return CCResponse
[ "json", "response", "you", "can", "pass", "an", "array", "of", "data", "wich", "will", "be", "converted", "to", "json" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCResponse.php#L123-L134
ClanCats/Core
src/classes/CCResponse.php
CCResponse.download
public static function download( $body, $filename = null, $status = 200 ) { return static::create( $body, $status )->as_download( $filename ); }
php
public static function download( $body, $filename = null, $status = 200 ) { return static::create( $body, $status )->as_download( $filename ); }
[ "public", "static", "function", "download", "(", "$", "body", ",", "$", "filename", "=", "null", ",", "$", "status", "=", "200", ")", "{", "return", "static", "::", "create", "(", "$", "body", ",", "$", "status", ")", "->", "as_download", "(", "$", "filename", ")", ";", "}" ]
download response creates an respose that forces the browser to download as file @param string $body @param string $filename @param int $status @return CCResponse
[ "download", "response", "creates", "an", "respose", "that", "forces", "the", "browser", "to", "download", "as", "file" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCResponse.php#L145-L148
ClanCats/Core
src/classes/CCResponse.php
CCResponse.status
public function status( $code = null ) { if ( !is_null( $code ) ) { if ( headers_sent() && !CLI ) { throw new CCException( "CCResponse::status - cannot change status header has already been send." ); } $this->_status = $code; return $this; } return $this->_status; }
php
public function status( $code = null ) { if ( !is_null( $code ) ) { if ( headers_sent() && !CLI ) { throw new CCException( "CCResponse::status - cannot change status header has already been send." ); } $this->_status = $code; return $this; } return $this->_status; }
[ "public", "function", "status", "(", "$", "code", "=", "null", ")", "{", "if", "(", "!", "is_null", "(", "$", "code", ")", ")", "{", "if", "(", "headers_sent", "(", ")", "&&", "!", "CLI", ")", "{", "throw", "new", "CCException", "(", "\"CCResponse::status - cannot change status header has already been send.\"", ")", ";", "}", "$", "this", "->", "_status", "=", "$", "code", ";", "return", "$", "this", ";", "}", "return", "$", "this", "->", "_status", ";", "}" ]
status setter and getter @param int|null $code @return int|self
[ "status", "setter", "and", "getter" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCResponse.php#L213-L226
ClanCats/Core
src/classes/CCResponse.php
CCResponse.header
public function header( $key, $str = null ) { if ( !is_null( $str ) ) { $this->_header[$key] = $str; return $this; } return $this->_header[$key]; }
php
public function header( $key, $str = null ) { if ( !is_null( $str ) ) { $this->_header[$key] = $str; return $this; } return $this->_header[$key]; }
[ "public", "function", "header", "(", "$", "key", ",", "$", "str", "=", "null", ")", "{", "if", "(", "!", "is_null", "(", "$", "str", ")", ")", "{", "$", "this", "->", "_header", "[", "$", "key", "]", "=", "$", "str", ";", "return", "$", "this", ";", "}", "return", "$", "this", "->", "_header", "[", "$", "key", "]", ";", "}" ]
status setter and getter @param string $key @param string|null $str @return string|self
[ "status", "setter", "and", "getter" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCResponse.php#L235-L243
ClanCats/Core
src/classes/CCResponse.php
CCResponse.as_download
public function as_download( $filename = null ) { if ( is_null( $filename ) ) { $filename = 'file.'.CCStr::suffix( $this->header( 'Content-Type' ), '/' ); } $this->header( 'Content-Description', 'File Transfer' ); $this->header( 'Content-Disposition', 'attachment; filename='.$filename ); $this->header( 'Content-Transfer-Encoding', 'binary' ); $this->header( 'Expires', '0' ); $this->header( 'Cache-Control', 'must-revalidate' ); $this->header( 'Pragma', 'public' ); $this->header( 'Content-Length', strlen( $this->body() ) ); return $this; }
php
public function as_download( $filename = null ) { if ( is_null( $filename ) ) { $filename = 'file.'.CCStr::suffix( $this->header( 'Content-Type' ), '/' ); } $this->header( 'Content-Description', 'File Transfer' ); $this->header( 'Content-Disposition', 'attachment; filename='.$filename ); $this->header( 'Content-Transfer-Encoding', 'binary' ); $this->header( 'Expires', '0' ); $this->header( 'Cache-Control', 'must-revalidate' ); $this->header( 'Pragma', 'public' ); $this->header( 'Content-Length', strlen( $this->body() ) ); return $this; }
[ "public", "function", "as_download", "(", "$", "filename", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "filename", ")", ")", "{", "$", "filename", "=", "'file.'", ".", "CCStr", "::", "suffix", "(", "$", "this", "->", "header", "(", "'Content-Type'", ")", ",", "'/'", ")", ";", "}", "$", "this", "->", "header", "(", "'Content-Description'", ",", "'File Transfer'", ")", ";", "$", "this", "->", "header", "(", "'Content-Disposition'", ",", "'attachment; filename='", ".", "$", "filename", ")", ";", "$", "this", "->", "header", "(", "'Content-Transfer-Encoding'", ",", "'binary'", ")", ";", "$", "this", "->", "header", "(", "'Expires'", ",", "'0'", ")", ";", "$", "this", "->", "header", "(", "'Cache-Control'", ",", "'must-revalidate'", ")", ";", "$", "this", "->", "header", "(", "'Pragma'", ",", "'public'", ")", ";", "$", "this", "->", "header", "(", "'Content-Length'", ",", "strlen", "(", "$", "this", "->", "body", "(", ")", ")", ")", ";", "return", "$", "this", ";", "}" ]
modify the headers to force a download @param string $filename @return void
[ "modify", "the", "headers", "to", "force", "a", "download" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCResponse.php#L251-L267
ClanCats/Core
src/classes/CCResponse.php
CCResponse.send
public function send( $headers = false ) { if ( $headers && headers_sent() && !CLI ) { throw new CCException( "CCResponse::send - cannot send header, header has already been send." ); } if ( $headers ) { // status header header( CCIn::server( 'SERVER_PROTOCOL' ).' '.$this->_status.' '.CCResponse::$messages[$this->_status] ); // check if content type is already set if ( !isset( $this->_header['Content-Type'] ) ) { $this->header( 'Content-Type', 'text/html; charset='.ClanCats::$config->get( 'charset', 'utf-8' ) ); } $this->header( 'X-Powered-By', 'ClanCatsFramework version: '.ClanCats::VERSION ); // set headers foreach( $this->_header as $key => $content ) { header( $key.': '.$content ); } } // profiler CCProfiler::check( 'CCResponse - sending response' ); // print the body echo CCEvent::pass( 'response.output', $this->body() ); }
php
public function send( $headers = false ) { if ( $headers && headers_sent() && !CLI ) { throw new CCException( "CCResponse::send - cannot send header, header has already been send." ); } if ( $headers ) { // status header header( CCIn::server( 'SERVER_PROTOCOL' ).' '.$this->_status.' '.CCResponse::$messages[$this->_status] ); // check if content type is already set if ( !isset( $this->_header['Content-Type'] ) ) { $this->header( 'Content-Type', 'text/html; charset='.ClanCats::$config->get( 'charset', 'utf-8' ) ); } $this->header( 'X-Powered-By', 'ClanCatsFramework version: '.ClanCats::VERSION ); // set headers foreach( $this->_header as $key => $content ) { header( $key.': '.$content ); } } // profiler CCProfiler::check( 'CCResponse - sending response' ); // print the body echo CCEvent::pass( 'response.output', $this->body() ); }
[ "public", "function", "send", "(", "$", "headers", "=", "false", ")", "{", "if", "(", "$", "headers", "&&", "headers_sent", "(", ")", "&&", "!", "CLI", ")", "{", "throw", "new", "CCException", "(", "\"CCResponse::send - cannot send header, header has already been send.\"", ")", ";", "}", "if", "(", "$", "headers", ")", "{", "// status header", "header", "(", "CCIn", "::", "server", "(", "'SERVER_PROTOCOL'", ")", ".", "' '", ".", "$", "this", "->", "_status", ".", "' '", ".", "CCResponse", "::", "$", "messages", "[", "$", "this", "->", "_status", "]", ")", ";", "// check if content type is already set", "if", "(", "!", "isset", "(", "$", "this", "->", "_header", "[", "'Content-Type'", "]", ")", ")", "{", "$", "this", "->", "header", "(", "'Content-Type'", ",", "'text/html; charset='", ".", "ClanCats", "::", "$", "config", "->", "get", "(", "'charset'", ",", "'utf-8'", ")", ")", ";", "}", "$", "this", "->", "header", "(", "'X-Powered-By'", ",", "'ClanCatsFramework version: '", ".", "ClanCats", "::", "VERSION", ")", ";", "// set headers", "foreach", "(", "$", "this", "->", "_header", "as", "$", "key", "=>", "$", "content", ")", "{", "header", "(", "$", "key", ".", "': '", ".", "$", "content", ")", ";", "}", "}", "// profiler", "CCProfiler", "::", "check", "(", "'CCResponse - sending response'", ")", ";", "// print the body", "echo", "CCEvent", "::", "pass", "(", "'response.output'", ",", "$", "this", "->", "body", "(", ")", ")", ";", "}" ]
send response means printing the response and setting the headers if set @param bool $headers @return void
[ "send", "response", "means", "printing", "the", "response", "and", "setting", "the", "headers", "if", "set" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCResponse.php#L276-L308
JeanWolf/yii2-jrbac
controllers/RuleController.php
RuleController.actionCreate
public function actionCreate() { $model = new RuleForm(); $model->isNewRecord = true; if ($model->load(\Yii::$app->getRequest()->post())) { $className = trim($model->className); if (class_exists($className)) { $item = new $className; if (trim($model->name)) { $item->name = trim($model->name); } $auth = \Yii::$app->getAuthManager(); if ($auth->getRule($item->name)) { $model->addError('className', '同类规则已存在'); } else if ($auth->add($item)) { return $this->redirect(['index']); } else { $model->addError('className', '保存失败'); } } else { $model->addError('className', '没有找到类:'.$className); } } return $this->render('create',[ 'model'=>$model ]); }
php
public function actionCreate() { $model = new RuleForm(); $model->isNewRecord = true; if ($model->load(\Yii::$app->getRequest()->post())) { $className = trim($model->className); if (class_exists($className)) { $item = new $className; if (trim($model->name)) { $item->name = trim($model->name); } $auth = \Yii::$app->getAuthManager(); if ($auth->getRule($item->name)) { $model->addError('className', '同类规则已存在'); } else if ($auth->add($item)) { return $this->redirect(['index']); } else { $model->addError('className', '保存失败'); } } else { $model->addError('className', '没有找到类:'.$className); } } return $this->render('create',[ 'model'=>$model ]); }
[ "public", "function", "actionCreate", "(", ")", "{", "$", "model", "=", "new", "RuleForm", "(", ")", ";", "$", "model", "->", "isNewRecord", "=", "true", ";", "if", "(", "$", "model", "->", "load", "(", "\\", "Yii", "::", "$", "app", "->", "getRequest", "(", ")", "->", "post", "(", ")", ")", ")", "{", "$", "className", "=", "trim", "(", "$", "model", "->", "className", ")", ";", "if", "(", "class_exists", "(", "$", "className", ")", ")", "{", "$", "item", "=", "new", "$", "className", ";", "if", "(", "trim", "(", "$", "model", "->", "name", ")", ")", "{", "$", "item", "->", "name", "=", "trim", "(", "$", "model", "->", "name", ")", ";", "}", "$", "auth", "=", "\\", "Yii", "::", "$", "app", "->", "getAuthManager", "(", ")", ";", "if", "(", "$", "auth", "->", "getRule", "(", "$", "item", "->", "name", ")", ")", "{", "$", "model", "->", "addError", "(", "'className'", ",", "'同类规则已存在');", "", "", "}", "else", "if", "(", "$", "auth", "->", "add", "(", "$", "item", ")", ")", "{", "return", "$", "this", "->", "redirect", "(", "[", "'index'", "]", ")", ";", "}", "else", "{", "$", "model", "->", "addError", "(", "'className'", ",", "'保存失败');", "", "", "}", "}", "else", "{", "$", "model", "->", "addError", "(", "'className'", ",", "'没有找到类:'.$classNam", "e", ")", ";", "", "", "}", "}", "return", "$", "this", "->", "render", "(", "'create'", ",", "[", "'model'", "=>", "$", "model", "]", ")", ";", "}" ]
创建规则
[ "创建规则" ]
train
https://github.com/JeanWolf/yii2-jrbac/blob/1e5c80038451bd5b385f83cb9344c3bd5edd85e0/controllers/RuleController.php#L27-L53
JeanWolf/yii2-jrbac
controllers/RuleController.php
RuleController.actionUpdate
public function actionUpdate($id) { $name = $id; $model = new RuleForm(); $model->isNewRecord = false; $auth = \Yii::$app->getAuthManager(); $item = $auth->getRule($name); if ($model->load(\Yii::$app->getRequest()->post())) { $className = trim($model->className); if ($item::className() == $className && $item->name == trim($model->name)) { return $this->redirect(['index']); } else if ($item::className() == $className) { $item->name = trim($model->name); if($auth->update($name,$item)) { return $this->redirect(['index']); } else { $model->addError('name', '保存失败'); } } else { if (class_exists($className)) { $item = new $className; if (trim($model->name)) { $item->name = trim($model->name); } if($auth->update($name,$item)) { return $this->redirect(['index']); } else { $model->addError('className', '保存失败'); } } else { $model->addError('className', '没有找到这个类'); } } } $model->name = $name; $model->className = $item::className(); return $this->render('update',[ 'model' => $model ]); }
php
public function actionUpdate($id) { $name = $id; $model = new RuleForm(); $model->isNewRecord = false; $auth = \Yii::$app->getAuthManager(); $item = $auth->getRule($name); if ($model->load(\Yii::$app->getRequest()->post())) { $className = trim($model->className); if ($item::className() == $className && $item->name == trim($model->name)) { return $this->redirect(['index']); } else if ($item::className() == $className) { $item->name = trim($model->name); if($auth->update($name,$item)) { return $this->redirect(['index']); } else { $model->addError('name', '保存失败'); } } else { if (class_exists($className)) { $item = new $className; if (trim($model->name)) { $item->name = trim($model->name); } if($auth->update($name,$item)) { return $this->redirect(['index']); } else { $model->addError('className', '保存失败'); } } else { $model->addError('className', '没有找到这个类'); } } } $model->name = $name; $model->className = $item::className(); return $this->render('update',[ 'model' => $model ]); }
[ "public", "function", "actionUpdate", "(", "$", "id", ")", "{", "$", "name", "=", "$", "id", ";", "$", "model", "=", "new", "RuleForm", "(", ")", ";", "$", "model", "->", "isNewRecord", "=", "false", ";", "$", "auth", "=", "\\", "Yii", "::", "$", "app", "->", "getAuthManager", "(", ")", ";", "$", "item", "=", "$", "auth", "->", "getRule", "(", "$", "name", ")", ";", "if", "(", "$", "model", "->", "load", "(", "\\", "Yii", "::", "$", "app", "->", "getRequest", "(", ")", "->", "post", "(", ")", ")", ")", "{", "$", "className", "=", "trim", "(", "$", "model", "->", "className", ")", ";", "if", "(", "$", "item", "::", "className", "(", ")", "==", "$", "className", "&&", "$", "item", "->", "name", "==", "trim", "(", "$", "model", "->", "name", ")", ")", "{", "return", "$", "this", "->", "redirect", "(", "[", "'index'", "]", ")", ";", "}", "else", "if", "(", "$", "item", "::", "className", "(", ")", "==", "$", "className", ")", "{", "$", "item", "->", "name", "=", "trim", "(", "$", "model", "->", "name", ")", ";", "if", "(", "$", "auth", "->", "update", "(", "$", "name", ",", "$", "item", ")", ")", "{", "return", "$", "this", "->", "redirect", "(", "[", "'index'", "]", ")", ";", "}", "else", "{", "$", "model", "->", "addError", "(", "'name'", ",", "'保存失败');", "", "", "}", "}", "else", "{", "if", "(", "class_exists", "(", "$", "className", ")", ")", "{", "$", "item", "=", "new", "$", "className", ";", "if", "(", "trim", "(", "$", "model", "->", "name", ")", ")", "{", "$", "item", "->", "name", "=", "trim", "(", "$", "model", "->", "name", ")", ";", "}", "if", "(", "$", "auth", "->", "update", "(", "$", "name", ",", "$", "item", ")", ")", "{", "return", "$", "this", "->", "redirect", "(", "[", "'index'", "]", ")", ";", "}", "else", "{", "$", "model", "->", "addError", "(", "'className'", ",", "'保存失败');", "", "", "}", "}", "else", "{", "$", "model", "->", "addError", "(", "'className'", ",", "'没有找到这个类');", "", "", "}", "}", "}", "$", "model", "->", "name", "=", "$", "name", ";", "$", "model", "->", "className", "=", "$", "item", "::", "className", "(", ")", ";", "return", "$", "this", "->", "render", "(", "'update'", ",", "[", "'model'", "=>", "$", "model", "]", ")", ";", "}" ]
更新规则
[ "更新规则" ]
train
https://github.com/JeanWolf/yii2-jrbac/blob/1e5c80038451bd5b385f83cb9344c3bd5edd85e0/controllers/RuleController.php#L56-L97
JeanWolf/yii2-jrbac
controllers/RuleController.php
RuleController.actionPermissionindex
public function actionPermissionindex($id) { $auth = \Yii::$app->getAuthManager(); $rule = $auth->getRule($id); $allItems = $auth->getPermissions(); $ruleItems = $auth->getPermissionsByRule($id); $dataProvider = new ArrayDataProvider(); $dataProvider->setModels($allItems); return $this->render('permissionindex',[ 'dataProvider' => $dataProvider, 'allItems' => $allItems, 'ruleItems' => $ruleItems, 'rule' => $rule ]); }
php
public function actionPermissionindex($id) { $auth = \Yii::$app->getAuthManager(); $rule = $auth->getRule($id); $allItems = $auth->getPermissions(); $ruleItems = $auth->getPermissionsByRule($id); $dataProvider = new ArrayDataProvider(); $dataProvider->setModels($allItems); return $this->render('permissionindex',[ 'dataProvider' => $dataProvider, 'allItems' => $allItems, 'ruleItems' => $ruleItems, 'rule' => $rule ]); }
[ "public", "function", "actionPermissionindex", "(", "$", "id", ")", "{", "$", "auth", "=", "\\", "Yii", "::", "$", "app", "->", "getAuthManager", "(", ")", ";", "$", "rule", "=", "$", "auth", "->", "getRule", "(", "$", "id", ")", ";", "$", "allItems", "=", "$", "auth", "->", "getPermissions", "(", ")", ";", "$", "ruleItems", "=", "$", "auth", "->", "getPermissionsByRule", "(", "$", "id", ")", ";", "$", "dataProvider", "=", "new", "ArrayDataProvider", "(", ")", ";", "$", "dataProvider", "->", "setModels", "(", "$", "allItems", ")", ";", "return", "$", "this", "->", "render", "(", "'permissionindex'", ",", "[", "'dataProvider'", "=>", "$", "dataProvider", ",", "'allItems'", "=>", "$", "allItems", ",", "'ruleItems'", "=>", "$", "ruleItems", ",", "'rule'", "=>", "$", "rule", "]", ")", ";", "}" ]
查看规则权限关联列表
[ "查看规则权限关联列表" ]
train
https://github.com/JeanWolf/yii2-jrbac/blob/1e5c80038451bd5b385f83cb9344c3bd5edd85e0/controllers/RuleController.php#L137-L151
JeanWolf/yii2-jrbac
controllers/RuleController.php
RuleController.actionSetpermission
public function actionSetpermission($name) { if (\Yii::$app->getRequest()->getIsPost() && isset($_POST['act'],$_POST['val'])) { $auth = \Yii::$app->getAuthManager(); $permission = $auth->getPermission($_POST['val']); try { $permission->ruleName = $name; $flag = true; if($_POST['act'] == 'add') { $permission->ruleName = $name; if (!$auth->update($permission->name, $permission)) $flag = false; } else if($_POST['act'] == 'del') { $permission->ruleName = NULL; if (!$auth->update($permission->name, $permission)) $flag = false; } else { $flag = false; } return $flag ? 1 : 0; } catch(\Exception $e) { return 0; } } return $this->redirect(['index']); }
php
public function actionSetpermission($name) { if (\Yii::$app->getRequest()->getIsPost() && isset($_POST['act'],$_POST['val'])) { $auth = \Yii::$app->getAuthManager(); $permission = $auth->getPermission($_POST['val']); try { $permission->ruleName = $name; $flag = true; if($_POST['act'] == 'add') { $permission->ruleName = $name; if (!$auth->update($permission->name, $permission)) $flag = false; } else if($_POST['act'] == 'del') { $permission->ruleName = NULL; if (!$auth->update($permission->name, $permission)) $flag = false; } else { $flag = false; } return $flag ? 1 : 0; } catch(\Exception $e) { return 0; } } return $this->redirect(['index']); }
[ "public", "function", "actionSetpermission", "(", "$", "name", ")", "{", "if", "(", "\\", "Yii", "::", "$", "app", "->", "getRequest", "(", ")", "->", "getIsPost", "(", ")", "&&", "isset", "(", "$", "_POST", "[", "'act'", "]", ",", "$", "_POST", "[", "'val'", "]", ")", ")", "{", "$", "auth", "=", "\\", "Yii", "::", "$", "app", "->", "getAuthManager", "(", ")", ";", "$", "permission", "=", "$", "auth", "->", "getPermission", "(", "$", "_POST", "[", "'val'", "]", ")", ";", "try", "{", "$", "permission", "->", "ruleName", "=", "$", "name", ";", "$", "flag", "=", "true", ";", "if", "(", "$", "_POST", "[", "'act'", "]", "==", "'add'", ")", "{", "$", "permission", "->", "ruleName", "=", "$", "name", ";", "if", "(", "!", "$", "auth", "->", "update", "(", "$", "permission", "->", "name", ",", "$", "permission", ")", ")", "$", "flag", "=", "false", ";", "}", "else", "if", "(", "$", "_POST", "[", "'act'", "]", "==", "'del'", ")", "{", "$", "permission", "->", "ruleName", "=", "NULL", ";", "if", "(", "!", "$", "auth", "->", "update", "(", "$", "permission", "->", "name", ",", "$", "permission", ")", ")", "$", "flag", "=", "false", ";", "}", "else", "{", "$", "flag", "=", "false", ";", "}", "return", "$", "flag", "?", "1", ":", "0", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "return", "0", ";", "}", "}", "return", "$", "this", "->", "redirect", "(", "[", "'index'", "]", ")", ";", "}" ]
设置规则关联权限
[ "设置规则关联权限" ]
train
https://github.com/JeanWolf/yii2-jrbac/blob/1e5c80038451bd5b385f83cb9344c3bd5edd85e0/controllers/RuleController.php#L154-L177
meccado/acl-admin-control-panel
src/Http/Controllers/Admin/UserController.php
UserController.store
public function store(Request $request) { $input = $request->all(); $input['password'] = Hash::make($input['password']); $user = $this->users->create($input); //create Blank profile $profile = Profile::create([ 'user_id' => $user->id, 'bio' => '', ]); $profile->save(); return \Redirect::route('admin.users.index', [ ])->withMessage(trans('acl::user.users-controller-successfully_created')); }
php
public function store(Request $request) { $input = $request->all(); $input['password'] = Hash::make($input['password']); $user = $this->users->create($input); //create Blank profile $profile = Profile::create([ 'user_id' => $user->id, 'bio' => '', ]); $profile->save(); return \Redirect::route('admin.users.index', [ ])->withMessage(trans('acl::user.users-controller-successfully_created')); }
[ "public", "function", "store", "(", "Request", "$", "request", ")", "{", "$", "input", "=", "$", "request", "->", "all", "(", ")", ";", "$", "input", "[", "'password'", "]", "=", "Hash", "::", "make", "(", "$", "input", "[", "'password'", "]", ")", ";", "$", "user", "=", "$", "this", "->", "users", "->", "create", "(", "$", "input", ")", ";", "//create Blank profile", "$", "profile", "=", "Profile", "::", "create", "(", "[", "'user_id'", "=>", "$", "user", "->", "id", ",", "'bio'", "=>", "''", ",", "]", ")", ";", "$", "profile", "->", "save", "(", ")", ";", "return", "\\", "Redirect", "::", "route", "(", "'admin.users.index'", ",", "[", "]", ")", "->", "withMessage", "(", "trans", "(", "'acl::user.users-controller-successfully_created'", ")", ")", ";", "}" ]
Store a newly created resource in storage. @param \Illuminate\Http\Request $request @return \Illuminate\Http\RedirectRespons
[ "Store", "a", "newly", "created", "resource", "in", "storage", "." ]
train
https://github.com/meccado/acl-admin-control-panel/blob/50ac4c0dbf8bd49944ecad6a70708a70411b7378/src/Http/Controllers/Admin/UserController.php#L60-L75
meccado/acl-admin-control-panel
src/Http/Controllers/Admin/UserController.php
UserController.show
public function show($id) { $user = $this->users->findOrFail($id); return \View::make('admin.users.show', [ 'user' => $user, 'title' => 'view', ]); }
php
public function show($id) { $user = $this->users->findOrFail($id); return \View::make('admin.users.show', [ 'user' => $user, 'title' => 'view', ]); }
[ "public", "function", "show", "(", "$", "id", ")", "{", "$", "user", "=", "$", "this", "->", "users", "->", "findOrFail", "(", "$", "id", ")", ";", "return", "\\", "View", "::", "make", "(", "'admin.users.show'", ",", "[", "'user'", "=>", "$", "user", ",", "'title'", "=>", "'view'", ",", "]", ")", ";", "}" ]
Display the specified resource. @param int $id @return \Illuminate\View\View
[ "Display", "the", "specified", "resource", "." ]
train
https://github.com/meccado/acl-admin-control-panel/blob/50ac4c0dbf8bd49944ecad6a70708a70411b7378/src/Http/Controllers/Admin/UserController.php#L83-L90
meccado/acl-admin-control-panel
src/Http/Controllers/Admin/UserController.php
UserController.edit
public function edit($id) { $user = $this->users->findOrFail($id); $roles = Role::pluck('name', 'id'); return \View::make('admin.users.edit', [ 'user' => $user, 'roles' => $roles, 'title' => 'edit', ]); }
php
public function edit($id) { $user = $this->users->findOrFail($id); $roles = Role::pluck('name', 'id'); return \View::make('admin.users.edit', [ 'user' => $user, 'roles' => $roles, 'title' => 'edit', ]); }
[ "public", "function", "edit", "(", "$", "id", ")", "{", "$", "user", "=", "$", "this", "->", "users", "->", "findOrFail", "(", "$", "id", ")", ";", "$", "roles", "=", "Role", "::", "pluck", "(", "'name'", ",", "'id'", ")", ";", "return", "\\", "View", "::", "make", "(", "'admin.users.edit'", ",", "[", "'user'", "=>", "$", "user", ",", "'roles'", "=>", "$", "roles", ",", "'title'", "=>", "'edit'", ",", "]", ")", ";", "}" ]
Show the form for editing the specified resource. @param int $id @return \Illuminate\View\View
[ "Show", "the", "form", "for", "editing", "the", "specified", "resource", "." ]
train
https://github.com/meccado/acl-admin-control-panel/blob/50ac4c0dbf8bd49944ecad6a70708a70411b7378/src/Http/Controllers/Admin/UserController.php#L98-L107
meccado/acl-admin-control-panel
src/Http/Controllers/Admin/UserController.php
UserController.update
public function update(Request $request, $id) { $user = $this->users->findOrFail($id); $input = $request->all(); $input['password'] = Hash::make($input['password']); $user->update($input); return \Redirect::route('admin.users.index', [ ])->withMessage(trans('acl::user.users-controller-successfully_updated')); }
php
public function update(Request $request, $id) { $user = $this->users->findOrFail($id); $input = $request->all(); $input['password'] = Hash::make($input['password']); $user->update($input); return \Redirect::route('admin.users.index', [ ])->withMessage(trans('acl::user.users-controller-successfully_updated')); }
[ "public", "function", "update", "(", "Request", "$", "request", ",", "$", "id", ")", "{", "$", "user", "=", "$", "this", "->", "users", "->", "findOrFail", "(", "$", "id", ")", ";", "$", "input", "=", "$", "request", "->", "all", "(", ")", ";", "$", "input", "[", "'password'", "]", "=", "Hash", "::", "make", "(", "$", "input", "[", "'password'", "]", ")", ";", "$", "user", "->", "update", "(", "$", "input", ")", ";", "return", "\\", "Redirect", "::", "route", "(", "'admin.users.index'", ",", "[", "]", ")", "->", "withMessage", "(", "trans", "(", "'acl::user.users-controller-successfully_updated'", ")", ")", ";", "}" ]
Update the specified resource in storage. @param \Illuminate\Http\Request $request @param int $id @return \Illuminate\View\View
[ "Update", "the", "specified", "resource", "in", "storage", "." ]
train
https://github.com/meccado/acl-admin-control-panel/blob/50ac4c0dbf8bd49944ecad6a70708a70411b7378/src/Http/Controllers/Admin/UserController.php#L116-L124
meccado/acl-admin-control-panel
src/Http/Controllers/Admin/UserController.php
UserController.destroy
public function destroy($id) { $user = $this->users->findOrFail($id); User::destroy($id); return \Redirect::route('admin.users.index', [ ])->withMessage(trans('acl::user.users-controller-successfully_deleted')); }
php
public function destroy($id) { $user = $this->users->findOrFail($id); User::destroy($id); return \Redirect::route('admin.users.index', [ ])->withMessage(trans('acl::user.users-controller-successfully_deleted')); }
[ "public", "function", "destroy", "(", "$", "id", ")", "{", "$", "user", "=", "$", "this", "->", "users", "->", "findOrFail", "(", "$", "id", ")", ";", "User", "::", "destroy", "(", "$", "id", ")", ";", "return", "\\", "Redirect", "::", "route", "(", "'admin.users.index'", ",", "[", "]", ")", "->", "withMessage", "(", "trans", "(", "'acl::user.users-controller-successfully_deleted'", ")", ")", ";", "}" ]
Remove the specified resource from storage. @param int $id @return \Illuminate\Http\RedirectRespons
[ "Remove", "the", "specified", "resource", "from", "storage", "." ]
train
https://github.com/meccado/acl-admin-control-panel/blob/50ac4c0dbf8bd49944ecad6a70708a70411b7378/src/Http/Controllers/Admin/UserController.php#L132-L138
inpsyde/inpsyde-filter
src/DateTime.php
DateTime.filter
public function filter( $value ) { try { $result = $this->normalize_date_time( $value ); } catch ( \Exception $e ) { do_action( 'inpsyde.filter.error', 'The given value caused an exception.', [ 'method' => __METHOD__, 'exception' => $e, 'value' => $value ] ); return ''; } if ( $result === FALSE ) { return $value; } return $result; }
php
public function filter( $value ) { try { $result = $this->normalize_date_time( $value ); } catch ( \Exception $e ) { do_action( 'inpsyde.filter.error', 'The given value caused an exception.', [ 'method' => __METHOD__, 'exception' => $e, 'value' => $value ] ); return ''; } if ( $result === FALSE ) { return $value; } return $result; }
[ "public", "function", "filter", "(", "$", "value", ")", "{", "try", "{", "$", "result", "=", "$", "this", "->", "normalize_date_time", "(", "$", "value", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "do_action", "(", "'inpsyde.filter.error'", ",", "'The given value caused an exception.'", ",", "[", "'method'", "=>", "__METHOD__", ",", "'exception'", "=>", "$", "e", ",", "'value'", "=>", "$", "value", "]", ")", ";", "return", "''", ";", "}", "if", "(", "$", "result", "===", "FALSE", ")", "{", "return", "$", "value", ";", "}", "return", "$", "result", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/inpsyde/inpsyde-filter/blob/777a6208ea4dfbeed89e6d0712a35dc25eab498b/src/DateTime.php#L22-L42
inpsyde/inpsyde-filter
src/DateTime.php
DateTime.normalize_date_time
protected function normalize_date_time( $value ) { if ( $value === '' || $value === NULL ) { return $value; } if ( ! is_string( $value ) && ! is_int( $value ) && ! $value instanceof DateTime ) { return $value; } if ( is_int( $value ) ) { //timestamp $value = new \DateTime( '@' . $value ); } elseif ( ! $value instanceof DateTime ) { $value = new \DateTime( $value ); } return $value->format( $this->options[ 'format' ] ); }
php
protected function normalize_date_time( $value ) { if ( $value === '' || $value === NULL ) { return $value; } if ( ! is_string( $value ) && ! is_int( $value ) && ! $value instanceof DateTime ) { return $value; } if ( is_int( $value ) ) { //timestamp $value = new \DateTime( '@' . $value ); } elseif ( ! $value instanceof DateTime ) { $value = new \DateTime( $value ); } return $value->format( $this->options[ 'format' ] ); }
[ "protected", "function", "normalize_date_time", "(", "$", "value", ")", "{", "if", "(", "$", "value", "===", "''", "||", "$", "value", "===", "NULL", ")", "{", "return", "$", "value", ";", "}", "if", "(", "!", "is_string", "(", "$", "value", ")", "&&", "!", "is_int", "(", "$", "value", ")", "&&", "!", "$", "value", "instanceof", "DateTime", ")", "{", "return", "$", "value", ";", "}", "if", "(", "is_int", "(", "$", "value", ")", ")", "{", "//timestamp", "$", "value", "=", "new", "\\", "DateTime", "(", "'@'", ".", "$", "value", ")", ";", "}", "elseif", "(", "!", "$", "value", "instanceof", "DateTime", ")", "{", "$", "value", "=", "new", "\\", "DateTime", "(", "$", "value", ")", ";", "}", "return", "$", "value", "->", "format", "(", "$", "this", "->", "options", "[", "'format'", "]", ")", ";", "}" ]
Normalize the provided value to a formatted string. @param string|int|DateTime $value @return string
[ "Normalize", "the", "provided", "value", "to", "a", "formatted", "string", "." ]
train
https://github.com/inpsyde/inpsyde-filter/blob/777a6208ea4dfbeed89e6d0712a35dc25eab498b/src/DateTime.php#L51-L67
spiral-modules/auth
source/Auth/AuthContext.php
AuthContext.init
public function init(TokenInterface $token) { $this->user = null; $this->token = $token; $this->closed = false; }
php
public function init(TokenInterface $token) { $this->user = null; $this->token = $token; $this->closed = false; }
[ "public", "function", "init", "(", "TokenInterface", "$", "token", ")", "{", "$", "this", "->", "user", "=", "null", ";", "$", "this", "->", "token", "=", "$", "token", ";", "$", "this", "->", "closed", "=", "false", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/spiral-modules/auth/blob/24e2070028f7257e8192914556963a4794428a99/source/Auth/AuthContext.php#L54-L59
spiral-modules/auth
source/Auth/AuthContext.php
AuthContext.getUser
public function getUser() { if (empty($this->token) || $this->isClosed()) { return null; } if (!empty($this->user)) { return $this->user; } return $this->user = $this->users->findByPK($this->token->getUserPK()); }
php
public function getUser() { if (empty($this->token) || $this->isClosed()) { return null; } if (!empty($this->user)) { return $this->user; } return $this->user = $this->users->findByPK($this->token->getUserPK()); }
[ "public", "function", "getUser", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "token", ")", "||", "$", "this", "->", "isClosed", "(", ")", ")", "{", "return", "null", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "user", ")", ")", "{", "return", "$", "this", "->", "user", ";", "}", "return", "$", "this", "->", "user", "=", "$", "this", "->", "users", "->", "findByPK", "(", "$", "this", "->", "token", "->", "getUserPK", "(", ")", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/spiral-modules/auth/blob/24e2070028f7257e8192914556963a4794428a99/source/Auth/AuthContext.php#L94-L105
rayrutjes/domain-foundation
src/Command/Gateway/DefaultCommandGateway.php
DefaultCommandGateway.sendAndWait
public function sendAndWait($command, $timeout = 300) { $commandMessage = $this->wrapCommandWithMessageEnvelope($command); // Todo: return future callback and pass it along for dispatching. return $this->commandBus->dispatch($commandMessage); }
php
public function sendAndWait($command, $timeout = 300) { $commandMessage = $this->wrapCommandWithMessageEnvelope($command); // Todo: return future callback and pass it along for dispatching. return $this->commandBus->dispatch($commandMessage); }
[ "public", "function", "sendAndWait", "(", "$", "command", ",", "$", "timeout", "=", "300", ")", "{", "$", "commandMessage", "=", "$", "this", "->", "wrapCommandWithMessageEnvelope", "(", "$", "command", ")", ";", "// Todo: return future callback and pass it along for dispatching.", "return", "$", "this", "->", "commandBus", "->", "dispatch", "(", "$", "commandMessage", ")", ";", "}" ]
@param mixed $command @param int $timeout Timeout in milliseconds. @return mixed
[ "@param", "mixed", "$command", "@param", "int", "$timeout", "Timeout", "in", "milliseconds", "." ]
train
https://github.com/rayrutjes/domain-foundation/blob/2bce7cd6a6612f718e70e3176589c1abf39d1a3e/src/Command/Gateway/DefaultCommandGateway.php#L41-L47
rayrutjes/domain-foundation
src/Command/Gateway/DefaultCommandGateway.php
DefaultCommandGateway.wrapCommandWithMessageEnvelope
private function wrapCommandWithMessageEnvelope($command) { if ($command instanceof Command) { return $command; } if ($command instanceof Serializable) { return new GenericCommand(MessageIdentifier::generate(), $command); } throw new \InvalidArgumentException('Unsupported data type.'); }
php
private function wrapCommandWithMessageEnvelope($command) { if ($command instanceof Command) { return $command; } if ($command instanceof Serializable) { return new GenericCommand(MessageIdentifier::generate(), $command); } throw new \InvalidArgumentException('Unsupported data type.'); }
[ "private", "function", "wrapCommandWithMessageEnvelope", "(", "$", "command", ")", "{", "if", "(", "$", "command", "instanceof", "Command", ")", "{", "return", "$", "command", ";", "}", "if", "(", "$", "command", "instanceof", "Serializable", ")", "{", "return", "new", "GenericCommand", "(", "MessageIdentifier", "::", "generate", "(", ")", ",", "$", "command", ")", ";", "}", "throw", "new", "\\", "InvalidArgumentException", "(", "'Unsupported data type.'", ")", ";", "}" ]
@param $command @return Command
[ "@param", "$command" ]
train
https://github.com/rayrutjes/domain-foundation/blob/2bce7cd6a6612f718e70e3176589c1abf39d1a3e/src/Command/Gateway/DefaultCommandGateway.php#L54-L65
factorio-item-browser/export-data
src/Entity/Recipe.php
Recipe.setIngredients
public function setIngredients(array $ingredients) { $this->ingredients = array_values(array_filter($ingredients, function ($ingredient): bool { return $ingredient instanceof Ingredient; })); return $this; }
php
public function setIngredients(array $ingredients) { $this->ingredients = array_values(array_filter($ingredients, function ($ingredient): bool { return $ingredient instanceof Ingredient; })); return $this; }
[ "public", "function", "setIngredients", "(", "array", "$", "ingredients", ")", "{", "$", "this", "->", "ingredients", "=", "array_values", "(", "array_filter", "(", "$", "ingredients", ",", "function", "(", "$", "ingredient", ")", ":", "bool", "{", "return", "$", "ingredient", "instanceof", "Ingredient", ";", "}", ")", ")", ";", "return", "$", "this", ";", "}" ]
Sets the ingredients of the recipe. @param array|Ingredient[] $ingredients @return $this Implementing fluent interface.
[ "Sets", "the", "ingredients", "of", "the", "recipe", "." ]
train
https://github.com/factorio-item-browser/export-data/blob/1413b2eed0fbfed0521457ac7ef0d668ac30c212/src/Entity/Recipe.php#L145-L151
factorio-item-browser/export-data
src/Entity/Recipe.php
Recipe.setProducts
public function setProducts(array $products) { $this->products = array_values(array_filter($products, function ($product): bool { return $product instanceof Product; })); return $this; }
php
public function setProducts(array $products) { $this->products = array_values(array_filter($products, function ($product): bool { return $product instanceof Product; })); return $this; }
[ "public", "function", "setProducts", "(", "array", "$", "products", ")", "{", "$", "this", "->", "products", "=", "array_values", "(", "array_filter", "(", "$", "products", ",", "function", "(", "$", "product", ")", ":", "bool", "{", "return", "$", "product", "instanceof", "Product", ";", "}", ")", ")", ";", "return", "$", "this", ";", "}" ]
Sets the products of the recipe. @param array|Product[] $products @return $this Implementing fluent interface.
[ "Sets", "the", "products", "of", "the", "recipe", "." ]
train
https://github.com/factorio-item-browser/export-data/blob/1413b2eed0fbfed0521457ac7ef0d668ac30c212/src/Entity/Recipe.php#L178-L184
factorio-item-browser/export-data
src/Entity/Recipe.php
Recipe.writeData
public function writeData(): array { $dataBuilder = new DataBuilder(); $dataBuilder->setString('n', $this->name, '') ->setString('m', $this->mode, '') ->setArray('i', $this->ingredients, function (Ingredient $ingredient): array { return $ingredient->writeData(); }, []) ->setArray('p', $this->products, function (Product $product): array { return $product->writeData(); }, []) ->setFloat('c', $this->craftingTime, 0.) ->setString('a', $this->craftingCategory, '') ->setArray('l', $this->labels->writeData(), null, []) ->setArray('d', $this->descriptions->writeData(), null, []) ->setString('h', $this->iconHash, ''); return $dataBuilder->getData(); }
php
public function writeData(): array { $dataBuilder = new DataBuilder(); $dataBuilder->setString('n', $this->name, '') ->setString('m', $this->mode, '') ->setArray('i', $this->ingredients, function (Ingredient $ingredient): array { return $ingredient->writeData(); }, []) ->setArray('p', $this->products, function (Product $product): array { return $product->writeData(); }, []) ->setFloat('c', $this->craftingTime, 0.) ->setString('a', $this->craftingCategory, '') ->setArray('l', $this->labels->writeData(), null, []) ->setArray('d', $this->descriptions->writeData(), null, []) ->setString('h', $this->iconHash, ''); return $dataBuilder->getData(); }
[ "public", "function", "writeData", "(", ")", ":", "array", "{", "$", "dataBuilder", "=", "new", "DataBuilder", "(", ")", ";", "$", "dataBuilder", "->", "setString", "(", "'n'", ",", "$", "this", "->", "name", ",", "''", ")", "->", "setString", "(", "'m'", ",", "$", "this", "->", "mode", ",", "''", ")", "->", "setArray", "(", "'i'", ",", "$", "this", "->", "ingredients", ",", "function", "(", "Ingredient", "$", "ingredient", ")", ":", "array", "{", "return", "$", "ingredient", "->", "writeData", "(", ")", ";", "}", ",", "[", "]", ")", "->", "setArray", "(", "'p'", ",", "$", "this", "->", "products", ",", "function", "(", "Product", "$", "product", ")", ":", "array", "{", "return", "$", "product", "->", "writeData", "(", ")", ";", "}", ",", "[", "]", ")", "->", "setFloat", "(", "'c'", ",", "$", "this", "->", "craftingTime", ",", "0.", ")", "->", "setString", "(", "'a'", ",", "$", "this", "->", "craftingCategory", ",", "''", ")", "->", "setArray", "(", "'l'", ",", "$", "this", "->", "labels", "->", "writeData", "(", ")", ",", "null", ",", "[", "]", ")", "->", "setArray", "(", "'d'", ",", "$", "this", "->", "descriptions", "->", "writeData", "(", ")", ",", "null", ",", "[", "]", ")", "->", "setString", "(", "'h'", ",", "$", "this", "->", "iconHash", ",", "''", ")", ";", "return", "$", "dataBuilder", "->", "getData", "(", ")", ";", "}" ]
Writes the entity data to an array. @return array
[ "Writes", "the", "entity", "data", "to", "an", "array", "." ]
train
https://github.com/factorio-item-browser/export-data/blob/1413b2eed0fbfed0521457ac7ef0d668ac30c212/src/Entity/Recipe.php#L310-L327
factorio-item-browser/export-data
src/Entity/Recipe.php
Recipe.readData
public function readData(DataContainer $data) { $this->name = $data->getString('n', ''); $this->mode = $data->getString('m', ''); $this->ingredients = array_map(function (DataContainer $data): Ingredient { return (new Ingredient())->readData($data); }, $data->getObjectArray('i')); $this->products = array_map(function (DataContainer $data): Product { return (new Product())->readData($data); }, $data->getObjectArray('p')); $this->craftingTime = $data->getFloat('c', 0.); $this->craftingCategory = $data->getString('a', ''); $this->labels->readData($data->getObject('l')); $this->descriptions->readData($data->getObject('d')); $this->iconHash = $data->getString('h', ''); return $this; }
php
public function readData(DataContainer $data) { $this->name = $data->getString('n', ''); $this->mode = $data->getString('m', ''); $this->ingredients = array_map(function (DataContainer $data): Ingredient { return (new Ingredient())->readData($data); }, $data->getObjectArray('i')); $this->products = array_map(function (DataContainer $data): Product { return (new Product())->readData($data); }, $data->getObjectArray('p')); $this->craftingTime = $data->getFloat('c', 0.); $this->craftingCategory = $data->getString('a', ''); $this->labels->readData($data->getObject('l')); $this->descriptions->readData($data->getObject('d')); $this->iconHash = $data->getString('h', ''); return $this; }
[ "public", "function", "readData", "(", "DataContainer", "$", "data", ")", "{", "$", "this", "->", "name", "=", "$", "data", "->", "getString", "(", "'n'", ",", "''", ")", ";", "$", "this", "->", "mode", "=", "$", "data", "->", "getString", "(", "'m'", ",", "''", ")", ";", "$", "this", "->", "ingredients", "=", "array_map", "(", "function", "(", "DataContainer", "$", "data", ")", ":", "Ingredient", "{", "return", "(", "new", "Ingredient", "(", ")", ")", "->", "readData", "(", "$", "data", ")", ";", "}", ",", "$", "data", "->", "getObjectArray", "(", "'i'", ")", ")", ";", "$", "this", "->", "products", "=", "array_map", "(", "function", "(", "DataContainer", "$", "data", ")", ":", "Product", "{", "return", "(", "new", "Product", "(", ")", ")", "->", "readData", "(", "$", "data", ")", ";", "}", ",", "$", "data", "->", "getObjectArray", "(", "'p'", ")", ")", ";", "$", "this", "->", "craftingTime", "=", "$", "data", "->", "getFloat", "(", "'c'", ",", "0.", ")", ";", "$", "this", "->", "craftingCategory", "=", "$", "data", "->", "getString", "(", "'a'", ",", "''", ")", ";", "$", "this", "->", "labels", "->", "readData", "(", "$", "data", "->", "getObject", "(", "'l'", ")", ")", ";", "$", "this", "->", "descriptions", "->", "readData", "(", "$", "data", "->", "getObject", "(", "'d'", ")", ")", ";", "$", "this", "->", "iconHash", "=", "$", "data", "->", "getString", "(", "'h'", ",", "''", ")", ";", "return", "$", "this", ";", "}" ]
Reads the entity data. @param DataContainer $data @return $this
[ "Reads", "the", "entity", "data", "." ]
train
https://github.com/factorio-item-browser/export-data/blob/1413b2eed0fbfed0521457ac7ef0d668ac30c212/src/Entity/Recipe.php#L334-L350
factorio-item-browser/export-data
src/Entity/Recipe.php
Recipe.calculateHash
public function calculateHash(): string { return EntityUtils::calculateHashOfArray([ $this->name, $this->mode, array_map(function (Ingredient $ingredient): string { return $ingredient->calculateHash(); }, $this->ingredients), array_map(function (Product $product): string { return $product->calculateHash(); }, $this->products), $this->craftingTime, $this->craftingCategory, $this->labels->calculateHash(), $this->descriptions->calculateHash(), $this->iconHash, ]); }
php
public function calculateHash(): string { return EntityUtils::calculateHashOfArray([ $this->name, $this->mode, array_map(function (Ingredient $ingredient): string { return $ingredient->calculateHash(); }, $this->ingredients), array_map(function (Product $product): string { return $product->calculateHash(); }, $this->products), $this->craftingTime, $this->craftingCategory, $this->labels->calculateHash(), $this->descriptions->calculateHash(), $this->iconHash, ]); }
[ "public", "function", "calculateHash", "(", ")", ":", "string", "{", "return", "EntityUtils", "::", "calculateHashOfArray", "(", "[", "$", "this", "->", "name", ",", "$", "this", "->", "mode", ",", "array_map", "(", "function", "(", "Ingredient", "$", "ingredient", ")", ":", "string", "{", "return", "$", "ingredient", "->", "calculateHash", "(", ")", ";", "}", ",", "$", "this", "->", "ingredients", ")", ",", "array_map", "(", "function", "(", "Product", "$", "product", ")", ":", "string", "{", "return", "$", "product", "->", "calculateHash", "(", ")", ";", "}", ",", "$", "this", "->", "products", ")", ",", "$", "this", "->", "craftingTime", ",", "$", "this", "->", "craftingCategory", ",", "$", "this", "->", "labels", "->", "calculateHash", "(", ")", ",", "$", "this", "->", "descriptions", "->", "calculateHash", "(", ")", ",", "$", "this", "->", "iconHash", ",", "]", ")", ";", "}" ]
Calculates a hash value representing the entity. @return string
[ "Calculates", "a", "hash", "value", "representing", "the", "entity", "." ]
train
https://github.com/factorio-item-browser/export-data/blob/1413b2eed0fbfed0521457ac7ef0d668ac30c212/src/Entity/Recipe.php#L356-L373
thienhungho/yii2-order-management
src/modules/MyOrder/controllers/OrderController.php
OrderController.actionIndex
public function actionIndex() { $searchModel = new OrderSearch(); $queryParams = request()->queryParams; $queryParams['OrderSearch']['customer_username'] = get_current_user_name(); $dataProvider = $searchModel->search($queryParams); $dataProvider->sort->defaultOrder = ['id' => SORT_DESC]; $dataProvider = $searchModel->search(request()->queryParams); return $this->render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); }
php
public function actionIndex() { $searchModel = new OrderSearch(); $queryParams = request()->queryParams; $queryParams['OrderSearch']['customer_username'] = get_current_user_name(); $dataProvider = $searchModel->search($queryParams); $dataProvider->sort->defaultOrder = ['id' => SORT_DESC]; $dataProvider = $searchModel->search(request()->queryParams); return $this->render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); }
[ "public", "function", "actionIndex", "(", ")", "{", "$", "searchModel", "=", "new", "OrderSearch", "(", ")", ";", "$", "queryParams", "=", "request", "(", ")", "->", "queryParams", ";", "$", "queryParams", "[", "'OrderSearch'", "]", "[", "'customer_username'", "]", "=", "get_current_user_name", "(", ")", ";", "$", "dataProvider", "=", "$", "searchModel", "->", "search", "(", "$", "queryParams", ")", ";", "$", "dataProvider", "->", "sort", "->", "defaultOrder", "=", "[", "'id'", "=>", "SORT_DESC", "]", ";", "$", "dataProvider", "=", "$", "searchModel", "->", "search", "(", "request", "(", ")", "->", "queryParams", ")", ";", "return", "$", "this", "->", "render", "(", "'index'", ",", "[", "'searchModel'", "=>", "$", "searchModel", ",", "'dataProvider'", "=>", "$", "dataProvider", ",", "]", ")", ";", "}" ]
Lists all Order models. @return mixed
[ "Lists", "all", "Order", "models", "." ]
train
https://github.com/thienhungho/yii2-order-management/blob/f263f0b2168d6f5e99cee2e20a5878d09d4e81c0/src/modules/MyOrder/controllers/OrderController.php#L33-L46
xinix-technology/norm
src/Norm/Type/NDateTime.php
NDateTime.tzFormat
public function tzFormat($format, $tz = null) { if (isset($tz)) { $this->setTimezone(new DateTimeZone($tz)); } return $this->format($format); }
php
public function tzFormat($format, $tz = null) { if (isset($tz)) { $this->setTimezone(new DateTimeZone($tz)); } return $this->format($format); }
[ "public", "function", "tzFormat", "(", "$", "format", ",", "$", "tz", "=", "null", ")", "{", "if", "(", "isset", "(", "$", "tz", ")", ")", "{", "$", "this", "->", "setTimezone", "(", "new", "DateTimeZone", "(", "$", "tz", ")", ")", ";", "}", "return", "$", "this", "->", "format", "(", "$", "format", ")", ";", "}" ]
Formatting by timezone @param string $format @param string $tz @return mixed
[ "Formatting", "by", "timezone" ]
train
https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Type/NDateTime.php#L38-L45
xinix-technology/norm
src/Norm/Type/NDateTime.php
NDateTime.jsonSerialize
public function jsonSerialize() { if ($tz = Norm::options('tz')) { $this->setTimezone(new DateTimeZone($tz)); } return $this->format('c'); }
php
public function jsonSerialize() { if ($tz = Norm::options('tz')) { $this->setTimezone(new DateTimeZone($tz)); } return $this->format('c'); }
[ "public", "function", "jsonSerialize", "(", ")", "{", "if", "(", "$", "tz", "=", "Norm", "::", "options", "(", "'tz'", ")", ")", "{", "$", "this", "->", "setTimezone", "(", "new", "DateTimeZone", "(", "$", "tz", ")", ")", ";", "}", "return", "$", "this", "->", "format", "(", "'c'", ")", ";", "}" ]
Perform serialization of this implementation. @return string
[ "Perform", "serialization", "of", "this", "implementation", "." ]
train
https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Type/NDateTime.php#L52-L59
javiacei/IdeupSimplePaginatorBundle
Twig/Extension/PaginatorExtension.php
PaginatorExtension.render
public function render($route, $id = null, $options = array(), $view = null) { return $this->pagebar->render($route, $id, $options, $view); }
php
public function render($route, $id = null, $options = array(), $view = null) { return $this->pagebar->render($route, $id, $options, $view); }
[ "public", "function", "render", "(", "$", "route", ",", "$", "id", "=", "null", ",", "$", "options", "=", "array", "(", ")", ",", "$", "view", "=", "null", ")", "{", "return", "$", "this", "->", "pagebar", "->", "render", "(", "$", "route", ",", "$", "id", ",", "$", "options", ",", "$", "view", ")", ";", "}" ]
Renders the paginator @param string $route @param string $id @param array $options @param string $view @return string
[ "Renders", "the", "paginator" ]
train
https://github.com/javiacei/IdeupSimplePaginatorBundle/blob/12639a9c75bc403649fc2b2881e190a017d8c5b2/Twig/Extension/PaginatorExtension.php#L46-L49
titon/db
src/Titon/Db/Behavior/ConverterBehavior.php
ConverterBehavior.convert
public function convert($field, $type, array $options = []) { if (!isset($this->_defaults[$type])) { throw new InvalidArgumentException(sprintf('Converter %s does not exist', $type)); } $this->_converters[$field] = Hash::merge([ 'encode' => true, 'decode' => true, 'type' => $type, ], $this->_defaults[$type], $options); return $this; }
php
public function convert($field, $type, array $options = []) { if (!isset($this->_defaults[$type])) { throw new InvalidArgumentException(sprintf('Converter %s does not exist', $type)); } $this->_converters[$field] = Hash::merge([ 'encode' => true, 'decode' => true, 'type' => $type, ], $this->_defaults[$type], $options); return $this; }
[ "public", "function", "convert", "(", "$", "field", ",", "$", "type", ",", "array", "$", "options", "=", "[", "]", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "_defaults", "[", "$", "type", "]", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'Converter %s does not exist'", ",", "$", "type", ")", ")", ";", "}", "$", "this", "->", "_converters", "[", "$", "field", "]", "=", "Hash", "::", "merge", "(", "[", "'encode'", "=>", "true", ",", "'decode'", "=>", "true", ",", "'type'", "=>", "$", "type", ",", "]", ",", "$", "this", "->", "_defaults", "[", "$", "type", "]", ",", "$", "options", ")", ";", "return", "$", "this", ";", "}" ]
Define a converter for a specific field. @param string $field @param string $type @param array $options @return $this @throws \Titon\Db\Exception\InvalidArgumentException
[ "Define", "a", "converter", "for", "a", "specific", "field", "." ]
train
https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Behavior/ConverterBehavior.php#L56-L68
titon/db
src/Titon/Db/Behavior/ConverterBehavior.php
ConverterBehavior.preSave
public function preSave(Event $event, Query $query, $id, array &$data) { $repo = $this->getRepository(); $converters = $this->getConverters(); foreach ($data as $key => $value) { if (empty($converters[$key])) { continue; } $converter = $converters[$key]; // Exit if encoding should not happen if (!$converter['encode']) { continue; } switch ($converter['type']) { case self::SERIALIZE: $value = $this->toSerialize($value, $converter); break; case self::JSON: $value = $this->toJson($value, $converter); break; case self::BASE64: $value = $this->toBase64($value, $converter); break; case self::CUSTOM: if (method_exists($repo, $converter['encode'])) { $value = call_user_func_array([$repo, $converter['encode']], [$value, $converter]); } break; } $data[$key] = $value; } return true; }
php
public function preSave(Event $event, Query $query, $id, array &$data) { $repo = $this->getRepository(); $converters = $this->getConverters(); foreach ($data as $key => $value) { if (empty($converters[$key])) { continue; } $converter = $converters[$key]; // Exit if encoding should not happen if (!$converter['encode']) { continue; } switch ($converter['type']) { case self::SERIALIZE: $value = $this->toSerialize($value, $converter); break; case self::JSON: $value = $this->toJson($value, $converter); break; case self::BASE64: $value = $this->toBase64($value, $converter); break; case self::CUSTOM: if (method_exists($repo, $converter['encode'])) { $value = call_user_func_array([$repo, $converter['encode']], [$value, $converter]); } break; } $data[$key] = $value; } return true; }
[ "public", "function", "preSave", "(", "Event", "$", "event", ",", "Query", "$", "query", ",", "$", "id", ",", "array", "&", "$", "data", ")", "{", "$", "repo", "=", "$", "this", "->", "getRepository", "(", ")", ";", "$", "converters", "=", "$", "this", "->", "getConverters", "(", ")", ";", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "empty", "(", "$", "converters", "[", "$", "key", "]", ")", ")", "{", "continue", ";", "}", "$", "converter", "=", "$", "converters", "[", "$", "key", "]", ";", "// Exit if encoding should not happen", "if", "(", "!", "$", "converter", "[", "'encode'", "]", ")", "{", "continue", ";", "}", "switch", "(", "$", "converter", "[", "'type'", "]", ")", "{", "case", "self", "::", "SERIALIZE", ":", "$", "value", "=", "$", "this", "->", "toSerialize", "(", "$", "value", ",", "$", "converter", ")", ";", "break", ";", "case", "self", "::", "JSON", ":", "$", "value", "=", "$", "this", "->", "toJson", "(", "$", "value", ",", "$", "converter", ")", ";", "break", ";", "case", "self", "::", "BASE64", ":", "$", "value", "=", "$", "this", "->", "toBase64", "(", "$", "value", ",", "$", "converter", ")", ";", "break", ";", "case", "self", "::", "CUSTOM", ":", "if", "(", "method_exists", "(", "$", "repo", ",", "$", "converter", "[", "'encode'", "]", ")", ")", "{", "$", "value", "=", "call_user_func_array", "(", "[", "$", "repo", ",", "$", "converter", "[", "'encode'", "]", "]", ",", "[", "$", "value", ",", "$", "converter", "]", ")", ";", "}", "break", ";", "}", "$", "data", "[", "$", "key", "]", "=", "$", "value", ";", "}", "return", "true", ";", "}" ]
Apply the encoding converter before a record is saved. @param \Titon\Event\Event $event @param \Titon\Db\Query $query @param int|int[] $id @param array $data @return bool
[ "Apply", "the", "encoding", "converter", "before", "a", "record", "is", "saved", "." ]
train
https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Behavior/ConverterBehavior.php#L121-L152
titon/db
src/Titon/Db/Behavior/ConverterBehavior.php
ConverterBehavior.postFind
public function postFind(Event $event, array &$results, $finder) { if (!in_array($finder, ['first', 'all'])) { return; } $repo = $this->getRepository(); $converters = $this->getConverters(); foreach ($results as $i => $result) { foreach ($result as $key => $value) { if (empty($converters[$key])) { continue; } $converter = $converters[$key]; // Exit if decoding should not happen if (!$converter['decode']) { continue; } switch ($converter['type']) { case self::SERIALIZE: $value = $this->fromSerialize($value, $converter); break; case self::JSON: $value = $this->fromJson($value, $converter); break; case self::BASE64: $value = $this->fromBase64($value, $converter); break; case self::CUSTOM: if (method_exists($repo, $converter['decode'])) { $value = call_user_func_array([$repo, $converter['decode']], [$value, $converter]); } break; } $results[$i][$key] = $value; } } }
php
public function postFind(Event $event, array &$results, $finder) { if (!in_array($finder, ['first', 'all'])) { return; } $repo = $this->getRepository(); $converters = $this->getConverters(); foreach ($results as $i => $result) { foreach ($result as $key => $value) { if (empty($converters[$key])) { continue; } $converter = $converters[$key]; // Exit if decoding should not happen if (!$converter['decode']) { continue; } switch ($converter['type']) { case self::SERIALIZE: $value = $this->fromSerialize($value, $converter); break; case self::JSON: $value = $this->fromJson($value, $converter); break; case self::BASE64: $value = $this->fromBase64($value, $converter); break; case self::CUSTOM: if (method_exists($repo, $converter['decode'])) { $value = call_user_func_array([$repo, $converter['decode']], [$value, $converter]); } break; } $results[$i][$key] = $value; } } }
[ "public", "function", "postFind", "(", "Event", "$", "event", ",", "array", "&", "$", "results", ",", "$", "finder", ")", "{", "if", "(", "!", "in_array", "(", "$", "finder", ",", "[", "'first'", ",", "'all'", "]", ")", ")", "{", "return", ";", "}", "$", "repo", "=", "$", "this", "->", "getRepository", "(", ")", ";", "$", "converters", "=", "$", "this", "->", "getConverters", "(", ")", ";", "foreach", "(", "$", "results", "as", "$", "i", "=>", "$", "result", ")", "{", "foreach", "(", "$", "result", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "empty", "(", "$", "converters", "[", "$", "key", "]", ")", ")", "{", "continue", ";", "}", "$", "converter", "=", "$", "converters", "[", "$", "key", "]", ";", "// Exit if decoding should not happen", "if", "(", "!", "$", "converter", "[", "'decode'", "]", ")", "{", "continue", ";", "}", "switch", "(", "$", "converter", "[", "'type'", "]", ")", "{", "case", "self", "::", "SERIALIZE", ":", "$", "value", "=", "$", "this", "->", "fromSerialize", "(", "$", "value", ",", "$", "converter", ")", ";", "break", ";", "case", "self", "::", "JSON", ":", "$", "value", "=", "$", "this", "->", "fromJson", "(", "$", "value", ",", "$", "converter", ")", ";", "break", ";", "case", "self", "::", "BASE64", ":", "$", "value", "=", "$", "this", "->", "fromBase64", "(", "$", "value", ",", "$", "converter", ")", ";", "break", ";", "case", "self", "::", "CUSTOM", ":", "if", "(", "method_exists", "(", "$", "repo", ",", "$", "converter", "[", "'decode'", "]", ")", ")", "{", "$", "value", "=", "call_user_func_array", "(", "[", "$", "repo", ",", "$", "converter", "[", "'decode'", "]", "]", ",", "[", "$", "value", ",", "$", "converter", "]", ")", ";", "}", "break", ";", "}", "$", "results", "[", "$", "i", "]", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "}" ]
Apply the decoding converter after a record is retrieved. @param \Titon\Event\Event $event @param array $results @param string $finder
[ "Apply", "the", "decoding", "converter", "after", "a", "record", "is", "retrieved", "." ]
train
https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Behavior/ConverterBehavior.php#L161-L196
nexusnetsoftgmbh/nexuscli
src/Nexus/DockerClient/Communication/Command/Compose/DockerComposeStopCommand.php
DockerComposeStopCommand.execute
protected function execute(InputInterface $input, OutputInterface $output) { $files = $input->getArgument('files'); $fileSuffix = ' -f ' . implode(' -f ', $files); $command = sprintf('%s stop -d', $fileSuffix); $response = $this->getFacade()->runDockerCompose($command); if ($output->isVerbose()) { $output->writeln($response); } }
php
protected function execute(InputInterface $input, OutputInterface $output) { $files = $input->getArgument('files'); $fileSuffix = ' -f ' . implode(' -f ', $files); $command = sprintf('%s stop -d', $fileSuffix); $response = $this->getFacade()->runDockerCompose($command); if ($output->isVerbose()) { $output->writeln($response); } }
[ "protected", "function", "execute", "(", "InputInterface", "$", "input", ",", "OutputInterface", "$", "output", ")", "{", "$", "files", "=", "$", "input", "->", "getArgument", "(", "'files'", ")", ";", "$", "fileSuffix", "=", "' -f '", ".", "implode", "(", "' -f '", ",", "$", "files", ")", ";", "$", "command", "=", "sprintf", "(", "'%s stop -d'", ",", "$", "fileSuffix", ")", ";", "$", "response", "=", "$", "this", "->", "getFacade", "(", ")", "->", "runDockerCompose", "(", "$", "command", ")", ";", "if", "(", "$", "output", "->", "isVerbose", "(", ")", ")", "{", "$", "output", "->", "writeln", "(", "$", "response", ")", ";", "}", "}" ]
@param \Symfony\Component\Console\Input\InputInterface $input @param \Symfony\Component\Console\Output\OutputInterface $output @return int|null|void
[ "@param", "\\", "Symfony", "\\", "Component", "\\", "Console", "\\", "Input", "\\", "InputInterface", "$input", "@param", "\\", "Symfony", "\\", "Component", "\\", "Console", "\\", "Output", "\\", "OutputInterface", "$output" ]
train
https://github.com/nexusnetsoftgmbh/nexuscli/blob/8416b43d31ad56ea379ae2b0bf85d456e78ba67a/src/Nexus/DockerClient/Communication/Command/Compose/DockerComposeStopCommand.php#L31-L42
arsengoian/viper-framework
src/Viper/Support/Libs/DataStream.php
DataStream.mergeData
private function mergeData($array) { $results = [ 'post' => new DataCollection(), 'file' => new DataCollection() ]; if (count($array['post']) > 0) { foreach($array['post'] as $key => $value) { foreach($value as $k => $v) { if (is_array($v)) { foreach($v as $kk => $vv) { $results['post'][$k][] = $vv; } } else { $results['post'][$k] = $v; } } } } if (count($array['file']) > 0) { foreach($array['file'] as $key => $value) { foreach($value as $k => $v) { if (is_array($v)) { foreach($v as $kk => $vv) { if(is_array($vv) && (count($vv) === 1)) { $results['file'][$k][$kk] = $vv[0]; } else { $results['file'][$k][$kk][] = $vv[0]; } } } else { $results['file'][$k][$key] = $v; } } } } return $results; }
php
private function mergeData($array) { $results = [ 'post' => new DataCollection(), 'file' => new DataCollection() ]; if (count($array['post']) > 0) { foreach($array['post'] as $key => $value) { foreach($value as $k => $v) { if (is_array($v)) { foreach($v as $kk => $vv) { $results['post'][$k][] = $vv; } } else { $results['post'][$k] = $v; } } } } if (count($array['file']) > 0) { foreach($array['file'] as $key => $value) { foreach($value as $k => $v) { if (is_array($v)) { foreach($v as $kk => $vv) { if(is_array($vv) && (count($vv) === 1)) { $results['file'][$k][$kk] = $vv[0]; } else { $results['file'][$k][$kk][] = $vv[0]; } } } else { $results['file'][$k][$key] = $v; } } } } return $results; }
[ "private", "function", "mergeData", "(", "$", "array", ")", "{", "$", "results", "=", "[", "'post'", "=>", "new", "DataCollection", "(", ")", ",", "'file'", "=>", "new", "DataCollection", "(", ")", "]", ";", "if", "(", "count", "(", "$", "array", "[", "'post'", "]", ")", ">", "0", ")", "{", "foreach", "(", "$", "array", "[", "'post'", "]", "as", "$", "key", "=>", "$", "value", ")", "{", "foreach", "(", "$", "value", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "is_array", "(", "$", "v", ")", ")", "{", "foreach", "(", "$", "v", "as", "$", "kk", "=>", "$", "vv", ")", "{", "$", "results", "[", "'post'", "]", "[", "$", "k", "]", "[", "]", "=", "$", "vv", ";", "}", "}", "else", "{", "$", "results", "[", "'post'", "]", "[", "$", "k", "]", "=", "$", "v", ";", "}", "}", "}", "}", "if", "(", "count", "(", "$", "array", "[", "'file'", "]", ")", ">", "0", ")", "{", "foreach", "(", "$", "array", "[", "'file'", "]", "as", "$", "key", "=>", "$", "value", ")", "{", "foreach", "(", "$", "value", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "is_array", "(", "$", "v", ")", ")", "{", "foreach", "(", "$", "v", "as", "$", "kk", "=>", "$", "vv", ")", "{", "if", "(", "is_array", "(", "$", "vv", ")", "&&", "(", "count", "(", "$", "vv", ")", "===", "1", ")", ")", "{", "$", "results", "[", "'file'", "]", "[", "$", "k", "]", "[", "$", "kk", "]", "=", "$", "vv", "[", "0", "]", ";", "}", "else", "{", "$", "results", "[", "'file'", "]", "[", "$", "k", "]", "[", "$", "kk", "]", "[", "]", "=", "$", "vv", "[", "0", "]", ";", "}", "}", "}", "else", "{", "$", "results", "[", "'file'", "]", "[", "$", "k", "]", "[", "$", "key", "]", "=", "$", "v", ";", "}", "}", "}", "}", "return", "$", "results", ";", "}" ]
@function mergeData @param $array array Ugly ugly ugly @returns array
[ "@function", "mergeData", "@param", "$array", "array" ]
train
https://github.com/arsengoian/viper-framework/blob/22796c5cc219cae3ca0b4af370a347ba2acab0f2/src/Viper/Support/Libs/DataStream.php#L227-L267
antonmedv/silicone
src/Silicone/Application.php
Application.getRootDir
public function getRootDir() { static $dir; if (empty($dir)) { $rc = new \ReflectionClass(get_class($this)); $dir = dirname(dirname($rc->getFileName())); } return $dir; }
php
public function getRootDir() { static $dir; if (empty($dir)) { $rc = new \ReflectionClass(get_class($this)); $dir = dirname(dirname($rc->getFileName())); } return $dir; }
[ "public", "function", "getRootDir", "(", ")", "{", "static", "$", "dir", ";", "if", "(", "empty", "(", "$", "dir", ")", ")", "{", "$", "rc", "=", "new", "\\", "ReflectionClass", "(", "get_class", "(", "$", "this", ")", ")", ";", "$", "dir", "=", "dirname", "(", "dirname", "(", "$", "rc", "->", "getFileName", "(", ")", ")", ")", ";", "}", "return", "$", "dir", ";", "}" ]
Get root directory. @return string
[ "Get", "root", "directory", "." ]
train
https://github.com/antonmedv/silicone/blob/e4a67ed41f0f419984df642b303f2a491c9a3933/src/Silicone/Application.php#L39-L47
antonmedv/silicone
src/Silicone/Application.php
Application.getCacheDir
public function getCacheDir() { static $dir; if (empty($dir)) { $dir = $this->getOpenDir() . '/cache/'; if (!is_dir($dir)) { mkdir($dir, 0755, true); } } return $dir; }
php
public function getCacheDir() { static $dir; if (empty($dir)) { $dir = $this->getOpenDir() . '/cache/'; if (!is_dir($dir)) { mkdir($dir, 0755, true); } } return $dir; }
[ "public", "function", "getCacheDir", "(", ")", "{", "static", "$", "dir", ";", "if", "(", "empty", "(", "$", "dir", ")", ")", "{", "$", "dir", "=", "$", "this", "->", "getOpenDir", "(", ")", ".", "'/cache/'", ";", "if", "(", "!", "is_dir", "(", "$", "dir", ")", ")", "{", "mkdir", "(", "$", "dir", ",", "0755", ",", "true", ")", ";", "}", "}", "return", "$", "dir", ";", "}" ]
Get cache directory. @return string
[ "Get", "cache", "directory", "." ]
train
https://github.com/antonmedv/silicone/blob/e4a67ed41f0f419984df642b303f2a491c9a3933/src/Silicone/Application.php#L66-L77
antonmedv/silicone
src/Silicone/Application.php
Application.getLogDir
public function getLogDir() { static $dir; if (empty($dir)) { $dir = $this->getOpenDir() . '/log/'; if (!is_dir($dir)) { mkdir($dir, 0755, true); } } return $dir; }
php
public function getLogDir() { static $dir; if (empty($dir)) { $dir = $this->getOpenDir() . '/log/'; if (!is_dir($dir)) { mkdir($dir, 0755, true); } } return $dir; }
[ "public", "function", "getLogDir", "(", ")", "{", "static", "$", "dir", ";", "if", "(", "empty", "(", "$", "dir", ")", ")", "{", "$", "dir", "=", "$", "this", "->", "getOpenDir", "(", ")", ".", "'/log/'", ";", "if", "(", "!", "is_dir", "(", "$", "dir", ")", ")", "{", "mkdir", "(", "$", "dir", ",", "0755", ",", "true", ")", ";", "}", "}", "return", "$", "dir", ";", "}" ]
Get log directory. @return string
[ "Get", "log", "directory", "." ]
train
https://github.com/antonmedv/silicone/blob/e4a67ed41f0f419984df642b303f2a491c9a3933/src/Silicone/Application.php#L83-L94
antonmedv/silicone
src/Silicone/Application.php
Application.formType
public function formType($type, $data = null, array $options = array()) { return $this['form.factory']->create($type, $data, $options); }
php
public function formType($type, $data = null, array $options = array()) { return $this['form.factory']->create($type, $data, $options); }
[ "public", "function", "formType", "(", "$", "type", ",", "$", "data", "=", "null", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "return", "$", "this", "[", "'form.factory'", "]", "->", "create", "(", "$", "type", ",", "$", "data", ",", "$", "options", ")", ";", "}" ]
Creates and returns a Form instance from the type of the form. @param string|FormTypeInterface $type The built type of the form @param mixed $data The initial data for the form @param array $options Options for the form @return Form
[ "Creates", "and", "returns", "a", "Form", "instance", "from", "the", "type", "of", "the", "form", "." ]
train
https://github.com/antonmedv/silicone/blob/e4a67ed41f0f419984df642b303f2a491c9a3933/src/Silicone/Application.php#L118-L121
antonmedv/silicone
src/Silicone/Application.php
Application.log
public function log($message, array $context = array(), $level = Logger::INFO) { return $this['monolog']->addRecord($level, $message, $context); }
php
public function log($message, array $context = array(), $level = Logger::INFO) { return $this['monolog']->addRecord($level, $message, $context); }
[ "public", "function", "log", "(", "$", "message", ",", "array", "$", "context", "=", "array", "(", ")", ",", "$", "level", "=", "Logger", "::", "INFO", ")", "{", "return", "$", "this", "[", "'monolog'", "]", "->", "addRecord", "(", "$", "level", ",", "$", "message", ",", "$", "context", ")", ";", "}" ]
Adds a log record. @param string $message The log message @param array $context The log context @param integer $level The logging level @return Boolean Whether the record has been processed
[ "Adds", "a", "log", "record", "." ]
train
https://github.com/antonmedv/silicone/blob/e4a67ed41f0f419984df642b303f2a491c9a3933/src/Silicone/Application.php#L132-L135
boekkooi/tactician-amqp
src/Middleware/PublishMiddleware.php
PublishMiddleware.execute
public function execute($command, callable $next) { if (!$command instanceof Message) { return $next($command); } return $this->locator ->getPublisherForMessage($command) ->publish($command); }
php
public function execute($command, callable $next) { if (!$command instanceof Message) { return $next($command); } return $this->locator ->getPublisherForMessage($command) ->publish($command); }
[ "public", "function", "execute", "(", "$", "command", ",", "callable", "$", "next", ")", "{", "if", "(", "!", "$", "command", "instanceof", "Message", ")", "{", "return", "$", "next", "(", "$", "command", ")", ";", "}", "return", "$", "this", "->", "locator", "->", "getPublisherForMessage", "(", "$", "command", ")", "->", "publish", "(", "$", "command", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/boekkooi/tactician-amqp/blob/55cbb8b9e20aab7891e6a6090b248377c599360e/src/Middleware/PublishMiddleware.php#L29-L38
prolic/Concurrent-PHP-Utils
src/ConcurrentPhpUtils/CountDownLatch.php
CountDownLatch.await
public function await($timeout = 0, TimeUnit $unit = null) { if (null !== $unit) { $timeout = $unit->toMicros($timeout); } $timeoutAt = microtime(true) + ($timeout / 1000000); while (0 != $this->count) { if ($timeout > 0 && (microtime(true) > $timeoutAt)) { return false; } time_nanosleep(0, 1); } return true; }
php
public function await($timeout = 0, TimeUnit $unit = null) { if (null !== $unit) { $timeout = $unit->toMicros($timeout); } $timeoutAt = microtime(true) + ($timeout / 1000000); while (0 != $this->count) { if ($timeout > 0 && (microtime(true) > $timeoutAt)) { return false; } time_nanosleep(0, 1); } return true; }
[ "public", "function", "await", "(", "$", "timeout", "=", "0", ",", "TimeUnit", "$", "unit", "=", "null", ")", "{", "if", "(", "null", "!==", "$", "unit", ")", "{", "$", "timeout", "=", "$", "unit", "->", "toMicros", "(", "$", "timeout", ")", ";", "}", "$", "timeoutAt", "=", "microtime", "(", "true", ")", "+", "(", "$", "timeout", "/", "1000000", ")", ";", "while", "(", "0", "!=", "$", "this", "->", "count", ")", "{", "if", "(", "$", "timeout", ">", "0", "&&", "(", "microtime", "(", "true", ")", ">", "$", "timeoutAt", ")", ")", "{", "return", "false", ";", "}", "time_nanosleep", "(", "0", ",", "1", ")", ";", "}", "return", "true", ";", "}" ]
Causes the current thread to wait until the latch has counted down to zero, unless the thread is interrupted. @param int $timeout @param TimeUnit|null $unit the timeunit of the given timeout @return bool true if the count reached zero and false if the waiting time elapsed before the count reached zero
[ "Causes", "the", "current", "thread", "to", "wait", "until", "the", "latch", "has", "counted", "down", "to", "zero", "unless", "the", "thread", "is", "interrupted", "." ]
train
https://github.com/prolic/Concurrent-PHP-Utils/blob/771b55b3ef79d9a7443c4f6d95373f41b9f34c4a/src/ConcurrentPhpUtils/CountDownLatch.php#L35-L48
transfer-framework/ezplatform
src/Transfer/EzPlatform/Repository/Values/LanguageObject.php
LanguageObject.getDefaultName
public function getDefaultName($code) { if (!array_key_exists($code, $this->defaultNameMapping)) { throw new LanguageNotFoundException(sprintf('Default language name for code "%s" not found.', $code)); } return $this->defaultNameMapping[$code]; }
php
public function getDefaultName($code) { if (!array_key_exists($code, $this->defaultNameMapping)) { throw new LanguageNotFoundException(sprintf('Default language name for code "%s" not found.', $code)); } return $this->defaultNameMapping[$code]; }
[ "public", "function", "getDefaultName", "(", "$", "code", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "code", ",", "$", "this", "->", "defaultNameMapping", ")", ")", "{", "throw", "new", "LanguageNotFoundException", "(", "sprintf", "(", "'Default language name for code \"%s\" not found.'", ",", "$", "code", ")", ")", ";", "}", "return", "$", "this", "->", "defaultNameMapping", "[", "$", "code", "]", ";", "}" ]
@param string $code @return string @throws LanguageNotFoundException
[ "@param", "string", "$code" ]
train
https://github.com/transfer-framework/ezplatform/blob/1b2d87caa1a6b79fd8fc78109c26a2d1d6359c2f/src/Transfer/EzPlatform/Repository/Values/LanguageObject.php#L122-L129
left-right/center
src/controllers/LoginController.php
LoginController.getIndex
public static function getIndex() { //show install form try { if (!DB::table(config('center.db.users'))->count()) return view('center::login.install'); } catch (\Exception $e) { if ($e->getCode() == 2002) { trigger_error('Center needs a valid database connection.'); } } return view('center::login.index'); }
php
public static function getIndex() { //show install form try { if (!DB::table(config('center.db.users'))->count()) return view('center::login.install'); } catch (\Exception $e) { if ($e->getCode() == 2002) { trigger_error('Center needs a valid database connection.'); } } return view('center::login.index'); }
[ "public", "static", "function", "getIndex", "(", ")", "{", "//show install form", "try", "{", "if", "(", "!", "DB", "::", "table", "(", "config", "(", "'center.db.users'", ")", ")", "->", "count", "(", ")", ")", "return", "view", "(", "'center::login.install'", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "if", "(", "$", "e", "->", "getCode", "(", ")", "==", "2002", ")", "{", "trigger_error", "(", "'Center needs a valid database connection.'", ")", ";", "}", "}", "return", "view", "(", "'center::login.index'", ")", ";", "}" ]
show login page if not logged in
[ "show", "login", "page", "if", "not", "logged", "in" ]
train
https://github.com/left-right/center/blob/47c225538475ca3e87fa49f31a323b6e6bd4eff2/src/controllers/LoginController.php#L16-L28
left-right/center
src/controllers/LoginController.php
LoginController.postIndex
public function postIndex(Request $request) { //regular login if (DB::table(config('center.db.users'))->count()) { //attempt auth if (Auth::attempt(['email'=>$request->input('email'), 'password'=>$request->input('password')], true)) { DB::table(config('center.db.users'))->where('id', Auth::user()->id)->update([ 'last_login'=>new DateTime ]); return redirect()->intended(action('\LeftRight\Center\Controllers\TableController@index')); } return redirect()->action('\LeftRight\Center\Controllers\TableController@index')->with('error', trans('center::site.login_invalid')); } //installing, make user $user_id = DB::table(config('center.db.users'))->insertGetId([ 'name' => $request->input('name'), 'email' => $request->input('email'), 'password' => Hash::make($request->input('password')), 'last_login' => new DateTime, 'updated_at' => new DateTime, 'updated_by' => 1, ]); Auth::loginUsingId($user_id, true); return redirect()->action('\LeftRight\Center\Controllers\TableController@index'); }
php
public function postIndex(Request $request) { //regular login if (DB::table(config('center.db.users'))->count()) { //attempt auth if (Auth::attempt(['email'=>$request->input('email'), 'password'=>$request->input('password')], true)) { DB::table(config('center.db.users'))->where('id', Auth::user()->id)->update([ 'last_login'=>new DateTime ]); return redirect()->intended(action('\LeftRight\Center\Controllers\TableController@index')); } return redirect()->action('\LeftRight\Center\Controllers\TableController@index')->with('error', trans('center::site.login_invalid')); } //installing, make user $user_id = DB::table(config('center.db.users'))->insertGetId([ 'name' => $request->input('name'), 'email' => $request->input('email'), 'password' => Hash::make($request->input('password')), 'last_login' => new DateTime, 'updated_at' => new DateTime, 'updated_by' => 1, ]); Auth::loginUsingId($user_id, true); return redirect()->action('\LeftRight\Center\Controllers\TableController@index'); }
[ "public", "function", "postIndex", "(", "Request", "$", "request", ")", "{", "//regular login", "if", "(", "DB", "::", "table", "(", "config", "(", "'center.db.users'", ")", ")", "->", "count", "(", ")", ")", "{", "//attempt auth", "if", "(", "Auth", "::", "attempt", "(", "[", "'email'", "=>", "$", "request", "->", "input", "(", "'email'", ")", ",", "'password'", "=>", "$", "request", "->", "input", "(", "'password'", ")", "]", ",", "true", ")", ")", "{", "DB", "::", "table", "(", "config", "(", "'center.db.users'", ")", ")", "->", "where", "(", "'id'", ",", "Auth", "::", "user", "(", ")", "->", "id", ")", "->", "update", "(", "[", "'last_login'", "=>", "new", "DateTime", "]", ")", ";", "return", "redirect", "(", ")", "->", "intended", "(", "action", "(", "'\\LeftRight\\Center\\Controllers\\TableController@index'", ")", ")", ";", "}", "return", "redirect", "(", ")", "->", "action", "(", "'\\LeftRight\\Center\\Controllers\\TableController@index'", ")", "->", "with", "(", "'error'", ",", "trans", "(", "'center::site.login_invalid'", ")", ")", ";", "}", "//installing, make user", "$", "user_id", "=", "DB", "::", "table", "(", "config", "(", "'center.db.users'", ")", ")", "->", "insertGetId", "(", "[", "'name'", "=>", "$", "request", "->", "input", "(", "'name'", ")", ",", "'email'", "=>", "$", "request", "->", "input", "(", "'email'", ")", ",", "'password'", "=>", "Hash", "::", "make", "(", "$", "request", "->", "input", "(", "'password'", ")", ")", ",", "'last_login'", "=>", "new", "DateTime", ",", "'updated_at'", "=>", "new", "DateTime", ",", "'updated_by'", "=>", "1", ",", "]", ")", ";", "Auth", "::", "loginUsingId", "(", "$", "user_id", ",", "true", ")", ";", "return", "redirect", "(", ")", "->", "action", "(", "'\\LeftRight\\Center\\Controllers\\TableController@index'", ")", ";", "}" ]
handle a post to the login or install form
[ "handle", "a", "post", "to", "the", "login", "or", "install", "form" ]
train
https://github.com/left-right/center/blob/47c225538475ca3e87fa49f31a323b6e6bd4eff2/src/controllers/LoginController.php#L31-L60
left-right/center
src/controllers/LoginController.php
LoginController.postReset
public function postReset(Request $request) { //get user if (!$user = DB::table(config('center.db.users'))->whereNull('deleted_at')->where('email', $request->input('email'))->first()) { return redirect()->action('\LeftRight\Center\Controllers\LoginController@getReset')->with([ 'error'=>trans('center::site.password_reset_error') ]); } //set new token every time $token = Str::random(); DB::table(config('center.db.users'))->where('id', $user->id)->update(['token'=>$token]); //reset link $link = URL::action('\LeftRight\Center\Controllers\LoginController@getChange', ['token'=>$token, 'email'=>$user->email]); //send reminder email Mail::send('center::emails.password', ['link'=>$link], function($message) use ($user) { $message->to($user->email)->subject(trans('center::site.password_reset')); }); return redirect()->action('\LeftRight\Center\Controllers\LoginController@getReset')->with(['message'=>trans('center::site.password_reset_sent')]); }
php
public function postReset(Request $request) { //get user if (!$user = DB::table(config('center.db.users'))->whereNull('deleted_at')->where('email', $request->input('email'))->first()) { return redirect()->action('\LeftRight\Center\Controllers\LoginController@getReset')->with([ 'error'=>trans('center::site.password_reset_error') ]); } //set new token every time $token = Str::random(); DB::table(config('center.db.users'))->where('id', $user->id)->update(['token'=>$token]); //reset link $link = URL::action('\LeftRight\Center\Controllers\LoginController@getChange', ['token'=>$token, 'email'=>$user->email]); //send reminder email Mail::send('center::emails.password', ['link'=>$link], function($message) use ($user) { $message->to($user->email)->subject(trans('center::site.password_reset')); }); return redirect()->action('\LeftRight\Center\Controllers\LoginController@getReset')->with(['message'=>trans('center::site.password_reset_sent')]); }
[ "public", "function", "postReset", "(", "Request", "$", "request", ")", "{", "//get user", "if", "(", "!", "$", "user", "=", "DB", "::", "table", "(", "config", "(", "'center.db.users'", ")", ")", "->", "whereNull", "(", "'deleted_at'", ")", "->", "where", "(", "'email'", ",", "$", "request", "->", "input", "(", "'email'", ")", ")", "->", "first", "(", ")", ")", "{", "return", "redirect", "(", ")", "->", "action", "(", "'\\LeftRight\\Center\\Controllers\\LoginController@getReset'", ")", "->", "with", "(", "[", "'error'", "=>", "trans", "(", "'center::site.password_reset_error'", ")", "]", ")", ";", "}", "//set new token every time", "$", "token", "=", "Str", "::", "random", "(", ")", ";", "DB", "::", "table", "(", "config", "(", "'center.db.users'", ")", ")", "->", "where", "(", "'id'", ",", "$", "user", "->", "id", ")", "->", "update", "(", "[", "'token'", "=>", "$", "token", "]", ")", ";", "//reset link", "$", "link", "=", "URL", "::", "action", "(", "'\\LeftRight\\Center\\Controllers\\LoginController@getChange'", ",", "[", "'token'", "=>", "$", "token", ",", "'email'", "=>", "$", "user", "->", "email", "]", ")", ";", "//send reminder email", "Mail", "::", "send", "(", "'center::emails.password'", ",", "[", "'link'", "=>", "$", "link", "]", ",", "function", "(", "$", "message", ")", "use", "(", "$", "user", ")", "{", "$", "message", "->", "to", "(", "$", "user", "->", "email", ")", "->", "subject", "(", "trans", "(", "'center::site.password_reset'", ")", ")", ";", "}", ")", ";", "return", "redirect", "(", ")", "->", "action", "(", "'\\LeftRight\\Center\\Controllers\\LoginController@getReset'", ")", "->", "with", "(", "[", "'message'", "=>", "trans", "(", "'center::site.password_reset_sent'", ")", "]", ")", ";", "}" ]
send reset email
[ "send", "reset", "email" ]
train
https://github.com/left-right/center/blob/47c225538475ca3e87fa49f31a323b6e6bd4eff2/src/controllers/LoginController.php#L74-L97
left-right/center
src/controllers/LoginController.php
LoginController.getChange
public function getChange($email, $token) { //todo check email / token combo if (!$user = DB::table(config('center.db.users'))->whereNull('deleted_at')->where('email', $email)->where('token', $token)->first()) { return redirect()->action('\LeftRight\Center\Controllers\LoginController@getReset')->with([ 'error'=>trans('center::site.password_change_error') ]); } return view('center::login.change', [ 'email'=>$email, 'token'=>$token, ]); }
php
public function getChange($email, $token) { //todo check email / token combo if (!$user = DB::table(config('center.db.users'))->whereNull('deleted_at')->where('email', $email)->where('token', $token)->first()) { return redirect()->action('\LeftRight\Center\Controllers\LoginController@getReset')->with([ 'error'=>trans('center::site.password_change_error') ]); } return view('center::login.change', [ 'email'=>$email, 'token'=>$token, ]); }
[ "public", "function", "getChange", "(", "$", "email", ",", "$", "token", ")", "{", "//todo check email / token combo", "if", "(", "!", "$", "user", "=", "DB", "::", "table", "(", "config", "(", "'center.db.users'", ")", ")", "->", "whereNull", "(", "'deleted_at'", ")", "->", "where", "(", "'email'", ",", "$", "email", ")", "->", "where", "(", "'token'", ",", "$", "token", ")", "->", "first", "(", ")", ")", "{", "return", "redirect", "(", ")", "->", "action", "(", "'\\LeftRight\\Center\\Controllers\\LoginController@getReset'", ")", "->", "with", "(", "[", "'error'", "=>", "trans", "(", "'center::site.password_change_error'", ")", "]", ")", ";", "}", "return", "view", "(", "'center::login.change'", ",", "[", "'email'", "=>", "$", "email", ",", "'token'", "=>", "$", "token", ",", "]", ")", ";", "}" ]
reset password form
[ "reset", "password", "form" ]
train
https://github.com/left-right/center/blob/47c225538475ca3e87fa49f31a323b6e6bd4eff2/src/controllers/LoginController.php#L100-L112
left-right/center
src/controllers/LoginController.php
LoginController.postChange
public function postChange(Request $request) { if (!$user = DB::table(config('center.db.users'))->whereNull('deleted_at')->where('email', $request->input('email'))->where('token', $request->input('token'))->first()) { return redirect()->action('\LeftRight\Center\Controllers\LoginController@getReset')->with([ 'error'=>trans('center::site.password_change_error') ]); } //successfully used reset token, time for it to die DB::table(config('center.db.users'))->where('id', $user->id)->update([ 'token'=>null, 'password'=>Hash::make($request->input('password')), 'last_login'=>new DateTime, ]); //log you in Auth::loginUsingId($user->id, true); return redirect()->action('\LeftRight\Center\Controllers\TableController@index')->with('message', trans('center::site.password_change_success')); }
php
public function postChange(Request $request) { if (!$user = DB::table(config('center.db.users'))->whereNull('deleted_at')->where('email', $request->input('email'))->where('token', $request->input('token'))->first()) { return redirect()->action('\LeftRight\Center\Controllers\LoginController@getReset')->with([ 'error'=>trans('center::site.password_change_error') ]); } //successfully used reset token, time for it to die DB::table(config('center.db.users'))->where('id', $user->id)->update([ 'token'=>null, 'password'=>Hash::make($request->input('password')), 'last_login'=>new DateTime, ]); //log you in Auth::loginUsingId($user->id, true); return redirect()->action('\LeftRight\Center\Controllers\TableController@index')->with('message', trans('center::site.password_change_success')); }
[ "public", "function", "postChange", "(", "Request", "$", "request", ")", "{", "if", "(", "!", "$", "user", "=", "DB", "::", "table", "(", "config", "(", "'center.db.users'", ")", ")", "->", "whereNull", "(", "'deleted_at'", ")", "->", "where", "(", "'email'", ",", "$", "request", "->", "input", "(", "'email'", ")", ")", "->", "where", "(", "'token'", ",", "$", "request", "->", "input", "(", "'token'", ")", ")", "->", "first", "(", ")", ")", "{", "return", "redirect", "(", ")", "->", "action", "(", "'\\LeftRight\\Center\\Controllers\\LoginController@getReset'", ")", "->", "with", "(", "[", "'error'", "=>", "trans", "(", "'center::site.password_change_error'", ")", "]", ")", ";", "}", "//successfully used reset token, time for it to die", "DB", "::", "table", "(", "config", "(", "'center.db.users'", ")", ")", "->", "where", "(", "'id'", ",", "$", "user", "->", "id", ")", "->", "update", "(", "[", "'token'", "=>", "null", ",", "'password'", "=>", "Hash", "::", "make", "(", "$", "request", "->", "input", "(", "'password'", ")", ")", ",", "'last_login'", "=>", "new", "DateTime", ",", "]", ")", ";", "//log you in", "Auth", "::", "loginUsingId", "(", "$", "user", "->", "id", ",", "true", ")", ";", "return", "redirect", "(", ")", "->", "action", "(", "'\\LeftRight\\Center\\Controllers\\TableController@index'", ")", "->", "with", "(", "'message'", ",", "trans", "(", "'center::site.password_change_success'", ")", ")", ";", "}" ]
send reset email
[ "send", "reset", "email" ]
train
https://github.com/left-right/center/blob/47c225538475ca3e87fa49f31a323b6e6bd4eff2/src/controllers/LoginController.php#L115-L132
goten4/GtnDataTables
src/GtnDataTables/Service/DataTableAbstractFactory.php
DataTableAbstractFactory.createServiceWithName
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) { $config = $this->getConfig($serviceLocator); $config = $config[$requestedName]; if (!isset($config['collectorFactory'])) { throw new MissingConfigurationException('Unable to create DataTable service: collectorFactory is missing'); } if (!isset($config['columns']) || empty($config['columns'])) { throw new MissingConfigurationException('Unable to create DataTable service: columns are missing'); } /** @var FactoryInterface $collectorFactory */ $collectorFactory = new $config['collectorFactory']; $datatable = new DataTable(isset($config['id']) ? $config['id'] : $requestedName); $datatable->setCollector($collectorFactory->createService($serviceLocator)); $columns = array(); foreach ($config['columns'] as $columnConfig) { $columns[] = Column::factory($serviceLocator, $columnConfig); } $datatable->setColumns($columns); if (isset($config['classes'])) { $datatable->setClasses($config['classes']); } return $datatable; }
php
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) { $config = $this->getConfig($serviceLocator); $config = $config[$requestedName]; if (!isset($config['collectorFactory'])) { throw new MissingConfigurationException('Unable to create DataTable service: collectorFactory is missing'); } if (!isset($config['columns']) || empty($config['columns'])) { throw new MissingConfigurationException('Unable to create DataTable service: columns are missing'); } /** @var FactoryInterface $collectorFactory */ $collectorFactory = new $config['collectorFactory']; $datatable = new DataTable(isset($config['id']) ? $config['id'] : $requestedName); $datatable->setCollector($collectorFactory->createService($serviceLocator)); $columns = array(); foreach ($config['columns'] as $columnConfig) { $columns[] = Column::factory($serviceLocator, $columnConfig); } $datatable->setColumns($columns); if (isset($config['classes'])) { $datatable->setClasses($config['classes']); } return $datatable; }
[ "public", "function", "createServiceWithName", "(", "ServiceLocatorInterface", "$", "serviceLocator", ",", "$", "name", ",", "$", "requestedName", ")", "{", "$", "config", "=", "$", "this", "->", "getConfig", "(", "$", "serviceLocator", ")", ";", "$", "config", "=", "$", "config", "[", "$", "requestedName", "]", ";", "if", "(", "!", "isset", "(", "$", "config", "[", "'collectorFactory'", "]", ")", ")", "{", "throw", "new", "MissingConfigurationException", "(", "'Unable to create DataTable service: collectorFactory is missing'", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "config", "[", "'columns'", "]", ")", "||", "empty", "(", "$", "config", "[", "'columns'", "]", ")", ")", "{", "throw", "new", "MissingConfigurationException", "(", "'Unable to create DataTable service: columns are missing'", ")", ";", "}", "/** @var FactoryInterface $collectorFactory */", "$", "collectorFactory", "=", "new", "$", "config", "[", "'collectorFactory'", "]", ";", "$", "datatable", "=", "new", "DataTable", "(", "isset", "(", "$", "config", "[", "'id'", "]", ")", "?", "$", "config", "[", "'id'", "]", ":", "$", "requestedName", ")", ";", "$", "datatable", "->", "setCollector", "(", "$", "collectorFactory", "->", "createService", "(", "$", "serviceLocator", ")", ")", ";", "$", "columns", "=", "array", "(", ")", ";", "foreach", "(", "$", "config", "[", "'columns'", "]", "as", "$", "columnConfig", ")", "{", "$", "columns", "[", "]", "=", "Column", "::", "factory", "(", "$", "serviceLocator", ",", "$", "columnConfig", ")", ";", "}", "$", "datatable", "->", "setColumns", "(", "$", "columns", ")", ";", "if", "(", "isset", "(", "$", "config", "[", "'classes'", "]", ")", ")", "{", "$", "datatable", "->", "setClasses", "(", "$", "config", "[", "'classes'", "]", ")", ";", "}", "return", "$", "datatable", ";", "}" ]
Create service with name @param ServiceLocatorInterface $serviceLocator @param $name @param $requestedName @return mixed @throws MissingConfigurationException
[ "Create", "service", "with", "name" ]
train
https://github.com/goten4/GtnDataTables/blob/59748ecf5a59492481789e2936a0c55b9df5da5e/src/GtnDataTables/Service/DataTableAbstractFactory.php#L51-L79
redaigbaria/oauth2
examples/relational/Storage/ClientStorage.php
ClientStorage.get
public function get($clientId, $clientSecret = null, $redirectUri = null, $grantType = null) { $query = Capsule::table('oauth_clients') ->select('oauth_clients.*') ->where('oauth_clients.id', $clientId); if ($clientSecret !== null) { $query->where('oauth_clients.secret', $clientSecret); } if ($redirectUri) { $query->join('oauth_client_redirect_uris', 'oauth_clients.id', '=', 'oauth_client_redirect_uris.client_id') ->select(['oauth_clients.*', 'oauth_client_redirect_uris.*']) ->where('oauth_client_redirect_uris.redirect_uri', $redirectUri); } $result = $query->get(); if (count($result) === 1) { $client = new ClientEntity($this->server); $client->hydrate([ 'id' => $result[0]['id'], 'name' => $result[0]['name'], ]); return $client; } return; }
php
public function get($clientId, $clientSecret = null, $redirectUri = null, $grantType = null) { $query = Capsule::table('oauth_clients') ->select('oauth_clients.*') ->where('oauth_clients.id', $clientId); if ($clientSecret !== null) { $query->where('oauth_clients.secret', $clientSecret); } if ($redirectUri) { $query->join('oauth_client_redirect_uris', 'oauth_clients.id', '=', 'oauth_client_redirect_uris.client_id') ->select(['oauth_clients.*', 'oauth_client_redirect_uris.*']) ->where('oauth_client_redirect_uris.redirect_uri', $redirectUri); } $result = $query->get(); if (count($result) === 1) { $client = new ClientEntity($this->server); $client->hydrate([ 'id' => $result[0]['id'], 'name' => $result[0]['name'], ]); return $client; } return; }
[ "public", "function", "get", "(", "$", "clientId", ",", "$", "clientSecret", "=", "null", ",", "$", "redirectUri", "=", "null", ",", "$", "grantType", "=", "null", ")", "{", "$", "query", "=", "Capsule", "::", "table", "(", "'oauth_clients'", ")", "->", "select", "(", "'oauth_clients.*'", ")", "->", "where", "(", "'oauth_clients.id'", ",", "$", "clientId", ")", ";", "if", "(", "$", "clientSecret", "!==", "null", ")", "{", "$", "query", "->", "where", "(", "'oauth_clients.secret'", ",", "$", "clientSecret", ")", ";", "}", "if", "(", "$", "redirectUri", ")", "{", "$", "query", "->", "join", "(", "'oauth_client_redirect_uris'", ",", "'oauth_clients.id'", ",", "'='", ",", "'oauth_client_redirect_uris.client_id'", ")", "->", "select", "(", "[", "'oauth_clients.*'", ",", "'oauth_client_redirect_uris.*'", "]", ")", "->", "where", "(", "'oauth_client_redirect_uris.redirect_uri'", ",", "$", "redirectUri", ")", ";", "}", "$", "result", "=", "$", "query", "->", "get", "(", ")", ";", "if", "(", "count", "(", "$", "result", ")", "===", "1", ")", "{", "$", "client", "=", "new", "ClientEntity", "(", "$", "this", "->", "server", ")", ";", "$", "client", "->", "hydrate", "(", "[", "'id'", "=>", "$", "result", "[", "0", "]", "[", "'id'", "]", ",", "'name'", "=>", "$", "result", "[", "0", "]", "[", "'name'", "]", ",", "]", ")", ";", "return", "$", "client", ";", "}", "return", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/redaigbaria/oauth2/blob/54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a/examples/relational/Storage/ClientStorage.php#L16-L45
redaigbaria/oauth2
examples/relational/Storage/ClientStorage.php
ClientStorage.getBySession
public function getBySession(SessionEntity $session) { $result = Capsule::table('oauth_clients') ->select(['oauth_clients.id', 'oauth_clients.name']) ->join('oauth_sessions', 'oauth_clients.id', '=', 'oauth_sessions.client_id') ->where('oauth_sessions.id', $session->getId()) ->get(); if (count($result) === 1) { $client = new ClientEntity($this->server); $client->hydrate([ 'id' => $result[0]['id'], 'name' => $result[0]['name'], ]); return $client; } return; }
php
public function getBySession(SessionEntity $session) { $result = Capsule::table('oauth_clients') ->select(['oauth_clients.id', 'oauth_clients.name']) ->join('oauth_sessions', 'oauth_clients.id', '=', 'oauth_sessions.client_id') ->where('oauth_sessions.id', $session->getId()) ->get(); if (count($result) === 1) { $client = new ClientEntity($this->server); $client->hydrate([ 'id' => $result[0]['id'], 'name' => $result[0]['name'], ]); return $client; } return; }
[ "public", "function", "getBySession", "(", "SessionEntity", "$", "session", ")", "{", "$", "result", "=", "Capsule", "::", "table", "(", "'oauth_clients'", ")", "->", "select", "(", "[", "'oauth_clients.id'", ",", "'oauth_clients.name'", "]", ")", "->", "join", "(", "'oauth_sessions'", ",", "'oauth_clients.id'", ",", "'='", ",", "'oauth_sessions.client_id'", ")", "->", "where", "(", "'oauth_sessions.id'", ",", "$", "session", "->", "getId", "(", ")", ")", "->", "get", "(", ")", ";", "if", "(", "count", "(", "$", "result", ")", "===", "1", ")", "{", "$", "client", "=", "new", "ClientEntity", "(", "$", "this", "->", "server", ")", ";", "$", "client", "->", "hydrate", "(", "[", "'id'", "=>", "$", "result", "[", "0", "]", "[", "'id'", "]", ",", "'name'", "=>", "$", "result", "[", "0", "]", "[", "'name'", "]", ",", "]", ")", ";", "return", "$", "client", ";", "}", "return", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/redaigbaria/oauth2/blob/54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a/examples/relational/Storage/ClientStorage.php#L50-L69
shrink0r/workflux
src/State/StateMap.php
StateMap.put
public function put(StateInterface $state): self { $cloned_map = clone $this; $cloned_map->internal_map->put($state->getName(), $state); return $cloned_map; }
php
public function put(StateInterface $state): self { $cloned_map = clone $this; $cloned_map->internal_map->put($state->getName(), $state); return $cloned_map; }
[ "public", "function", "put", "(", "StateInterface", "$", "state", ")", ":", "self", "{", "$", "cloned_map", "=", "clone", "$", "this", ";", "$", "cloned_map", "->", "internal_map", "->", "put", "(", "$", "state", "->", "getName", "(", ")", ",", "$", "state", ")", ";", "return", "$", "cloned_map", ";", "}" ]
@param StateInterface @return self
[ "@param", "StateInterface" ]
train
https://github.com/shrink0r/workflux/blob/008f45c64f52b1f795ab7f6ddbfc1a55580254d9/src/State/StateMap.php#L37-L42
shrink0r/workflux
src/State/StateMap.php
StateMap.find
public function find(Closure $query): self { $states = []; foreach ($this->internal_map as $state) { if (true === $query($state)) { $states[] = $state; } } return new self($states); }
php
public function find(Closure $query): self { $states = []; foreach ($this->internal_map as $state) { if (true === $query($state)) { $states[] = $state; } } return new self($states); }
[ "public", "function", "find", "(", "Closure", "$", "query", ")", ":", "self", "{", "$", "states", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "internal_map", "as", "$", "state", ")", "{", "if", "(", "true", "===", "$", "query", "(", "$", "state", ")", ")", "{", "$", "states", "[", "]", "=", "$", "state", ";", "}", "}", "return", "new", "self", "(", "$", "states", ")", ";", "}" ]
@param Closure $query @return self
[ "@param", "Closure", "$query" ]
train
https://github.com/shrink0r/workflux/blob/008f45c64f52b1f795ab7f6ddbfc1a55580254d9/src/State/StateMap.php#L49-L58
shrink0r/workflux
src/State/StateMap.php
StateMap.findOne
public function findOne(Closure $query) { foreach ($this->internal_map as $state) { if (true === $query($state)) { return $state; } } return null; }
php
public function findOne(Closure $query) { foreach ($this->internal_map as $state) { if (true === $query($state)) { return $state; } } return null; }
[ "public", "function", "findOne", "(", "Closure", "$", "query", ")", "{", "foreach", "(", "$", "this", "->", "internal_map", "as", "$", "state", ")", "{", "if", "(", "true", "===", "$", "query", "(", "$", "state", ")", ")", "{", "return", "$", "state", ";", "}", "}", "return", "null", ";", "}" ]
@param Closure $query @return StateInterface|null
[ "@param", "Closure", "$query" ]
train
https://github.com/shrink0r/workflux/blob/008f45c64f52b1f795ab7f6ddbfc1a55580254d9/src/State/StateMap.php#L65-L73
qcubed/orm
src/Codegen/DatabaseCodeGen.php
DatabaseCodeGen.validateTableColumn
public function validateTableColumn($strTableName, $strColumnName) { $strTableName = trim(strtolower($strTableName)); $strColumnName = trim(strtolower($strColumnName)); if (array_key_exists($strTableName, $this->objTableArray)) { $strTableName = $this->objTableArray[$strTableName]->Name; } else { if (array_key_exists($strTableName, $this->objTypeTableArray)) { $strTableName = $this->objTypeTableArray[$strTableName]->Name; } else { if (array_key_exists($strTableName, $this->strAssociationTableNameArray)) { $strTableName = $this->strAssociationTableNameArray[$strTableName]; } else { return false; } } } $objFieldArray = $this->objDb->getFieldsForTable($strTableName); foreach ($objFieldArray as $objField) { if (trim(strtolower($objField->Name)) == $strColumnName) { return true; } } return false; }
php
public function validateTableColumn($strTableName, $strColumnName) { $strTableName = trim(strtolower($strTableName)); $strColumnName = trim(strtolower($strColumnName)); if (array_key_exists($strTableName, $this->objTableArray)) { $strTableName = $this->objTableArray[$strTableName]->Name; } else { if (array_key_exists($strTableName, $this->objTypeTableArray)) { $strTableName = $this->objTypeTableArray[$strTableName]->Name; } else { if (array_key_exists($strTableName, $this->strAssociationTableNameArray)) { $strTableName = $this->strAssociationTableNameArray[$strTableName]; } else { return false; } } } $objFieldArray = $this->objDb->getFieldsForTable($strTableName); foreach ($objFieldArray as $objField) { if (trim(strtolower($objField->Name)) == $strColumnName) { return true; } } return false; }
[ "public", "function", "validateTableColumn", "(", "$", "strTableName", ",", "$", "strColumnName", ")", "{", "$", "strTableName", "=", "trim", "(", "strtolower", "(", "$", "strTableName", ")", ")", ";", "$", "strColumnName", "=", "trim", "(", "strtolower", "(", "$", "strColumnName", ")", ")", ";", "if", "(", "array_key_exists", "(", "$", "strTableName", ",", "$", "this", "->", "objTableArray", ")", ")", "{", "$", "strTableName", "=", "$", "this", "->", "objTableArray", "[", "$", "strTableName", "]", "->", "Name", ";", "}", "else", "{", "if", "(", "array_key_exists", "(", "$", "strTableName", ",", "$", "this", "->", "objTypeTableArray", ")", ")", "{", "$", "strTableName", "=", "$", "this", "->", "objTypeTableArray", "[", "$", "strTableName", "]", "->", "Name", ";", "}", "else", "{", "if", "(", "array_key_exists", "(", "$", "strTableName", ",", "$", "this", "->", "strAssociationTableNameArray", ")", ")", "{", "$", "strTableName", "=", "$", "this", "->", "strAssociationTableNameArray", "[", "$", "strTableName", "]", ";", "}", "else", "{", "return", "false", ";", "}", "}", "}", "$", "objFieldArray", "=", "$", "this", "->", "objDb", "->", "getFieldsForTable", "(", "$", "strTableName", ")", ";", "foreach", "(", "$", "objFieldArray", "as", "$", "objField", ")", "{", "if", "(", "trim", "(", "strtolower", "(", "$", "objField", "->", "Name", ")", ")", "==", "$", "strColumnName", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Given a CASE INSENSITIVE table and column name, it will return TRUE if the Table/Column exists ANYWHERE in the already analyzed database @param string $strTableName @param string $strColumnName @return boolean true if it is found/validated
[ "Given", "a", "CASE", "INSENSITIVE", "table", "and", "column", "name", "it", "will", "return", "TRUE", "if", "the", "Table", "/", "Column", "exists", "ANYWHERE", "in", "the", "already", "analyzed", "database" ]
train
https://github.com/qcubed/orm/blob/f320eba671f20874b1f3809c5293f8c02d5b1204/src/Codegen/DatabaseCodeGen.php#L125-L153
qcubed/orm
src/Codegen/DatabaseCodeGen.php
DatabaseCodeGen.getForeignKeysFromRelationshipsScript
protected function getForeignKeysFromRelationshipsScript($strTableName, $objForeignKeyArray) { foreach ($this->strRelationshipLinesQcubed as $strLine) { if ($strLine) { $objForeignKey = $this->getForeignKeyForQcubedRelationshipDefinition($strTableName, $strLine); if ($objForeignKey) { array_push($objForeignKeyArray, $objForeignKey); $this->strRelationshipLinesQcubed[$strLine] = null; } } } foreach ($this->strRelationshipLinesSql as $strLine) { if ($strLine) { $objForeignKey = $this->getForeignKeyForSqlRelationshipDefinition($strTableName, $strLine); if ($objForeignKey) { array_push($objForeignKeyArray, $objForeignKey); $this->strRelationshipLinesSql[$strLine] = null; } } } return $objForeignKeyArray; }
php
protected function getForeignKeysFromRelationshipsScript($strTableName, $objForeignKeyArray) { foreach ($this->strRelationshipLinesQcubed as $strLine) { if ($strLine) { $objForeignKey = $this->getForeignKeyForQcubedRelationshipDefinition($strTableName, $strLine); if ($objForeignKey) { array_push($objForeignKeyArray, $objForeignKey); $this->strRelationshipLinesQcubed[$strLine] = null; } } } foreach ($this->strRelationshipLinesSql as $strLine) { if ($strLine) { $objForeignKey = $this->getForeignKeyForSqlRelationshipDefinition($strTableName, $strLine); if ($objForeignKey) { array_push($objForeignKeyArray, $objForeignKey); $this->strRelationshipLinesSql[$strLine] = null; } } } return $objForeignKeyArray; }
[ "protected", "function", "getForeignKeysFromRelationshipsScript", "(", "$", "strTableName", ",", "$", "objForeignKeyArray", ")", "{", "foreach", "(", "$", "this", "->", "strRelationshipLinesQcubed", "as", "$", "strLine", ")", "{", "if", "(", "$", "strLine", ")", "{", "$", "objForeignKey", "=", "$", "this", "->", "getForeignKeyForQcubedRelationshipDefinition", "(", "$", "strTableName", ",", "$", "strLine", ")", ";", "if", "(", "$", "objForeignKey", ")", "{", "array_push", "(", "$", "objForeignKeyArray", ",", "$", "objForeignKey", ")", ";", "$", "this", "->", "strRelationshipLinesQcubed", "[", "$", "strLine", "]", "=", "null", ";", "}", "}", "}", "foreach", "(", "$", "this", "->", "strRelationshipLinesSql", "as", "$", "strLine", ")", "{", "if", "(", "$", "strLine", ")", "{", "$", "objForeignKey", "=", "$", "this", "->", "getForeignKeyForSqlRelationshipDefinition", "(", "$", "strTableName", ",", "$", "strLine", ")", ";", "if", "(", "$", "objForeignKey", ")", "{", "array_push", "(", "$", "objForeignKeyArray", ",", "$", "objForeignKey", ")", ";", "$", "this", "->", "strRelationshipLinesSql", "[", "$", "strLine", "]", "=", "null", ";", "}", "}", "}", "return", "$", "objForeignKeyArray", ";", "}" ]
This will go through the various Relationships Script lines (if applicable) as setup during the __constructor() through the <relationships> and <relationshipsScript> tags in the configuration settings. If no Relationships are defined, this method will simply exit making no changes. @param string $strTableName Name of the table to pull foreign keys for @param Database\ForeignKey[] Array of currently found DB FK objects which will be appended to @return Database\ForeignKey[] Array of DB FK objects that were parsed out
[ "This", "will", "go", "through", "the", "various", "Relationships", "Script", "lines", "(", "if", "applicable", ")", "as", "setup", "during", "the", "__constructor", "()", "through", "the", "<relationships", ">", "and", "<relationshipsScript", ">", "tags", "in", "the", "configuration", "settings", "." ]
train
https://github.com/qcubed/orm/blob/f320eba671f20874b1f3809c5293f8c02d5b1204/src/Codegen/DatabaseCodeGen.php#L1500-L1525
qcubed/orm
src/Codegen/DatabaseCodeGen.php
DatabaseCodeGen.getCastString
public function getCastString(SqlColumn $objColumn) { switch ($objColumn->DbType) { case Database\FieldType::BIT: return ('$mixVal = (bool)$mixVal;'); case Database\FieldType::BLOB: case Database\FieldType::CHAR: case Database\FieldType::VAR_CHAR: case Database\FieldType::JSON: return ''; // no need to cast, since its already a string or a null case Database\FieldType::DATE: return ('$mixVal = new \QCubed\QDateTime($mixVal, null, \QCubed\QDateTime::DATE_ONLY_TYPE);'); case Database\FieldType::DATE_TIME: return ('$mixVal = new \QCubed\QDateTime($mixVal);'); case Database\FieldType::TIME: return ('$mixVal = new \QCubed\QDateTime($mixVal, null, \QCubed\QDateTime::TIME_ONLY_TYPE);'); case Database\FieldType::FLOAT: case Database\FieldType::INTEGER: return ('$mixVal = (' . $objColumn->VariableType . ')$mixVal;'); default: throw new \Exception ('Invalid database field type'); } }
php
public function getCastString(SqlColumn $objColumn) { switch ($objColumn->DbType) { case Database\FieldType::BIT: return ('$mixVal = (bool)$mixVal;'); case Database\FieldType::BLOB: case Database\FieldType::CHAR: case Database\FieldType::VAR_CHAR: case Database\FieldType::JSON: return ''; // no need to cast, since its already a string or a null case Database\FieldType::DATE: return ('$mixVal = new \QCubed\QDateTime($mixVal, null, \QCubed\QDateTime::DATE_ONLY_TYPE);'); case Database\FieldType::DATE_TIME: return ('$mixVal = new \QCubed\QDateTime($mixVal);'); case Database\FieldType::TIME: return ('$mixVal = new \QCubed\QDateTime($mixVal, null, \QCubed\QDateTime::TIME_ONLY_TYPE);'); case Database\FieldType::FLOAT: case Database\FieldType::INTEGER: return ('$mixVal = (' . $objColumn->VariableType . ')$mixVal;'); default: throw new \Exception ('Invalid database field type'); } }
[ "public", "function", "getCastString", "(", "SqlColumn", "$", "objColumn", ")", "{", "switch", "(", "$", "objColumn", "->", "DbType", ")", "{", "case", "Database", "\\", "FieldType", "::", "BIT", ":", "return", "(", "'$mixVal = (bool)$mixVal;'", ")", ";", "case", "Database", "\\", "FieldType", "::", "BLOB", ":", "case", "Database", "\\", "FieldType", "::", "CHAR", ":", "case", "Database", "\\", "FieldType", "::", "VAR_CHAR", ":", "case", "Database", "\\", "FieldType", "::", "JSON", ":", "return", "''", ";", "// no need to cast, since its already a string or a null", "case", "Database", "\\", "FieldType", "::", "DATE", ":", "return", "(", "'$mixVal = new \\QCubed\\QDateTime($mixVal, null, \\QCubed\\QDateTime::DATE_ONLY_TYPE);'", ")", ";", "case", "Database", "\\", "FieldType", "::", "DATE_TIME", ":", "return", "(", "'$mixVal = new \\QCubed\\QDateTime($mixVal);'", ")", ";", "case", "Database", "\\", "FieldType", "::", "TIME", ":", "return", "(", "'$mixVal = new \\QCubed\\QDateTime($mixVal, null, \\QCubed\\QDateTime::TIME_ONLY_TYPE);'", ")", ";", "case", "Database", "\\", "FieldType", "::", "FLOAT", ":", "case", "Database", "\\", "FieldType", "::", "INTEGER", ":", "return", "(", "'$mixVal = ('", ".", "$", "objColumn", "->", "VariableType", ".", "')$mixVal;'", ")", ";", "default", ":", "throw", "new", "\\", "Exception", "(", "'Invalid database field type'", ")", ";", "}", "}" ]
Returns a string that will cast a variable coming from the database into a php type. Doing this in the template saves significant amounts of time over using Type::cast() or GetColumn. @param SqlColumn $objColumn @return string @throws \Exception
[ "Returns", "a", "string", "that", "will", "cast", "a", "variable", "coming", "from", "the", "database", "into", "a", "php", "type", ".", "Doing", "this", "in", "the", "template", "saves", "significant", "amounts", "of", "time", "over", "using", "Type", "::", "cast", "()", "or", "GetColumn", "." ]
train
https://github.com/qcubed/orm/blob/f320eba671f20874b1f3809c5293f8c02d5b1204/src/Codegen/DatabaseCodeGen.php#L1552-L1580
lmammino/e-foundation
src/Address/Model/Zone.php
Zone.setMembers
public function setMembers(Collection $members) { foreach ($members as $member) { $this->addMember($member); } return $this; }
php
public function setMembers(Collection $members) { foreach ($members as $member) { $this->addMember($member); } return $this; }
[ "public", "function", "setMembers", "(", "Collection", "$", "members", ")", "{", "foreach", "(", "$", "members", "as", "$", "member", ")", "{", "$", "this", "->", "addMember", "(", "$", "member", ")", ";", "}", "return", "$", "this", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/lmammino/e-foundation/blob/198b7047d93eb11c9bc0c7ddf0bfa8229d42807a/src/Address/Model/Zone.php#L88-L95
lmammino/e-foundation
src/Address/Model/Zone.php
Zone.addMember
public function addMember(ZoneMemberInterface $member) { if (!$this->members->contains($member)) { $member->setParentZone($this); $this->members->add($member); } return $this; }
php
public function addMember(ZoneMemberInterface $member) { if (!$this->members->contains($member)) { $member->setParentZone($this); $this->members->add($member); } return $this; }
[ "public", "function", "addMember", "(", "ZoneMemberInterface", "$", "member", ")", "{", "if", "(", "!", "$", "this", "->", "members", "->", "contains", "(", "$", "member", ")", ")", "{", "$", "member", "->", "setParentZone", "(", "$", "this", ")", ";", "$", "this", "->", "members", "->", "add", "(", "$", "member", ")", ";", "}", "return", "$", "this", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/lmammino/e-foundation/blob/198b7047d93eb11c9bc0c7ddf0bfa8229d42807a/src/Address/Model/Zone.php#L100-L108
lmammino/e-foundation
src/Address/Model/Zone.php
Zone.removeMember
public function removeMember(ZoneMemberInterface $member) { if ($this->members->contains($member)) { $member->setParentZone(null); $this->members->removeElement($member); } return $this; }
php
public function removeMember(ZoneMemberInterface $member) { if ($this->members->contains($member)) { $member->setParentZone(null); $this->members->removeElement($member); } return $this; }
[ "public", "function", "removeMember", "(", "ZoneMemberInterface", "$", "member", ")", "{", "if", "(", "$", "this", "->", "members", "->", "contains", "(", "$", "member", ")", ")", "{", "$", "member", "->", "setParentZone", "(", "null", ")", ";", "$", "this", "->", "members", "->", "removeElement", "(", "$", "member", ")", ";", "}", "return", "$", "this", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/lmammino/e-foundation/blob/198b7047d93eb11c9bc0c7ddf0bfa8229d42807a/src/Address/Model/Zone.php#L121-L129
ClanCats/Core
src/classes/CCViewController.php
CCViewController._respond
protected function _respond( $string ) { // if no view isset create one with the output buffer if ( is_null( $this->view ) ) { $this->theme->content = $string; } else { $this->theme->content = $this->view->render(); } // dont render the theme? Or does the request force render in modal? if ( CCRequest::current()->args->force_modal || $this->modal ) { return CCResponse::create( $this->theme->content, $this->status ); } // render theme and return response return CCResponse::create( $this->theme->render(), $this->status ); }
php
protected function _respond( $string ) { // if no view isset create one with the output buffer if ( is_null( $this->view ) ) { $this->theme->content = $string; } else { $this->theme->content = $this->view->render(); } // dont render the theme? Or does the request force render in modal? if ( CCRequest::current()->args->force_modal || $this->modal ) { return CCResponse::create( $this->theme->content, $this->status ); } // render theme and return response return CCResponse::create( $this->theme->render(), $this->status ); }
[ "protected", "function", "_respond", "(", "$", "string", ")", "{", "// if no view isset create one with the output buffer", "if", "(", "is_null", "(", "$", "this", "->", "view", ")", ")", "{", "$", "this", "->", "theme", "->", "content", "=", "$", "string", ";", "}", "else", "{", "$", "this", "->", "theme", "->", "content", "=", "$", "this", "->", "view", "->", "render", "(", ")", ";", "}", "// dont render the theme? Or does the request force render in modal?", "if", "(", "CCRequest", "::", "current", "(", ")", "->", "args", "->", "force_modal", "||", "$", "this", "->", "modal", ")", "{", "return", "CCResponse", "::", "create", "(", "$", "this", "->", "theme", "->", "content", ",", "$", "this", "->", "status", ")", ";", "}", "// render theme and return response", "return", "CCResponse", "::", "create", "(", "$", "this", "->", "theme", "->", "render", "(", ")", ",", "$", "this", "->", "status", ")", ";", "}" ]
When a controller gives us a string make a response out of it @param string @return CCResponse
[ "When", "a", "controller", "gives", "us", "a", "string", "make", "a", "response", "out", "of", "it" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCViewController.php#L82-L100
transfer-framework/ezplatform
src/Transfer/EzPlatform/Repository/Manager/ContentTypeManager.php
ContentTypeManager.find
public function find(ValueObject $object) { try { if (isset($object->data['identifier'])) { $contentType = $this->contentTypeService->loadContentTypeByIdentifier($object->data['identifier']); } } catch (NotFoundException $notFoundException) { // We'll throw our own exception later instead. } if (!isset($contentType)) { throw new ObjectNotFoundException(ContentType::class, array('identifier')); } return $contentType; }
php
public function find(ValueObject $object) { try { if (isset($object->data['identifier'])) { $contentType = $this->contentTypeService->loadContentTypeByIdentifier($object->data['identifier']); } } catch (NotFoundException $notFoundException) { // We'll throw our own exception later instead. } if (!isset($contentType)) { throw new ObjectNotFoundException(ContentType::class, array('identifier')); } return $contentType; }
[ "public", "function", "find", "(", "ValueObject", "$", "object", ")", "{", "try", "{", "if", "(", "isset", "(", "$", "object", "->", "data", "[", "'identifier'", "]", ")", ")", "{", "$", "contentType", "=", "$", "this", "->", "contentTypeService", "->", "loadContentTypeByIdentifier", "(", "$", "object", "->", "data", "[", "'identifier'", "]", ")", ";", "}", "}", "catch", "(", "NotFoundException", "$", "notFoundException", ")", "{", "// We'll throw our own exception later instead.", "}", "if", "(", "!", "isset", "(", "$", "contentType", ")", ")", "{", "throw", "new", "ObjectNotFoundException", "(", "ContentType", "::", "class", ",", "array", "(", "'identifier'", ")", ")", ";", "}", "return", "$", "contentType", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/transfer-framework/ezplatform/blob/1b2d87caa1a6b79fd8fc78109c26a2d1d6359c2f/src/Transfer/EzPlatform/Repository/Manager/ContentTypeManager.php#L96-L111
transfer-framework/ezplatform
src/Transfer/EzPlatform/Repository/Manager/ContentTypeManager.php
ContentTypeManager.create
public function create(ObjectInterface $object) { if (!$object instanceof ContentTypeObject) { throw new UnsupportedObjectOperationException(ContentTypeObject::class, get_class($object)); } if ($this->logger) { $this->logger->info(sprintf('Creating contenttype %s.', $object->data['identifier'])); } $this->updateContentTypeLanguages($object); $contentTypeCreateStruct = $this->contentTypeService->newContentTypeCreateStruct($object->data['identifier']); $object->getMapper()->mapObjectToCreateStruct($contentTypeCreateStruct); $this->fieldDefinitionSubManager->addFieldsToCreateStruct($contentTypeCreateStruct, $object->data['fields']); $contentTypeGroups = $this->contentTypeGroupSubManager->loadContentTypeGroupsByIdentifiers($object->data['contenttype_groups']); $contentTypeDraft = $this->contentTypeService->createContentType($contentTypeCreateStruct, $contentTypeGroups); if ($this->logger) { $this->logger->info(sprintf('Created contenttype draft %s.', $object->data['identifier'])); } $this->contentTypeService->publishContentTypeDraft($contentTypeDraft); if ($this->logger) { $this->logger->info(sprintf('Published contenttype draft %s.', $object->data['identifier'])); } $this->contentTypeGroupSubManager->updateContentTypeGroupsAssignment($object); $object->getMapper()->contentTypeToObject( $this->find($object) ); return $object; }
php
public function create(ObjectInterface $object) { if (!$object instanceof ContentTypeObject) { throw new UnsupportedObjectOperationException(ContentTypeObject::class, get_class($object)); } if ($this->logger) { $this->logger->info(sprintf('Creating contenttype %s.', $object->data['identifier'])); } $this->updateContentTypeLanguages($object); $contentTypeCreateStruct = $this->contentTypeService->newContentTypeCreateStruct($object->data['identifier']); $object->getMapper()->mapObjectToCreateStruct($contentTypeCreateStruct); $this->fieldDefinitionSubManager->addFieldsToCreateStruct($contentTypeCreateStruct, $object->data['fields']); $contentTypeGroups = $this->contentTypeGroupSubManager->loadContentTypeGroupsByIdentifiers($object->data['contenttype_groups']); $contentTypeDraft = $this->contentTypeService->createContentType($contentTypeCreateStruct, $contentTypeGroups); if ($this->logger) { $this->logger->info(sprintf('Created contenttype draft %s.', $object->data['identifier'])); } $this->contentTypeService->publishContentTypeDraft($contentTypeDraft); if ($this->logger) { $this->logger->info(sprintf('Published contenttype draft %s.', $object->data['identifier'])); } $this->contentTypeGroupSubManager->updateContentTypeGroupsAssignment($object); $object->getMapper()->contentTypeToObject( $this->find($object) ); return $object; }
[ "public", "function", "create", "(", "ObjectInterface", "$", "object", ")", "{", "if", "(", "!", "$", "object", "instanceof", "ContentTypeObject", ")", "{", "throw", "new", "UnsupportedObjectOperationException", "(", "ContentTypeObject", "::", "class", ",", "get_class", "(", "$", "object", ")", ")", ";", "}", "if", "(", "$", "this", "->", "logger", ")", "{", "$", "this", "->", "logger", "->", "info", "(", "sprintf", "(", "'Creating contenttype %s.'", ",", "$", "object", "->", "data", "[", "'identifier'", "]", ")", ")", ";", "}", "$", "this", "->", "updateContentTypeLanguages", "(", "$", "object", ")", ";", "$", "contentTypeCreateStruct", "=", "$", "this", "->", "contentTypeService", "->", "newContentTypeCreateStruct", "(", "$", "object", "->", "data", "[", "'identifier'", "]", ")", ";", "$", "object", "->", "getMapper", "(", ")", "->", "mapObjectToCreateStruct", "(", "$", "contentTypeCreateStruct", ")", ";", "$", "this", "->", "fieldDefinitionSubManager", "->", "addFieldsToCreateStruct", "(", "$", "contentTypeCreateStruct", ",", "$", "object", "->", "data", "[", "'fields'", "]", ")", ";", "$", "contentTypeGroups", "=", "$", "this", "->", "contentTypeGroupSubManager", "->", "loadContentTypeGroupsByIdentifiers", "(", "$", "object", "->", "data", "[", "'contenttype_groups'", "]", ")", ";", "$", "contentTypeDraft", "=", "$", "this", "->", "contentTypeService", "->", "createContentType", "(", "$", "contentTypeCreateStruct", ",", "$", "contentTypeGroups", ")", ";", "if", "(", "$", "this", "->", "logger", ")", "{", "$", "this", "->", "logger", "->", "info", "(", "sprintf", "(", "'Created contenttype draft %s.'", ",", "$", "object", "->", "data", "[", "'identifier'", "]", ")", ")", ";", "}", "$", "this", "->", "contentTypeService", "->", "publishContentTypeDraft", "(", "$", "contentTypeDraft", ")", ";", "if", "(", "$", "this", "->", "logger", ")", "{", "$", "this", "->", "logger", "->", "info", "(", "sprintf", "(", "'Published contenttype draft %s.'", ",", "$", "object", "->", "data", "[", "'identifier'", "]", ")", ")", ";", "}", "$", "this", "->", "contentTypeGroupSubManager", "->", "updateContentTypeGroupsAssignment", "(", "$", "object", ")", ";", "$", "object", "->", "getMapper", "(", ")", "->", "contentTypeToObject", "(", "$", "this", "->", "find", "(", "$", "object", ")", ")", ";", "return", "$", "object", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/transfer-framework/ezplatform/blob/1b2d87caa1a6b79fd8fc78109c26a2d1d6359c2f/src/Transfer/EzPlatform/Repository/Manager/ContentTypeManager.php#L116-L151
transfer-framework/ezplatform
src/Transfer/EzPlatform/Repository/Manager/ContentTypeManager.php
ContentTypeManager.update
public function update(ObjectInterface $object) { if (!$object instanceof ContentTypeObject) { throw new UnsupportedObjectOperationException(ContentTypeObject::class, get_class($object)); } if ($this->logger) { $this->logger->info(sprintf('Updating contenttype %s.', $object->data['identifier'])); } $contentType = $this->find($object); $this->updateContentTypeLanguages($object); $contentTypeDraft = $this->getNewContentTypeDraft($contentType); // Creating or updating the fielddefinitions $this->fieldDefinitionSubManager->createOrUpdateFieldDefinitions( $object->data['fields'], $contentType->getFieldDefinitions(), $contentTypeDraft ); $contentTypeUpdateStruct = $this->contentTypeService->newContentTypeUpdateStruct(); $object->getMapper()->mapObjectToUpdateStruct($contentTypeUpdateStruct); $this->contentTypeService->updateContentTypeDraft($contentTypeDraft, $contentTypeUpdateStruct); $this->contentTypeService->publishContentTypeDraft($contentTypeDraft); $this->contentTypeGroupSubManager->updateContentTypeGroupsAssignment($object); if ($this->logger) { $this->logger->info(sprintf('Updated contenttype %s.', $object->data['identifier'])); } $object->getMapper()->contentTypeToObject( $this->find($object) ); return $object; }
php
public function update(ObjectInterface $object) { if (!$object instanceof ContentTypeObject) { throw new UnsupportedObjectOperationException(ContentTypeObject::class, get_class($object)); } if ($this->logger) { $this->logger->info(sprintf('Updating contenttype %s.', $object->data['identifier'])); } $contentType = $this->find($object); $this->updateContentTypeLanguages($object); $contentTypeDraft = $this->getNewContentTypeDraft($contentType); // Creating or updating the fielddefinitions $this->fieldDefinitionSubManager->createOrUpdateFieldDefinitions( $object->data['fields'], $contentType->getFieldDefinitions(), $contentTypeDraft ); $contentTypeUpdateStruct = $this->contentTypeService->newContentTypeUpdateStruct(); $object->getMapper()->mapObjectToUpdateStruct($contentTypeUpdateStruct); $this->contentTypeService->updateContentTypeDraft($contentTypeDraft, $contentTypeUpdateStruct); $this->contentTypeService->publishContentTypeDraft($contentTypeDraft); $this->contentTypeGroupSubManager->updateContentTypeGroupsAssignment($object); if ($this->logger) { $this->logger->info(sprintf('Updated contenttype %s.', $object->data['identifier'])); } $object->getMapper()->contentTypeToObject( $this->find($object) ); return $object; }
[ "public", "function", "update", "(", "ObjectInterface", "$", "object", ")", "{", "if", "(", "!", "$", "object", "instanceof", "ContentTypeObject", ")", "{", "throw", "new", "UnsupportedObjectOperationException", "(", "ContentTypeObject", "::", "class", ",", "get_class", "(", "$", "object", ")", ")", ";", "}", "if", "(", "$", "this", "->", "logger", ")", "{", "$", "this", "->", "logger", "->", "info", "(", "sprintf", "(", "'Updating contenttype %s.'", ",", "$", "object", "->", "data", "[", "'identifier'", "]", ")", ")", ";", "}", "$", "contentType", "=", "$", "this", "->", "find", "(", "$", "object", ")", ";", "$", "this", "->", "updateContentTypeLanguages", "(", "$", "object", ")", ";", "$", "contentTypeDraft", "=", "$", "this", "->", "getNewContentTypeDraft", "(", "$", "contentType", ")", ";", "// Creating or updating the fielddefinitions", "$", "this", "->", "fieldDefinitionSubManager", "->", "createOrUpdateFieldDefinitions", "(", "$", "object", "->", "data", "[", "'fields'", "]", ",", "$", "contentType", "->", "getFieldDefinitions", "(", ")", ",", "$", "contentTypeDraft", ")", ";", "$", "contentTypeUpdateStruct", "=", "$", "this", "->", "contentTypeService", "->", "newContentTypeUpdateStruct", "(", ")", ";", "$", "object", "->", "getMapper", "(", ")", "->", "mapObjectToUpdateStruct", "(", "$", "contentTypeUpdateStruct", ")", ";", "$", "this", "->", "contentTypeService", "->", "updateContentTypeDraft", "(", "$", "contentTypeDraft", ",", "$", "contentTypeUpdateStruct", ")", ";", "$", "this", "->", "contentTypeService", "->", "publishContentTypeDraft", "(", "$", "contentTypeDraft", ")", ";", "$", "this", "->", "contentTypeGroupSubManager", "->", "updateContentTypeGroupsAssignment", "(", "$", "object", ")", ";", "if", "(", "$", "this", "->", "logger", ")", "{", "$", "this", "->", "logger", "->", "info", "(", "sprintf", "(", "'Updated contenttype %s.'", ",", "$", "object", "->", "data", "[", "'identifier'", "]", ")", ")", ";", "}", "$", "object", "->", "getMapper", "(", ")", "->", "contentTypeToObject", "(", "$", "this", "->", "find", "(", "$", "object", ")", ")", ";", "return", "$", "object", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/transfer-framework/ezplatform/blob/1b2d87caa1a6b79fd8fc78109c26a2d1d6359c2f/src/Transfer/EzPlatform/Repository/Manager/ContentTypeManager.php#L156-L196
transfer-framework/ezplatform
src/Transfer/EzPlatform/Repository/Manager/ContentTypeManager.php
ContentTypeManager.getNewContentTypeDraft
private function getNewContentTypeDraft(ContentType $contentType) { try { $contentTypeDraft = $this->contentTypeService->loadContentTypeDraft($contentType->id); } catch (NotFoundException $e) { $contentTypeDraft = $this->contentTypeService->createContentTypeDraft($contentType); } return $contentTypeDraft; }
php
private function getNewContentTypeDraft(ContentType $contentType) { try { $contentTypeDraft = $this->contentTypeService->loadContentTypeDraft($contentType->id); } catch (NotFoundException $e) { $contentTypeDraft = $this->contentTypeService->createContentTypeDraft($contentType); } return $contentTypeDraft; }
[ "private", "function", "getNewContentTypeDraft", "(", "ContentType", "$", "contentType", ")", "{", "try", "{", "$", "contentTypeDraft", "=", "$", "this", "->", "contentTypeService", "->", "loadContentTypeDraft", "(", "$", "contentType", "->", "id", ")", ";", "}", "catch", "(", "NotFoundException", "$", "e", ")", "{", "$", "contentTypeDraft", "=", "$", "this", "->", "contentTypeService", "->", "createContentTypeDraft", "(", "$", "contentType", ")", ";", "}", "return", "$", "contentTypeDraft", ";", "}" ]
@param ContentType $contentType @return ContentTypeDraft
[ "@param", "ContentType", "$contentType" ]
train
https://github.com/transfer-framework/ezplatform/blob/1b2d87caa1a6b79fd8fc78109c26a2d1d6359c2f/src/Transfer/EzPlatform/Repository/Manager/ContentTypeManager.php#L203-L212
transfer-framework/ezplatform
src/Transfer/EzPlatform/Repository/Manager/ContentTypeManager.php
ContentTypeManager.createOrUpdate
public function createOrUpdate(ObjectInterface $object) { if (!$object instanceof ContentTypeObject) { throw new UnsupportedObjectOperationException(ContentTypeObject::class, get_class($object)); } try { $this->find($object); return $this->update($object); } catch (NotFoundException $notFound) { return $this->create($object); } }
php
public function createOrUpdate(ObjectInterface $object) { if (!$object instanceof ContentTypeObject) { throw new UnsupportedObjectOperationException(ContentTypeObject::class, get_class($object)); } try { $this->find($object); return $this->update($object); } catch (NotFoundException $notFound) { return $this->create($object); } }
[ "public", "function", "createOrUpdate", "(", "ObjectInterface", "$", "object", ")", "{", "if", "(", "!", "$", "object", "instanceof", "ContentTypeObject", ")", "{", "throw", "new", "UnsupportedObjectOperationException", "(", "ContentTypeObject", "::", "class", ",", "get_class", "(", "$", "object", ")", ")", ";", "}", "try", "{", "$", "this", "->", "find", "(", "$", "object", ")", ";", "return", "$", "this", "->", "update", "(", "$", "object", ")", ";", "}", "catch", "(", "NotFoundException", "$", "notFound", ")", "{", "return", "$", "this", "->", "create", "(", "$", "object", ")", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/transfer-framework/ezplatform/blob/1b2d87caa1a6b79fd8fc78109c26a2d1d6359c2f/src/Transfer/EzPlatform/Repository/Manager/ContentTypeManager.php#L217-L230
transfer-framework/ezplatform
src/Transfer/EzPlatform/Repository/Manager/ContentTypeManager.php
ContentTypeManager.remove
public function remove(ObjectInterface $object) { if (!$object instanceof ContentTypeObject) { throw new UnsupportedObjectOperationException(ContentTypeObject::class, get_class($object)); } try { $contentType = $this->find($object); $this->contentTypeService->deleteContentType($contentType); return true; } catch (NotFoundException $notFound) { return false; } }
php
public function remove(ObjectInterface $object) { if (!$object instanceof ContentTypeObject) { throw new UnsupportedObjectOperationException(ContentTypeObject::class, get_class($object)); } try { $contentType = $this->find($object); $this->contentTypeService->deleteContentType($contentType); return true; } catch (NotFoundException $notFound) { return false; } }
[ "public", "function", "remove", "(", "ObjectInterface", "$", "object", ")", "{", "if", "(", "!", "$", "object", "instanceof", "ContentTypeObject", ")", "{", "throw", "new", "UnsupportedObjectOperationException", "(", "ContentTypeObject", "::", "class", ",", "get_class", "(", "$", "object", ")", ")", ";", "}", "try", "{", "$", "contentType", "=", "$", "this", "->", "find", "(", "$", "object", ")", ";", "$", "this", "->", "contentTypeService", "->", "deleteContentType", "(", "$", "contentType", ")", ";", "return", "true", ";", "}", "catch", "(", "NotFoundException", "$", "notFound", ")", "{", "return", "false", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/transfer-framework/ezplatform/blob/1b2d87caa1a6b79fd8fc78109c26a2d1d6359c2f/src/Transfer/EzPlatform/Repository/Manager/ContentTypeManager.php#L235-L249
lode/fem
src/routing.php
routing.handle
protected function handle($handler) { $handler_type = $this->get_handler_type($handler); // unmatched requests if (empty($handler) || empty($handler_type)) { $exception = bootstrap::get_library('exception'); throw new $exception('no route found', response::STATUS_NOT_FOUND); } // default flow: matched requests $this->{'load_handler_as_'.$handler_type}($handler); }
php
protected function handle($handler) { $handler_type = $this->get_handler_type($handler); // unmatched requests if (empty($handler) || empty($handler_type)) { $exception = bootstrap::get_library('exception'); throw new $exception('no route found', response::STATUS_NOT_FOUND); } // default flow: matched requests $this->{'load_handler_as_'.$handler_type}($handler); }
[ "protected", "function", "handle", "(", "$", "handler", ")", "{", "$", "handler_type", "=", "$", "this", "->", "get_handler_type", "(", "$", "handler", ")", ";", "// unmatched requests", "if", "(", "empty", "(", "$", "handler", ")", "||", "empty", "(", "$", "handler_type", ")", ")", "{", "$", "exception", "=", "bootstrap", "::", "get_library", "(", "'exception'", ")", ";", "throw", "new", "$", "exception", "(", "'no route found'", ",", "response", "::", "STATUS_NOT_FOUND", ")", ";", "}", "// default flow: matched requests", "$", "this", "->", "{", "'load_handler_as_'", ".", "$", "handler_type", "}", "(", "$", "handler", ")", ";", "}" ]
find someone else and let them handle the request @param mixed $handler @see get_handler_type() @return void however, it will fire a handler or an error
[ "find", "someone", "else", "and", "let", "them", "handle", "the", "request" ]
train
https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/routing.php#L102-L113
lode/fem
src/routing.php
routing.find_handler_path
protected function find_handler_path($filename) { $filename = strtolower($filename); if (preg_match('{[^a-z0-9/_-]}', $filename)) { return false; } $base_path = \alsvanzelf\fem\ROOT_DIR_APP.$this->handler_base_path.'/'; $full_path = $base_path.$filename.'.php'; if (file_exists($full_path) == false) { return false; } // sanity check to prevent escaping outside the base dir if (strpos($full_path, $base_path) !== 0) { return false; } return $full_path; }
php
protected function find_handler_path($filename) { $filename = strtolower($filename); if (preg_match('{[^a-z0-9/_-]}', $filename)) { return false; } $base_path = \alsvanzelf\fem\ROOT_DIR_APP.$this->handler_base_path.'/'; $full_path = $base_path.$filename.'.php'; if (file_exists($full_path) == false) { return false; } // sanity check to prevent escaping outside the base dir if (strpos($full_path, $base_path) !== 0) { return false; } return $full_path; }
[ "protected", "function", "find_handler_path", "(", "$", "filename", ")", "{", "$", "filename", "=", "strtolower", "(", "$", "filename", ")", ";", "if", "(", "preg_match", "(", "'{[^a-z0-9/_-]}'", ",", "$", "filename", ")", ")", "{", "return", "false", ";", "}", "$", "base_path", "=", "\\", "alsvanzelf", "\\", "fem", "\\", "ROOT_DIR_APP", ".", "$", "this", "->", "handler_base_path", ".", "'/'", ";", "$", "full_path", "=", "$", "base_path", ".", "$", "filename", ".", "'.php'", ";", "if", "(", "file_exists", "(", "$", "full_path", ")", "==", "false", ")", "{", "return", "false", ";", "}", "// sanity check to prevent escaping outside the base dir", "if", "(", "strpos", "(", "$", "full_path", ",", "$", "base_path", ")", "!==", "0", ")", "{", "return", "false", ";", "}", "return", "$", "full_path", ";", "}" ]
finds the handler's file @param string $filename a filename, relative to the handlers directory, and w/o '.php' @return string|boolean the full path, including \alsvanzelf\fem\ROOT_DIR_APP or false when not found
[ "finds", "the", "handler", "s", "file" ]
train
https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/routing.php#L122-L141
lode/fem
src/routing.php
routing.initialize
protected function initialize() { $request = bootstrap::get_library('request'); $response = bootstrap::get_library('response'); $exception = bootstrap::get_library('exception'); $this->url = $request::get_url(); $this->method = $request::get_method(); if (empty($this->method)) { throw new $exception('unknown http method', $response::STATUS_METHOD_NOT_ALLOWED); } }
php
protected function initialize() { $request = bootstrap::get_library('request'); $response = bootstrap::get_library('response'); $exception = bootstrap::get_library('exception'); $this->url = $request::get_url(); $this->method = $request::get_method(); if (empty($this->method)) { throw new $exception('unknown http method', $response::STATUS_METHOD_NOT_ALLOWED); } }
[ "protected", "function", "initialize", "(", ")", "{", "$", "request", "=", "bootstrap", "::", "get_library", "(", "'request'", ")", ";", "$", "response", "=", "bootstrap", "::", "get_library", "(", "'response'", ")", ";", "$", "exception", "=", "bootstrap", "::", "get_library", "(", "'exception'", ")", ";", "$", "this", "->", "url", "=", "$", "request", "::", "get_url", "(", ")", ";", "$", "this", "->", "method", "=", "$", "request", "::", "get_method", "(", ")", ";", "if", "(", "empty", "(", "$", "this", "->", "method", ")", ")", "{", "throw", "new", "$", "exception", "(", "'unknown http method'", ",", "$", "response", "::", "STATUS_METHOD_NOT_ALLOWED", ")", ";", "}", "}" ]
makes sure $this->url and $this->method exist @return void, however, it can fire an error for unknown http methods @see \alsvanzelf\fem\request::get_method() for which ones are supported
[ "makes", "sure", "$this", "-", ">", "url", "and", "$this", "-", ">", "method", "exist" ]
train
https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/routing.php#L149-L160
lode/fem
src/routing.php
routing.find_handler
private function find_handler() { $handler = false; // empty url leads to the default handler if (empty($this->url)) { return $this->default_handler; } // simple mapping urls to the filesystem if ($this->map_to_filesystem && $this->find_handler_path($this->url)) { // url == handler return $this->url; } // custom mapping via regex to various handler formats if ($this->map_to_filesystem == false) { $handler = $this->find_custom_handler(); // don't return, it could be a 404 } // fallback for unmatched requests if (empty($handler) && $this->fallback_to_default) { return $this->default_handler; } // 404 when file or regex is unmatched return $handler; }
php
private function find_handler() { $handler = false; // empty url leads to the default handler if (empty($this->url)) { return $this->default_handler; } // simple mapping urls to the filesystem if ($this->map_to_filesystem && $this->find_handler_path($this->url)) { // url == handler return $this->url; } // custom mapping via regex to various handler formats if ($this->map_to_filesystem == false) { $handler = $this->find_custom_handler(); // don't return, it could be a 404 } // fallback for unmatched requests if (empty($handler) && $this->fallback_to_default) { return $this->default_handler; } // 404 when file or regex is unmatched return $handler; }
[ "private", "function", "find_handler", "(", ")", "{", "$", "handler", "=", "false", ";", "// empty url leads to the default handler", "if", "(", "empty", "(", "$", "this", "->", "url", ")", ")", "{", "return", "$", "this", "->", "default_handler", ";", "}", "// simple mapping urls to the filesystem", "if", "(", "$", "this", "->", "map_to_filesystem", "&&", "$", "this", "->", "find_handler_path", "(", "$", "this", "->", "url", ")", ")", "{", "// url == handler", "return", "$", "this", "->", "url", ";", "}", "// custom mapping via regex to various handler formats", "if", "(", "$", "this", "->", "map_to_filesystem", "==", "false", ")", "{", "$", "handler", "=", "$", "this", "->", "find_custom_handler", "(", ")", ";", "// don't return, it could be a 404", "}", "// fallback for unmatched requests", "if", "(", "empty", "(", "$", "handler", ")", "&&", "$", "this", "->", "fallback_to_default", ")", "{", "return", "$", "this", "->", "default_handler", ";", "}", "// 404 when file or regex is unmatched", "return", "$", "handler", ";", "}" ]
find a handler for the requested url checks the filesystem directly if $this->map_to_filesystem is true checks user defined routes otherwise gives the default handler for empty url .. .. or when $this->fallback_to_default is true @return mixed $handler see get_handler_type()
[ "find", "a", "handler", "for", "the", "requested", "url" ]
train
https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/routing.php#L173-L200