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
sequencelengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
sequencelengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
heidelpay/PhpDoc
src/phpDocumentor/Descriptor/ConstantDescriptor.php
ConstantDescriptor.getTypes
public function getTypes() { if ($this->types === null) { $this->types = new Collection(); /** @var VarDescriptor $var */ $var = $this->getVar()->get(0); if ($var) { $this->types = $var->getTypes(); } } return $this->types; }
php
public function getTypes() { if ($this->types === null) { $this->types = new Collection(); /** @var VarDescriptor $var */ $var = $this->getVar()->get(0); if ($var) { $this->types = $var->getTypes(); } } return $this->types; }
[ "public", "function", "getTypes", "(", ")", "{", "if", "(", "$", "this", "->", "types", "===", "null", ")", "{", "$", "this", "->", "types", "=", "new", "Collection", "(", ")", ";", "/** @var VarDescriptor $var */", "$", "var", "=", "$", "this", "->", "getVar", "(", ")", "->", "get", "(", "0", ")", ";", "if", "(", "$", "var", ")", "{", "$", "this", "->", "types", "=", "$", "var", "->", "getTypes", "(", ")", ";", "}", "}", "return", "$", "this", "->", "types", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Descriptor/ConstantDescriptor.php#L73-L86
kenphp/ken
src/Utils/ArrayDot.php
ArrayDot.get
public function get($key, $defaultValue = null) { $keys = explode('.', $key); $config = $this->_arr; foreach ($keys as $value) { if (is_array($config)) { if (array_key_exists($value, $config)) { $config = $config[$value]; } else { return $defaultValue; } } else { return $defaultValue; } } return $config; }
php
public function get($key, $defaultValue = null) { $keys = explode('.', $key); $config = $this->_arr; foreach ($keys as $value) { if (is_array($config)) { if (array_key_exists($value, $config)) { $config = $config[$value]; } else { return $defaultValue; } } else { return $defaultValue; } } return $config; }
[ "public", "function", "get", "(", "$", "key", ",", "$", "defaultValue", "=", "null", ")", "{", "$", "keys", "=", "explode", "(", "'.'", ",", "$", "key", ")", ";", "$", "config", "=", "$", "this", "->", "_arr", ";", "foreach", "(", "$", "keys", "as", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "config", ")", ")", "{", "if", "(", "array_key_exists", "(", "$", "value", ",", "$", "config", ")", ")", "{", "$", "config", "=", "$", "config", "[", "$", "value", "]", ";", "}", "else", "{", "return", "$", "defaultValue", ";", "}", "}", "else", "{", "return", "$", "defaultValue", ";", "}", "}", "return", "$", "config", ";", "}" ]
Gets config value based on key. To access a sub-array you can use a dot separated key. For example, given this configuration array : array( 'basePath' => 'somepath', 'params' => array( 'somekey' => 'value of key' ) ); To access the value of 'somekey', you can call the method like this : echo $config->get('params.somekey'); The code above will print 'value of key' which is the value of config 'somekey' in the 'params' array. @param string $key Dot-separated string of key @param mixed $defaultValue Default value returned when **$key** is not found. @return mixed Value of config
[ "Gets", "config", "value", "based", "on", "key", "." ]
train
https://github.com/kenphp/ken/blob/c454a86f0ab55c52c88e9bff5bc6fb4e7bd9e0eb/src/Utils/ArrayDot.php#L58-L76
kenphp/ken
src/Utils/ArrayDot.php
ArrayDot.set
public function set($key, $value) { $keys = explode('.', $key); $config = &$this->_arr; foreach ($keys as $val) { $config = &$config[$val]; } $config = $value; }
php
public function set($key, $value) { $keys = explode('.', $key); $config = &$this->_arr; foreach ($keys as $val) { $config = &$config[$val]; } $config = $value; }
[ "public", "function", "set", "(", "$", "key", ",", "$", "value", ")", "{", "$", "keys", "=", "explode", "(", "'.'", ",", "$", "key", ")", ";", "$", "config", "=", "&", "$", "this", "->", "_arr", ";", "foreach", "(", "$", "keys", "as", "$", "val", ")", "{", "$", "config", "=", "&", "$", "config", "[", "$", "val", "]", ";", "}", "$", "config", "=", "$", "value", ";", "}" ]
Sets config value based on key. To set a sub-array configuration, you can use a dot separated key. For example, given this configuration array : array( 'basePath' => 'somepath', 'params' => array( 'somekey' => 'value of key' ) ); To set the value of 'somekey' to 'another value of key', you can call the method like this : $config->set('params.somekey','another value of key'); @param string $key Dot-separated string of key @param mixed $value
[ "Sets", "config", "value", "based", "on", "key", "." ]
train
https://github.com/kenphp/ken/blob/c454a86f0ab55c52c88e9bff5bc6fb4e7bd9e0eb/src/Utils/ArrayDot.php#L98-L108
kenphp/ken
src/Utils/ArrayDot.php
ArrayDot.remove
public function remove($key) { $keys = explode('.', $key); $cKeys = count($keys); $config = &$this->_arr; for ($i = 0; $i < $cKeys; ++$i) { if ($i === ($cKeys - 1)) { unset($config[$keys[$i]]); } elseif (is_array($config)) { if (array_key_exists($keys[$i], $config)) { $config = &$config[$keys[$i]]; } else { return; } } } }
php
public function remove($key) { $keys = explode('.', $key); $cKeys = count($keys); $config = &$this->_arr; for ($i = 0; $i < $cKeys; ++$i) { if ($i === ($cKeys - 1)) { unset($config[$keys[$i]]); } elseif (is_array($config)) { if (array_key_exists($keys[$i], $config)) { $config = &$config[$keys[$i]]; } else { return; } } } }
[ "public", "function", "remove", "(", "$", "key", ")", "{", "$", "keys", "=", "explode", "(", "'.'", ",", "$", "key", ")", ";", "$", "cKeys", "=", "count", "(", "$", "keys", ")", ";", "$", "config", "=", "&", "$", "this", "->", "_arr", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "cKeys", ";", "++", "$", "i", ")", "{", "if", "(", "$", "i", "===", "(", "$", "cKeys", "-", "1", ")", ")", "{", "unset", "(", "$", "config", "[", "$", "keys", "[", "$", "i", "]", "]", ")", ";", "}", "elseif", "(", "is_array", "(", "$", "config", ")", ")", "{", "if", "(", "array_key_exists", "(", "$", "keys", "[", "$", "i", "]", ",", "$", "config", ")", ")", "{", "$", "config", "=", "&", "$", "config", "[", "$", "keys", "[", "$", "i", "]", "]", ";", "}", "else", "{", "return", ";", "}", "}", "}", "}" ]
Removes config value based on key. To unset a sub-array configuration, you can use a dot separated key. For example, given this configuration array : array( 'basePath' => 'somepath', 'params' => array( 'somekey' => 'value of key' ) ); To unset the value of 'somekey', you can call the method like this : $config->unset('params.somekey'); @param string $key Dot-separated string of key
[ "Removes", "config", "value", "based", "on", "key", "." ]
train
https://github.com/kenphp/ken/blob/c454a86f0ab55c52c88e9bff5bc6fb4e7bd9e0eb/src/Utils/ArrayDot.php#L129-L146
kenphp/ken
src/Utils/ArrayDot.php
ArrayDot.has
public function has($key) { $keys = explode('.', $key); $cKeys = count($keys); $config = $this->_arr; for ($i = 0; $i < $cKeys; ++$i) { if (is_array($config)) { if (array_key_exists($keys[$i], $config)) { $config = $config[$keys[$i]]; } else { return false; } } else { return false; } } return true; }
php
public function has($key) { $keys = explode('.', $key); $cKeys = count($keys); $config = $this->_arr; for ($i = 0; $i < $cKeys; ++$i) { if (is_array($config)) { if (array_key_exists($keys[$i], $config)) { $config = $config[$keys[$i]]; } else { return false; } } else { return false; } } return true; }
[ "public", "function", "has", "(", "$", "key", ")", "{", "$", "keys", "=", "explode", "(", "'.'", ",", "$", "key", ")", ";", "$", "cKeys", "=", "count", "(", "$", "keys", ")", ";", "$", "config", "=", "$", "this", "->", "_arr", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "cKeys", ";", "++", "$", "i", ")", "{", "if", "(", "is_array", "(", "$", "config", ")", ")", "{", "if", "(", "array_key_exists", "(", "$", "keys", "[", "$", "i", "]", ",", "$", "config", ")", ")", "{", "$", "config", "=", "$", "config", "[", "$", "keys", "[", "$", "i", "]", "]", ";", "}", "else", "{", "return", "false", ";", "}", "}", "else", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Checks whether config has a certain key. @param string $key Dot-separated string of key @return bool
[ "Checks", "whether", "config", "has", "a", "certain", "key", "." ]
train
https://github.com/kenphp/ken/blob/c454a86f0ab55c52c88e9bff5bc6fb4e7bd9e0eb/src/Utils/ArrayDot.php#L155-L174
nabab/bbn
src/bbn/file/pdf.php
pdf.add_fonts
public function add_fonts(array $fonts){ if ( !\defined('BBN_LIB_PATH') ){ die('You must define BBN_LIB_PATH!'); } if ( !is_dir(BBN_LIB_PATH . 'mpdf/mpdf/ttfonts/') ){ die("You don't have the mpdf/mpdf/ttfonts directory."); } foreach ($fonts as $f => $fs) { // add to available fonts array foreach ( $fs as $i => $v ){ if ( !empty($v) ){ // check if file exists in mpdf/ttfonts directory if ( !is_file(BBN_LIB_PATH . 'mpdf/mpdf/ttfonts/' . basename($v)) ){ \bbn\file\dir::copy($v, BBN_LIB_PATH . 'mpdf/mpdf/ttfonts/' . basename($v)); } $fs[$i] = basename($v); if ( $i === 'R' ){ array_push($this->pdf->available_unifonts, $f); } else { array_push($this->pdf->available_unifonts, $f.$i); } } else { unset($fs[$i]); } } // add to fontdata array $this->pdf->fontdata[$f] = $fs; } $this->pdf->default_available_fonts = $this->pdf->available_unifonts; }
php
public function add_fonts(array $fonts){ if ( !\defined('BBN_LIB_PATH') ){ die('You must define BBN_LIB_PATH!'); } if ( !is_dir(BBN_LIB_PATH . 'mpdf/mpdf/ttfonts/') ){ die("You don't have the mpdf/mpdf/ttfonts directory."); } foreach ($fonts as $f => $fs) { // add to available fonts array foreach ( $fs as $i => $v ){ if ( !empty($v) ){ // check if file exists in mpdf/ttfonts directory if ( !is_file(BBN_LIB_PATH . 'mpdf/mpdf/ttfonts/' . basename($v)) ){ \bbn\file\dir::copy($v, BBN_LIB_PATH . 'mpdf/mpdf/ttfonts/' . basename($v)); } $fs[$i] = basename($v); if ( $i === 'R' ){ array_push($this->pdf->available_unifonts, $f); } else { array_push($this->pdf->available_unifonts, $f.$i); } } else { unset($fs[$i]); } } // add to fontdata array $this->pdf->fontdata[$f] = $fs; } $this->pdf->default_available_fonts = $this->pdf->available_unifonts; }
[ "public", "function", "add_fonts", "(", "array", "$", "fonts", ")", "{", "if", "(", "!", "\\", "defined", "(", "'BBN_LIB_PATH'", ")", ")", "{", "die", "(", "'You must define BBN_LIB_PATH!'", ")", ";", "}", "if", "(", "!", "is_dir", "(", "BBN_LIB_PATH", ".", "'mpdf/mpdf/ttfonts/'", ")", ")", "{", "die", "(", "\"You don't have the mpdf/mpdf/ttfonts directory.\"", ")", ";", "}", "foreach", "(", "$", "fonts", "as", "$", "f", "=>", "$", "fs", ")", "{", "// add to available fonts array", "foreach", "(", "$", "fs", "as", "$", "i", "=>", "$", "v", ")", "{", "if", "(", "!", "empty", "(", "$", "v", ")", ")", "{", "// check if file exists in mpdf/ttfonts directory", "if", "(", "!", "is_file", "(", "BBN_LIB_PATH", ".", "'mpdf/mpdf/ttfonts/'", ".", "basename", "(", "$", "v", ")", ")", ")", "{", "\\", "bbn", "\\", "file", "\\", "dir", "::", "copy", "(", "$", "v", ",", "BBN_LIB_PATH", ".", "'mpdf/mpdf/ttfonts/'", ".", "basename", "(", "$", "v", ")", ")", ";", "}", "$", "fs", "[", "$", "i", "]", "=", "basename", "(", "$", "v", ")", ";", "if", "(", "$", "i", "===", "'R'", ")", "{", "array_push", "(", "$", "this", "->", "pdf", "->", "available_unifonts", ",", "$", "f", ")", ";", "}", "else", "{", "array_push", "(", "$", "this", "->", "pdf", "->", "available_unifonts", ",", "$", "f", ".", "$", "i", ")", ";", "}", "}", "else", "{", "unset", "(", "$", "fs", "[", "$", "i", "]", ")", ";", "}", "}", "// add to fontdata array", "$", "this", "->", "pdf", "->", "fontdata", "[", "$", "f", "]", "=", "$", "fs", ";", "}", "$", "this", "->", "pdf", "->", "default_available_fonts", "=", "$", "this", "->", "pdf", "->", "available_unifonts", ";", "}" ]
Adds custom fonts $pdf->add_fonts([ 'dawningofanewday' => [ 'R' => BBN_DATA_PATH.'files/DawningofaNewDay.ttf' ] ]); @param array $fonts
[ "Adds", "custom", "fonts" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/pdf.php#L239-L270
cirrusidentity/simplesamlphp-test-utils
src/SanityChecker.php
SanityChecker.confirmAspectMockConfigured
static public function confirmAspectMockConfigured() { // Ensure mocks are configured for SSP classes $httpDouble = test::double('SimpleSAML\Utils\HTTP', [ 'getAcceptLanguage' => ['some-lang'] ]); if ( ['some-lang'] !== \SimpleSAML\Utils\HTTP::getAcceptLanguage()) { throw new \Exception("Aspect mock does not seem to be configured"); } // You can also validate the that a method was called. // $httpDouble->verifyInvokedOnce('getAcceptLanguage'); return $httpDouble; }
php
static public function confirmAspectMockConfigured() { // Ensure mocks are configured for SSP classes $httpDouble = test::double('SimpleSAML\Utils\HTTP', [ 'getAcceptLanguage' => ['some-lang'] ]); if ( ['some-lang'] !== \SimpleSAML\Utils\HTTP::getAcceptLanguage()) { throw new \Exception("Aspect mock does not seem to be configured"); } // You can also validate the that a method was called. // $httpDouble->verifyInvokedOnce('getAcceptLanguage'); return $httpDouble; }
[ "static", "public", "function", "confirmAspectMockConfigured", "(", ")", "{", "// Ensure mocks are configured for SSP classes", "$", "httpDouble", "=", "test", "::", "double", "(", "'SimpleSAML\\Utils\\HTTP'", ",", "[", "'getAcceptLanguage'", "=>", "[", "'some-lang'", "]", "]", ")", ";", "if", "(", "[", "'some-lang'", "]", "!==", "\\", "SimpleSAML", "\\", "Utils", "\\", "HTTP", "::", "getAcceptLanguage", "(", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "\"Aspect mock does not seem to be configured\"", ")", ";", "}", "// You can also validate the that a method was called.", "// $httpDouble->verifyInvokedOnce('getAcceptLanguage');", "return", "$", "httpDouble", ";", "}" ]
Checks that AspectMock is configured and can override HTTP Util methods @return \AspectMock\Proxy\ClassProxy|\AspectMock\Proxy\InstanceProxy|\AspectMock\Proxy\Verifier @throws \Exception
[ "Checks", "that", "AspectMock", "is", "configured", "and", "can", "override", "HTTP", "Util", "methods" ]
train
https://github.com/cirrusidentity/simplesamlphp-test-utils/blob/79150efb8bca89c180b604dc1d6194f819ebe2b2/src/SanityChecker.php#L18-L30
php-lug/lug
src/Bundle/LocaleBundle/DependencyInjection/Compiler/RegisterValidationMetadataPass.php
RegisterValidationMetadataPass.process
public function process(ContainerBuilder $container) { $driver = $this->getLocaleDriver($container->getDefinition('lug.resource.locale')); if ($driver === null) { return; } $builder = $container->getDefinition('validator.builder'); $path = realpath(__DIR__.'/../../Resources/config/validator'); if ($driver === ResourceInterface::DRIVER_DOCTRINE_ORM) { $builder->addMethodCall('addXmlMapping', [$path.'/Locale.orm.xml']); } elseif ($driver === ResourceInterface::DRIVER_DOCTRINE_MONGODB) { $builder->addMethodCall('addXmlMapping', [$path.'/Locale.mongodb.xml']); } }
php
public function process(ContainerBuilder $container) { $driver = $this->getLocaleDriver($container->getDefinition('lug.resource.locale')); if ($driver === null) { return; } $builder = $container->getDefinition('validator.builder'); $path = realpath(__DIR__.'/../../Resources/config/validator'); if ($driver === ResourceInterface::DRIVER_DOCTRINE_ORM) { $builder->addMethodCall('addXmlMapping', [$path.'/Locale.orm.xml']); } elseif ($driver === ResourceInterface::DRIVER_DOCTRINE_MONGODB) { $builder->addMethodCall('addXmlMapping', [$path.'/Locale.mongodb.xml']); } }
[ "public", "function", "process", "(", "ContainerBuilder", "$", "container", ")", "{", "$", "driver", "=", "$", "this", "->", "getLocaleDriver", "(", "$", "container", "->", "getDefinition", "(", "'lug.resource.locale'", ")", ")", ";", "if", "(", "$", "driver", "===", "null", ")", "{", "return", ";", "}", "$", "builder", "=", "$", "container", "->", "getDefinition", "(", "'validator.builder'", ")", ";", "$", "path", "=", "realpath", "(", "__DIR__", ".", "'/../../Resources/config/validator'", ")", ";", "if", "(", "$", "driver", "===", "ResourceInterface", "::", "DRIVER_DOCTRINE_ORM", ")", "{", "$", "builder", "->", "addMethodCall", "(", "'addXmlMapping'", ",", "[", "$", "path", ".", "'/Locale.orm.xml'", "]", ")", ";", "}", "elseif", "(", "$", "driver", "===", "ResourceInterface", "::", "DRIVER_DOCTRINE_MONGODB", ")", "{", "$", "builder", "->", "addMethodCall", "(", "'addXmlMapping'", ",", "[", "$", "path", ".", "'/Locale.mongodb.xml'", "]", ")", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/LocaleBundle/DependencyInjection/Compiler/RegisterValidationMetadataPass.php#L27-L43
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Database/src/handlers/mssql.php
ezcDbHandlerMssql.setupConnection
private function setupConnection() { $requiredMode = $this->options->quoteIdentifier; if ( $requiredMode == ezcDbMssqlOptions::QUOTES_GUESS ) { $result = parent::query( "SELECT sessionproperty('QUOTED_IDENTIFIER')" ); $rows = $result->fetchAll(); $mode = (int)$rows[0][0]; if ( $mode == 0 ) { $this->identifierQuoteChars = array( 'start' => '[', 'end' => ']' ); } else { $this->identifierQuoteChars = array( 'start' => '"', 'end' => '"' ); } } else if ( $requiredMode == ezcDbMssqlOptions::QUOTES_COMPLIANT ) { parent::exec( 'SET QUOTED_IDENTIFIER ON' ); $this->identifierQuoteChars = array( 'start' => '"', 'end' => '"' ); } else if ( $requiredMode == ezcDbMssqlOptions::QUOTES_LEGACY ) { parent::exec( 'SET QUOTED_IDENTIFIER OFF' ); $this->identifierQuoteChars = array( 'start' => '[', 'end' => ']' ); } }
php
private function setupConnection() { $requiredMode = $this->options->quoteIdentifier; if ( $requiredMode == ezcDbMssqlOptions::QUOTES_GUESS ) { $result = parent::query( "SELECT sessionproperty('QUOTED_IDENTIFIER')" ); $rows = $result->fetchAll(); $mode = (int)$rows[0][0]; if ( $mode == 0 ) { $this->identifierQuoteChars = array( 'start' => '[', 'end' => ']' ); } else { $this->identifierQuoteChars = array( 'start' => '"', 'end' => '"' ); } } else if ( $requiredMode == ezcDbMssqlOptions::QUOTES_COMPLIANT ) { parent::exec( 'SET QUOTED_IDENTIFIER ON' ); $this->identifierQuoteChars = array( 'start' => '"', 'end' => '"' ); } else if ( $requiredMode == ezcDbMssqlOptions::QUOTES_LEGACY ) { parent::exec( 'SET QUOTED_IDENTIFIER OFF' ); $this->identifierQuoteChars = array( 'start' => '[', 'end' => ']' ); } }
[ "private", "function", "setupConnection", "(", ")", "{", "$", "requiredMode", "=", "$", "this", "->", "options", "->", "quoteIdentifier", ";", "if", "(", "$", "requiredMode", "==", "ezcDbMssqlOptions", "::", "QUOTES_GUESS", ")", "{", "$", "result", "=", "parent", "::", "query", "(", "\"SELECT sessionproperty('QUOTED_IDENTIFIER')\"", ")", ";", "$", "rows", "=", "$", "result", "->", "fetchAll", "(", ")", ";", "$", "mode", "=", "(", "int", ")", "$", "rows", "[", "0", "]", "[", "0", "]", ";", "if", "(", "$", "mode", "==", "0", ")", "{", "$", "this", "->", "identifierQuoteChars", "=", "array", "(", "'start'", "=>", "'['", ",", "'end'", "=>", "']'", ")", ";", "}", "else", "{", "$", "this", "->", "identifierQuoteChars", "=", "array", "(", "'start'", "=>", "'\"'", ",", "'end'", "=>", "'\"'", ")", ";", "}", "}", "else", "if", "(", "$", "requiredMode", "==", "ezcDbMssqlOptions", "::", "QUOTES_COMPLIANT", ")", "{", "parent", "::", "exec", "(", "'SET QUOTED_IDENTIFIER ON'", ")", ";", "$", "this", "->", "identifierQuoteChars", "=", "array", "(", "'start'", "=>", "'\"'", ",", "'end'", "=>", "'\"'", ")", ";", "}", "else", "if", "(", "$", "requiredMode", "==", "ezcDbMssqlOptions", "::", "QUOTES_LEGACY", ")", "{", "parent", "::", "exec", "(", "'SET QUOTED_IDENTIFIER OFF'", ")", ";", "$", "this", "->", "identifierQuoteChars", "=", "array", "(", "'start'", "=>", "'['", ",", "'end'", "=>", "']'", ")", ";", "}", "}" ]
Sets up opened connection according to options.
[ "Sets", "up", "opened", "connection", "according", "to", "options", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/handlers/mssql.php#L92-L119
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Database/src/handlers/mssql.php
ezcDbHandlerMssql.beginTransaction
public function beginTransaction() { $retval = true; if ( $this->transactionNestingLevel == 0 ) { $retval = $this->exec( "BEGIN TRANSACTION" ); } // else NOP $this->transactionNestingLevel++; return $retval; }
php
public function beginTransaction() { $retval = true; if ( $this->transactionNestingLevel == 0 ) { $retval = $this->exec( "BEGIN TRANSACTION" ); } // else NOP $this->transactionNestingLevel++; return $retval; }
[ "public", "function", "beginTransaction", "(", ")", "{", "$", "retval", "=", "true", ";", "if", "(", "$", "this", "->", "transactionNestingLevel", "==", "0", ")", "{", "$", "retval", "=", "$", "this", "->", "exec", "(", "\"BEGIN TRANSACTION\"", ")", ";", "}", "// else NOP", "$", "this", "->", "transactionNestingLevel", "++", ";", "return", "$", "retval", ";", "}" ]
Begins a transaction. This method executes a begin transaction query unless a transaction has already been started (transaction nesting level > 0 ). Each call to begin() must have a corresponding commit() or rollback() call. @see commit() @see rollback() @return bool
[ "Begins", "a", "transaction", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/handlers/mssql.php#L165-L176
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Database/src/handlers/mssql.php
ezcDbHandlerMssql.commit
public function commit() { if ( $this->transactionNestingLevel <= 0 ) { $this->transactionNestingLevel = 0; throw new ezcDbTransactionException( "commit() called before beginTransaction()." ); } $retval = true; if ( $this->transactionNestingLevel == 1 ) { if ( $this->transactionErrorFlag ) { $this->exec( "ROLLBACK TRANSACTION" ); $this->transactionErrorFlag = false; // reset error flag $retval = false; } else { $this->exec( "COMMIT TRANSACTION" ); } } // else NOP $this->transactionNestingLevel--; return $retval; }
php
public function commit() { if ( $this->transactionNestingLevel <= 0 ) { $this->transactionNestingLevel = 0; throw new ezcDbTransactionException( "commit() called before beginTransaction()." ); } $retval = true; if ( $this->transactionNestingLevel == 1 ) { if ( $this->transactionErrorFlag ) { $this->exec( "ROLLBACK TRANSACTION" ); $this->transactionErrorFlag = false; // reset error flag $retval = false; } else { $this->exec( "COMMIT TRANSACTION" ); } } // else NOP $this->transactionNestingLevel--; return $retval; }
[ "public", "function", "commit", "(", ")", "{", "if", "(", "$", "this", "->", "transactionNestingLevel", "<=", "0", ")", "{", "$", "this", "->", "transactionNestingLevel", "=", "0", ";", "throw", "new", "ezcDbTransactionException", "(", "\"commit() called before beginTransaction().\"", ")", ";", "}", "$", "retval", "=", "true", ";", "if", "(", "$", "this", "->", "transactionNestingLevel", "==", "1", ")", "{", "if", "(", "$", "this", "->", "transactionErrorFlag", ")", "{", "$", "this", "->", "exec", "(", "\"ROLLBACK TRANSACTION\"", ")", ";", "$", "this", "->", "transactionErrorFlag", "=", "false", ";", "// reset error flag", "$", "retval", "=", "false", ";", "}", "else", "{", "$", "this", "->", "exec", "(", "\"COMMIT TRANSACTION\"", ")", ";", "}", "}", "// else NOP", "$", "this", "->", "transactionNestingLevel", "--", ";", "return", "$", "retval", ";", "}" ]
Commits a transaction. If this this call to commit corresponds to the outermost call to begin() and all queries within this transaction were successful, a commit query is executed. If one of the queries returned with an error, a rollback query is executed instead. This method returns true if the transaction was successful. If the transaction failed and rollback was called, false is returned. @see begin() @see rollback() @return bool
[ "Commits", "a", "transaction", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/handlers/mssql.php#L193-L220
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Database/src/handlers/mssql.php
ezcDbHandlerMssql.rollback
public function rollback() { if ( $this->transactionNestingLevel <= 0 ) { $this->transactionNestingLevel = 0; throw new ezcDbTransactionException( "rollback() called without previous beginTransaction()." ); } if ( $this->transactionNestingLevel == 1 ) { $this->exec( "ROLLBACK TRANSACTION" ); $this->transactionErrorFlag = false; // reset error flag } else { // set the error flag, so that if there is outermost commit // then ROLLBACK will be done instead of COMMIT $this->transactionErrorFlag = true; } $this->transactionNestingLevel--; return true; }
php
public function rollback() { if ( $this->transactionNestingLevel <= 0 ) { $this->transactionNestingLevel = 0; throw new ezcDbTransactionException( "rollback() called without previous beginTransaction()." ); } if ( $this->transactionNestingLevel == 1 ) { $this->exec( "ROLLBACK TRANSACTION" ); $this->transactionErrorFlag = false; // reset error flag } else { // set the error flag, so that if there is outermost commit // then ROLLBACK will be done instead of COMMIT $this->transactionErrorFlag = true; } $this->transactionNestingLevel--; return true; }
[ "public", "function", "rollback", "(", ")", "{", "if", "(", "$", "this", "->", "transactionNestingLevel", "<=", "0", ")", "{", "$", "this", "->", "transactionNestingLevel", "=", "0", ";", "throw", "new", "ezcDbTransactionException", "(", "\"rollback() called without previous beginTransaction().\"", ")", ";", "}", "if", "(", "$", "this", "->", "transactionNestingLevel", "==", "1", ")", "{", "$", "this", "->", "exec", "(", "\"ROLLBACK TRANSACTION\"", ")", ";", "$", "this", "->", "transactionErrorFlag", "=", "false", ";", "// reset error flag", "}", "else", "{", "// set the error flag, so that if there is outermost commit", "// then ROLLBACK will be done instead of COMMIT", "$", "this", "->", "transactionErrorFlag", "=", "true", ";", "}", "$", "this", "->", "transactionNestingLevel", "--", ";", "return", "true", ";", "}" ]
Rollback a transaction. If this this call to rollback corresponds to the outermost call to begin(), a rollback query is executed. If this is an inner transaction (nesting level > 1) the error flag is set, leaving the rollback to the outermost transaction. This method always returns true. @see begin() @see commit() @return bool
[ "Rollback", "a", "transaction", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/handlers/mssql.php#L236-L258
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo/Loader.php
Dwoo_Loader.rebuildClassPathCache
protected function rebuildClassPathCache($path, $cacheFile) { if ($cacheFile!==false) { $tmp = $this->classPath; $this->classPath = array(); } // iterates over all files/folders $list = glob(rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . '*'); if (is_array($list)) { foreach ($list as $f) { if (is_dir($f)) { $this->rebuildClassPathCache($f, false); } else { $this->classPath[str_replace(array('function.','block.','modifier.','outputfilter.','filter.','prefilter.','postfilter.','pre.','post.','output.','shared.','helper.'), '', basename($f, '.php'))] = $f; } } } // save in file if it's the first call (not recursed) if ($cacheFile!==false) { if (!file_put_contents($cacheFile, serialize($this->classPath))) { throw new Dwoo_Exception('Could not write into '.$cacheFile.', either because the folder is not there (create it) or because of the chmod configuration (please ensure this directory is writable by php), alternatively you can change the directory used with $dwoo->setCompileDir() or provide a custom loader object with $dwoo->setLoader()'); } $this->classPath += $tmp; } }
php
protected function rebuildClassPathCache($path, $cacheFile) { if ($cacheFile!==false) { $tmp = $this->classPath; $this->classPath = array(); } // iterates over all files/folders $list = glob(rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . '*'); if (is_array($list)) { foreach ($list as $f) { if (is_dir($f)) { $this->rebuildClassPathCache($f, false); } else { $this->classPath[str_replace(array('function.','block.','modifier.','outputfilter.','filter.','prefilter.','postfilter.','pre.','post.','output.','shared.','helper.'), '', basename($f, '.php'))] = $f; } } } // save in file if it's the first call (not recursed) if ($cacheFile!==false) { if (!file_put_contents($cacheFile, serialize($this->classPath))) { throw new Dwoo_Exception('Could not write into '.$cacheFile.', either because the folder is not there (create it) or because of the chmod configuration (please ensure this directory is writable by php), alternatively you can change the directory used with $dwoo->setCompileDir() or provide a custom loader object with $dwoo->setLoader()'); } $this->classPath += $tmp; } }
[ "protected", "function", "rebuildClassPathCache", "(", "$", "path", ",", "$", "cacheFile", ")", "{", "if", "(", "$", "cacheFile", "!==", "false", ")", "{", "$", "tmp", "=", "$", "this", "->", "classPath", ";", "$", "this", "->", "classPath", "=", "array", "(", ")", ";", "}", "// iterates over all files/folders", "$", "list", "=", "glob", "(", "rtrim", "(", "$", "path", ",", "DIRECTORY_SEPARATOR", ")", ".", "DIRECTORY_SEPARATOR", ".", "'*'", ")", ";", "if", "(", "is_array", "(", "$", "list", ")", ")", "{", "foreach", "(", "$", "list", "as", "$", "f", ")", "{", "if", "(", "is_dir", "(", "$", "f", ")", ")", "{", "$", "this", "->", "rebuildClassPathCache", "(", "$", "f", ",", "false", ")", ";", "}", "else", "{", "$", "this", "->", "classPath", "[", "str_replace", "(", "array", "(", "'function.'", ",", "'block.'", ",", "'modifier.'", ",", "'outputfilter.'", ",", "'filter.'", ",", "'prefilter.'", ",", "'postfilter.'", ",", "'pre.'", ",", "'post.'", ",", "'output.'", ",", "'shared.'", ",", "'helper.'", ")", ",", "''", ",", "basename", "(", "$", "f", ",", "'.php'", ")", ")", "]", "=", "$", "f", ";", "}", "}", "}", "// save in file if it's the first call (not recursed)", "if", "(", "$", "cacheFile", "!==", "false", ")", "{", "if", "(", "!", "file_put_contents", "(", "$", "cacheFile", ",", "serialize", "(", "$", "this", "->", "classPath", ")", ")", ")", "{", "throw", "new", "Dwoo_Exception", "(", "'Could not write into '", ".", "$", "cacheFile", ".", "', either because the folder is not there (create it) or because of the chmod configuration (please ensure this directory is writable by php), alternatively you can change the directory used with $dwoo->setCompileDir() or provide a custom loader object with $dwoo->setLoader()'", ")", ";", "}", "$", "this", "->", "classPath", "+=", "$", "tmp", ";", "}", "}" ]
rebuilds class paths, scans the given directory recursively and saves all paths in the given file @param string $path the plugin path to scan @param string $cacheFile the file where to store the plugin paths cache, it will be overwritten
[ "rebuilds", "class", "paths", "scans", "the", "given", "directory", "recursively", "and", "saves", "all", "paths", "in", "the", "given", "file" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Loader.php#L66-L92
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo/Loader.php
Dwoo_Loader.loadPlugin
public function loadPlugin($class, $forceRehash = true) { // a new class was added or the include failed so we rebuild the cache if (!isset($this->classPath[$class]) || !(include $this->classPath[$class])) { if ($forceRehash) { $this->rebuildClassPathCache($this->corePluginDir, $this->cacheDir . 'classpath.cache.d'.Dwoo::RELEASE_TAG.'.php'); foreach ($this->paths as $path=>$file) { $this->rebuildClassPathCache($path, $file); } if (isset($this->classPath[$class])) { include $this->classPath[$class]; } else { throw new Dwoo_Exception('Plugin <em>'.$class.'</em> can not be found, maybe you forgot to bind it if it\'s a custom plugin ?', E_USER_NOTICE); } } else { throw new Dwoo_Exception('Plugin <em>'.$class.'</em> can not be found, maybe you forgot to bind it if it\'s a custom plugin ?', E_USER_NOTICE); } } }
php
public function loadPlugin($class, $forceRehash = true) { // a new class was added or the include failed so we rebuild the cache if (!isset($this->classPath[$class]) || !(include $this->classPath[$class])) { if ($forceRehash) { $this->rebuildClassPathCache($this->corePluginDir, $this->cacheDir . 'classpath.cache.d'.Dwoo::RELEASE_TAG.'.php'); foreach ($this->paths as $path=>$file) { $this->rebuildClassPathCache($path, $file); } if (isset($this->classPath[$class])) { include $this->classPath[$class]; } else { throw new Dwoo_Exception('Plugin <em>'.$class.'</em> can not be found, maybe you forgot to bind it if it\'s a custom plugin ?', E_USER_NOTICE); } } else { throw new Dwoo_Exception('Plugin <em>'.$class.'</em> can not be found, maybe you forgot to bind it if it\'s a custom plugin ?', E_USER_NOTICE); } } }
[ "public", "function", "loadPlugin", "(", "$", "class", ",", "$", "forceRehash", "=", "true", ")", "{", "// a new class was added or the include failed so we rebuild the cache", "if", "(", "!", "isset", "(", "$", "this", "->", "classPath", "[", "$", "class", "]", ")", "||", "!", "(", "include", "$", "this", "->", "classPath", "[", "$", "class", "]", ")", ")", "{", "if", "(", "$", "forceRehash", ")", "{", "$", "this", "->", "rebuildClassPathCache", "(", "$", "this", "->", "corePluginDir", ",", "$", "this", "->", "cacheDir", ".", "'classpath.cache.d'", ".", "Dwoo", "::", "RELEASE_TAG", ".", "'.php'", ")", ";", "foreach", "(", "$", "this", "->", "paths", "as", "$", "path", "=>", "$", "file", ")", "{", "$", "this", "->", "rebuildClassPathCache", "(", "$", "path", ",", "$", "file", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "classPath", "[", "$", "class", "]", ")", ")", "{", "include", "$", "this", "->", "classPath", "[", "$", "class", "]", ";", "}", "else", "{", "throw", "new", "Dwoo_Exception", "(", "'Plugin <em>'", ".", "$", "class", ".", "'</em> can not be found, maybe you forgot to bind it if it\\'s a custom plugin ?'", ",", "E_USER_NOTICE", ")", ";", "}", "}", "else", "{", "throw", "new", "Dwoo_Exception", "(", "'Plugin <em>'", ".", "$", "class", ".", "'</em> can not be found, maybe you forgot to bind it if it\\'s a custom plugin ?'", ",", "E_USER_NOTICE", ")", ";", "}", "}", "}" ]
loads a plugin file @param string $class the plugin name, without the Dwoo_Plugin_ prefix @param bool $forceRehash if true, the class path caches will be rebuilt if the plugin is not found, in case it has just been added, defaults to true
[ "loads", "a", "plugin", "file" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Loader.php#L100-L118
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo/Loader.php
Dwoo_Loader.addDirectory
public function addDirectory($pluginDirectory) { $pluginDir = realpath($pluginDirectory); if (!$pluginDir) { throw new Dwoo_Exception('Plugin directory does not exist or can not be read : '.$pluginDirectory); } $cacheFile = $this->cacheDir . 'classpath-'.substr(strtr($pluginDir, '/\\:'.PATH_SEPARATOR, '----'), strlen($pluginDir) > 80 ? -80 : 0).'.d'.Dwoo::RELEASE_TAG.'.php'; $this->paths[$pluginDir] = $cacheFile; if (file_exists($cacheFile)) { $classpath = file_get_contents($cacheFile); $this->classPath = unserialize($classpath) + $this->classPath; } else { $this->rebuildClassPathCache($pluginDir, $cacheFile); } }
php
public function addDirectory($pluginDirectory) { $pluginDir = realpath($pluginDirectory); if (!$pluginDir) { throw new Dwoo_Exception('Plugin directory does not exist or can not be read : '.$pluginDirectory); } $cacheFile = $this->cacheDir . 'classpath-'.substr(strtr($pluginDir, '/\\:'.PATH_SEPARATOR, '----'), strlen($pluginDir) > 80 ? -80 : 0).'.d'.Dwoo::RELEASE_TAG.'.php'; $this->paths[$pluginDir] = $cacheFile; if (file_exists($cacheFile)) { $classpath = file_get_contents($cacheFile); $this->classPath = unserialize($classpath) + $this->classPath; } else { $this->rebuildClassPathCache($pluginDir, $cacheFile); } }
[ "public", "function", "addDirectory", "(", "$", "pluginDirectory", ")", "{", "$", "pluginDir", "=", "realpath", "(", "$", "pluginDirectory", ")", ";", "if", "(", "!", "$", "pluginDir", ")", "{", "throw", "new", "Dwoo_Exception", "(", "'Plugin directory does not exist or can not be read : '", ".", "$", "pluginDirectory", ")", ";", "}", "$", "cacheFile", "=", "$", "this", "->", "cacheDir", ".", "'classpath-'", ".", "substr", "(", "strtr", "(", "$", "pluginDir", ",", "'/\\\\:'", ".", "PATH_SEPARATOR", ",", "'----'", ")", ",", "strlen", "(", "$", "pluginDir", ")", ">", "80", "?", "-", "80", ":", "0", ")", ".", "'.d'", ".", "Dwoo", "::", "RELEASE_TAG", ".", "'.php'", ";", "$", "this", "->", "paths", "[", "$", "pluginDir", "]", "=", "$", "cacheFile", ";", "if", "(", "file_exists", "(", "$", "cacheFile", ")", ")", "{", "$", "classpath", "=", "file_get_contents", "(", "$", "cacheFile", ")", ";", "$", "this", "->", "classPath", "=", "unserialize", "(", "$", "classpath", ")", "+", "$", "this", "->", "classPath", ";", "}", "else", "{", "$", "this", "->", "rebuildClassPathCache", "(", "$", "pluginDir", ",", "$", "cacheFile", ")", ";", "}", "}" ]
adds a plugin directory, the plugins found in the new plugin directory will take precedence over the other directories (including the default dwoo plugin directory), you can use this for example to override plugins in a specific directory for a specific application while keeping all your usual plugins in the same place for all applications. TOCOM don't forget that php functions overrides are not rehashed so you need to clear the classpath caches by hand when adding those @param string $pluginDirectory the plugin path to scan
[ "adds", "a", "plugin", "directory", "the", "plugins", "found", "in", "the", "new", "plugin", "directory", "will", "take", "precedence", "over", "the", "other", "directories", "(", "including", "the", "default", "dwoo", "plugin", "directory", ")", "you", "can", "use", "this", "for", "example", "to", "override", "plugins", "in", "a", "specific", "directory", "for", "a", "specific", "application", "while", "keeping", "all", "your", "usual", "plugins", "in", "the", "same", "place", "for", "all", "applications", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Loader.php#L132-L146
eghojansu/moe
src/tools/Crypto.php
Crypto.encrypt
public function encrypt($string) { $string = serialize($string); $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC), MCRYPT_DEV_URANDOM); $key = pack('H*', $this->key); $mac = hash_hmac('sha256', $string, substr(bin2hex($key), -32)); $passcrypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $string.$mac, MCRYPT_MODE_CBC, $iv); return base64_encode($passcrypt).'|'.base64_encode($iv); }
php
public function encrypt($string) { $string = serialize($string); $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC), MCRYPT_DEV_URANDOM); $key = pack('H*', $this->key); $mac = hash_hmac('sha256', $string, substr(bin2hex($key), -32)); $passcrypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $string.$mac, MCRYPT_MODE_CBC, $iv); return base64_encode($passcrypt).'|'.base64_encode($iv); }
[ "public", "function", "encrypt", "(", "$", "string", ")", "{", "$", "string", "=", "serialize", "(", "$", "string", ")", ";", "$", "iv", "=", "mcrypt_create_iv", "(", "mcrypt_get_iv_size", "(", "MCRYPT_RIJNDAEL_256", ",", "MCRYPT_MODE_CBC", ")", ",", "MCRYPT_DEV_URANDOM", ")", ";", "$", "key", "=", "pack", "(", "'H*'", ",", "$", "this", "->", "key", ")", ";", "$", "mac", "=", "hash_hmac", "(", "'sha256'", ",", "$", "string", ",", "substr", "(", "bin2hex", "(", "$", "key", ")", ",", "-", "32", ")", ")", ";", "$", "passcrypt", "=", "mcrypt_encrypt", "(", "MCRYPT_RIJNDAEL_256", ",", "$", "key", ",", "$", "string", ".", "$", "mac", ",", "MCRYPT_MODE_CBC", ",", "$", "iv", ")", ";", "return", "base64_encode", "(", "$", "passcrypt", ")", ".", "'|'", ".", "base64_encode", "(", "$", "iv", ")", ";", "}" ]
Encrypt Function
[ "Encrypt", "Function" ]
train
https://github.com/eghojansu/moe/blob/f58ec75a3116d1a572782256e2b38bb9aab95e3c/src/tools/Crypto.php#L20-L28
eghojansu/moe
src/tools/Crypto.php
Crypto.decrypt
public function decrypt($string){ $string = explode('|', $string.'|'); $decoded = base64_decode($string[0]); $iv = base64_decode($string[1]); if(strlen($iv)!==mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC)) return false; $key = pack('H*', $this->key); $decrypted = trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $decoded, MCRYPT_MODE_CBC, $iv)); $mac = substr($decrypted, -64); $decrypted = substr($decrypted, 0, -64); $calcmac = hash_hmac('sha256', $decrypted, substr(bin2hex($key), -32)); if($calcmac!==$mac) return false; return unserialize($decrypted); }
php
public function decrypt($string){ $string = explode('|', $string.'|'); $decoded = base64_decode($string[0]); $iv = base64_decode($string[1]); if(strlen($iv)!==mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC)) return false; $key = pack('H*', $this->key); $decrypted = trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $decoded, MCRYPT_MODE_CBC, $iv)); $mac = substr($decrypted, -64); $decrypted = substr($decrypted, 0, -64); $calcmac = hash_hmac('sha256', $decrypted, substr(bin2hex($key), -32)); if($calcmac!==$mac) return false; return unserialize($decrypted); }
[ "public", "function", "decrypt", "(", "$", "string", ")", "{", "$", "string", "=", "explode", "(", "'|'", ",", "$", "string", ".", "'|'", ")", ";", "$", "decoded", "=", "base64_decode", "(", "$", "string", "[", "0", "]", ")", ";", "$", "iv", "=", "base64_decode", "(", "$", "string", "[", "1", "]", ")", ";", "if", "(", "strlen", "(", "$", "iv", ")", "!==", "mcrypt_get_iv_size", "(", "MCRYPT_RIJNDAEL_256", ",", "MCRYPT_MODE_CBC", ")", ")", "return", "false", ";", "$", "key", "=", "pack", "(", "'H*'", ",", "$", "this", "->", "key", ")", ";", "$", "decrypted", "=", "trim", "(", "mcrypt_decrypt", "(", "MCRYPT_RIJNDAEL_256", ",", "$", "key", ",", "$", "decoded", ",", "MCRYPT_MODE_CBC", ",", "$", "iv", ")", ")", ";", "$", "mac", "=", "substr", "(", "$", "decrypted", ",", "-", "64", ")", ";", "$", "decrypted", "=", "substr", "(", "$", "decrypted", ",", "0", ",", "-", "64", ")", ";", "$", "calcmac", "=", "hash_hmac", "(", "'sha256'", ",", "$", "decrypted", ",", "substr", "(", "bin2hex", "(", "$", "key", ")", ",", "-", "32", ")", ")", ";", "if", "(", "$", "calcmac", "!==", "$", "mac", ")", "return", "false", ";", "return", "unserialize", "(", "$", "decrypted", ")", ";", "}" ]
Decrypt Function
[ "Decrypt", "Function" ]
train
https://github.com/eghojansu/moe/blob/f58ec75a3116d1a572782256e2b38bb9aab95e3c/src/tools/Crypto.php#L31-L45
ekuiter/feature-php
FeaturePhp/File/TemplateFile.php
TemplateFile.render
public static function render($source, $rules = array(), $directory = null) { if (!$directory) $directory = getcwd(); return self::fromSpecification( fphp\Specification\TemplateSpecification::fromArrayAndSettings( array( "source" => $source, "rules" => $rules ), fphp\Settings::inDirectory($directory)) )->getContent()->getSummary(); }
php
public static function render($source, $rules = array(), $directory = null) { if (!$directory) $directory = getcwd(); return self::fromSpecification( fphp\Specification\TemplateSpecification::fromArrayAndSettings( array( "source" => $source, "rules" => $rules ), fphp\Settings::inDirectory($directory)) )->getContent()->getSummary(); }
[ "public", "static", "function", "render", "(", "$", "source", ",", "$", "rules", "=", "array", "(", ")", ",", "$", "directory", "=", "null", ")", "{", "if", "(", "!", "$", "directory", ")", "$", "directory", "=", "getcwd", "(", ")", ";", "return", "self", "::", "fromSpecification", "(", "fphp", "\\", "Specification", "\\", "TemplateSpecification", "::", "fromArrayAndSettings", "(", "array", "(", "\"source\"", "=>", "$", "source", ",", "\"rules\"", "=>", "$", "rules", ")", ",", "fphp", "\\", "Settings", "::", "inDirectory", "(", "$", "directory", ")", ")", ")", "->", "getContent", "(", ")", "->", "getSummary", "(", ")", ";", "}" ]
A quick way to directly render a template file with some replacement rules. @param string $source @param array[] $rules @param string $directory @return string
[ "A", "quick", "way", "to", "directly", "render", "a", "template", "file", "with", "some", "replacement", "rules", "." ]
train
https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/File/TemplateFile.php#L52-L63
ekuiter/feature-php
FeaturePhp/File/TemplateFile.php
TemplateFile.extend
public function extend($templateSpecification) { $rules = $templateSpecification->getRules(); $this->rules = array_merge($this->rules, $rules); $places = array(); $oldContent = file_get_contents($this->fileSource); foreach ($rules as $rule) { $newContent = $rule->apply($oldContent); foreach (fphp\Helper\Diff::compare($oldContent, $newContent) as $diff) if ($diff[1] === fphp\Helper\Diff::INSERTED) { $lineNumber = "?"; foreach (explode("\n", $newContent) as $idx => $line) if ($line === $diff[0]) $lineNumber = $idx + 1; $places[] = array( new fphp\Artifact\LinePlace($templateSpecification->getSource(), $lineNumber), new fphp\Artifact\LinePlace($templateSpecification->getTarget(), $lineNumber) ); } } return $places; }
php
public function extend($templateSpecification) { $rules = $templateSpecification->getRules(); $this->rules = array_merge($this->rules, $rules); $places = array(); $oldContent = file_get_contents($this->fileSource); foreach ($rules as $rule) { $newContent = $rule->apply($oldContent); foreach (fphp\Helper\Diff::compare($oldContent, $newContent) as $diff) if ($diff[1] === fphp\Helper\Diff::INSERTED) { $lineNumber = "?"; foreach (explode("\n", $newContent) as $idx => $line) if ($line === $diff[0]) $lineNumber = $idx + 1; $places[] = array( new fphp\Artifact\LinePlace($templateSpecification->getSource(), $lineNumber), new fphp\Artifact\LinePlace($templateSpecification->getTarget(), $lineNumber) ); } } return $places; }
[ "public", "function", "extend", "(", "$", "templateSpecification", ")", "{", "$", "rules", "=", "$", "templateSpecification", "->", "getRules", "(", ")", ";", "$", "this", "->", "rules", "=", "array_merge", "(", "$", "this", "->", "rules", ",", "$", "rules", ")", ";", "$", "places", "=", "array", "(", ")", ";", "$", "oldContent", "=", "file_get_contents", "(", "$", "this", "->", "fileSource", ")", ";", "foreach", "(", "$", "rules", "as", "$", "rule", ")", "{", "$", "newContent", "=", "$", "rule", "->", "apply", "(", "$", "oldContent", ")", ";", "foreach", "(", "fphp", "\\", "Helper", "\\", "Diff", "::", "compare", "(", "$", "oldContent", ",", "$", "newContent", ")", "as", "$", "diff", ")", "if", "(", "$", "diff", "[", "1", "]", "===", "fphp", "\\", "Helper", "\\", "Diff", "::", "INSERTED", ")", "{", "$", "lineNumber", "=", "\"?\"", ";", "foreach", "(", "explode", "(", "\"\\n\"", ",", "$", "newContent", ")", "as", "$", "idx", "=>", "$", "line", ")", "if", "(", "$", "line", "===", "$", "diff", "[", "0", "]", ")", "$", "lineNumber", "=", "$", "idx", "+", "1", ";", "$", "places", "[", "]", "=", "array", "(", "new", "fphp", "\\", "Artifact", "\\", "LinePlace", "(", "$", "templateSpecification", "->", "getSource", "(", ")", ",", "$", "lineNumber", ")", ",", "new", "fphp", "\\", "Artifact", "\\", "LinePlace", "(", "$", "templateSpecification", "->", "getTarget", "(", ")", ",", "$", "lineNumber", ")", ")", ";", "}", "}", "return", "$", "places", ";", "}" ]
Adds rules to the template file. This is expected to be called only be a {@see \FeaturePhp\Generator\TemplateGenerator}. Only uses the rules of the template specification. @param \FeaturePhp\Specification\TemplateSpecification $templateSpecification @return \FeaturePhp\Place\Place[]
[ "Adds", "rules", "to", "the", "template", "file", ".", "This", "is", "expected", "to", "be", "called", "only", "be", "a", "{" ]
train
https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/File/TemplateFile.php#L72-L93
ekuiter/feature-php
FeaturePhp/File/TemplateFile.php
TemplateFile.getContent
public function getContent() { $content = file_get_contents($this->fileSource); foreach ($this->rules as $rule) $content = $rule->apply($content); return new TextFileContent($content); }
php
public function getContent() { $content = file_get_contents($this->fileSource); foreach ($this->rules as $rule) $content = $rule->apply($content); return new TextFileContent($content); }
[ "public", "function", "getContent", "(", ")", "{", "$", "content", "=", "file_get_contents", "(", "$", "this", "->", "fileSource", ")", ";", "foreach", "(", "$", "this", "->", "rules", "as", "$", "rule", ")", "$", "content", "=", "$", "rule", "->", "apply", "(", "$", "content", ")", ";", "return", "new", "TextFileContent", "(", "$", "content", ")", ";", "}" ]
Returns the template file's content. The content consists of the file content with every rule applied. @return TextFileContent
[ "Returns", "the", "template", "file", "s", "content", ".", "The", "content", "consists", "of", "the", "file", "content", "with", "every", "rule", "applied", "." ]
train
https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/File/TemplateFile.php#L100-L105
phPoirot/psr7
Stream.php
Stream.getSize
function getSize() { if (!$this->_assertUsable()) return null; $size = null; if ($uri = $this->getMetadata('uri')) ## clear the stat cache of stream URI clearstatcache(true, $uri); $stats = fstat($this->rHandler); if (isset($stats['size'])) $size = $stats['size']; return $size; }
php
function getSize() { if (!$this->_assertUsable()) return null; $size = null; if ($uri = $this->getMetadata('uri')) ## clear the stat cache of stream URI clearstatcache(true, $uri); $stats = fstat($this->rHandler); if (isset($stats['size'])) $size = $stats['size']; return $size; }
[ "function", "getSize", "(", ")", "{", "if", "(", "!", "$", "this", "->", "_assertUsable", "(", ")", ")", "return", "null", ";", "$", "size", "=", "null", ";", "if", "(", "$", "uri", "=", "$", "this", "->", "getMetadata", "(", "'uri'", ")", ")", "## clear the stat cache of stream URI", "clearstatcache", "(", "true", ",", "$", "uri", ")", ";", "$", "stats", "=", "fstat", "(", "$", "this", "->", "rHandler", ")", ";", "if", "(", "isset", "(", "$", "stats", "[", "'size'", "]", ")", ")", "$", "size", "=", "$", "stats", "[", "'size'", "]", ";", "return", "$", "size", ";", "}" ]
Get the size of the stream if known. @return int|null Returns the size in bytes if known, or null if unknown.
[ "Get", "the", "size", "of", "the", "stream", "if", "known", "." ]
train
https://github.com/phPoirot/psr7/blob/e90295e806dc2eb0cc422f315075f673c63a0780/Stream.php#L115-L130
phPoirot/psr7
Stream.php
Stream.tell
function tell() { if (!$this->_assertUsable()) throw new \RuntimeException('No resource available; cannot tell position'); if (false === $r = ftell($this->rHandler)) throw new \RuntimeException('Unable to determine stream position'); return $r; }
php
function tell() { if (!$this->_assertUsable()) throw new \RuntimeException('No resource available; cannot tell position'); if (false === $r = ftell($this->rHandler)) throw new \RuntimeException('Unable to determine stream position'); return $r; }
[ "function", "tell", "(", ")", "{", "if", "(", "!", "$", "this", "->", "_assertUsable", "(", ")", ")", "throw", "new", "\\", "RuntimeException", "(", "'No resource available; cannot tell position'", ")", ";", "if", "(", "false", "===", "$", "r", "=", "ftell", "(", "$", "this", "->", "rHandler", ")", ")", "throw", "new", "\\", "RuntimeException", "(", "'Unable to determine stream position'", ")", ";", "return", "$", "r", ";", "}" ]
Returns the current position of the file read/write pointer @return int Position of the file pointer @throws \RuntimeException on error.
[ "Returns", "the", "current", "position", "of", "the", "file", "read", "/", "write", "pointer" ]
train
https://github.com/phPoirot/psr7/blob/e90295e806dc2eb0cc422f315075f673c63a0780/Stream.php#L138-L147
phPoirot/psr7
Stream.php
Stream.isSeekable
function isSeekable() { if (!$this->_assertUsable()) return false; if ($this->getMetadata('wrapper_type')) { // This is a wrapper resource; challenge seekable ... $pos = $this->tell(); if (-1 === @fseek($this->rHandler, $pos, SEEK_SET)) return false; } return $this->getMetadata('seekable'); }
php
function isSeekable() { if (!$this->_assertUsable()) return false; if ($this->getMetadata('wrapper_type')) { // This is a wrapper resource; challenge seekable ... $pos = $this->tell(); if (-1 === @fseek($this->rHandler, $pos, SEEK_SET)) return false; } return $this->getMetadata('seekable'); }
[ "function", "isSeekable", "(", ")", "{", "if", "(", "!", "$", "this", "->", "_assertUsable", "(", ")", ")", "return", "false", ";", "if", "(", "$", "this", "->", "getMetadata", "(", "'wrapper_type'", ")", ")", "{", "// This is a wrapper resource; challenge seekable ...", "$", "pos", "=", "$", "this", "->", "tell", "(", ")", ";", "if", "(", "-", "1", "===", "@", "fseek", "(", "$", "this", "->", "rHandler", ",", "$", "pos", ",", "SEEK_SET", ")", ")", "return", "false", ";", "}", "return", "$", "this", "->", "getMetadata", "(", "'seekable'", ")", ";", "}" ]
Returns whether or not the stream is seekable. note: StreamWrapper implementations have no control over the "seekable" property of stream_get_meta_data() and always advertise themselves as seekable. @return bool
[ "Returns", "whether", "or", "not", "the", "stream", "is", "seekable", "." ]
train
https://github.com/phPoirot/psr7/blob/e90295e806dc2eb0cc422f315075f673c63a0780/Stream.php#L168-L181
phPoirot/psr7
Stream.php
Stream.seek
function seek($offset, $whence = SEEK_SET) { if (!$this->_assertUsable()) throw new \RuntimeException('No resource available; cannot seek position'); if (-1 === @fseek($this->rHandler, $offset, $whence)) throw new \RuntimeException('Cannot seek on stream'); }
php
function seek($offset, $whence = SEEK_SET) { if (!$this->_assertUsable()) throw new \RuntimeException('No resource available; cannot seek position'); if (-1 === @fseek($this->rHandler, $offset, $whence)) throw new \RuntimeException('Cannot seek on stream'); }
[ "function", "seek", "(", "$", "offset", ",", "$", "whence", "=", "SEEK_SET", ")", "{", "if", "(", "!", "$", "this", "->", "_assertUsable", "(", ")", ")", "throw", "new", "\\", "RuntimeException", "(", "'No resource available; cannot seek position'", ")", ";", "if", "(", "-", "1", "===", "@", "fseek", "(", "$", "this", "->", "rHandler", ",", "$", "offset", ",", "$", "whence", ")", ")", "throw", "new", "\\", "RuntimeException", "(", "'Cannot seek on stream'", ")", ";", "}" ]
Seek to a position in the stream. @link http://www.php.net/manual/en/function.fseek.php @param int $offset Stream offset @param int $whence Specifies how the cursor position will be calculated based on the seek offset. Valid values are identical to the built-in PHP $whence values for `fseek()`. SEEK_SET: Set position equal to offset bytes SEEK_CUR: Set position to current location plus offset SEEK_END: Set position to end-of-stream plus offset. @throws \RuntimeException on failure.
[ "Seek", "to", "a", "position", "in", "the", "stream", "." ]
train
https://github.com/phPoirot/psr7/blob/e90295e806dc2eb0cc422f315075f673c63a0780/Stream.php#L195-L202
phPoirot/psr7
Stream.php
Stream.isWritable
function isWritable() { if (!$this->_assertUsable()) return false; $mode = $this->getMetadata('mode'); return in_array($mode, self::$readWriteHash['write']); }
php
function isWritable() { if (!$this->_assertUsable()) return false; $mode = $this->getMetadata('mode'); return in_array($mode, self::$readWriteHash['write']); }
[ "function", "isWritable", "(", ")", "{", "if", "(", "!", "$", "this", "->", "_assertUsable", "(", ")", ")", "return", "false", ";", "$", "mode", "=", "$", "this", "->", "getMetadata", "(", "'mode'", ")", ";", "return", "in_array", "(", "$", "mode", ",", "self", "::", "$", "readWriteHash", "[", "'write'", "]", ")", ";", "}" ]
Returns whether or not the stream is writable. @return bool
[ "Returns", "whether", "or", "not", "the", "stream", "is", "writable", "." ]
train
https://github.com/phPoirot/psr7/blob/e90295e806dc2eb0cc422f315075f673c63a0780/Stream.php#L225-L232
phPoirot/psr7
Stream.php
Stream.write
function write($string) { if (!$this->_assertUsable()) throw new \RuntimeException('No resource available; cannot write'); if (!$this->isWritable()) throw new \RuntimeException('resource is not writable.'); $content = (string) $string; $result = fwrite($this->rHandler, $content); if (false === $result) throw new \RuntimeException('Cannot write on stream.'); if (function_exists('mb_strlen')) $transCount = mb_strlen($content, '8bit'); else $transCount = strlen($content); return $transCount; }
php
function write($string) { if (!$this->_assertUsable()) throw new \RuntimeException('No resource available; cannot write'); if (!$this->isWritable()) throw new \RuntimeException('resource is not writable.'); $content = (string) $string; $result = fwrite($this->rHandler, $content); if (false === $result) throw new \RuntimeException('Cannot write on stream.'); if (function_exists('mb_strlen')) $transCount = mb_strlen($content, '8bit'); else $transCount = strlen($content); return $transCount; }
[ "function", "write", "(", "$", "string", ")", "{", "if", "(", "!", "$", "this", "->", "_assertUsable", "(", ")", ")", "throw", "new", "\\", "RuntimeException", "(", "'No resource available; cannot write'", ")", ";", "if", "(", "!", "$", "this", "->", "isWritable", "(", ")", ")", "throw", "new", "\\", "RuntimeException", "(", "'resource is not writable.'", ")", ";", "$", "content", "=", "(", "string", ")", "$", "string", ";", "$", "result", "=", "fwrite", "(", "$", "this", "->", "rHandler", ",", "$", "content", ")", ";", "if", "(", "false", "===", "$", "result", ")", "throw", "new", "\\", "RuntimeException", "(", "'Cannot write on stream.'", ")", ";", "if", "(", "function_exists", "(", "'mb_strlen'", ")", ")", "$", "transCount", "=", "mb_strlen", "(", "$", "content", ",", "'8bit'", ")", ";", "else", "$", "transCount", "=", "strlen", "(", "$", "content", ")", ";", "return", "$", "transCount", ";", "}" ]
Write data to the stream. @param string $string The string that is to be written. @return int Returns the number of bytes written to the stream. @throws \RuntimeException on failure.
[ "Write", "data", "to", "the", "stream", "." ]
train
https://github.com/phPoirot/psr7/blob/e90295e806dc2eb0cc422f315075f673c63a0780/Stream.php#L241-L261
phPoirot/psr7
Stream.php
Stream.read
function read($length) { if (!$this->_assertUsable()) throw new \RuntimeException('No resource alive; cannot read.'); if (!$this->isReadable()) throw new \RuntimeException('resource is not readable.'); $data = stream_get_contents($this->rHandler, $length); if (false === $data) throw new \RuntimeException('Cannot read stream.'); return $data; }
php
function read($length) { if (!$this->_assertUsable()) throw new \RuntimeException('No resource alive; cannot read.'); if (!$this->isReadable()) throw new \RuntimeException('resource is not readable.'); $data = stream_get_contents($this->rHandler, $length); if (false === $data) throw new \RuntimeException('Cannot read stream.'); return $data; }
[ "function", "read", "(", "$", "length", ")", "{", "if", "(", "!", "$", "this", "->", "_assertUsable", "(", ")", ")", "throw", "new", "\\", "RuntimeException", "(", "'No resource alive; cannot read.'", ")", ";", "if", "(", "!", "$", "this", "->", "isReadable", "(", ")", ")", "throw", "new", "\\", "RuntimeException", "(", "'resource is not readable.'", ")", ";", "$", "data", "=", "stream_get_contents", "(", "$", "this", "->", "rHandler", ",", "$", "length", ")", ";", "if", "(", "false", "===", "$", "data", ")", "throw", "new", "\\", "RuntimeException", "(", "'Cannot read stream.'", ")", ";", "return", "$", "data", ";", "}" ]
Read data from the stream. @param int $length Read up to $length bytes from the object and return them. Fewer than $length bytes may be returned if underlying stream call returns fewer bytes. @return string Returns the data read from the stream, or an empty string if no bytes are available. @throws \RuntimeException if an error occurs.
[ "Read", "data", "from", "the", "stream", "." ]
train
https://github.com/phPoirot/psr7/blob/e90295e806dc2eb0cc422f315075f673c63a0780/Stream.php#L288-L301
phPoirot/psr7
Stream.php
Stream.getContents
function getContents() { if (!$this->isReadable()) throw new \RuntimeException('Stream is not readable.'); $content = ''; while (!$this->eof()) { $buf = $this->read(1048576); // match on '' and false by loose equal if ($buf == null) break; $content .= $buf; } return $content; }
php
function getContents() { if (!$this->isReadable()) throw new \RuntimeException('Stream is not readable.'); $content = ''; while (!$this->eof()) { $buf = $this->read(1048576); // match on '' and false by loose equal if ($buf == null) break; $content .= $buf; } return $content; }
[ "function", "getContents", "(", ")", "{", "if", "(", "!", "$", "this", "->", "isReadable", "(", ")", ")", "throw", "new", "\\", "RuntimeException", "(", "'Stream is not readable.'", ")", ";", "$", "content", "=", "''", ";", "while", "(", "!", "$", "this", "->", "eof", "(", ")", ")", "{", "$", "buf", "=", "$", "this", "->", "read", "(", "1048576", ")", ";", "// match on '' and false by loose equal", "if", "(", "$", "buf", "==", "null", ")", "break", ";", "$", "content", ".=", "$", "buf", ";", "}", "return", "$", "content", ";", "}" ]
Returns the remaining contents in a string @return string @throws \RuntimeException if unable to read or an error occurs while reading.
[ "Returns", "the", "remaining", "contents", "in", "a", "string" ]
train
https://github.com/phPoirot/psr7/blob/e90295e806dc2eb0cc422f315075f673c63a0780/Stream.php#L310-L326
phPoirot/psr7
Stream.php
Stream.getMetadata
function getMetadata($key = null) { if (!$this->_assertUsable()) return ($key === null) ? array() : null; $meta = stream_get_meta_data($this->rHandler); if ($key === null) return $meta; return (array_key_exists($key, $meta)) ? $meta[$key] : null; }
php
function getMetadata($key = null) { if (!$this->_assertUsable()) return ($key === null) ? array() : null; $meta = stream_get_meta_data($this->rHandler); if ($key === null) return $meta; return (array_key_exists($key, $meta)) ? $meta[$key] : null; }
[ "function", "getMetadata", "(", "$", "key", "=", "null", ")", "{", "if", "(", "!", "$", "this", "->", "_assertUsable", "(", ")", ")", "return", "(", "$", "key", "===", "null", ")", "?", "array", "(", ")", ":", "null", ";", "$", "meta", "=", "stream_get_meta_data", "(", "$", "this", "->", "rHandler", ")", ";", "if", "(", "$", "key", "===", "null", ")", "return", "$", "meta", ";", "return", "(", "array_key_exists", "(", "$", "key", ",", "$", "meta", ")", ")", "?", "$", "meta", "[", "$", "key", "]", ":", "null", ";", "}" ]
Get stream metadata as an associative array or retrieve a specific key. The keys returned are identical to the keys returned from PHP's stream_get_meta_data() function. @link http://php.net/manual/en/function.stream-get-meta-data.php @param string $key Specific metadata to retrieve. @return array|mixed|null Returns an associative array if no key is provided. Returns a specific key value if a key is provided and the value is found, or null if the key is not found.
[ "Get", "stream", "metadata", "as", "an", "associative", "array", "or", "retrieve", "a", "specific", "key", "." ]
train
https://github.com/phPoirot/psr7/blob/e90295e806dc2eb0cc422f315075f673c63a0780/Stream.php#L340-L352
Smile-SA/EzUICronBundle
Controller/CronsController.php
CronsController.listAction
public function listAction() { $this->performAccessChecks(); $crons = $this->cronService->getCrons(); return $this->render('SmileEzUICronBundle:cron:tab/crons/list.html.twig', [ 'datas' => $crons ]); }
php
public function listAction() { $this->performAccessChecks(); $crons = $this->cronService->getCrons(); return $this->render('SmileEzUICronBundle:cron:tab/crons/list.html.twig', [ 'datas' => $crons ]); }
[ "public", "function", "listAction", "(", ")", "{", "$", "this", "->", "performAccessChecks", "(", ")", ";", "$", "crons", "=", "$", "this", "->", "cronService", "->", "getCrons", "(", ")", ";", "return", "$", "this", "->", "render", "(", "'SmileEzUICronBundle:cron:tab/crons/list.html.twig'", ",", "[", "'datas'", "=>", "$", "crons", "]", ")", ";", "}" ]
List crons definition @return Response
[ "List", "crons", "definition" ]
train
https://github.com/Smile-SA/EzUICronBundle/blob/c62fc6a3ab0b39e3f911742d9affe4aade90cf66/Controller/CronsController.php#L44-L53
Smile-SA/EzUICronBundle
Controller/CronsController.php
CronsController.editAction
public function editAction(Request $request, $type, $alias) { $this->performAccessChecks(); $value = $request->get('value'); $response = new Response(); try { $this->cronService->updateCron($alias, $type, $value); $response->setStatusCode( 200, $this->translator->trans('cron.edit.done', ['%type%' => $type, '%alias%' => $alias], 'smileezcron') ); } catch (NotFoundException $e) { $response->setStatusCode(500, $e->getMessage()); } catch (InvalidArgumentException $e) { $response->setStatusCode(500, $e->getMessage()); } return $response; }
php
public function editAction(Request $request, $type, $alias) { $this->performAccessChecks(); $value = $request->get('value'); $response = new Response(); try { $this->cronService->updateCron($alias, $type, $value); $response->setStatusCode( 200, $this->translator->trans('cron.edit.done', ['%type%' => $type, '%alias%' => $alias], 'smileezcron') ); } catch (NotFoundException $e) { $response->setStatusCode(500, $e->getMessage()); } catch (InvalidArgumentException $e) { $response->setStatusCode(500, $e->getMessage()); } return $response; }
[ "public", "function", "editAction", "(", "Request", "$", "request", ",", "$", "type", ",", "$", "alias", ")", "{", "$", "this", "->", "performAccessChecks", "(", ")", ";", "$", "value", "=", "$", "request", "->", "get", "(", "'value'", ")", ";", "$", "response", "=", "new", "Response", "(", ")", ";", "try", "{", "$", "this", "->", "cronService", "->", "updateCron", "(", "$", "alias", ",", "$", "type", ",", "$", "value", ")", ";", "$", "response", "->", "setStatusCode", "(", "200", ",", "$", "this", "->", "translator", "->", "trans", "(", "'cron.edit.done'", ",", "[", "'%type%'", "=>", "$", "type", ",", "'%alias%'", "=>", "$", "alias", "]", ",", "'smileezcron'", ")", ")", ";", "}", "catch", "(", "NotFoundException", "$", "e", ")", "{", "$", "response", "->", "setStatusCode", "(", "500", ",", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "catch", "(", "InvalidArgumentException", "$", "e", ")", "{", "$", "response", "->", "setStatusCode", "(", "500", ",", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "return", "$", "response", ";", "}" ]
Edition cron definition @param Request $request @param string $type cron property identifier @param string $alias cron alias identifier @return Response
[ "Edition", "cron", "definition" ]
train
https://github.com/Smile-SA/EzUICronBundle/blob/c62fc6a3ab0b39e3f911742d9affe4aade90cf66/Controller/CronsController.php#L63-L84
lyt8384/pingpp-laravel5-plus
src/PingppServiceProvider.php
PingppServiceProvider.register
public function register() { $config = config('pingpp'); $this->app->bind('pingpp', function () use ($config) { Pingpp::setApiKey( $config['live'] === true ? $config['live_secret_key'] : $config['test_secret_key'] ); if(!empty($config['private_key_path']) && file_exists($config['private_key_path'])){ Pingpp::setPrivateKeyPath($config['private_key_path']); } return new PingppCollertion(); }); }
php
public function register() { $config = config('pingpp'); $this->app->bind('pingpp', function () use ($config) { Pingpp::setApiKey( $config['live'] === true ? $config['live_secret_key'] : $config['test_secret_key'] ); if(!empty($config['private_key_path']) && file_exists($config['private_key_path'])){ Pingpp::setPrivateKeyPath($config['private_key_path']); } return new PingppCollertion(); }); }
[ "public", "function", "register", "(", ")", "{", "$", "config", "=", "config", "(", "'pingpp'", ")", ";", "$", "this", "->", "app", "->", "bind", "(", "'pingpp'", ",", "function", "(", ")", "use", "(", "$", "config", ")", "{", "Pingpp", "::", "setApiKey", "(", "$", "config", "[", "'live'", "]", "===", "true", "?", "$", "config", "[", "'live_secret_key'", "]", ":", "$", "config", "[", "'test_secret_key'", "]", ")", ";", "if", "(", "!", "empty", "(", "$", "config", "[", "'private_key_path'", "]", ")", "&&", "file_exists", "(", "$", "config", "[", "'private_key_path'", "]", ")", ")", "{", "Pingpp", "::", "setPrivateKeyPath", "(", "$", "config", "[", "'private_key_path'", "]", ")", ";", "}", "return", "new", "PingppCollertion", "(", ")", ";", "}", ")", ";", "}" ]
Register the service provider. @return void
[ "Register", "the", "service", "provider", "." ]
train
https://github.com/lyt8384/pingpp-laravel5-plus/blob/6266d764e51cdc13b37e71d184ac257bff8ee5d7/src/PingppServiceProvider.php#L22-L39
codezero-be/laravel-localizer
src/Localizer.php
Localizer.detect
public function detect() { foreach ($this->detectors as $detector) { $locales = (array) $this->getInstance($detector)->detect(); foreach ($locales as $locale) { if ($this->isSupportedLocale($locale)) { return $locale; } } } return false; }
php
public function detect() { foreach ($this->detectors as $detector) { $locales = (array) $this->getInstance($detector)->detect(); foreach ($locales as $locale) { if ($this->isSupportedLocale($locale)) { return $locale; } } } return false; }
[ "public", "function", "detect", "(", ")", "{", "foreach", "(", "$", "this", "->", "detectors", "as", "$", "detector", ")", "{", "$", "locales", "=", "(", "array", ")", "$", "this", "->", "getInstance", "(", "$", "detector", ")", "->", "detect", "(", ")", ";", "foreach", "(", "$", "locales", "as", "$", "locale", ")", "{", "if", "(", "$", "this", "->", "isSupportedLocale", "(", "$", "locale", ")", ")", "{", "return", "$", "locale", ";", "}", "}", "}", "return", "false", ";", "}" ]
Detect any supported locale and return the first match. @return string|false
[ "Detect", "any", "supported", "locale", "and", "return", "the", "first", "match", "." ]
train
https://github.com/codezero-be/laravel-localizer/blob/812692796a73bd38fc205404d8ef90df5bfa0d83/src/Localizer.php#L49-L62
codezero-be/laravel-localizer
src/Localizer.php
Localizer.store
public function store($locale) { foreach ($this->stores as $store) { $this->getInstance($store)->store($locale); } }
php
public function store($locale) { foreach ($this->stores as $store) { $this->getInstance($store)->store($locale); } }
[ "public", "function", "store", "(", "$", "locale", ")", "{", "foreach", "(", "$", "this", "->", "stores", "as", "$", "store", ")", "{", "$", "this", "->", "getInstance", "(", "$", "store", ")", "->", "store", "(", "$", "locale", ")", ";", "}", "}" ]
Store the given locale. @param string $locale @return void
[ "Store", "the", "given", "locale", "." ]
train
https://github.com/codezero-be/laravel-localizer/blob/812692796a73bd38fc205404d8ef90df5bfa0d83/src/Localizer.php#L71-L76
zhouyl/mellivora
Mellivora/Helper/Protobuf/MessageWrapper.php
MessageWrapper.from
public function from($data) { if (is_string($data)) { $this->message->mergeFromString($data); } elseif (!empty($data)) { $this->set(Arr::convert($data)); } return $this; }
php
public function from($data) { if (is_string($data)) { $this->message->mergeFromString($data); } elseif (!empty($data)) { $this->set(Arr::convert($data)); } return $this; }
[ "public", "function", "from", "(", "$", "data", ")", "{", "if", "(", "is_string", "(", "$", "data", ")", ")", "{", "$", "this", "->", "message", "->", "mergeFromString", "(", "$", "data", ")", ";", "}", "elseif", "(", "!", "empty", "(", "$", "data", ")", ")", "{", "$", "this", "->", "set", "(", "Arr", "::", "convert", "(", "$", "data", ")", ")", ";", "}", "return", "$", "this", ";", "}" ]
设定来源数据,可以是序列化之后的字符,也可以是数组数据 @param mixed $data @return \Mellivora\Helper\Protobuf\MessageWrapper
[ "设定来源数据,可以是序列化之后的字符,也可以是数组数据" ]
train
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Helper/Protobuf/MessageWrapper.php#L83-L92
zhouyl/mellivora
Mellivora/Helper/Protobuf/MessageWrapper.php
MessageWrapper.set
public function set($property, $value = null) { if (is_array($property)) { foreach ($property as $k => $v) { $this->set($k, $v); } return $this; } if ($this->has($property)) { $method = 'set' . Str::studly($property); $value = $this->sanitizeSetterValue($method, $value); $this->message->{$method}($value); } return $this; }
php
public function set($property, $value = null) { if (is_array($property)) { foreach ($property as $k => $v) { $this->set($k, $v); } return $this; } if ($this->has($property)) { $method = 'set' . Str::studly($property); $value = $this->sanitizeSetterValue($method, $value); $this->message->{$method}($value); } return $this; }
[ "public", "function", "set", "(", "$", "property", ",", "$", "value", "=", "null", ")", "{", "if", "(", "is_array", "(", "$", "property", ")", ")", "{", "foreach", "(", "$", "property", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "this", "->", "set", "(", "$", "k", ",", "$", "v", ")", ";", "}", "return", "$", "this", ";", "}", "if", "(", "$", "this", "->", "has", "(", "$", "property", ")", ")", "{", "$", "method", "=", "'set'", ".", "Str", "::", "studly", "(", "$", "property", ")", ";", "$", "value", "=", "$", "this", "->", "sanitizeSetterValue", "(", "$", "method", ",", "$", "value", ")", ";", "$", "this", "->", "message", "->", "{", "$", "method", "}", "(", "$", "value", ")", ";", "}", "return", "$", "this", ";", "}" ]
为 Message 设定数据 @param mixed $property @param mixed $data @param null|mixed $value @return \Mellivora\Helper\Protobuf\MessageWrapper
[ "为", "Message", "设定数据" ]
train
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Helper/Protobuf/MessageWrapper.php#L123-L141
zhouyl/mellivora
Mellivora/Helper/Protobuf/MessageWrapper.php
MessageWrapper.get
public function get($property, $default = null) { if ($this->has($property)) { $method = 'get' . Str::studly($property); $return = $this->message->{$method}(); return is_null($return) ? $default : $return; } return $default; }
php
public function get($property, $default = null) { if ($this->has($property)) { $method = 'get' . Str::studly($property); $return = $this->message->{$method}(); return is_null($return) ? $default : $return; } return $default; }
[ "public", "function", "get", "(", "$", "property", ",", "$", "default", "=", "null", ")", "{", "if", "(", "$", "this", "->", "has", "(", "$", "property", ")", ")", "{", "$", "method", "=", "'get'", ".", "Str", "::", "studly", "(", "$", "property", ")", ";", "$", "return", "=", "$", "this", "->", "message", "->", "{", "$", "method", "}", "(", ")", ";", "return", "is_null", "(", "$", "return", ")", "?", "$", "default", ":", "$", "return", ";", "}", "return", "$", "default", ";", "}" ]
从 Message 中获取数据 @param string $property @param mixed $default @return mixed
[ "从", "Message", "中获取数据" ]
train
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Helper/Protobuf/MessageWrapper.php#L151-L161
zhouyl/mellivora
Mellivora/Helper/Protobuf/MessageWrapper.php
MessageWrapper.has
public function has($key) { return $this->ref->hasProperty($key) || $this->ref->hasProperty(Str::snake($key)); }
php
public function has($key) { return $this->ref->hasProperty($key) || $this->ref->hasProperty(Str::snake($key)); }
[ "public", "function", "has", "(", "$", "key", ")", "{", "return", "$", "this", "->", "ref", "->", "hasProperty", "(", "$", "key", ")", "||", "$", "this", "->", "ref", "->", "hasProperty", "(", "Str", "::", "snake", "(", "$", "key", ")", ")", ";", "}" ]
判断 Message 中是否存在指定的属性 @param string $key @return bool
[ "判断", "Message", "中是否存在指定的属性" ]
train
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Helper/Protobuf/MessageWrapper.php#L170-L173
zhouyl/mellivora
Mellivora/Helper/Protobuf/MessageWrapper.php
MessageWrapper.toArray
public function toArray() { $data = []; foreach ($this->ref->getProperties() as $property) { $name = $property->getName(); $data[$name] = $this->sanitizeToArrayValue($this->get($name)); } return $data; }
php
public function toArray() { $data = []; foreach ($this->ref->getProperties() as $property) { $name = $property->getName(); $data[$name] = $this->sanitizeToArrayValue($this->get($name)); } return $data; }
[ "public", "function", "toArray", "(", ")", "{", "$", "data", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "ref", "->", "getProperties", "(", ")", "as", "$", "property", ")", "{", "$", "name", "=", "$", "property", "->", "getName", "(", ")", ";", "$", "data", "[", "$", "name", "]", "=", "$", "this", "->", "sanitizeToArrayValue", "(", "$", "this", "->", "get", "(", "$", "name", ")", ")", ";", "}", "return", "$", "data", ";", "}" ]
将 Message 属性数据转换为 array @return array
[ "将", "Message", "属性数据转换为", "array" ]
train
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Helper/Protobuf/MessageWrapper.php#L192-L202
zhouyl/mellivora
Mellivora/Helper/Protobuf/MessageWrapper.php
MessageWrapper.getSetterRestrict
protected function getSetterRestrict($method) { $namespace = $this->ref->getNamespaceName(); $document = $this->ref->getMethod($method)->getDocComment(); $regex = sprintf( '~<code>(repeated\s*)?\.?(%s\.[\w\-]+).*<\/code>~', preg_quote(str_replace('\\', '.', $namespace)) ); preg_match($regex, $document, $matches); if (isset($matches[2])) { $class = str_replace('.', '\\', $matches[2]); if (class_exists($class) && is_subclass_of($class, Message::class)) { return [!empty($matches[1]), $class]; } } return false; }
php
protected function getSetterRestrict($method) { $namespace = $this->ref->getNamespaceName(); $document = $this->ref->getMethod($method)->getDocComment(); $regex = sprintf( '~<code>(repeated\s*)?\.?(%s\.[\w\-]+).*<\/code>~', preg_quote(str_replace('\\', '.', $namespace)) ); preg_match($regex, $document, $matches); if (isset($matches[2])) { $class = str_replace('.', '\\', $matches[2]); if (class_exists($class) && is_subclass_of($class, Message::class)) { return [!empty($matches[1]), $class]; } } return false; }
[ "protected", "function", "getSetterRestrict", "(", "$", "method", ")", "{", "$", "namespace", "=", "$", "this", "->", "ref", "->", "getNamespaceName", "(", ")", ";", "$", "document", "=", "$", "this", "->", "ref", "->", "getMethod", "(", "$", "method", ")", "->", "getDocComment", "(", ")", ";", "$", "regex", "=", "sprintf", "(", "'~<code>(repeated\\s*)?\\.?(%s\\.[\\w\\-]+).*<\\/code>~'", ",", "preg_quote", "(", "str_replace", "(", "'\\\\'", ",", "'.'", ",", "$", "namespace", ")", ")", ")", ";", "preg_match", "(", "$", "regex", ",", "$", "document", ",", "$", "matches", ")", ";", "if", "(", "isset", "(", "$", "matches", "[", "2", "]", ")", ")", "{", "$", "class", "=", "str_replace", "(", "'.'", ",", "'\\\\'", ",", "$", "matches", "[", "2", "]", ")", ";", "if", "(", "class_exists", "(", "$", "class", ")", "&&", "is_subclass_of", "(", "$", "class", ",", "Message", "::", "class", ")", ")", "{", "return", "[", "!", "empty", "(", "$", "matches", "[", "1", "]", ")", ",", "$", "class", "]", ";", "}", "}", "return", "false", ";", "}" ]
根据 protobuf 生成的代码,尝试从注释中匹配参数的约束类 例如 <code>.Proto.PayCenter.StatusInfo status_info = 1;</code> <code>repeated .Proto.PayCenter.PayPaymentItem payment_list = 3;</code> @param string $method @return array|false
[ "根据", "protobuf", "生成的代码,尝试从注释中匹配参数的约束类" ]
train
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Helper/Protobuf/MessageWrapper.php#L246-L266
zhouyl/mellivora
Mellivora/Helper/Protobuf/MessageWrapper.php
MessageWrapper.sanitizeSetterValue
protected function sanitizeSetterValue($setter, $value) { if ($value instanceof self) { return $value->raw(); } // 获取 setter 方法的约束条件 if (!(is_array($value) && $restrict = $this->getSetterRestrict($setter))) { return $value; } list($repeated, $class) = $restrict; if ($repeated) { $values = []; foreach ($value as $val) { if (is_array($val)) { $val = new self($class, $val); } if ($val instanceof self) { $val = $val->raw(); } $values[] = $val; } return $values; } return (new self($class, $value))->raw(); }
php
protected function sanitizeSetterValue($setter, $value) { if ($value instanceof self) { return $value->raw(); } // 获取 setter 方法的约束条件 if (!(is_array($value) && $restrict = $this->getSetterRestrict($setter))) { return $value; } list($repeated, $class) = $restrict; if ($repeated) { $values = []; foreach ($value as $val) { if (is_array($val)) { $val = new self($class, $val); } if ($val instanceof self) { $val = $val->raw(); } $values[] = $val; } return $values; } return (new self($class, $value))->raw(); }
[ "protected", "function", "sanitizeSetterValue", "(", "$", "setter", ",", "$", "value", ")", "{", "if", "(", "$", "value", "instanceof", "self", ")", "{", "return", "$", "value", "->", "raw", "(", ")", ";", "}", "// 获取 setter 方法的约束条件", "if", "(", "!", "(", "is_array", "(", "$", "value", ")", "&&", "$", "restrict", "=", "$", "this", "->", "getSetterRestrict", "(", "$", "setter", ")", ")", ")", "{", "return", "$", "value", ";", "}", "list", "(", "$", "repeated", ",", "$", "class", ")", "=", "$", "restrict", ";", "if", "(", "$", "repeated", ")", "{", "$", "values", "=", "[", "]", ";", "foreach", "(", "$", "value", "as", "$", "val", ")", "{", "if", "(", "is_array", "(", "$", "val", ")", ")", "{", "$", "val", "=", "new", "self", "(", "$", "class", ",", "$", "val", ")", ";", "}", "if", "(", "$", "val", "instanceof", "self", ")", "{", "$", "val", "=", "$", "val", "->", "raw", "(", ")", ";", "}", "$", "values", "[", "]", "=", "$", "val", ";", "}", "return", "$", "values", ";", "}", "return", "(", "new", "self", "(", "$", "class", ",", "$", "value", ")", ")", "->", "raw", "(", ")", ";", "}" ]
应用于 setter 方法的 value 转换 @param string $setter @param mixed $value @return mixed
[ "应用于", "setter", "方法的", "value", "转换" ]
train
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Helper/Protobuf/MessageWrapper.php#L276-L307
zhouyl/mellivora
Mellivora/Helper/Protobuf/MessageWrapper.php
MessageWrapper.sanitizeToArrayValue
protected function sanitizeToArrayValue($value) { if ($value instanceof Message) { return (new self($value))->toArray(); } if ($value instanceof RepeatedField) { $values = []; foreach ($value as $k => $v) { $values[] = $this->sanitizeToArrayValue($v); } return $values; } if ($value instanceof self) { return $value->toArray(); } return $value; }
php
protected function sanitizeToArrayValue($value) { if ($value instanceof Message) { return (new self($value))->toArray(); } if ($value instanceof RepeatedField) { $values = []; foreach ($value as $k => $v) { $values[] = $this->sanitizeToArrayValue($v); } return $values; } if ($value instanceof self) { return $value->toArray(); } return $value; }
[ "protected", "function", "sanitizeToArrayValue", "(", "$", "value", ")", "{", "if", "(", "$", "value", "instanceof", "Message", ")", "{", "return", "(", "new", "self", "(", "$", "value", ")", ")", "->", "toArray", "(", ")", ";", "}", "if", "(", "$", "value", "instanceof", "RepeatedField", ")", "{", "$", "values", "=", "[", "]", ";", "foreach", "(", "$", "value", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "values", "[", "]", "=", "$", "this", "->", "sanitizeToArrayValue", "(", "$", "v", ")", ";", "}", "return", "$", "values", ";", "}", "if", "(", "$", "value", "instanceof", "self", ")", "{", "return", "$", "value", "->", "toArray", "(", ")", ";", "}", "return", "$", "value", ";", "}" ]
应用于 toArray 方法的 value 转换 @param mixed $value @return mixed
[ "应用于", "toArray", "方法的", "value", "转换" ]
train
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Helper/Protobuf/MessageWrapper.php#L316-L336
jakzal/injector
src/Service/Injector.php
Injector.splitOnVisibilityAndMapToClasses
private function splitOnVisibilityAndMapToClasses(array $properties): array { return \array_reduce($properties, function (array $tuple, Property $p) { $tuple[$this->isPrivate($p) ? 0 : 1][] = $p->getClassName(); return $tuple; }, [[], []]); }
php
private function splitOnVisibilityAndMapToClasses(array $properties): array { return \array_reduce($properties, function (array $tuple, Property $p) { $tuple[$this->isPrivate($p) ? 0 : 1][] = $p->getClassName(); return $tuple; }, [[], []]); }
[ "private", "function", "splitOnVisibilityAndMapToClasses", "(", "array", "$", "properties", ")", ":", "array", "{", "return", "\\", "array_reduce", "(", "$", "properties", ",", "function", "(", "array", "$", "tuple", ",", "Property", "$", "p", ")", "{", "$", "tuple", "[", "$", "this", "->", "isPrivate", "(", "$", "p", ")", "?", "0", ":", "1", "]", "[", "]", "=", "$", "p", "->", "getClassName", "(", ")", ";", "return", "$", "tuple", ";", "}", ",", "[", "[", "]", ",", "[", "]", "]", ")", ";", "}" ]
@param Property[] $properties @return string[][] tuple of class names with a private (left) or non-private (right) property
[ "@param", "Property", "[]", "$properties" ]
train
https://github.com/jakzal/injector/blob/16ece2d449f6b395e632f498f95865532ec72245/src/Service/Injector.php#L133-L140
songshenzong/log
src/DataCollector/AuthCollector.php
AuthCollector.getUserInformation
protected function getUserInformation($user = null) { // Defaults if (is_null($user)) { return [ 'name' => 'Guest', 'user' => ['guest' => true], ]; } // The default auth identifer is the ID number, which isn't all that // useful. Try username and email. $identifier = $user->getAuthIdentifier(); if (is_numeric($identifier)) { try { if ($user->username) { $identifier = $user->username; } elseif ($user->email) { $identifier = $user->email; } } catch (\Exception $e) { } } return [ 'name' => $identifier, 'user' => $user instanceof Arrayable ? $user->toArray() : $user, ]; }
php
protected function getUserInformation($user = null) { // Defaults if (is_null($user)) { return [ 'name' => 'Guest', 'user' => ['guest' => true], ]; } // The default auth identifer is the ID number, which isn't all that // useful. Try username and email. $identifier = $user->getAuthIdentifier(); if (is_numeric($identifier)) { try { if ($user->username) { $identifier = $user->username; } elseif ($user->email) { $identifier = $user->email; } } catch (\Exception $e) { } } return [ 'name' => $identifier, 'user' => $user instanceof Arrayable ? $user->toArray() : $user, ]; }
[ "protected", "function", "getUserInformation", "(", "$", "user", "=", "null", ")", "{", "// Defaults", "if", "(", "is_null", "(", "$", "user", ")", ")", "{", "return", "[", "'name'", "=>", "'Guest'", ",", "'user'", "=>", "[", "'guest'", "=>", "true", "]", ",", "]", ";", "}", "// The default auth identifer is the ID number, which isn't all that", "// useful. Try username and email.", "$", "identifier", "=", "$", "user", "->", "getAuthIdentifier", "(", ")", ";", "if", "(", "is_numeric", "(", "$", "identifier", ")", ")", "{", "try", "{", "if", "(", "$", "user", "->", "username", ")", "{", "$", "identifier", "=", "$", "user", "->", "username", ";", "}", "elseif", "(", "$", "user", "->", "email", ")", "{", "$", "identifier", "=", "$", "user", "->", "email", ";", "}", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "}", "}", "return", "[", "'name'", "=>", "$", "identifier", ",", "'user'", "=>", "$", "user", "instanceof", "Arrayable", "?", "$", "user", "->", "toArray", "(", ")", ":", "$", "user", ",", "]", ";", "}" ]
Get displayed user information @param \Illuminate\Auth\UserInterface $user @return array
[ "Get", "displayed", "user", "information" ]
train
https://github.com/songshenzong/log/blob/b1e01f7994da47737866eabf82367490eab17c46/src/DataCollector/AuthCollector.php#L57-L85
josh-taylor/migrations-generator
src/Generator.php
Generator.tables
public function tables() { $schema = $this->db->connection() ->getDoctrineConnection() ->getSchemaManager(); $tables = $schema->listTableNames(); foreach ($tables as $table) { $columns = $this->describer->describe($table); yield compact('table', 'columns'); } }
php
public function tables() { $schema = $this->db->connection() ->getDoctrineConnection() ->getSchemaManager(); $tables = $schema->listTableNames(); foreach ($tables as $table) { $columns = $this->describer->describe($table); yield compact('table', 'columns'); } }
[ "public", "function", "tables", "(", ")", "{", "$", "schema", "=", "$", "this", "->", "db", "->", "connection", "(", ")", "->", "getDoctrineConnection", "(", ")", "->", "getSchemaManager", "(", ")", ";", "$", "tables", "=", "$", "schema", "->", "listTableNames", "(", ")", ";", "foreach", "(", "$", "tables", "as", "$", "table", ")", "{", "$", "columns", "=", "$", "this", "->", "describer", "->", "describe", "(", "$", "table", ")", ";", "yield", "compact", "(", "'table'", ",", "'columns'", ")", ";", "}", "}" ]
Return a description for each table. @return \Generator
[ "Return", "a", "description", "for", "each", "table", "." ]
train
https://github.com/josh-taylor/migrations-generator/blob/bb6edc78773d11491881f12265a658bf058cb218/src/Generator.php#L36-L49
WellCommerce/StandardEditionBundle
DataFixtures/ORM/LoadOrderStatusGroupData.php
LoadOrderStatusGroupData.load
public function load(ObjectManager $manager) { if (!$this->isEnabled()) { return; } foreach (self::$samples as $name) { $orderStatusGroup = new OrderStatusGroup(); foreach ($this->getLocales() as $locale) { $orderStatusGroup->translate($locale->getCode())->setName($name); } $orderStatusGroup->mergeNewTranslations(); $manager->persist($orderStatusGroup); $this->setReference('order_status_group_' . $name, $orderStatusGroup); } $manager->flush(); }
php
public function load(ObjectManager $manager) { if (!$this->isEnabled()) { return; } foreach (self::$samples as $name) { $orderStatusGroup = new OrderStatusGroup(); foreach ($this->getLocales() as $locale) { $orderStatusGroup->translate($locale->getCode())->setName($name); } $orderStatusGroup->mergeNewTranslations(); $manager->persist($orderStatusGroup); $this->setReference('order_status_group_' . $name, $orderStatusGroup); } $manager->flush(); }
[ "public", "function", "load", "(", "ObjectManager", "$", "manager", ")", "{", "if", "(", "!", "$", "this", "->", "isEnabled", "(", ")", ")", "{", "return", ";", "}", "foreach", "(", "self", "::", "$", "samples", "as", "$", "name", ")", "{", "$", "orderStatusGroup", "=", "new", "OrderStatusGroup", "(", ")", ";", "foreach", "(", "$", "this", "->", "getLocales", "(", ")", "as", "$", "locale", ")", "{", "$", "orderStatusGroup", "->", "translate", "(", "$", "locale", "->", "getCode", "(", ")", ")", "->", "setName", "(", "$", "name", ")", ";", "}", "$", "orderStatusGroup", "->", "mergeNewTranslations", "(", ")", ";", "$", "manager", "->", "persist", "(", "$", "orderStatusGroup", ")", ";", "$", "this", "->", "setReference", "(", "'order_status_group_'", ".", "$", "name", ",", "$", "orderStatusGroup", ")", ";", "}", "$", "manager", "->", "flush", "(", ")", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/WellCommerce/StandardEditionBundle/blob/6367bd20bbb6bde37c710a6ba87ae72b5f05f61e/DataFixtures/ORM/LoadOrderStatusGroupData.php#L32-L50
inhere/php-librarys
src/Utils/LiteLogger.php
LiteLogger.log
public function log($level, $message, array $context = [], array $extra = []) { if (!$this->isCanRecord($level)) { return; } if (!$this->name) { throw new \InvalidArgumentException('Logger name is required.'); } $levelName = self::getLevelName($level); $record = [ 'message' => trim($message), 'context' => $context, 'level' => $level, 'level_name' => $levelName, 'channel' => $this->name, 'datetime' => date('Y-m-d H:i:s'), 'extra' => $extra, ]; // serve is running in php build in server env. if ($this->logConsole && (Php::isBuiltInServer() || Php::isCli())) { \defined('STDOUT') or \define('STDOUT', fopen('php://stdout', 'wb')); fwrite(STDOUT, "[{$record['datetime']}] [$levelName] $message\n"); } $this->records[] = $record; $this->recordSize++; // 检查阀值 if ($this->recordSize > $this->bufferSize) { $this->flush(); } }
php
public function log($level, $message, array $context = [], array $extra = []) { if (!$this->isCanRecord($level)) { return; } if (!$this->name) { throw new \InvalidArgumentException('Logger name is required.'); } $levelName = self::getLevelName($level); $record = [ 'message' => trim($message), 'context' => $context, 'level' => $level, 'level_name' => $levelName, 'channel' => $this->name, 'datetime' => date('Y-m-d H:i:s'), 'extra' => $extra, ]; // serve is running in php build in server env. if ($this->logConsole && (Php::isBuiltInServer() || Php::isCli())) { \defined('STDOUT') or \define('STDOUT', fopen('php://stdout', 'wb')); fwrite(STDOUT, "[{$record['datetime']}] [$levelName] $message\n"); } $this->records[] = $record; $this->recordSize++; // 检查阀值 if ($this->recordSize > $this->bufferSize) { $this->flush(); } }
[ "public", "function", "log", "(", "$", "level", ",", "$", "message", ",", "array", "$", "context", "=", "[", "]", ",", "array", "$", "extra", "=", "[", "]", ")", "{", "if", "(", "!", "$", "this", "->", "isCanRecord", "(", "$", "level", ")", ")", "{", "return", ";", "}", "if", "(", "!", "$", "this", "->", "name", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Logger name is required.'", ")", ";", "}", "$", "levelName", "=", "self", "::", "getLevelName", "(", "$", "level", ")", ";", "$", "record", "=", "[", "'message'", "=>", "trim", "(", "$", "message", ")", ",", "'context'", "=>", "$", "context", ",", "'level'", "=>", "$", "level", ",", "'level_name'", "=>", "$", "levelName", ",", "'channel'", "=>", "$", "this", "->", "name", ",", "'datetime'", "=>", "date", "(", "'Y-m-d H:i:s'", ")", ",", "'extra'", "=>", "$", "extra", ",", "]", ";", "// serve is running in php build in server env.", "if", "(", "$", "this", "->", "logConsole", "&&", "(", "Php", "::", "isBuiltInServer", "(", ")", "||", "Php", "::", "isCli", "(", ")", ")", ")", "{", "\\", "defined", "(", "'STDOUT'", ")", "or", "\\", "define", "(", "'STDOUT'", ",", "fopen", "(", "'php://stdout'", ",", "'wb'", ")", ")", ";", "fwrite", "(", "STDOUT", ",", "\"[{$record['datetime']}] [$levelName] $message\\n\"", ")", ";", "}", "$", "this", "->", "records", "[", "]", "=", "$", "record", ";", "$", "this", "->", "recordSize", "++", ";", "// 检查阀值", "if", "(", "$", "this", "->", "recordSize", ">", "$", "this", "->", "bufferSize", ")", "{", "$", "this", "->", "flush", "(", ")", ";", "}", "}" ]
record log info to file @param int $level @param string $message @param array $context @param array $extra @throws \InvalidArgumentException
[ "record", "log", "info", "to", "file" ]
train
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Utils/LiteLogger.php#L290-L324
inhere/php-librarys
src/Utils/LiteLogger.php
LiteLogger.flush
public function flush() { if ($this->recordSize === 0) { return; } $str = ''; foreach ($this->records as $record) { $str .= $this->recordFormat($record); } $this->clear(); $this->write($str); }
php
public function flush() { if ($this->recordSize === 0) { return; } $str = ''; foreach ($this->records as $record) { $str .= $this->recordFormat($record); } $this->clear(); $this->write($str); }
[ "public", "function", "flush", "(", ")", "{", "if", "(", "$", "this", "->", "recordSize", "===", "0", ")", "{", "return", ";", "}", "$", "str", "=", "''", ";", "foreach", "(", "$", "this", "->", "records", "as", "$", "record", ")", "{", "$", "str", ".=", "$", "this", "->", "recordFormat", "(", "$", "record", ")", ";", "}", "$", "this", "->", "clear", "(", ")", ";", "$", "this", "->", "write", "(", "$", "str", ")", ";", "}" ]
flush data to file. @throws \Inhere\Exceptions\FileSystemException
[ "flush", "data", "to", "file", "." ]
train
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Utils/LiteLogger.php#L330-L343
inhere/php-librarys
src/Utils/LiteLogger.php
LiteLogger.write
protected function write($str) { $file = $this->getLogPath() . $this->getFilename(); $dir = \dirname($file); if (!Directory::create($dir)) { throw new FileSystemException("Create log directory failed. $dir"); } // check file size if (is_file($file) && filesize($file) > $this->fileMaxSize * 1000 * 1000) { rename($file, substr($file, 0, -3) . time() . '.log'); } // return error_log($str, 3, $file); return file_put_contents($file, $str, FILE_APPEND); }
php
protected function write($str) { $file = $this->getLogPath() . $this->getFilename(); $dir = \dirname($file); if (!Directory::create($dir)) { throw new FileSystemException("Create log directory failed. $dir"); } // check file size if (is_file($file) && filesize($file) > $this->fileMaxSize * 1000 * 1000) { rename($file, substr($file, 0, -3) . time() . '.log'); } // return error_log($str, 3, $file); return file_put_contents($file, $str, FILE_APPEND); }
[ "protected", "function", "write", "(", "$", "str", ")", "{", "$", "file", "=", "$", "this", "->", "getLogPath", "(", ")", ".", "$", "this", "->", "getFilename", "(", ")", ";", "$", "dir", "=", "\\", "dirname", "(", "$", "file", ")", ";", "if", "(", "!", "Directory", "::", "create", "(", "$", "dir", ")", ")", "{", "throw", "new", "FileSystemException", "(", "\"Create log directory failed. $dir\"", ")", ";", "}", "// check file size", "if", "(", "is_file", "(", "$", "file", ")", "&&", "filesize", "(", "$", "file", ")", ">", "$", "this", "->", "fileMaxSize", "*", "1000", "*", "1000", ")", "{", "rename", "(", "$", "file", ",", "substr", "(", "$", "file", ",", "0", ",", "-", "3", ")", ".", "time", "(", ")", ".", "'.log'", ")", ";", "}", "// return error_log($str, 3, $file);", "return", "file_put_contents", "(", "$", "file", ",", "$", "str", ",", "FILE_APPEND", ")", ";", "}" ]
write log info to file @param string $str @return bool @throws \InvalidArgumentException @throws FileSystemException
[ "write", "log", "info", "to", "file" ]
train
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Utils/LiteLogger.php#L384-L400
inhere/php-librarys
src/Utils/LiteLogger.php
LiteLogger.getLogPath
public function getLogPath() { if (!$this->basePath) { throw new \InvalidArgumentException('The property basePath is required.'); } return $this->getBasePath() . '/' . ($this->subFolder ? $this->subFolder . '/' : ''); }
php
public function getLogPath() { if (!$this->basePath) { throw new \InvalidArgumentException('The property basePath is required.'); } return $this->getBasePath() . '/' . ($this->subFolder ? $this->subFolder . '/' : ''); }
[ "public", "function", "getLogPath", "(", ")", "{", "if", "(", "!", "$", "this", "->", "basePath", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'The property basePath is required.'", ")", ";", "}", "return", "$", "this", "->", "getBasePath", "(", ")", ".", "'/'", ".", "(", "$", "this", "->", "subFolder", "?", "$", "this", "->", "subFolder", ".", "'/'", ":", "''", ")", ";", "}" ]
get log path @return string @throws \InvalidArgumentException
[ "get", "log", "path" ]
train
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Utils/LiteLogger.php#L449-L456
inhere/php-librarys
src/Utils/LiteLogger.php
LiteLogger.getFilename
public function getFilename() { if ($handler = $this->filenameHandler) { return $handler($this); } if ($this->splitType === 'hour') { return $this->name . '.' . date('Ymd_H') . '.log'; } return $this->name . '.' . date('Ymd') . '.log'; }
php
public function getFilename() { if ($handler = $this->filenameHandler) { return $handler($this); } if ($this->splitType === 'hour') { return $this->name . '.' . date('Ymd_H') . '.log'; } return $this->name . '.' . date('Ymd') . '.log'; }
[ "public", "function", "getFilename", "(", ")", "{", "if", "(", "$", "handler", "=", "$", "this", "->", "filenameHandler", ")", "{", "return", "$", "handler", "(", "$", "this", ")", ";", "}", "if", "(", "$", "this", "->", "splitType", "===", "'hour'", ")", "{", "return", "$", "this", "->", "name", ".", "'.'", ".", "date", "(", "'Ymd_H'", ")", ".", "'.log'", ";", "}", "return", "$", "this", "->", "name", ".", "'.'", ".", "date", "(", "'Ymd'", ")", ".", "'.log'", ";", "}" ]
得到日志文件名 @return string
[ "得到日志文件名" ]
train
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Utils/LiteLogger.php#L474-L485
AbuseIO/parser-ipechelon
src/Ipechelon.php
Ipechelon.parse
public function parse() { // ACNS: Automated Copyright Notice System $foundAcnsFile = false; foreach ($this->parsedMail->getAttachments() as $attachment) { // Only use the Copyrightcompliance formatted reports, skip all others if (preg_match(config("{$this->configBase}.parser.report_file"), $attachment->filename) && $attachment->contentType == 'application/xml' ) { $foundAcnsFile = true; $xmlReport = $attachment->getContent(); $this->saveIncident($xmlReport); } } // Sadly their report is not consistantly an attachment and might end up // in the body so we need to fallback to a body XML search if there was // nothing found in attachments. if ($foundAcnsFile === false) { if (preg_match( '/(?<xml>\<\?xml.*\<\/Infringement\>)/s', $this->parsedMail->getMessageBody(), $match ) !== false ) { if (!empty($match['xml'])) { $xmlReport = $match['xml']; $this->saveIncident($xmlReport); } else { $this->warningCount++; } } else { $this->warningCount++; } } return $this->success(); }
php
public function parse() { // ACNS: Automated Copyright Notice System $foundAcnsFile = false; foreach ($this->parsedMail->getAttachments() as $attachment) { // Only use the Copyrightcompliance formatted reports, skip all others if (preg_match(config("{$this->configBase}.parser.report_file"), $attachment->filename) && $attachment->contentType == 'application/xml' ) { $foundAcnsFile = true; $xmlReport = $attachment->getContent(); $this->saveIncident($xmlReport); } } // Sadly their report is not consistantly an attachment and might end up // in the body so we need to fallback to a body XML search if there was // nothing found in attachments. if ($foundAcnsFile === false) { if (preg_match( '/(?<xml>\<\?xml.*\<\/Infringement\>)/s', $this->parsedMail->getMessageBody(), $match ) !== false ) { if (!empty($match['xml'])) { $xmlReport = $match['xml']; $this->saveIncident($xmlReport); } else { $this->warningCount++; } } else { $this->warningCount++; } } return $this->success(); }
[ "public", "function", "parse", "(", ")", "{", "// ACNS: Automated Copyright Notice System", "$", "foundAcnsFile", "=", "false", ";", "foreach", "(", "$", "this", "->", "parsedMail", "->", "getAttachments", "(", ")", "as", "$", "attachment", ")", "{", "// Only use the Copyrightcompliance formatted reports, skip all others", "if", "(", "preg_match", "(", "config", "(", "\"{$this->configBase}.parser.report_file\"", ")", ",", "$", "attachment", "->", "filename", ")", "&&", "$", "attachment", "->", "contentType", "==", "'application/xml'", ")", "{", "$", "foundAcnsFile", "=", "true", ";", "$", "xmlReport", "=", "$", "attachment", "->", "getContent", "(", ")", ";", "$", "this", "->", "saveIncident", "(", "$", "xmlReport", ")", ";", "}", "}", "// Sadly their report is not consistantly an attachment and might end up", "// in the body so we need to fallback to a body XML search if there was", "// nothing found in attachments.", "if", "(", "$", "foundAcnsFile", "===", "false", ")", "{", "if", "(", "preg_match", "(", "'/(?<xml>\\<\\?xml.*\\<\\/Infringement\\>)/s'", ",", "$", "this", "->", "parsedMail", "->", "getMessageBody", "(", ")", ",", "$", "match", ")", "!==", "false", ")", "{", "if", "(", "!", "empty", "(", "$", "match", "[", "'xml'", "]", ")", ")", "{", "$", "xmlReport", "=", "$", "match", "[", "'xml'", "]", ";", "$", "this", "->", "saveIncident", "(", "$", "xmlReport", ")", ";", "}", "else", "{", "$", "this", "->", "warningCount", "++", ";", "}", "}", "else", "{", "$", "this", "->", "warningCount", "++", ";", "}", "}", "return", "$", "this", "->", "success", "(", ")", ";", "}" ]
Parse attachments @return array Returns array with failed or success data (See parser-common/src/Parser.php) for more info.
[ "Parse", "attachments" ]
train
https://github.com/AbuseIO/parser-ipechelon/blob/41154a5aa88f7762db0941edca95363fac9f6886/src/Ipechelon.php#L29-L70
AbuseIO/parser-ipechelon
src/Ipechelon.php
Ipechelon.saveIncident
private function saveIncident($report_xml) { if (!empty($report_xml) && $report_xml = simplexml_load_string($report_xml)) { $this->feedName = 'default'; // If feed is known and enabled, validate data and save report if ($this->isKnownFeed() && $this->isEnabledFeed()) { // Create a corrected array $report_raw = json_decode(json_encode($report_xml), true); // Sanity check $report = $this->applyFilters($report_raw['Source']); if ($this->hasRequiredFields($report) === true) { // incident has all requirements met, add! $incident = new Incident(); $incident->source = config("{$this->configBase}.parser.name"); $incident->source_id = false; $incident->ip = $report['IP_Address']; $incident->domain = false; $incident->class = config("{$this->configBase}.feeds.{$this->feedName}.class"); $incident->type = config("{$this->configBase}.feeds.{$this->feedName}.type"); $incident->timestamp = strtotime($report['TimeStamp']); $incident->information = json_encode($report_raw); $this->incidents[] = $incident; } } } }
php
private function saveIncident($report_xml) { if (!empty($report_xml) && $report_xml = simplexml_load_string($report_xml)) { $this->feedName = 'default'; // If feed is known and enabled, validate data and save report if ($this->isKnownFeed() && $this->isEnabledFeed()) { // Create a corrected array $report_raw = json_decode(json_encode($report_xml), true); // Sanity check $report = $this->applyFilters($report_raw['Source']); if ($this->hasRequiredFields($report) === true) { // incident has all requirements met, add! $incident = new Incident(); $incident->source = config("{$this->configBase}.parser.name"); $incident->source_id = false; $incident->ip = $report['IP_Address']; $incident->domain = false; $incident->class = config("{$this->configBase}.feeds.{$this->feedName}.class"); $incident->type = config("{$this->configBase}.feeds.{$this->feedName}.type"); $incident->timestamp = strtotime($report['TimeStamp']); $incident->information = json_encode($report_raw); $this->incidents[] = $incident; } } } }
[ "private", "function", "saveIncident", "(", "$", "report_xml", ")", "{", "if", "(", "!", "empty", "(", "$", "report_xml", ")", "&&", "$", "report_xml", "=", "simplexml_load_string", "(", "$", "report_xml", ")", ")", "{", "$", "this", "->", "feedName", "=", "'default'", ";", "// If feed is known and enabled, validate data and save report", "if", "(", "$", "this", "->", "isKnownFeed", "(", ")", "&&", "$", "this", "->", "isEnabledFeed", "(", ")", ")", "{", "// Create a corrected array", "$", "report_raw", "=", "json_decode", "(", "json_encode", "(", "$", "report_xml", ")", ",", "true", ")", ";", "// Sanity check", "$", "report", "=", "$", "this", "->", "applyFilters", "(", "$", "report_raw", "[", "'Source'", "]", ")", ";", "if", "(", "$", "this", "->", "hasRequiredFields", "(", "$", "report", ")", "===", "true", ")", "{", "// incident has all requirements met, add!", "$", "incident", "=", "new", "Incident", "(", ")", ";", "$", "incident", "->", "source", "=", "config", "(", "\"{$this->configBase}.parser.name\"", ")", ";", "$", "incident", "->", "source_id", "=", "false", ";", "$", "incident", "->", "ip", "=", "$", "report", "[", "'IP_Address'", "]", ";", "$", "incident", "->", "domain", "=", "false", ";", "$", "incident", "->", "class", "=", "config", "(", "\"{$this->configBase}.feeds.{$this->feedName}.class\"", ")", ";", "$", "incident", "->", "type", "=", "config", "(", "\"{$this->configBase}.feeds.{$this->feedName}.type\"", ")", ";", "$", "incident", "->", "timestamp", "=", "strtotime", "(", "$", "report", "[", "'TimeStamp'", "]", ")", ";", "$", "incident", "->", "information", "=", "json_encode", "(", "$", "report_raw", ")", ";", "$", "this", "->", "incidents", "[", "]", "=", "$", "incident", ";", "}", "}", "}", "}" ]
Uses the XML to create incidents @param string $report_xml
[ "Uses", "the", "XML", "to", "create", "incidents" ]
train
https://github.com/AbuseIO/parser-ipechelon/blob/41154a5aa88f7762db0941edca95363fac9f6886/src/Ipechelon.php#L77-L104
phpgears/dto
src/PayloadBehaviour.php
PayloadBehaviour.setPayload
private function setPayload(array $parameters): void { $this->payload = []; foreach ($parameters as $parameter => $value) { $this->setPayloadParameter($parameter, $value); } }
php
private function setPayload(array $parameters): void { $this->payload = []; foreach ($parameters as $parameter => $value) { $this->setPayloadParameter($parameter, $value); } }
[ "private", "function", "setPayload", "(", "array", "$", "parameters", ")", ":", "void", "{", "$", "this", "->", "payload", "=", "[", "]", ";", "foreach", "(", "$", "parameters", "as", "$", "parameter", "=>", "$", "value", ")", "{", "$", "this", "->", "setPayloadParameter", "(", "$", "parameter", ",", "$", "value", ")", ";", "}", "}" ]
Set payload. @param array<string, mixed> $parameters
[ "Set", "payload", "." ]
train
https://github.com/phpgears/dto/blob/404b2cdea108538b55caa261c29280062dd0e3db/src/PayloadBehaviour.php#L34-L41
phpgears/dto
src/PayloadBehaviour.php
PayloadBehaviour.get
final public function get(string $parameter) { if (!\array_key_exists($parameter, $this->payload)) { throw new InvalidParameterException(\sprintf( 'Payload parameter %s on %s does not exist', $parameter, static::class )); } $value = $this->payload[$parameter]; $transformer = $this->getParameterTransformerMethod($parameter); if (\method_exists($this, $transformer)) { $value = $this->$transformer($value); } return $value; }
php
final public function get(string $parameter) { if (!\array_key_exists($parameter, $this->payload)) { throw new InvalidParameterException(\sprintf( 'Payload parameter %s on %s does not exist', $parameter, static::class )); } $value = $this->payload[$parameter]; $transformer = $this->getParameterTransformerMethod($parameter); if (\method_exists($this, $transformer)) { $value = $this->$transformer($value); } return $value; }
[ "final", "public", "function", "get", "(", "string", "$", "parameter", ")", "{", "if", "(", "!", "\\", "array_key_exists", "(", "$", "parameter", ",", "$", "this", "->", "payload", ")", ")", "{", "throw", "new", "InvalidParameterException", "(", "\\", "sprintf", "(", "'Payload parameter %s on %s does not exist'", ",", "$", "parameter", ",", "static", "::", "class", ")", ")", ";", "}", "$", "value", "=", "$", "this", "->", "payload", "[", "$", "parameter", "]", ";", "$", "transformer", "=", "$", "this", "->", "getParameterTransformerMethod", "(", "$", "parameter", ")", ";", "if", "(", "\\", "method_exists", "(", "$", "this", ",", "$", "transformer", ")", ")", "{", "$", "value", "=", "$", "this", "->", "$", "transformer", "(", "$", "value", ")", ";", "}", "return", "$", "value", ";", "}" ]
Get parameter. @param string $parameter @throws InvalidParameterException @return mixed
[ "Get", "parameter", "." ]
train
https://github.com/phpgears/dto/blob/404b2cdea108538b55caa261c29280062dd0e3db/src/PayloadBehaviour.php#L75-L93
php-lug/lug
src/Bundle/GridBundle/Form/EventSubscriber/Filter/BooleanFilterSubscriber.php
BooleanFilterSubscriber.onPreSubmit
public function onPreSubmit(FormEvent $event) { $data = $event->getData(); if (in_array($data, ['true', true, '1', 1, 'yes', 'on'], true)) { $data = 'true'; } elseif (in_array($data, ['false', false, '0', 0, 'no', 'off'], true)) { $data = 'false'; } $event->setData($data); }
php
public function onPreSubmit(FormEvent $event) { $data = $event->getData(); if (in_array($data, ['true', true, '1', 1, 'yes', 'on'], true)) { $data = 'true'; } elseif (in_array($data, ['false', false, '0', 0, 'no', 'off'], true)) { $data = 'false'; } $event->setData($data); }
[ "public", "function", "onPreSubmit", "(", "FormEvent", "$", "event", ")", "{", "$", "data", "=", "$", "event", "->", "getData", "(", ")", ";", "if", "(", "in_array", "(", "$", "data", ",", "[", "'true'", ",", "true", ",", "'1'", ",", "1", ",", "'yes'", ",", "'on'", "]", ",", "true", ")", ")", "{", "$", "data", "=", "'true'", ";", "}", "elseif", "(", "in_array", "(", "$", "data", ",", "[", "'false'", ",", "false", ",", "'0'", ",", "0", ",", "'no'", ",", "'off'", "]", ",", "true", ")", ")", "{", "$", "data", "=", "'false'", ";", "}", "$", "event", "->", "setData", "(", "$", "data", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/GridBundle/Form/EventSubscriber/Filter/BooleanFilterSubscriber.php#L26-L37
j-d/draggy
src/Draggy/Autocode/Templates/CPP/Entity.php
Entity.getAttributeLines
public function getAttributeLines(CPPAttribute $attribute) { $lines = []; if ('object' === $attribute->getType()) { $lines[] = $attribute->getEntitySubtype()->getName() . ' ' . $attribute->getName() . ';'; } else { $lines[] = $attribute->getType() . ' ' . $attribute->getName() . ';'; } return $lines; }
php
public function getAttributeLines(CPPAttribute $attribute) { $lines = []; if ('object' === $attribute->getType()) { $lines[] = $attribute->getEntitySubtype()->getName() . ' ' . $attribute->getName() . ';'; } else { $lines[] = $attribute->getType() . ' ' . $attribute->getName() . ';'; } return $lines; }
[ "public", "function", "getAttributeLines", "(", "CPPAttribute", "$", "attribute", ")", "{", "$", "lines", "=", "[", "]", ";", "if", "(", "'object'", "===", "$", "attribute", "->", "getType", "(", ")", ")", "{", "$", "lines", "[", "]", "=", "$", "attribute", "->", "getEntitySubtype", "(", ")", "->", "getName", "(", ")", ".", "' '", ".", "$", "attribute", "->", "getName", "(", ")", ".", "';'", ";", "}", "else", "{", "$", "lines", "[", "]", "=", "$", "attribute", "->", "getType", "(", ")", ".", "' '", ".", "$", "attribute", "->", "getName", "(", ")", ".", "';'", ";", "}", "return", "$", "lines", ";", "}" ]
<editor-fold desc="Attributes">
[ "<editor", "-", "fold", "desc", "=", "Attributes", ">" ]
train
https://github.com/j-d/draggy/blob/97ffc66e1aacb5f685d7aac5251c4abb8888d4bb/src/Draggy/Autocode/Templates/CPP/Entity.php#L84-L95
j-d/draggy
src/Draggy/Autocode/Templates/CPP/Entity.php
Entity.getSetterDeclarationLine
public function getSetterDeclarationLine(CPPAttribute $attribute) { if ('object' === $attribute->getType()) { return $this->getEntity()->getProject()->getAutocodeProperty('base') ? $this->getEntity()->getNameBase() . ' ' . $this->getEntity()->getNameBase() . '::' . $attribute->getSetterName() . '(' . $attribute->getEntitySubtype()->getName() . ' _' . $attribute->getName() . ')' : $this->getEntity()->getName() . ' ' . $this->getEntity()->getName() . '::' . $attribute->getSetterName() . '(' . $attribute->getEntitySubtype()->getName() . ' _' . $attribute->getName() . ')'; } else { return $this->getEntity()->getProject()->getAutocodeProperty('base') ? $this->getEntity()->getNameBase() . ' ' . $this->getEntity()->getNameBase() . '::' . $attribute->getSetterName() . '(' . $attribute->getType() . ' _' . $attribute->getName() . ')' : $this->getEntity()->getName() . ' ' . $this->getEntity()->getName() . '::' . $attribute->getSetterName() . '(' . $attribute->getType() . ' _' . $attribute->getName() . ')'; } }
php
public function getSetterDeclarationLine(CPPAttribute $attribute) { if ('object' === $attribute->getType()) { return $this->getEntity()->getProject()->getAutocodeProperty('base') ? $this->getEntity()->getNameBase() . ' ' . $this->getEntity()->getNameBase() . '::' . $attribute->getSetterName() . '(' . $attribute->getEntitySubtype()->getName() . ' _' . $attribute->getName() . ')' : $this->getEntity()->getName() . ' ' . $this->getEntity()->getName() . '::' . $attribute->getSetterName() . '(' . $attribute->getEntitySubtype()->getName() . ' _' . $attribute->getName() . ')'; } else { return $this->getEntity()->getProject()->getAutocodeProperty('base') ? $this->getEntity()->getNameBase() . ' ' . $this->getEntity()->getNameBase() . '::' . $attribute->getSetterName() . '(' . $attribute->getType() . ' _' . $attribute->getName() . ')' : $this->getEntity()->getName() . ' ' . $this->getEntity()->getName() . '::' . $attribute->getSetterName() . '(' . $attribute->getType() . ' _' . $attribute->getName() . ')'; } }
[ "public", "function", "getSetterDeclarationLine", "(", "CPPAttribute", "$", "attribute", ")", "{", "if", "(", "'object'", "===", "$", "attribute", "->", "getType", "(", ")", ")", "{", "return", "$", "this", "->", "getEntity", "(", ")", "->", "getProject", "(", ")", "->", "getAutocodeProperty", "(", "'base'", ")", "?", "$", "this", "->", "getEntity", "(", ")", "->", "getNameBase", "(", ")", ".", "' '", ".", "$", "this", "->", "getEntity", "(", ")", "->", "getNameBase", "(", ")", ".", "'::'", ".", "$", "attribute", "->", "getSetterName", "(", ")", ".", "'('", ".", "$", "attribute", "->", "getEntitySubtype", "(", ")", "->", "getName", "(", ")", ".", "' _'", ".", "$", "attribute", "->", "getName", "(", ")", ".", "')'", ":", "$", "this", "->", "getEntity", "(", ")", "->", "getName", "(", ")", ".", "' '", ".", "$", "this", "->", "getEntity", "(", ")", "->", "getName", "(", ")", ".", "'::'", ".", "$", "attribute", "->", "getSetterName", "(", ")", ".", "'('", ".", "$", "attribute", "->", "getEntitySubtype", "(", ")", "->", "getName", "(", ")", ".", "' _'", ".", "$", "attribute", "->", "getName", "(", ")", ".", "')'", ";", "}", "else", "{", "return", "$", "this", "->", "getEntity", "(", ")", "->", "getProject", "(", ")", "->", "getAutocodeProperty", "(", "'base'", ")", "?", "$", "this", "->", "getEntity", "(", ")", "->", "getNameBase", "(", ")", ".", "' '", ".", "$", "this", "->", "getEntity", "(", ")", "->", "getNameBase", "(", ")", ".", "'::'", ".", "$", "attribute", "->", "getSetterName", "(", ")", ".", "'('", ".", "$", "attribute", "->", "getType", "(", ")", ".", "' _'", ".", "$", "attribute", "->", "getName", "(", ")", ".", "')'", ":", "$", "this", "->", "getEntity", "(", ")", "->", "getName", "(", ")", ".", "' '", ".", "$", "this", "->", "getEntity", "(", ")", "->", "getName", "(", ")", ".", "'::'", ".", "$", "attribute", "->", "getSetterName", "(", ")", ".", "'('", ".", "$", "attribute", "->", "getType", "(", ")", ".", "' _'", ".", "$", "attribute", "->", "getName", "(", ")", ".", "')'", ";", "}", "}" ]
<editor-fold desc="Setters">
[ "<editor", "-", "fold", "desc", "=", "Setters", ">" ]
train
https://github.com/j-d/draggy/blob/97ffc66e1aacb5f685d7aac5251c4abb8888d4bb/src/Draggy/Autocode/Templates/CPP/Entity.php#L99-L110
j-d/draggy
src/Draggy/Autocode/Templates/CPP/Entity.php
Entity.getGetterCodeLines
public function getGetterCodeLines(CPPAttribute $attribute) { $lines = []; $base = $this->getEntity()->getProject()->getAutocodeProperty('base'); if ('object' === $attribute->getType()) { $lines[] = $attribute->getStatic() ? $attribute->getEntitySubtype()->getName() . ' ' . ($base ? $this->getEntity()->getNameBase() : $this->getEntity()->getName()) . '::' . $attribute->getGetterName() . '()' : $attribute->getEntitySubtype()->getName() . ' ' . ($base ? $this->getEntity()->getNameBase() : $this->getEntity()->getName()) . '::' . $attribute->getGetterName() . '()'; } else { $lines[] = $attribute->getStatic() ? $attribute->getType() . ' ' . ($base ? $this->getEntity()->getNameBase() : $this->getEntity()->getName()) . '::' . $attribute->getGetterName() . '()' : $attribute->getType() . ' ' . ($base ? $this->getEntity()->getNameBase() : $this->getEntity()->getName()) . '::' . $attribute->getGetterName() . '()'; } $lines[] = '{'; $lines[] = 'return ' . $attribute->getName() . ';'; $lines[] = '};'; return $lines; }
php
public function getGetterCodeLines(CPPAttribute $attribute) { $lines = []; $base = $this->getEntity()->getProject()->getAutocodeProperty('base'); if ('object' === $attribute->getType()) { $lines[] = $attribute->getStatic() ? $attribute->getEntitySubtype()->getName() . ' ' . ($base ? $this->getEntity()->getNameBase() : $this->getEntity()->getName()) . '::' . $attribute->getGetterName() . '()' : $attribute->getEntitySubtype()->getName() . ' ' . ($base ? $this->getEntity()->getNameBase() : $this->getEntity()->getName()) . '::' . $attribute->getGetterName() . '()'; } else { $lines[] = $attribute->getStatic() ? $attribute->getType() . ' ' . ($base ? $this->getEntity()->getNameBase() : $this->getEntity()->getName()) . '::' . $attribute->getGetterName() . '()' : $attribute->getType() . ' ' . ($base ? $this->getEntity()->getNameBase() : $this->getEntity()->getName()) . '::' . $attribute->getGetterName() . '()'; } $lines[] = '{'; $lines[] = 'return ' . $attribute->getName() . ';'; $lines[] = '};'; return $lines; }
[ "public", "function", "getGetterCodeLines", "(", "CPPAttribute", "$", "attribute", ")", "{", "$", "lines", "=", "[", "]", ";", "$", "base", "=", "$", "this", "->", "getEntity", "(", ")", "->", "getProject", "(", ")", "->", "getAutocodeProperty", "(", "'base'", ")", ";", "if", "(", "'object'", "===", "$", "attribute", "->", "getType", "(", ")", ")", "{", "$", "lines", "[", "]", "=", "$", "attribute", "->", "getStatic", "(", ")", "?", "$", "attribute", "->", "getEntitySubtype", "(", ")", "->", "getName", "(", ")", ".", "' '", ".", "(", "$", "base", "?", "$", "this", "->", "getEntity", "(", ")", "->", "getNameBase", "(", ")", ":", "$", "this", "->", "getEntity", "(", ")", "->", "getName", "(", ")", ")", ".", "'::'", ".", "$", "attribute", "->", "getGetterName", "(", ")", ".", "'()'", ":", "$", "attribute", "->", "getEntitySubtype", "(", ")", "->", "getName", "(", ")", ".", "' '", ".", "(", "$", "base", "?", "$", "this", "->", "getEntity", "(", ")", "->", "getNameBase", "(", ")", ":", "$", "this", "->", "getEntity", "(", ")", "->", "getName", "(", ")", ")", ".", "'::'", ".", "$", "attribute", "->", "getGetterName", "(", ")", ".", "'()'", ";", "}", "else", "{", "$", "lines", "[", "]", "=", "$", "attribute", "->", "getStatic", "(", ")", "?", "$", "attribute", "->", "getType", "(", ")", ".", "' '", ".", "(", "$", "base", "?", "$", "this", "->", "getEntity", "(", ")", "->", "getNameBase", "(", ")", ":", "$", "this", "->", "getEntity", "(", ")", "->", "getName", "(", ")", ")", ".", "'::'", ".", "$", "attribute", "->", "getGetterName", "(", ")", ".", "'()'", ":", "$", "attribute", "->", "getType", "(", ")", ".", "' '", ".", "(", "$", "base", "?", "$", "this", "->", "getEntity", "(", ")", "->", "getNameBase", "(", ")", ":", "$", "this", "->", "getEntity", "(", ")", "->", "getName", "(", ")", ")", ".", "'::'", ".", "$", "attribute", "->", "getGetterName", "(", ")", ".", "'()'", ";", "}", "$", "lines", "[", "]", "=", "'{'", ";", "$", "lines", "[", "]", "=", "'return '", ".", "$", "attribute", "->", "getName", "(", ")", ".", "';'", ";", "$", "lines", "[", "]", "=", "'};'", ";", "return", "$", "lines", ";", "}" ]
<editor-fold desc="Getters">
[ "<editor", "-", "fold", "desc", "=", "Getters", ">" ]
train
https://github.com/j-d/draggy/blob/97ffc66e1aacb5f685d7aac5251c4abb8888d4bb/src/Draggy/Autocode/Templates/CPP/Entity.php#L143-L164
shipmile/shipmile-api-php
lib/Shipmile/HttpClient/AuthHandler.php
AuthHandler.getAuthType
public function getAuthType() { if (isset($this->auth['username']) && isset($this->auth['password'])) { return self::HTTP_PASSWORD; } if (isset($this->auth['client_id']) && isset($this->auth['client_secret'])) { return self::URL_SECRET; } if (isset($this->auth['access_token'])) { return self::URL_TOKEN; } return -1; }
php
public function getAuthType() { if (isset($this->auth['username']) && isset($this->auth['password'])) { return self::HTTP_PASSWORD; } if (isset($this->auth['client_id']) && isset($this->auth['client_secret'])) { return self::URL_SECRET; } if (isset($this->auth['access_token'])) { return self::URL_TOKEN; } return -1; }
[ "public", "function", "getAuthType", "(", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "auth", "[", "'username'", "]", ")", "&&", "isset", "(", "$", "this", "->", "auth", "[", "'password'", "]", ")", ")", "{", "return", "self", "::", "HTTP_PASSWORD", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "auth", "[", "'client_id'", "]", ")", "&&", "isset", "(", "$", "this", "->", "auth", "[", "'client_secret'", "]", ")", ")", "{", "return", "self", "::", "URL_SECRET", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "auth", "[", "'access_token'", "]", ")", ")", "{", "return", "self", "::", "URL_TOKEN", ";", "}", "return", "-", "1", ";", "}" ]
Calculating the Authentication Type
[ "Calculating", "the", "Authentication", "Type" ]
train
https://github.com/shipmile/shipmile-api-php/blob/b8272613b3a27f0f27e8722cbee277e41e9dfe59/lib/Shipmile/HttpClient/AuthHandler.php#L27-L43
shipmile/shipmile-api-php
lib/Shipmile/HttpClient/AuthHandler.php
AuthHandler.httpPassword
public function httpPassword(Event $event) { $event['request']->setHeader('Authorization', sprintf('Basic %s', base64_encode($this->auth['username'] . ':' . $this->auth['password']))); }
php
public function httpPassword(Event $event) { $event['request']->setHeader('Authorization', sprintf('Basic %s', base64_encode($this->auth['username'] . ':' . $this->auth['password']))); }
[ "public", "function", "httpPassword", "(", "Event", "$", "event", ")", "{", "$", "event", "[", "'request'", "]", "->", "setHeader", "(", "'Authorization'", ",", "sprintf", "(", "'Basic %s'", ",", "base64_encode", "(", "$", "this", "->", "auth", "[", "'username'", "]", ".", "':'", ".", "$", "this", "->", "auth", "[", "'password'", "]", ")", ")", ")", ";", "}" ]
Basic Authorization with username and password
[ "Basic", "Authorization", "with", "username", "and", "password" ]
train
https://github.com/shipmile/shipmile-api-php/blob/b8272613b3a27f0f27e8722cbee277e41e9dfe59/lib/Shipmile/HttpClient/AuthHandler.php#L77-L80
shipmile/shipmile-api-php
lib/Shipmile/HttpClient/AuthHandler.php
AuthHandler.urlSecret
public function urlSecret(Event $event) { $query = $event['request']->getQuery(); $query->set('client_id', $this->auth['client_id']); $query->set('client_secret', $this->auth['client_secret']); }
php
public function urlSecret(Event $event) { $query = $event['request']->getQuery(); $query->set('client_id', $this->auth['client_id']); $query->set('client_secret', $this->auth['client_secret']); }
[ "public", "function", "urlSecret", "(", "Event", "$", "event", ")", "{", "$", "query", "=", "$", "event", "[", "'request'", "]", "->", "getQuery", "(", ")", ";", "$", "query", "->", "set", "(", "'client_id'", ",", "$", "this", "->", "auth", "[", "'client_id'", "]", ")", ";", "$", "query", "->", "set", "(", "'client_secret'", ",", "$", "this", "->", "auth", "[", "'client_secret'", "]", ")", ";", "}" ]
OAUTH2 Authorization with client secret
[ "OAUTH2", "Authorization", "with", "client", "secret" ]
train
https://github.com/shipmile/shipmile-api-php/blob/b8272613b3a27f0f27e8722cbee277e41e9dfe59/lib/Shipmile/HttpClient/AuthHandler.php#L85-L91
nathan-fiscaletti/extended-arrays
src/ExtendedArrays/AssociativeArray.php
AssociativeArray.offsetSet
public function offsetSet($offset, $value) { if (is_null($offset)) { throw new \Exception('Must supply key to modify arguments in an AssociativeArray.'); } else { $this->_args[$offset] = $value; } }
php
public function offsetSet($offset, $value) { if (is_null($offset)) { throw new \Exception('Must supply key to modify arguments in an AssociativeArray.'); } else { $this->_args[$offset] = $value; } }
[ "public", "function", "offsetSet", "(", "$", "offset", ",", "$", "value", ")", "{", "if", "(", "is_null", "(", "$", "offset", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'Must supply key to modify arguments in an AssociativeArray.'", ")", ";", "}", "else", "{", "$", "this", "->", "_args", "[", "$", "offset", "]", "=", "$", "value", ";", "}", "}" ]
Override the offsetSet function to modify values of the wrapped array. Key is enforced. @param mixed $offset @param mixed $value @return mixed @throws \Exception
[ "Override", "the", "offsetSet", "function", "to", "modify", "values", "of", "the", "wrapped", "array", ".", "Key", "is", "enforced", "." ]
train
https://github.com/nathan-fiscaletti/extended-arrays/blob/a641856115131f76417521d3e4aa2d951158050a/src/ExtendedArrays/AssociativeArray.php#L34-L41
DomAndTom/dnt_laravel-swagger-alpha_framework
src/seeds/LaravelSwaggerSeeder.php
LaravelSwaggerSeeder.run
public function run() { Eloquent::unguard(); $this->call('DomAndTom\LaravelSwagger\CategoryTableSeeder'); $this->command->info('Laravel Swagger Demo Categories seeded!'); $this->call('DomAndTom\LaravelSwagger\TagTableSeeder'); $this->command->info('Laravel Swagger Demo Tags seeded!'); $this->call('DomAndTom\LaravelSwagger\PetTableSeeder'); $this->command->info('Laravel Swagger Demo Pets seeded!'); }
php
public function run() { Eloquent::unguard(); $this->call('DomAndTom\LaravelSwagger\CategoryTableSeeder'); $this->command->info('Laravel Swagger Demo Categories seeded!'); $this->call('DomAndTom\LaravelSwagger\TagTableSeeder'); $this->command->info('Laravel Swagger Demo Tags seeded!'); $this->call('DomAndTom\LaravelSwagger\PetTableSeeder'); $this->command->info('Laravel Swagger Demo Pets seeded!'); }
[ "public", "function", "run", "(", ")", "{", "Eloquent", "::", "unguard", "(", ")", ";", "$", "this", "->", "call", "(", "'DomAndTom\\LaravelSwagger\\CategoryTableSeeder'", ")", ";", "$", "this", "->", "command", "->", "info", "(", "'Laravel Swagger Demo Categories seeded!'", ")", ";", "$", "this", "->", "call", "(", "'DomAndTom\\LaravelSwagger\\TagTableSeeder'", ")", ";", "$", "this", "->", "command", "->", "info", "(", "'Laravel Swagger Demo Tags seeded!'", ")", ";", "$", "this", "->", "call", "(", "'DomAndTom\\LaravelSwagger\\PetTableSeeder'", ")", ";", "$", "this", "->", "command", "->", "info", "(", "'Laravel Swagger Demo Pets seeded!'", ")", ";", "}" ]
Run the database seeds. @return void
[ "Run", "the", "database", "seeds", "." ]
train
https://github.com/DomAndTom/dnt_laravel-swagger-alpha_framework/blob/489fc5398583682b8372bdadd6631a4cbff6099f/src/seeds/LaravelSwaggerSeeder.php#L17-L29
zhouyl/mellivora
Mellivora/Session/SessionServiceProvider.php
SessionServiceProvider.register
public function register() { $this->container['session'] = function ($container) { $handler = null; if ($config = $container['config']->get('session.saveHandler')) { if (!$class = $config->handler) { throw new InvalidArgumentException( 'Invalid "handler" parameter in the session save handler' ); } if (!is_subclass_of($class, SessionHandlerInterface::class)) { throw new InvalidArgumentException( $class . ' must implement of ' . SessionHandlerInterface::class ); } $handler = new $class($config->options ? $config->options->toArray() : null); } $session = new Session($handler); $session->start(); return $session; }; }
php
public function register() { $this->container['session'] = function ($container) { $handler = null; if ($config = $container['config']->get('session.saveHandler')) { if (!$class = $config->handler) { throw new InvalidArgumentException( 'Invalid "handler" parameter in the session save handler' ); } if (!is_subclass_of($class, SessionHandlerInterface::class)) { throw new InvalidArgumentException( $class . ' must implement of ' . SessionHandlerInterface::class ); } $handler = new $class($config->options ? $config->options->toArray() : null); } $session = new Session($handler); $session->start(); return $session; }; }
[ "public", "function", "register", "(", ")", "{", "$", "this", "->", "container", "[", "'session'", "]", "=", "function", "(", "$", "container", ")", "{", "$", "handler", "=", "null", ";", "if", "(", "$", "config", "=", "$", "container", "[", "'config'", "]", "->", "get", "(", "'session.saveHandler'", ")", ")", "{", "if", "(", "!", "$", "class", "=", "$", "config", "->", "handler", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Invalid \"handler\" parameter in the session save handler'", ")", ";", "}", "if", "(", "!", "is_subclass_of", "(", "$", "class", ",", "SessionHandlerInterface", "::", "class", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "$", "class", ".", "' must implement of '", ".", "SessionHandlerInterface", "::", "class", ")", ";", "}", "$", "handler", "=", "new", "$", "class", "(", "$", "config", "->", "options", "?", "$", "config", "->", "options", "->", "toArray", "(", ")", ":", "null", ")", ";", "}", "$", "session", "=", "new", "Session", "(", "$", "handler", ")", ";", "$", "session", "->", "start", "(", ")", ";", "return", "$", "session", ";", "}", ";", "}" ]
Register the service provider. @return void
[ "Register", "the", "service", "provider", "." ]
train
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Session/SessionServiceProvider.php#L16-L41
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Cache/src/backends/apc/apc_backend.php
ezcCacheApcBackend.store
public function store( $key, $var, $ttl = 0 ) { $data = new ezcCacheMemoryVarStruct( $key, $var, $ttl ); return apc_store( $key, $data, $ttl ); }
php
public function store( $key, $var, $ttl = 0 ) { $data = new ezcCacheMemoryVarStruct( $key, $var, $ttl ); return apc_store( $key, $data, $ttl ); }
[ "public", "function", "store", "(", "$", "key", ",", "$", "var", ",", "$", "ttl", "=", "0", ")", "{", "$", "data", "=", "new", "ezcCacheMemoryVarStruct", "(", "$", "key", ",", "$", "var", ",", "$", "ttl", ")", ";", "return", "apc_store", "(", "$", "key", ",", "$", "data", ",", "$", "ttl", ")", ";", "}" ]
Stores the data $var under the key $key. Returns true or false depending on the success of the operation. @param string $key @param mixed $var @param int $ttl @return bool
[ "Stores", "the", "data", "$var", "under", "the", "key", "$key", ".", "Returns", "true", "or", "false", "depending", "on", "the", "success", "of", "the", "operation", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Cache/src/backends/apc/apc_backend.php#L47-L51
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Cache/src/backends/apc/apc_backend.php
ezcCacheApcBackend.acquireLock
public function acquireLock( $key, $waitTime, $maxTime ) { $counter = 0; // add() does not replace and returns true on success. $maxTime is // obeyed by Memcache expiry. while ( apc_add( $key, time(), $maxTime ) === false ) { // Wait for next check usleep( $waitTime ); // Don't check expiry time too frquently, since it requires restoring if ( ( ++$counter % 10 === 0 ) && ( time() - (int)apc_fetch( $key ) > $maxTime ) ) { // Release expired lock and place own lock apc_store( $key, time(), $maxTime ); break; } } }
php
public function acquireLock( $key, $waitTime, $maxTime ) { $counter = 0; // add() does not replace and returns true on success. $maxTime is // obeyed by Memcache expiry. while ( apc_add( $key, time(), $maxTime ) === false ) { // Wait for next check usleep( $waitTime ); // Don't check expiry time too frquently, since it requires restoring if ( ( ++$counter % 10 === 0 ) && ( time() - (int)apc_fetch( $key ) > $maxTime ) ) { // Release expired lock and place own lock apc_store( $key, time(), $maxTime ); break; } } }
[ "public", "function", "acquireLock", "(", "$", "key", ",", "$", "waitTime", ",", "$", "maxTime", ")", "{", "$", "counter", "=", "0", ";", "// add() does not replace and returns true on success. $maxTime is", "// obeyed by Memcache expiry.", "while", "(", "apc_add", "(", "$", "key", ",", "time", "(", ")", ",", "$", "maxTime", ")", "===", "false", ")", "{", "// Wait for next check", "usleep", "(", "$", "waitTime", ")", ";", "// Don't check expiry time too frquently, since it requires restoring", "if", "(", "(", "++", "$", "counter", "%", "10", "===", "0", ")", "&&", "(", "time", "(", ")", "-", "(", "int", ")", "apc_fetch", "(", "$", "key", ")", ">", "$", "maxTime", ")", ")", "{", "// Release expired lock and place own lock", "apc_store", "(", "$", "key", ",", "time", "(", ")", ",", "$", "maxTime", ")", ";", "break", ";", "}", "}", "}" ]
Acquires a lock on the given $key. @param string $key @param int $waitTime usleep() @param int $maxTime seconds
[ "Acquires", "a", "lock", "on", "the", "given", "$key", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Cache/src/backends/apc/apc_backend.php#L99-L116
giftcards/Encryption
Command/RotateRangeInStoreCommand.php
RotateRangeInStoreCommand.configure
protected function configure() { $this ->addArgument('stores', InputArgument::IS_ARRAY | InputArgument::REQUIRED, 'A list of stores to re-encrypt.') ->addOption( 'new-profile', null, InputOption::VALUE_REQUIRED, 'The new profile the current data is encrypted with.', null ) ->addOption( 'offset', null, InputOption::VALUE_REQUIRED, 'Starting record', 0 ) ->addOption( 'limit', null, InputOption::VALUE_REQUIRED, 'Max records to process', null ) ->addOption( 'batch-size', null, InputOption::VALUE_REQUIRED, 'Records per batch to process', 1 ); }
php
protected function configure() { $this ->addArgument('stores', InputArgument::IS_ARRAY | InputArgument::REQUIRED, 'A list of stores to re-encrypt.') ->addOption( 'new-profile', null, InputOption::VALUE_REQUIRED, 'The new profile the current data is encrypted with.', null ) ->addOption( 'offset', null, InputOption::VALUE_REQUIRED, 'Starting record', 0 ) ->addOption( 'limit', null, InputOption::VALUE_REQUIRED, 'Max records to process', null ) ->addOption( 'batch-size', null, InputOption::VALUE_REQUIRED, 'Records per batch to process', 1 ); }
[ "protected", "function", "configure", "(", ")", "{", "$", "this", "->", "addArgument", "(", "'stores'", ",", "InputArgument", "::", "IS_ARRAY", "|", "InputArgument", "::", "REQUIRED", ",", "'A list of stores to re-encrypt.'", ")", "->", "addOption", "(", "'new-profile'", ",", "null", ",", "InputOption", "::", "VALUE_REQUIRED", ",", "'The new profile the current data is encrypted with.'", ",", "null", ")", "->", "addOption", "(", "'offset'", ",", "null", ",", "InputOption", "::", "VALUE_REQUIRED", ",", "'Starting record'", ",", "0", ")", "->", "addOption", "(", "'limit'", ",", "null", ",", "InputOption", "::", "VALUE_REQUIRED", ",", "'Max records to process'", ",", "null", ")", "->", "addOption", "(", "'batch-size'", ",", "null", ",", "InputOption", "::", "VALUE_REQUIRED", ",", "'Records per batch to process'", ",", "1", ")", ";", "}" ]
Configures the current command.
[ "Configures", "the", "current", "command", "." ]
train
https://github.com/giftcards/Encryption/blob/a48f92408538e2ffe1c8603f168d57803aad7100/Command/RotateRangeInStoreCommand.php#L38-L71
nblum/silverstripe-flexible-content
code/ContentPage.php
ContentPage_Controller.Elements
public function Elements() { $fcvdo = new \Nblum\FlexibleContent\FlexibleContentVersionedDataObject(); $defaultStage = $fcvdo->getDefaultStage(); if (isset($_GET['stage']) && $defaultStage == $_GET['stage'] && \Permission::check('CMS_ACCESS')) { $stage = $defaultStage; } else { $stage = \Nblum\FlexibleContent\FlexibleContentVersionedDataObject::get_live_stage(); } $results = \Nblum\FlexibleContent\FlexibleContentVersionedDataObject::get_by_stage( \ContentElement::class, $stage , [ 'Active' => '1', 'ParentID' => $this->getField('ID') ], [ 'Sort' => 'ASC' ]); return $results; }
php
public function Elements() { $fcvdo = new \Nblum\FlexibleContent\FlexibleContentVersionedDataObject(); $defaultStage = $fcvdo->getDefaultStage(); if (isset($_GET['stage']) && $defaultStage == $_GET['stage'] && \Permission::check('CMS_ACCESS')) { $stage = $defaultStage; } else { $stage = \Nblum\FlexibleContent\FlexibleContentVersionedDataObject::get_live_stage(); } $results = \Nblum\FlexibleContent\FlexibleContentVersionedDataObject::get_by_stage( \ContentElement::class, $stage , [ 'Active' => '1', 'ParentID' => $this->getField('ID') ], [ 'Sort' => 'ASC' ]); return $results; }
[ "public", "function", "Elements", "(", ")", "{", "$", "fcvdo", "=", "new", "\\", "Nblum", "\\", "FlexibleContent", "\\", "FlexibleContentVersionedDataObject", "(", ")", ";", "$", "defaultStage", "=", "$", "fcvdo", "->", "getDefaultStage", "(", ")", ";", "if", "(", "isset", "(", "$", "_GET", "[", "'stage'", "]", ")", "&&", "$", "defaultStage", "==", "$", "_GET", "[", "'stage'", "]", "&&", "\\", "Permission", "::", "check", "(", "'CMS_ACCESS'", ")", ")", "{", "$", "stage", "=", "$", "defaultStage", ";", "}", "else", "{", "$", "stage", "=", "\\", "Nblum", "\\", "FlexibleContent", "\\", "FlexibleContentVersionedDataObject", "::", "get_live_stage", "(", ")", ";", "}", "$", "results", "=", "\\", "Nblum", "\\", "FlexibleContent", "\\", "FlexibleContentVersionedDataObject", "::", "get_by_stage", "(", "\\", "ContentElement", "::", "class", ",", "$", "stage", ",", "[", "'Active'", "=>", "'1'", ",", "'ParentID'", "=>", "$", "this", "->", "getField", "(", "'ID'", ")", "]", ",", "[", "'Sort'", "=>", "'ASC'", "]", ")", ";", "return", "$", "results", ";", "}" ]
creates List of all rows with content @return DataList
[ "creates", "List", "of", "all", "rows", "with", "content" ]
train
https://github.com/nblum/silverstripe-flexible-content/blob/e20a06ee98b7f884965a951653d98af11eb6bc67/code/ContentPage.php#L197-L218
inhere/php-librarys
src/Components/Pipeline.php
Pipeline.add
public function add(callable $stage) { if ($stage instanceof $this) { $stage->add(function ($payload) { return $this->invokeStage($payload); }); } $this->stages->attach($stage); return $this; }
php
public function add(callable $stage) { if ($stage instanceof $this) { $stage->add(function ($payload) { return $this->invokeStage($payload); }); } $this->stages->attach($stage); return $this; }
[ "public", "function", "add", "(", "callable", "$", "stage", ")", "{", "if", "(", "$", "stage", "instanceof", "$", "this", ")", "{", "$", "stage", "->", "add", "(", "function", "(", "$", "payload", ")", "{", "return", "$", "this", "->", "invokeStage", "(", "$", "payload", ")", ";", "}", ")", ";", "}", "$", "this", "->", "stages", "->", "attach", "(", "$", "stage", ")", ";", "return", "$", "this", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Components/Pipeline.php#L31-L42
DevGroup-ru/yii2-measure
src/helpers/MeasureHelper.php
MeasureHelper.convert
public static function convert($value, $to, $from) { if ($from instanceof Measure === false || $to instanceof Measure === false) { throw new Exception('`from` or `to` parameter is not a Measure'); } if ($from->type !== $to->type) { throw new Exception('Measures have different types'); } if ($from->id == $to->id) { return $value; } $converterClass = isset(static::$converters[$to->type]) === true ? static::$converters[$to->type] : 'DevGroup\Measure\converters\DefaultMeasureTypeConverter'; return $converterClass::convert($value, $to, $from); }
php
public static function convert($value, $to, $from) { if ($from instanceof Measure === false || $to instanceof Measure === false) { throw new Exception('`from` or `to` parameter is not a Measure'); } if ($from->type !== $to->type) { throw new Exception('Measures have different types'); } if ($from->id == $to->id) { return $value; } $converterClass = isset(static::$converters[$to->type]) === true ? static::$converters[$to->type] : 'DevGroup\Measure\converters\DefaultMeasureTypeConverter'; return $converterClass::convert($value, $to, $from); }
[ "public", "static", "function", "convert", "(", "$", "value", ",", "$", "to", ",", "$", "from", ")", "{", "if", "(", "$", "from", "instanceof", "Measure", "===", "false", "||", "$", "to", "instanceof", "Measure", "===", "false", ")", "{", "throw", "new", "Exception", "(", "'`from` or `to` parameter is not a Measure'", ")", ";", "}", "if", "(", "$", "from", "->", "type", "!==", "$", "to", "->", "type", ")", "{", "throw", "new", "Exception", "(", "'Measures have different types'", ")", ";", "}", "if", "(", "$", "from", "->", "id", "==", "$", "to", "->", "id", ")", "{", "return", "$", "value", ";", "}", "$", "converterClass", "=", "isset", "(", "static", "::", "$", "converters", "[", "$", "to", "->", "type", "]", ")", "===", "true", "?", "static", "::", "$", "converters", "[", "$", "to", "->", "type", "]", ":", "'DevGroup\\Measure\\converters\\DefaultMeasureTypeConverter'", ";", "return", "$", "converterClass", "::", "convert", "(", "$", "value", ",", "$", "to", ",", "$", "from", ")", ";", "}" ]
Convert a value from one measure to another @param float $value @param Measure $from @param Measure $to @return float @throws Exception
[ "Convert", "a", "value", "from", "one", "measure", "to", "another" ]
train
https://github.com/DevGroup-ru/yii2-measure/blob/1d41a4af6ad3f2e34cabc32fa1c97bfd3643269c/src/helpers/MeasureHelper.php#L30-L45
DevGroup-ru/yii2-measure
src/helpers/MeasureHelper.php
MeasureHelper.format
public static function format($value, $to, $from = null) { if ($to instanceof Measure === false) { throw new Exception('Unknown object'); } if ($from instanceof Measure) { $value = static::convert($value, $to, $from); } $formatter = $to->use_custom_formatter == true ? $to->formatter : \Yii::$app->formatter; return strtr( $to->format, [ '#' => $formatter->asDecimal($value), '$' => static::t($to->unit), ] ); }
php
public static function format($value, $to, $from = null) { if ($to instanceof Measure === false) { throw new Exception('Unknown object'); } if ($from instanceof Measure) { $value = static::convert($value, $to, $from); } $formatter = $to->use_custom_formatter == true ? $to->formatter : \Yii::$app->formatter; return strtr( $to->format, [ '#' => $formatter->asDecimal($value), '$' => static::t($to->unit), ] ); }
[ "public", "static", "function", "format", "(", "$", "value", ",", "$", "to", ",", "$", "from", "=", "null", ")", "{", "if", "(", "$", "to", "instanceof", "Measure", "===", "false", ")", "{", "throw", "new", "Exception", "(", "'Unknown object'", ")", ";", "}", "if", "(", "$", "from", "instanceof", "Measure", ")", "{", "$", "value", "=", "static", "::", "convert", "(", "$", "value", ",", "$", "to", ",", "$", "from", ")", ";", "}", "$", "formatter", "=", "$", "to", "->", "use_custom_formatter", "==", "true", "?", "$", "to", "->", "formatter", ":", "\\", "Yii", "::", "$", "app", "->", "formatter", ";", "return", "strtr", "(", "$", "to", "->", "format", ",", "[", "'#'", "=>", "$", "formatter", "->", "asDecimal", "(", "$", "value", ")", ",", "'$'", "=>", "static", "::", "t", "(", "$", "to", "->", "unit", ")", ",", "]", ")", ";", "}" ]
Format a value by rule as a string @param double $value @param Measure $to @param Measure|null $from @return string @throws Exception
[ "Format", "a", "value", "by", "rule", "as", "a", "string" ]
train
https://github.com/DevGroup-ru/yii2-measure/blob/1d41a4af6ad3f2e34cabc32fa1c97bfd3643269c/src/helpers/MeasureHelper.php#L55-L71
DevGroup-ru/yii2-measure
src/helpers/MeasureHelper.php
MeasureHelper.parseString
public static function parseString($source, $matchRules) { foreach ((array) $matchRules as $matchRule) { if (is_callable($matchRule) === true) { return call_user_func($matchRule, $source); } else { if (preg_match($matchRule, $source, $matches) === 1) { $value = $matches['integral']; if (isset($matches['fractional'])) { $value .= '.' . $matches['fractional']; } return (double) $value; } } } return false; }
php
public static function parseString($source, $matchRules) { foreach ((array) $matchRules as $matchRule) { if (is_callable($matchRule) === true) { return call_user_func($matchRule, $source); } else { if (preg_match($matchRule, $source, $matches) === 1) { $value = $matches['integral']; if (isset($matches['fractional'])) { $value .= '.' . $matches['fractional']; } return (double) $value; } } } return false; }
[ "public", "static", "function", "parseString", "(", "$", "source", ",", "$", "matchRules", ")", "{", "foreach", "(", "(", "array", ")", "$", "matchRules", "as", "$", "matchRule", ")", "{", "if", "(", "is_callable", "(", "$", "matchRule", ")", "===", "true", ")", "{", "return", "call_user_func", "(", "$", "matchRule", ",", "$", "source", ")", ";", "}", "else", "{", "if", "(", "preg_match", "(", "$", "matchRule", ",", "$", "source", ",", "$", "matches", ")", "===", "1", ")", "{", "$", "value", "=", "$", "matches", "[", "'integral'", "]", ";", "if", "(", "isset", "(", "$", "matches", "[", "'fractional'", "]", ")", ")", "{", "$", "value", ".=", "'.'", ".", "$", "matches", "[", "'fractional'", "]", ";", "}", "return", "(", "double", ")", "$", "value", ";", "}", "}", "}", "return", "false", ";", "}" ]
Parse string by regexp or closure. @param string $source @param \Closure[]|string[]|\Closure|string $matchRules @return false|float
[ "Parse", "string", "by", "regexp", "or", "closure", "." ]
train
https://github.com/DevGroup-ru/yii2-measure/blob/1d41a4af6ad3f2e34cabc32fa1c97bfd3643269c/src/helpers/MeasureHelper.php#L79-L95
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Mail/src/parts/delivery_status.php
ezcMailDeliveryStatus.generateBody
public function generateBody() { $result = $this->addHeadersSection( $this->message ) . ezcMailTools::lineBreak(); for ( $i = 0; $i < count( $this->recipients ); $i++ ) { $result .= $this->addHeadersSection( $this->recipients[$i] ) . ezcMailTools::lineBreak(); } return $result; }
php
public function generateBody() { $result = $this->addHeadersSection( $this->message ) . ezcMailTools::lineBreak(); for ( $i = 0; $i < count( $this->recipients ); $i++ ) { $result .= $this->addHeadersSection( $this->recipients[$i] ) . ezcMailTools::lineBreak(); } return $result; }
[ "public", "function", "generateBody", "(", ")", "{", "$", "result", "=", "$", "this", "->", "addHeadersSection", "(", "$", "this", "->", "message", ")", ".", "ezcMailTools", "::", "lineBreak", "(", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "count", "(", "$", "this", "->", "recipients", ")", ";", "$", "i", "++", ")", "{", "$", "result", ".=", "$", "this", "->", "addHeadersSection", "(", "$", "this", "->", "recipients", "[", "$", "i", "]", ")", ".", "ezcMailTools", "::", "lineBreak", "(", ")", ";", "}", "return", "$", "result", ";", "}" ]
Returns the generated text body of this part as a string. @return string
[ "Returns", "the", "generated", "text", "body", "of", "this", "part", "as", "a", "string", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/parts/delivery_status.php#L139-L147
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Mail/src/parts/delivery_status.php
ezcMailDeliveryStatus.addHeadersSection
private function addHeadersSection( ezcMailHeadersHolder $headers ) { $result = ""; foreach ( $headers->getCaseSensitiveArray() as $header => $value ) { $result .= $header . ": " . $value . ezcMailTools::lineBreak(); } return $result; }
php
private function addHeadersSection( ezcMailHeadersHolder $headers ) { $result = ""; foreach ( $headers->getCaseSensitiveArray() as $header => $value ) { $result .= $header . ": " . $value . ezcMailTools::lineBreak(); } return $result; }
[ "private", "function", "addHeadersSection", "(", "ezcMailHeadersHolder", "$", "headers", ")", "{", "$", "result", "=", "\"\"", ";", "foreach", "(", "$", "headers", "->", "getCaseSensitiveArray", "(", ")", "as", "$", "header", "=>", "$", "value", ")", "{", "$", "result", ".=", "$", "header", ".", "\": \"", ".", "$", "value", ".", "ezcMailTools", "::", "lineBreak", "(", ")", ";", "}", "return", "$", "result", ";", "}" ]
Returns the generated text for a section of the delivery-status part. @param ezcMailHeadersHolder $headers @return string
[ "Returns", "the", "generated", "text", "for", "a", "section", "of", "the", "delivery", "-", "status", "part", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/parts/delivery_status.php#L155-L163
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Mail/src/parts/delivery_status.php
ezcMailDeliveryStatus.createRecipient
public function createRecipient() { $result = count( $this->recipients ); $this->recipients[$result] = new ezcMailHeadersHolder(); return $result; }
php
public function createRecipient() { $result = count( $this->recipients ); $this->recipients[$result] = new ezcMailHeadersHolder(); return $result; }
[ "public", "function", "createRecipient", "(", ")", "{", "$", "result", "=", "count", "(", "$", "this", "->", "recipients", ")", ";", "$", "this", "->", "recipients", "[", "$", "result", "]", "=", "new", "ezcMailHeadersHolder", "(", ")", ";", "return", "$", "result", ";", "}" ]
Adds a new recipient to this delivery-status message and returns the index of the last added recipient. @return int
[ "Adds", "a", "new", "recipient", "to", "this", "delivery", "-", "status", "message", "and", "returns", "the", "index", "of", "the", "last", "added", "recipient", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/parts/delivery_status.php#L171-L176
oroinc/OroLayoutComponent
LayoutRendererRegistry.php
LayoutRendererRegistry.getRenderer
public function getRenderer($name = null) { if (!$name) { $name = $this->defaultRendererName; } if (!isset($this->renderers[$name])) { throw new Exception\LogicException( sprintf('The layout renderer named "%s" was not found.', $name) ); } return $this->renderers[$name]; }
php
public function getRenderer($name = null) { if (!$name) { $name = $this->defaultRendererName; } if (!isset($this->renderers[$name])) { throw new Exception\LogicException( sprintf('The layout renderer named "%s" was not found.', $name) ); } return $this->renderers[$name]; }
[ "public", "function", "getRenderer", "(", "$", "name", "=", "null", ")", "{", "if", "(", "!", "$", "name", ")", "{", "$", "name", "=", "$", "this", "->", "defaultRendererName", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "renderers", "[", "$", "name", "]", ")", ")", "{", "throw", "new", "Exception", "\\", "LogicException", "(", "sprintf", "(", "'The layout renderer named \"%s\" was not found.'", ",", "$", "name", ")", ")", ";", "}", "return", "$", "this", "->", "renderers", "[", "$", "name", "]", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/LayoutRendererRegistry.php#L18-L30
mergado/mergado-api-client-php
src/mergadoclient/OAuth2/AccessToken.php
AccessToken.jsonSerialize
public function jsonSerialize() { $parameters = []; if ($this->accessToken) { $parameters['access_token'] = $this->accessToken; } if ($this->userId) { $parameters['user_id'] = $this->userId; } if ($this->entityId) { $parameters['entity_id'] = $this->entityId; } if ($this->expires) { $parameters['expires'] = $this->expires; } return $parameters; }
php
public function jsonSerialize() { $parameters = []; if ($this->accessToken) { $parameters['access_token'] = $this->accessToken; } if ($this->userId) { $parameters['user_id'] = $this->userId; } if ($this->entityId) { $parameters['entity_id'] = $this->entityId; } if ($this->expires) { $parameters['expires'] = $this->expires; } return $parameters; }
[ "public", "function", "jsonSerialize", "(", ")", "{", "$", "parameters", "=", "[", "]", ";", "if", "(", "$", "this", "->", "accessToken", ")", "{", "$", "parameters", "[", "'access_token'", "]", "=", "$", "this", "->", "accessToken", ";", "}", "if", "(", "$", "this", "->", "userId", ")", "{", "$", "parameters", "[", "'user_id'", "]", "=", "$", "this", "->", "userId", ";", "}", "if", "(", "$", "this", "->", "entityId", ")", "{", "$", "parameters", "[", "'entity_id'", "]", "=", "$", "this", "->", "entityId", ";", "}", "if", "(", "$", "this", "->", "expires", ")", "{", "$", "parameters", "[", "'expires'", "]", "=", "$", "this", "->", "expires", ";", "}", "return", "$", "parameters", ";", "}" ]
Returns an array of parameters to serialize when this is serialized with json_encode(). @return array
[ "Returns", "an", "array", "of", "parameters", "to", "serialize", "when", "this", "is", "serialized", "with", "json_encode", "()", "." ]
train
https://github.com/mergado/mergado-api-client-php/blob/6c13b994a81bf5a3d6f3f791ea1dfbe2c420565f/src/mergadoclient/OAuth2/AccessToken.php#L162-L183
lukasz-adamski/teamspeak3-framework
src/TeamSpeak3/Viewer/Text.php
Text.fetchObject
public function fetchObject(Node $node, array $siblings = array()) { $this->currObj = $node; $this->currSib = $siblings; $args = array( $this->getPrefix(), $this->getCorpusIcon(), $this->getCorpusName(), ); return Str::factory($this->pattern)->arg($args); }
php
public function fetchObject(Node $node, array $siblings = array()) { $this->currObj = $node; $this->currSib = $siblings; $args = array( $this->getPrefix(), $this->getCorpusIcon(), $this->getCorpusName(), ); return Str::factory($this->pattern)->arg($args); }
[ "public", "function", "fetchObject", "(", "Node", "$", "node", ",", "array", "$", "siblings", "=", "array", "(", ")", ")", "{", "$", "this", "->", "currObj", "=", "$", "node", ";", "$", "this", "->", "currSib", "=", "$", "siblings", ";", "$", "args", "=", "array", "(", "$", "this", "->", "getPrefix", "(", ")", ",", "$", "this", "->", "getCorpusIcon", "(", ")", ",", "$", "this", "->", "getCorpusName", "(", ")", ",", ")", ";", "return", "Str", "::", "factory", "(", "$", "this", "->", "pattern", ")", "->", "arg", "(", "$", "args", ")", ";", "}" ]
Returns the code needed to display a node in a TeamSpeak 3 viewer. @param Node $node @param array $siblings @return string
[ "Returns", "the", "code", "needed", "to", "display", "a", "node", "in", "a", "TeamSpeak", "3", "viewer", "." ]
train
https://github.com/lukasz-adamski/teamspeak3-framework/blob/39a56eca608da6b56b6aa386a7b5b31dc576c41a/src/TeamSpeak3/Viewer/Text.php#L51-L63
phapi/cache-nullcache
src/Phapi/Di/Validator/Cache.php
Cache.validate
public function validate($cache) { $original = $cache; // Make sure the cache is configured using a closure if (is_callable($cache)) { $failed = false; try { $cache = $cache($this->container); } catch (\Exception $e) { $failed = true; // Add a note to the log that we are unable to connect to the cache backend $this->container['log']->warning( 'Unable to connect to the cache backend.' ); } // Return original closure if connection didn't fail and if // the cache is an instance of the Cache Contract if (!$failed && $cache instanceof CacheContract) { return $original; } } else { // Add a note to the log that the configuration must be updated $this->container['log']->warning( 'A cache must be configured as a closure. See the documentation for more information.' ); } // Return a NullCache as a fallback return function ($app) { return new NullCache(); }; }
php
public function validate($cache) { $original = $cache; // Make sure the cache is configured using a closure if (is_callable($cache)) { $failed = false; try { $cache = $cache($this->container); } catch (\Exception $e) { $failed = true; // Add a note to the log that we are unable to connect to the cache backend $this->container['log']->warning( 'Unable to connect to the cache backend.' ); } // Return original closure if connection didn't fail and if // the cache is an instance of the Cache Contract if (!$failed && $cache instanceof CacheContract) { return $original; } } else { // Add a note to the log that the configuration must be updated $this->container['log']->warning( 'A cache must be configured as a closure. See the documentation for more information.' ); } // Return a NullCache as a fallback return function ($app) { return new NullCache(); }; }
[ "public", "function", "validate", "(", "$", "cache", ")", "{", "$", "original", "=", "$", "cache", ";", "// Make sure the cache is configured using a closure", "if", "(", "is_callable", "(", "$", "cache", ")", ")", "{", "$", "failed", "=", "false", ";", "try", "{", "$", "cache", "=", "$", "cache", "(", "$", "this", "->", "container", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "failed", "=", "true", ";", "// Add a note to the log that we are unable to connect to the cache backend", "$", "this", "->", "container", "[", "'log'", "]", "->", "warning", "(", "'Unable to connect to the cache backend.'", ")", ";", "}", "// Return original closure if connection didn't fail and if", "// the cache is an instance of the Cache Contract", "if", "(", "!", "$", "failed", "&&", "$", "cache", "instanceof", "CacheContract", ")", "{", "return", "$", "original", ";", "}", "}", "else", "{", "// Add a note to the log that the configuration must be updated", "$", "this", "->", "container", "[", "'log'", "]", "->", "warning", "(", "'A cache must be configured as a closure. See the documentation for more information.'", ")", ";", "}", "// Return a NullCache as a fallback", "return", "function", "(", "$", "app", ")", "{", "return", "new", "NullCache", "(", ")", ";", "}", ";", "}" ]
Validate a cache to ensure it implements the Cache Contract and that we are able to connect to the cache backend. If we are unable to connect to the cache backend an Exception should be thrown. That Exception will be handled by the validator. A working cache is NOT a requirement for the application to run so it's important to handle the exception and let the application run. If the exception below is thrown a new NullCache will be created instead. @param $cache @return callable
[ "Validate", "a", "cache", "to", "ensure", "it", "implements", "the", "Cache", "Contract", "and", "that", "we", "are", "able", "to", "connect", "to", "the", "cache", "backend", "." ]
train
https://github.com/phapi/cache-nullcache/blob/89e1c16f2d50b77cd112c27627d6733de32fb5c3/src/Phapi/Di/Validator/Cache.php#L49-L82
vaibhavpandeyvpz/sandesh
src/ServerRequestFactory.php
ServerRequestFactory.createServerRequest
public function createServerRequest($method, $uri) { if (is_string($uri)) { $factory = new UriFactory(); $uri = $factory->createUri($uri); } return new ServerRequest($method, $uri); }
php
public function createServerRequest($method, $uri) { if (is_string($uri)) { $factory = new UriFactory(); $uri = $factory->createUri($uri); } return new ServerRequest($method, $uri); }
[ "public", "function", "createServerRequest", "(", "$", "method", ",", "$", "uri", ")", "{", "if", "(", "is_string", "(", "$", "uri", ")", ")", "{", "$", "factory", "=", "new", "UriFactory", "(", ")", ";", "$", "uri", "=", "$", "factory", "->", "createUri", "(", "$", "uri", ")", ";", "}", "return", "new", "ServerRequest", "(", "$", "method", ",", "$", "uri", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/vaibhavpandeyvpz/sandesh/blob/bea2d06c7cac099ed82da973c922859de4158de0/src/ServerRequestFactory.php#L27-L34
vaibhavpandeyvpz/sandesh
src/ServerRequestFactory.php
ServerRequestFactory.createServerRequestFromArray
public function createServerRequestFromArray(array $server) { $body = self::getPhpInputStream(); $method = $server['REQUEST_METHOD']; $protocolVersion = self::getProtocolVersion($server); $uri = self::getUri($server); $request = new ServerRequest($method, $uri); $request = $request->withBody($body) ->withProtocolVersion($protocolVersion) ->withServerParams($server); $headers = self::getHeaders($server); foreach ($headers as $name => $value) { $request = $request->withHeader($name, $value); } return $request; }
php
public function createServerRequestFromArray(array $server) { $body = self::getPhpInputStream(); $method = $server['REQUEST_METHOD']; $protocolVersion = self::getProtocolVersion($server); $uri = self::getUri($server); $request = new ServerRequest($method, $uri); $request = $request->withBody($body) ->withProtocolVersion($protocolVersion) ->withServerParams($server); $headers = self::getHeaders($server); foreach ($headers as $name => $value) { $request = $request->withHeader($name, $value); } return $request; }
[ "public", "function", "createServerRequestFromArray", "(", "array", "$", "server", ")", "{", "$", "body", "=", "self", "::", "getPhpInputStream", "(", ")", ";", "$", "method", "=", "$", "server", "[", "'REQUEST_METHOD'", "]", ";", "$", "protocolVersion", "=", "self", "::", "getProtocolVersion", "(", "$", "server", ")", ";", "$", "uri", "=", "self", "::", "getUri", "(", "$", "server", ")", ";", "$", "request", "=", "new", "ServerRequest", "(", "$", "method", ",", "$", "uri", ")", ";", "$", "request", "=", "$", "request", "->", "withBody", "(", "$", "body", ")", "->", "withProtocolVersion", "(", "$", "protocolVersion", ")", "->", "withServerParams", "(", "$", "server", ")", ";", "$", "headers", "=", "self", "::", "getHeaders", "(", "$", "server", ")", ";", "foreach", "(", "$", "headers", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "request", "=", "$", "request", "->", "withHeader", "(", "$", "name", ",", "$", "value", ")", ";", "}", "return", "$", "request", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/vaibhavpandeyvpz/sandesh/blob/bea2d06c7cac099ed82da973c922859de4158de0/src/ServerRequestFactory.php#L39-L54
old-town/workflow-designer-server
src/View/WorkflowDescriptorApiStrategy.php
WorkflowDescriptorApiStrategy.selectRenderer
public function selectRenderer(ViewEvent $e) { $model = $e->getModel(); if (!($model instanceof WorkflowDescriptorApiModel || $model instanceof HalEntity)) { return null; } $this->renderer->setViewEvent($e); return $this->renderer; }
php
public function selectRenderer(ViewEvent $e) { $model = $e->getModel(); if (!($model instanceof WorkflowDescriptorApiModel || $model instanceof HalEntity)) { return null; } $this->renderer->setViewEvent($e); return $this->renderer; }
[ "public", "function", "selectRenderer", "(", "ViewEvent", "$", "e", ")", "{", "$", "model", "=", "$", "e", "->", "getModel", "(", ")", ";", "if", "(", "!", "(", "$", "model", "instanceof", "WorkflowDescriptorApiModel", "||", "$", "model", "instanceof", "HalEntity", ")", ")", "{", "return", "null", ";", "}", "$", "this", "->", "renderer", "->", "setViewEvent", "(", "$", "e", ")", ";", "return", "$", "this", "->", "renderer", ";", "}" ]
Detect if we should use the FeedRenderer based on model type and/or Accept header @param ViewEvent $e @return null|WorkflowDescriptorApiRenderer
[ "Detect", "if", "we", "should", "use", "the", "FeedRenderer", "based", "on", "model", "type", "and", "/", "or", "Accept", "header" ]
train
https://github.com/old-town/workflow-designer-server/blob/6389c5a515861cc8e0b769f1ca7be12c6b78c611/src/View/WorkflowDescriptorApiStrategy.php#L53-L64
old-town/workflow-designer-server
src/View/WorkflowDescriptorApiStrategy.php
WorkflowDescriptorApiStrategy.injectResponse
public function injectResponse(ViewEvent $e) { $renderer = $e->getRenderer(); if ($renderer !== $this->renderer) { return; } $result = $e->getResult(); /** @var HttpResponse $response */ $response = $e->getResponse(); $response->setContent($result); $headers = $response->getHeaders(); //$headers->addHeaderLine('Content-length', strlen($result)); $headers->addHeaderLine('content-type', 'text/xml'); }
php
public function injectResponse(ViewEvent $e) { $renderer = $e->getRenderer(); if ($renderer !== $this->renderer) { return; } $result = $e->getResult(); /** @var HttpResponse $response */ $response = $e->getResponse(); $response->setContent($result); $headers = $response->getHeaders(); //$headers->addHeaderLine('Content-length', strlen($result)); $headers->addHeaderLine('content-type', 'text/xml'); }
[ "public", "function", "injectResponse", "(", "ViewEvent", "$", "e", ")", "{", "$", "renderer", "=", "$", "e", "->", "getRenderer", "(", ")", ";", "if", "(", "$", "renderer", "!==", "$", "this", "->", "renderer", ")", "{", "return", ";", "}", "$", "result", "=", "$", "e", "->", "getResult", "(", ")", ";", "/** @var HttpResponse $response */", "$", "response", "=", "$", "e", "->", "getResponse", "(", ")", ";", "$", "response", "->", "setContent", "(", "$", "result", ")", ";", "$", "headers", "=", "$", "response", "->", "getHeaders", "(", ")", ";", "//$headers->addHeaderLine('Content-length', strlen($result));", "$", "headers", "->", "addHeaderLine", "(", "'content-type'", ",", "'text/xml'", ")", ";", "}" ]
Inject the response with the feed payload and appropriate Content-Type header @param ViewEvent $e @return void @throws \Zend\Http\Exception\InvalidArgumentException
[ "Inject", "the", "response", "with", "the", "feed", "payload", "and", "appropriate", "Content", "-", "Type", "header" ]
train
https://github.com/old-town/workflow-designer-server/blob/6389c5a515861cc8e0b769f1ca7be12c6b78c611/src/View/WorkflowDescriptorApiStrategy.php#L73-L89
gn36/phpbb-oo-posting-api
src/Gn36/OoPostingApi/posting_base.php
posting_base.submit_post
protected function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $update_message = true, $update_search_index = true) { global $db, $user, $config, $auth, $phpEx, $template, $phpbb_root_path, $phpbb_container, $phpbb_dispatcher; /** * Modify the data for post submitting * * @event core.modify_submit_post_data * * @var string containing posting mode value * @var string containing post subject value * @var string containing post author name * @var int containing topic type value * @var array with the poll data for the post * @var array with the data for the post * @var bool indicating if the post will be updated * @var bool indicating if the search index will be updated * @since 3.1.0-a4 */ $vars = array( 'mode', 'subject', 'username', 'topic_type', 'poll', 'data', 'update_message', 'update_search_index' ); extract($phpbb_dispatcher->trigger_event('core.modify_submit_post_data', compact($vars))); // We do not handle erasing posts here if ($mode == 'delete') { return false; } // User Info if ($mode != 'edit' && isset($data['poster_id']) && $data['poster_id'] && $data['poster_id'] != ANONYMOUS && $data['poster_id'] != $user->data['user_id']) { $userdata = $this->get_userdata($data['poster_id']); } else { $userdata = array( 'username' => $user->data['username'], 'user_colour' => $user->data['user_colour'], 'user_id' => $user->data['user_id'], 'is_registered' => $user->data['is_registered'], ); } if (! empty($data['post_time'])) { $current_time = $data['post_time']; } else { $current_time = time(); } if ($mode == 'post') { $post_mode = 'post'; $update_message = true; } else if ($mode != 'edit') { $post_mode = 'reply'; $update_message = true; } else if ($mode == 'edit') { $post_mode = ($data['topic_posts_approved'] + $data['topic_posts_unapproved'] + $data['topic_posts_softdeleted'] == 1) ? 'edit_topic' : (($data['topic_first_post_id'] == $data['post_id']) ? 'edit_first_post' : (($data['topic_last_post_id'] == $data['post_id']) ? 'edit_last_post' : 'edit')); } // First of all make sure the subject and topic title are having the correct length. // To achieve this without cutting off between special chars we convert to an array and then count the elements. $subject = truncate_string($subject, 120); $data['topic_title'] = truncate_string($data['topic_title'], 120); // Collect some basic information about which tables and which rows to update/insert $sql_data = $topic_row = array(); $poster_id = isset($data['poster_id']) ? $data['poster_id'] : (int) $userdata['user_id']; // Retrieve some additional information if not present if ($mode == 'edit' && (! isset($data['post_visibility']) || ! isset($data['topic_visibility']) || $data['post_visibility'] === false || $data['topic_visibility'] === false)) { $sql = 'SELECT p.post_visibility, t.topic_type, t.topic_posts_approved, t.topic_posts_unapproved, t.topic_posts_softdeleted, t.topic_visibility FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p WHERE t.topic_id = p.topic_id AND p.post_id = ' . $data['post_id']; $result = $db->sql_query($sql); $topic_row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $data['topic_visibility'] = $topic_row['topic_visibility']; $data['post_visibility'] = $topic_row['post_visibility']; } // This variable indicates if the user is able to post or put into the queue $post_visibility = isset($data['post_visibility']) ? $data['post_visibility'] : ITEM_APPROVED; // MODs/Extensions are able to force any visibility on posts if (isset($data['force_approved_state'])) { $post_visibility = (in_array((int) $data['force_approved_state'], array( ITEM_APPROVED, ITEM_UNAPPROVED, ITEM_DELETED, ITEM_REAPPROVE ))) ? (int) $data['force_approved_state'] : $post_visibility; } if (isset($data['force_visibility'])) { $post_visibility = (in_array((int) $data['force_visibility'], array( ITEM_APPROVED, ITEM_UNAPPROVED, ITEM_DELETED, ITEM_REAPPROVE ))) ? (int) $data['force_visibility'] : $post_visibility; } // Start the transaction here $db->sql_transaction('begin'); // Collect Information switch ($post_mode) { case 'post': case 'reply': $sql_data[POSTS_TABLE]['sql'] = array( 'forum_id' => $data['forum_id'], 'poster_id' => (int) $userdata['user_id'], 'icon_id' => $data['icon_id'], 'poster_ip' => $user->ip, 'post_time' => $current_time, 'post_visibility' => $post_visibility, 'enable_bbcode' => $data['enable_bbcode'], 'enable_smilies' => $data['enable_smilies'], 'enable_magic_url' => $data['enable_urls'], 'enable_sig' => $data['enable_sig'], 'post_username' => ($userdata['user_id'] != ANONYMOUS) ? $username : '', 'post_subject' => $subject, 'post_text' => $data['message'], 'post_checksum' => $data['message_md5'], 'post_attachment' => (! empty($data['attachment_data'])) ? 1 : 0, 'bbcode_bitfield' => $data['bbcode_bitfield'], 'bbcode_uid' => $data['bbcode_uid'], 'post_postcount' => isset($data['post_postcount']) ? $data['post_postcount'] : 1, 'post_edit_locked' => $data['post_edit_locked'] ); break; case 'edit_first_post': case 'edit': case 'edit_last_post': case 'edit_topic': // If edit reason is given always display edit info // If editing last post then display no edit info // If m_edit permission then display no edit info // If normal edit display edit info // Display edit info if edit reason given or user is editing his post, which is not the last within the topic. if ($data['post_edit_reason'] || ($post_mode == 'edit' || $post_mode == 'edit_first_post')) { $data['post_edit_reason'] = truncate_string($data['post_edit_reason'], 255, 255, false); $sql_data[POSTS_TABLE]['sql'] = array( 'post_edit_time' => $current_time, 'post_edit_reason' => $data['post_edit_reason'], 'post_edit_user' => (int) $data['post_edit_user'] ); $sql_data[POSTS_TABLE]['stat'][] = 'post_edit_count = post_edit_count + 1'; } else if (! $data['post_edit_reason'] && $mode == 'edit') { $sql_data[POSTS_TABLE]['sql'] = array( 'post_edit_reason' => '' ); } // If the person editing this post is different to the one having posted then we will add a log entry stating the edit // Could be simplified by only adding to the log if the edit is not tracked - but this may confuse admins/mods if ($user->data['user_id'] != $poster_id) { $log_subject = ($subject) ? $subject : $data['topic_title']; add_log('mod', $data['forum_id'], $data['topic_id'], 'LOG_POST_EDITED', $log_subject, (! empty($username)) ? $username : $user->lang['GUEST'], $data['post_edit_reason']); } if (! isset($sql_data[POSTS_TABLE]['sql'])) { $sql_data[POSTS_TABLE]['sql'] = array(); } $sql_data[POSTS_TABLE]['sql'] = array_merge($sql_data[POSTS_TABLE]['sql'], array( 'forum_id' => $data['forum_id'], 'poster_id' => $data['poster_id'], 'icon_id' => $data['icon_id'], // We will change the visibility later // 'post_visibility' => $post_visibility, 'enable_bbcode' => $data['enable_bbcode'], 'enable_smilies' => $data['enable_smilies'], 'enable_magic_url' => $data['enable_urls'], 'enable_sig' => $data['enable_sig'], 'post_username' => ($username ? $username : ''), 'post_subject' => $subject, 'post_checksum' => $data['message_md5'], 'post_attachment' => (! empty($data['attachment_data'])) ? 1 : 0, 'bbcode_bitfield' => $data['bbcode_bitfield'], 'bbcode_uid' => $data['bbcode_uid'], 'post_edit_locked' => $data['post_edit_locked'] )); if ($update_message) { $sql_data[POSTS_TABLE]['sql']['post_text'] = $data['message']; } break; } $topic_row = array(); // And the topic ladies and gentlemen switch ($post_mode) { case 'post': $sql_data[TOPICS_TABLE]['sql'] = array( 'topic_poster' => (int) $user->data['user_id'], 'topic_time' => $current_time, 'topic_last_view_time' => $current_time, 'forum_id' => $data['forum_id'], 'icon_id' => $data['icon_id'], 'topic_posts_approved' => ($post_visibility == ITEM_APPROVED) ? 1 : 0, 'topic_posts_softdeleted' => ($post_visibility == ITEM_DELETED) ? 1 : 0, 'topic_posts_unapproved' => ($post_visibility == ITEM_UNAPPROVED) ? 1 : 0, 'topic_visibility' => $post_visibility, 'topic_delete_user' => ($post_visibility != ITEM_APPROVED) ? (int) $user->data['user_id'] : 0, 'topic_title' => $subject, 'topic_first_poster_name' => (! $userdata['user_id'] != ANONYMOUS && $username) ? $username : (($userdata['user_id'] != ANONYMOUS) ? $userdata['username'] : ''), 'topic_first_poster_colour' => $userdata['user_colour'], 'topic_type' => $topic_type, 'topic_time_limit' => ($topic_type == POST_STICKY || $topic_type == POST_ANNOUNCE) ? ($data['topic_time_limit'] * 86400) : 0, 'topic_attachment' => (! empty($data['attachment_data'])) ? 1 : 0, 'topic_status' => (isset($data['topic_status'])) ? $data['topic_status'] : ITEM_UNLOCKED ); if (isset($poll['poll_options']) && ! empty($poll['poll_options'])) { $poll_start = ($poll['poll_start']) ? $poll['poll_start'] : $current_time; $poll_length = $poll['poll_length'] * 86400; if ($poll_length < 0) { $poll_start = $poll_start + $poll_length; if ($poll_start < 0) { $poll_start = 0; } $poll_length = 1; } $sql_data[TOPICS_TABLE]['sql'] = array_merge($sql_data[TOPICS_TABLE]['sql'], array( 'poll_title' => $poll['poll_title'], 'poll_start' => $poll_start, 'poll_max_options' => $poll['poll_max_options'], 'poll_length' => $poll_length, 'poll_vote_change' => $poll['poll_vote_change'] )); } $sql_data[USERS_TABLE]['stat'][] = "user_lastpost_time = $current_time" . (($post_visibility == ITEM_APPROVED) ? ', user_posts = user_posts + 1' : ''); if ($post_visibility == ITEM_APPROVED) { $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_approved = forum_topics_approved + 1'; $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts_approved = forum_posts_approved + 1'; } else if ($post_visibility == ITEM_UNAPPROVED) { $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_unapproved = forum_topics_unapproved + 1'; $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts_unapproved = forum_posts_unapproved + 1'; } else if ($post_visibility == ITEM_DELETED) { $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_softdeleted = forum_topics_softdeleted + 1'; $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts_softdeleted = forum_posts_softdeleted + 1'; } break; case 'reply': $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_view_time = ' . $current_time . ', topic_bumped = 0, topic_bumper = 0' . (($post_visibility == ITEM_APPROVED) ? ', topic_posts_approved = topic_posts_approved + 1' : '') . (($post_visibility == ITEM_UNAPPROVED) ? ', topic_posts_unapproved = topic_posts_unapproved + 1' : '') . (($post_visibility == ITEM_DELETED) ? ', topic_posts_softdeleted = topic_posts_softdeleted + 1' : '') . ((! empty($data['attachment_data']) || (isset($data['topic_attachment']) && $data['topic_attachment'])) ? ', topic_attachment = 1' : ''); $sql_data[USERS_TABLE]['stat'][] = "user_lastpost_time = $current_time" . ((($data['post_postcount']) && $post_visibility == ITEM_APPROVED) ? ', user_posts = user_posts + 1' : ''); if ($post_visibility == ITEM_APPROVED) { $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts_approved = forum_posts_approved + 1'; } else if ($post_visibility == ITEM_UNAPPROVED) { $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts_unapproved = forum_posts_unapproved + 1'; } else if ($post_visibility == ITEM_DELETED) { $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts_softdeleted = forum_posts_softdeleted + 1'; } break; case 'edit_topic': case 'edit_first_post': if (isset($poll['poll_options'])) { $poll_start = ($poll['poll_start'] || empty($poll['poll_options'])) ? $poll['poll_start'] : $current_time; $poll_length = $poll['poll_length'] * 86400; if ($poll_length < 0) { $poll_start = $poll_start + $poll_length; if ($poll_start < 0) { $poll_start = 0; } $poll_length = 1; } } $sql_data[TOPICS_TABLE]['sql'] = array( 'forum_id' => $data['forum_id'], 'icon_id' => $data['icon_id'], 'topic_title' => $subject, 'topic_first_poster_name' => $username, 'topic_type' => $topic_type, 'topic_time_limit' => ($topic_type == POST_STICKY || $topic_type == POST_ANNOUNCE) ? ($data['topic_time_limit'] * 86400) : 0, 'poll_title' => (isset($poll['poll_options'])) ? $poll['poll_title'] : '', 'poll_start' => (isset($poll['poll_options'])) ? $poll_start : 0, 'poll_max_options' => (isset($poll['poll_options'])) ? $poll['poll_max_options'] : 1, 'poll_length' => (isset($poll['poll_options'])) ? $poll_length : 0, 'poll_vote_change' => (isset($poll['poll_vote_change'])) ? $poll['poll_vote_change'] : 0, 'topic_last_view_time' => $current_time, 'topic_attachment' => (! empty($data['attachment_data'])) ? 1 : (isset($data['topic_attachment']) ? $data['topic_attachment'] : 0) ); break; } /** * Modify sql query data for post submitting * * @event core.submit_post_modify_sql_data * * @var array with the data for the post * @var array with the poll data for the post * @var string containing posting mode value * @var bool with the data for the posting SQL query * @var string containing post subject value * @var int containing topic type value * @var string containing post author name * @since 3.1.3-RC1 */ $vars = array( 'data', 'poll', 'post_mode', 'sql_data', 'subject', 'topic_type', 'username' ); extract($phpbb_dispatcher->trigger_event('core.submit_post_modify_sql_data', compact($vars))); // Submit new topic if ($post_mode == 'post') { $sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_data[TOPICS_TABLE]['sql']); $db->sql_query($sql); $data['topic_id'] = $db->sql_nextid(); $sql_data[POSTS_TABLE]['sql'] = array_merge($sql_data[POSTS_TABLE]['sql'], array( 'topic_id' => $data['topic_id'] )); unset($sql_data[TOPICS_TABLE]['sql']); } // Submit new post if ($post_mode == 'post' || $post_mode == 'reply') { if ($post_mode == 'reply') { $sql_data[POSTS_TABLE]['sql'] = array_merge($sql_data[POSTS_TABLE]['sql'], array( 'topic_id' => $data['topic_id'] )); } $sql = 'INSERT INTO ' . POSTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_data[POSTS_TABLE]['sql']); $db->sql_query($sql); $data['post_id'] = $db->sql_nextid(); if ($post_mode == 'post' || $post_visibility == ITEM_APPROVED) { $sql_data[TOPICS_TABLE]['sql'] = array( 'topic_last_post_id' => $data['post_id'], 'topic_last_post_time' => $current_time, 'topic_last_poster_id' => $sql_data[POSTS_TABLE]['sql']['poster_id'], 'topic_last_poster_name' => ($userdata['user_id'] == ANONYMOUS) ? $sql_data[POSTS_TABLE]['sql']['post_username'] : $userdata['username'], 'topic_last_poster_colour' => $userdata['user_colour'], 'topic_last_post_subject' => (string) $subject, ); } if ($post_mode == 'post') { $sql_data[TOPICS_TABLE]['sql']['topic_first_post_id'] = $data['post_id']; } // Update total post count and forum information if ($post_visibility == ITEM_APPROVED) { if ($post_mode == 'post') { set_config_count('num_topics', 1, true); } set_config_count('num_posts', 1, true); //TODO Name & Color $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_id = ' . $data['post_id']; $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = '" . $db->sql_escape($subject) . "'"; $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_time = ' . $current_time; $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_poster_id = ' . (int) $userdata['user_id']; $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape((!$userdata['is_registered'] && $username) ? $username : (($userdata['user_id'] != ANONYMOUS) ? $userdata['username'] : '')) . "'"; $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_colour = '" . $db->sql_escape($userdata['user_colour']) . "'"; } unset($sql_data[POSTS_TABLE]['sql']); } // Update the topics table if (isset($sql_data[TOPICS_TABLE]['sql'])) { $sql = 'UPDATE ' . TOPICS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_data[TOPICS_TABLE]['sql']) . ' WHERE topic_id = ' . $data['topic_id']; $db->sql_query($sql); unset($sql_data[TOPICS_TABLE]['sql']); } // Update the posts table if (isset($sql_data[POSTS_TABLE]['sql'])) { $sql = 'UPDATE ' . POSTS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_data[POSTS_TABLE]['sql']) . ' WHERE post_id = ' . $data['post_id']; $db->sql_query($sql); unset($sql_data[POSTS_TABLE]['sql']); } // Update Poll Tables if (isset($poll['poll_options'])) { $cur_poll_options = array(); if ($mode == 'edit') { $sql = 'SELECT * FROM ' . POLL_OPTIONS_TABLE . ' WHERE topic_id = ' . $data['topic_id'] . ' ORDER BY poll_option_id'; $result = $db->sql_query($sql); $cur_poll_options = array(); while ($row = $db->sql_fetchrow($result)) { $cur_poll_options[] = $row; } $db->sql_freeresult($result); } $sql_insert_ary = array(); for ($i = 0, $size = sizeof($poll['poll_options']); $i < $size; $i ++) { if (strlen(trim($poll['poll_options'][$i]))) { if (empty($cur_poll_options[$i])) { // If we add options we need to put them to the end to be able to preserve votes... $sql_insert_ary[] = array( 'poll_option_id' => (int) sizeof($cur_poll_options) + 1 + sizeof($sql_insert_ary), 'topic_id' => (int) $data['topic_id'], 'poll_option_text' => (string) $poll['poll_options'][$i] ); } else if ($poll['poll_options'][$i] != $cur_poll_options[$i]) { $sql = 'UPDATE ' . POLL_OPTIONS_TABLE . " SET poll_option_text = '" . $db->sql_escape($poll['poll_options'][$i]) . "' WHERE poll_option_id = " . $cur_poll_options[$i]['poll_option_id'] . ' AND topic_id = ' . $data['topic_id']; $db->sql_query($sql); } } } $db->sql_multi_insert(POLL_OPTIONS_TABLE, $sql_insert_ary); if (sizeof($poll['poll_options']) < sizeof($cur_poll_options)) { $sql = 'DELETE FROM ' . POLL_OPTIONS_TABLE . ' WHERE poll_option_id > ' . sizeof($poll['poll_options']) . ' AND topic_id = ' . $data['topic_id']; $db->sql_query($sql); } // If edited, we would need to reset votes (since options can be re-ordered above, you can't be sure if the change is for changing the text or adding an option if ($mode == 'edit' && sizeof($poll['poll_options']) != sizeof($cur_poll_options)) { $db->sql_query('DELETE FROM ' . POLL_VOTES_TABLE . ' WHERE topic_id = ' . $data['topic_id']); $db->sql_query('UPDATE ' . POLL_OPTIONS_TABLE . ' SET poll_option_total = 0 WHERE topic_id = ' . $data['topic_id']); } } // Submit Attachments if (! empty($data['attachment_data']) && $data['post_id'] && in_array($mode, array( 'post', 'reply', 'quote', 'edit' ))) { $space_taken = $files_added = 0; $orphan_rows = array(); foreach ($data['attachment_data'] as $pos => $attach_row) { $orphan_rows[(int) $attach_row['attach_id']] = array(); } if (sizeof($orphan_rows)) { $sql = 'SELECT attach_id, filesize, physical_filename FROM ' . ATTACHMENTS_TABLE . ' WHERE ' . $db->sql_in_set('attach_id', array_keys($orphan_rows)) . ' AND is_orphan = 1 AND poster_id = ' . $user->data['user_id']; $result = $db->sql_query($sql); $orphan_rows = array(); while ($row = $db->sql_fetchrow($result)) { $orphan_rows[$row['attach_id']] = $row; } $db->sql_freeresult($result); } foreach ($data['attachment_data'] as $pos => $attach_row) { if ($attach_row['is_orphan'] && ! isset($orphan_rows[$attach_row['attach_id']])) { continue; } if (! $attach_row['is_orphan']) { // update entry in db if attachment already stored in db and filespace $sql = 'UPDATE ' . ATTACHMENTS_TABLE . " SET attach_comment = '" . $db->sql_escape($attach_row['attach_comment']) . "' WHERE attach_id = " . (int) $attach_row['attach_id'] . ' AND is_orphan = 0'; $db->sql_query($sql); } else { // insert attachment into db if (! @file_exists($phpbb_root_path . $config['upload_path'] . '/' . utf8_basename($orphan_rows[$attach_row['attach_id']]['physical_filename']))) { continue; } $space_taken += $orphan_rows[$attach_row['attach_id']]['filesize']; $files_added ++; $attach_sql = array( 'post_msg_id' => $data['post_id'], 'topic_id' => $data['topic_id'], 'is_orphan' => 0, 'poster_id' => $poster_id, 'attach_comment' => $attach_row['attach_comment'] ); $sql = 'UPDATE ' . ATTACHMENTS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $attach_sql) . ' WHERE attach_id = ' . $attach_row['attach_id'] . ' AND is_orphan = 1 AND poster_id = ' . $user->data['user_id']; $db->sql_query($sql); } } if ($space_taken && $files_added) { set_config_count('upload_dir_size', $space_taken, true); set_config_count('num_files', $files_added, true); } } $first_post_has_topic_info = ($post_mode == 'edit_first_post' && (($post_visibility == ITEM_DELETED && $data['topic_posts_softdeleted'] == 1) || ($post_visibility == ITEM_UNAPPROVED && $data['topic_posts_unapproved'] == 1) || ($post_visibility == ITEM_REAPPROVE && $data['topic_posts_unapproved'] == 1) || ($post_visibility == ITEM_APPROVED && $data['topic_posts_approved'] == 1))); // Fix the post's and topic's visibility and first/last post information, when the post is edited if (($post_mode != 'post' && $post_mode != 'reply') && $data['post_visibility'] != $post_visibility) { // If the post was not approved, it could also be the starter, // so we sync the starter after approving/restoring, to ensure that the stats are correct // Same applies for the last post $is_starter = ($post_mode == 'edit_first_post' || $post_mode == 'edit_topic' || $data['post_visibility'] != ITEM_APPROVED); $is_latest = ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || $data['post_visibility'] != ITEM_APPROVED); $phpbb_content_visibility = $phpbb_container->get('content.visibility'); $phpbb_content_visibility->set_post_visibility($post_visibility, $data['post_id'], $data['topic_id'], $data['forum_id'], $userdata['user_id'], time(), '', $is_starter, $is_latest); } else if ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || $first_post_has_topic_info) { if ($post_visibility == ITEM_APPROVED || $data['topic_visibility'] == $post_visibility) { // only the subject can be changed from edit $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_post_subject = '" . $db->sql_escape($subject) . "'"; // Maybe not only the subject, but also changing anonymous usernames. ;) if ($data['poster_id'] == ANONYMOUS) { $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_poster_name = '" . $db->sql_escape($username) . "'"; } if ($post_visibility == ITEM_APPROVED) { // this does not _necessarily_ mean that we must update the info again, // it just means that we might have to $sql = 'SELECT forum_last_post_id, forum_last_post_subject FROM ' . FORUMS_TABLE . ' WHERE forum_id = ' . (int) $data['forum_id']; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); // this post is the latest post in the forum, better update if ($row['forum_last_post_id'] == $data['post_id'] && ($row['forum_last_post_subject'] !== $subject || $data['poster_id'] == ANONYMOUS)) { // the post's subject changed if ($row['forum_last_post_subject'] !== $subject) { $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = '" . $db->sql_escape($subject) . "'"; } // Update the user name if poster is anonymous... just in case a moderator changed it if ($data['poster_id'] == ANONYMOUS) { $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape($username) . "'"; } } } } } // Update forum stats $where_sql = array( POSTS_TABLE => 'post_id = ' . $data['post_id'], TOPICS_TABLE => 'topic_id = ' . $data['topic_id'], FORUMS_TABLE => 'forum_id = ' . $data['forum_id'], USERS_TABLE => 'user_id = ' . $poster_id ); foreach ($sql_data as $table => $update_ary) { if (isset($update_ary['stat']) && implode('', $update_ary['stat'])) { $sql = "UPDATE $table SET " . implode(', ', $update_ary['stat']) . ' WHERE ' . $where_sql[$table]; $db->sql_query($sql); } } // Delete topic shadows (if any exist). We do not need a shadow topic for an global announcement if ($topic_type == POST_GLOBAL) { $sql = 'DELETE FROM ' . TOPICS_TABLE . ' WHERE topic_moved_id = ' . $data['topic_id']; $db->sql_query($sql); } // Committing the transaction before updating search index $db->sql_transaction('commit'); // Delete draft if post was loaded... $draft_id = request_var('draft_loaded', 0); if ($draft_id) { $sql = 'DELETE FROM ' . DRAFTS_TABLE . " WHERE draft_id = $draft_id AND user_id = {$userdata['user_id']}"; $db->sql_query($sql); } // Index message contents if ($update_search_index && $data['enable_indexing']) { // Select the search method and do some additional checks to ensure it can actually be utilised $search_type = $config['search_type']; if (! class_exists($search_type)) { trigger_error('NO_SUCH_SEARCH_MODULE'); } $error = false; $search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user, $phpbb_dispatcher); if ($error) { trigger_error($error); } $search->index($mode, $data['post_id'], $data['message'], $subject, $poster_id, $data['forum_id']); } // Topic Notification, do not change if moderator is changing other users posts... if ($userdata['user_id'] == $poster_id) { if (! $data['notify_set'] && $data['notify']) { $sql = 'INSERT INTO ' . TOPICS_WATCH_TABLE . ' (user_id, topic_id) VALUES (' . $user->data['user_id'] . ', ' . $data['topic_id'] . ')'; $db->sql_query($sql); } else if (($config['email_enable'] || $config['jab_enable']) && $data['notify_set'] && ! $data['notify']) { $sql = 'DELETE FROM ' . TOPICS_WATCH_TABLE . ' WHERE user_id = ' . $user->data['user_id'] . ' AND topic_id = ' . $data['topic_id']; $db->sql_query($sql); } } if ($mode == 'post' || $mode == 'reply' || $mode == 'quote') { // Mark this topic as posted to markread('post', $data['forum_id'], $data['topic_id']); } // Mark this topic as read // We do not use post_time here, this is intended (post_time can have a date in the past if editing a message) markread('topic', $data['forum_id'], $data['topic_id'], time()); // if ($config['load_db_lastread'] && $userdata['is_registered']) { $sql = 'SELECT mark_time FROM ' . FORUMS_TRACK_TABLE . ' WHERE user_id = ' . $userdata['user_id'] . ' AND forum_id = ' . $data['forum_id']; $result = $db->sql_query($sql); $f_mark_time = (int) $db->sql_fetchfield('mark_time'); $db->sql_freeresult($result); } else if ($config['load_anon_lastread'] || $userdata['is_registered']) { $f_mark_time = false; } if (($config['load_db_lastread'] && $user->data['is_registered']) || $config['load_anon_lastread'] || $userdata['is_registered']) { // Update forum info $sql = 'SELECT forum_last_post_time FROM ' . FORUMS_TABLE . ' WHERE forum_id = ' . $data['forum_id']; $result = $db->sql_query($sql); $forum_last_post_time = (int) $db->sql_fetchfield('forum_last_post_time'); $db->sql_freeresult($result); update_forum_tracking_info($data['forum_id'], $forum_last_post_time, $f_mark_time, false); } // If a username was supplied or the poster is a guest, we will use the supplied username. // Doing it this way we can use "...post by guest-username..." in notifications when // "guest-username" is supplied or ommit the username if it is not. $username = ($username !== '' || ! $userdata['is_registered']) ? $username : $userdata['username']; // Send Notifications $notification_data = array_merge($data, array( 'topic_title' => (isset($data['topic_title'])) ? $data['topic_title'] : $subject, 'forum_name' => (isset($data['forum_name']) ? $data['forum_name'] : ''), 'post_username' => $username, 'poster_id' => $poster_id, 'post_text' => $data['message'], 'post_time' => $current_time, 'post_subject' => $subject )); $phpbb_notifications = $phpbb_container->get('notification_manager'); if ($post_visibility == ITEM_APPROVED) { switch ($mode) { case 'post': $phpbb_notifications->add_notifications(array( 'notification.type.quote', 'notification.type.topic' ), $notification_data); break; case 'reply': case 'quote': $phpbb_notifications->add_notifications(array( 'notification.type.quote', 'notification.type.bookmark', 'notification.type.post' ), $notification_data); break; case 'edit_topic': case 'edit_first_post': case 'edit': case 'edit_last_post': $phpbb_notifications->update_notifications(array( 'notification.type.quote', 'notification.type.bookmark', 'notification.type.topic', 'notification.type.post' ), $notification_data); break; } } else if ($post_visibility == ITEM_UNAPPROVED) { switch ($mode) { case 'post': $phpbb_notifications->add_notifications('notification.type.topic_in_queue', $notification_data); break; case 'reply': case 'quote': $phpbb_notifications->add_notifications('notification.type.post_in_queue', $notification_data); break; case 'edit_topic': case 'edit_first_post': case 'edit': case 'edit_last_post': // Nothing to do here break; } } else if ($post_visibility == ITEM_REAPPROVE) { switch ($mode) { case 'edit_topic': case 'edit_first_post': $phpbb_notifications->add_notifications('notification.type.topic_in_queue', $notification_data); // Delete the approve_post notification so we can notify the user again, // when his post got reapproved $phpbb_notifications->delete_notifications('notification.type.approve_post', $notification_data['post_id']); break; case 'edit': case 'edit_last_post': $phpbb_notifications->add_notifications('notification.type.post_in_queue', $notification_data); // Delete the approve_post notification so we can notify the user again, // when his post got reapproved $phpbb_notifications->delete_notifications('notification.type.approve_post', $notification_data['post_id']); break; case 'post': case 'reply': case 'quote': // Nothing to do here break; } } else if ($post_visibility == ITEM_DELETED) { switch ($mode) { case 'post': case 'reply': case 'quote': case 'edit_topic': case 'edit_first_post': case 'edit': case 'edit_last_post': // Nothing to do here break; } } $params = $add_anchor = ''; if ($post_visibility == ITEM_APPROVED) { $params .= '&amp;t=' . $data['topic_id']; if ($mode != 'post') { $params .= '&amp;p=' . $data['post_id']; $add_anchor = '#p' . $data['post_id']; } } else if ($mode != 'post' && $post_mode != 'edit_first_post' && $post_mode != 'edit_topic') { $params .= '&amp;t=' . $data['topic_id']; } $url = (! $params) ? "{$phpbb_root_path}viewforum.$phpEx" : "{$phpbb_root_path}viewtopic.$phpEx"; $url = append_sid($url, 'f=' . $data['forum_id'] . $params) . $add_anchor; /** * This event is used for performing actions directly after a post or topic * has been submitted. * When a new topic is posted, the topic ID is * available in the $data array. * * The only action that can be done by altering data made available to this * event is to modify the return URL ($url). * * @event core.submit_post_end * * @var string containing posting mode value * @var string containing post subject value * @var string containing post author name * @var int containing topic type value * @var array with the poll data for the post * @var array with the data for the post * @var int containing up to date post visibility * @var bool indicating if the post will be updated * @var bool indicating if the search index will be updated * @var string "Return to topic" URL * * @since 3.1.0-a3 * @change 3.1.0-RC3 Added vars mode, subject, username, topic_type, * poll, update_message, update_search_index */ $vars = array( 'mode', 'subject', 'username', 'topic_type', 'poll', 'data', 'post_visibility', 'update_message', 'update_search_index', 'url' ); extract($phpbb_dispatcher->trigger_event('core.submit_post_end', compact($vars))); return $data; }
php
protected function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $update_message = true, $update_search_index = true) { global $db, $user, $config, $auth, $phpEx, $template, $phpbb_root_path, $phpbb_container, $phpbb_dispatcher; /** * Modify the data for post submitting * * @event core.modify_submit_post_data * * @var string containing posting mode value * @var string containing post subject value * @var string containing post author name * @var int containing topic type value * @var array with the poll data for the post * @var array with the data for the post * @var bool indicating if the post will be updated * @var bool indicating if the search index will be updated * @since 3.1.0-a4 */ $vars = array( 'mode', 'subject', 'username', 'topic_type', 'poll', 'data', 'update_message', 'update_search_index' ); extract($phpbb_dispatcher->trigger_event('core.modify_submit_post_data', compact($vars))); // We do not handle erasing posts here if ($mode == 'delete') { return false; } // User Info if ($mode != 'edit' && isset($data['poster_id']) && $data['poster_id'] && $data['poster_id'] != ANONYMOUS && $data['poster_id'] != $user->data['user_id']) { $userdata = $this->get_userdata($data['poster_id']); } else { $userdata = array( 'username' => $user->data['username'], 'user_colour' => $user->data['user_colour'], 'user_id' => $user->data['user_id'], 'is_registered' => $user->data['is_registered'], ); } if (! empty($data['post_time'])) { $current_time = $data['post_time']; } else { $current_time = time(); } if ($mode == 'post') { $post_mode = 'post'; $update_message = true; } else if ($mode != 'edit') { $post_mode = 'reply'; $update_message = true; } else if ($mode == 'edit') { $post_mode = ($data['topic_posts_approved'] + $data['topic_posts_unapproved'] + $data['topic_posts_softdeleted'] == 1) ? 'edit_topic' : (($data['topic_first_post_id'] == $data['post_id']) ? 'edit_first_post' : (($data['topic_last_post_id'] == $data['post_id']) ? 'edit_last_post' : 'edit')); } // First of all make sure the subject and topic title are having the correct length. // To achieve this without cutting off between special chars we convert to an array and then count the elements. $subject = truncate_string($subject, 120); $data['topic_title'] = truncate_string($data['topic_title'], 120); // Collect some basic information about which tables and which rows to update/insert $sql_data = $topic_row = array(); $poster_id = isset($data['poster_id']) ? $data['poster_id'] : (int) $userdata['user_id']; // Retrieve some additional information if not present if ($mode == 'edit' && (! isset($data['post_visibility']) || ! isset($data['topic_visibility']) || $data['post_visibility'] === false || $data['topic_visibility'] === false)) { $sql = 'SELECT p.post_visibility, t.topic_type, t.topic_posts_approved, t.topic_posts_unapproved, t.topic_posts_softdeleted, t.topic_visibility FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p WHERE t.topic_id = p.topic_id AND p.post_id = ' . $data['post_id']; $result = $db->sql_query($sql); $topic_row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $data['topic_visibility'] = $topic_row['topic_visibility']; $data['post_visibility'] = $topic_row['post_visibility']; } // This variable indicates if the user is able to post or put into the queue $post_visibility = isset($data['post_visibility']) ? $data['post_visibility'] : ITEM_APPROVED; // MODs/Extensions are able to force any visibility on posts if (isset($data['force_approved_state'])) { $post_visibility = (in_array((int) $data['force_approved_state'], array( ITEM_APPROVED, ITEM_UNAPPROVED, ITEM_DELETED, ITEM_REAPPROVE ))) ? (int) $data['force_approved_state'] : $post_visibility; } if (isset($data['force_visibility'])) { $post_visibility = (in_array((int) $data['force_visibility'], array( ITEM_APPROVED, ITEM_UNAPPROVED, ITEM_DELETED, ITEM_REAPPROVE ))) ? (int) $data['force_visibility'] : $post_visibility; } // Start the transaction here $db->sql_transaction('begin'); // Collect Information switch ($post_mode) { case 'post': case 'reply': $sql_data[POSTS_TABLE]['sql'] = array( 'forum_id' => $data['forum_id'], 'poster_id' => (int) $userdata['user_id'], 'icon_id' => $data['icon_id'], 'poster_ip' => $user->ip, 'post_time' => $current_time, 'post_visibility' => $post_visibility, 'enable_bbcode' => $data['enable_bbcode'], 'enable_smilies' => $data['enable_smilies'], 'enable_magic_url' => $data['enable_urls'], 'enable_sig' => $data['enable_sig'], 'post_username' => ($userdata['user_id'] != ANONYMOUS) ? $username : '', 'post_subject' => $subject, 'post_text' => $data['message'], 'post_checksum' => $data['message_md5'], 'post_attachment' => (! empty($data['attachment_data'])) ? 1 : 0, 'bbcode_bitfield' => $data['bbcode_bitfield'], 'bbcode_uid' => $data['bbcode_uid'], 'post_postcount' => isset($data['post_postcount']) ? $data['post_postcount'] : 1, 'post_edit_locked' => $data['post_edit_locked'] ); break; case 'edit_first_post': case 'edit': case 'edit_last_post': case 'edit_topic': // If edit reason is given always display edit info // If editing last post then display no edit info // If m_edit permission then display no edit info // If normal edit display edit info // Display edit info if edit reason given or user is editing his post, which is not the last within the topic. if ($data['post_edit_reason'] || ($post_mode == 'edit' || $post_mode == 'edit_first_post')) { $data['post_edit_reason'] = truncate_string($data['post_edit_reason'], 255, 255, false); $sql_data[POSTS_TABLE]['sql'] = array( 'post_edit_time' => $current_time, 'post_edit_reason' => $data['post_edit_reason'], 'post_edit_user' => (int) $data['post_edit_user'] ); $sql_data[POSTS_TABLE]['stat'][] = 'post_edit_count = post_edit_count + 1'; } else if (! $data['post_edit_reason'] && $mode == 'edit') { $sql_data[POSTS_TABLE]['sql'] = array( 'post_edit_reason' => '' ); } // If the person editing this post is different to the one having posted then we will add a log entry stating the edit // Could be simplified by only adding to the log if the edit is not tracked - but this may confuse admins/mods if ($user->data['user_id'] != $poster_id) { $log_subject = ($subject) ? $subject : $data['topic_title']; add_log('mod', $data['forum_id'], $data['topic_id'], 'LOG_POST_EDITED', $log_subject, (! empty($username)) ? $username : $user->lang['GUEST'], $data['post_edit_reason']); } if (! isset($sql_data[POSTS_TABLE]['sql'])) { $sql_data[POSTS_TABLE]['sql'] = array(); } $sql_data[POSTS_TABLE]['sql'] = array_merge($sql_data[POSTS_TABLE]['sql'], array( 'forum_id' => $data['forum_id'], 'poster_id' => $data['poster_id'], 'icon_id' => $data['icon_id'], // We will change the visibility later // 'post_visibility' => $post_visibility, 'enable_bbcode' => $data['enable_bbcode'], 'enable_smilies' => $data['enable_smilies'], 'enable_magic_url' => $data['enable_urls'], 'enable_sig' => $data['enable_sig'], 'post_username' => ($username ? $username : ''), 'post_subject' => $subject, 'post_checksum' => $data['message_md5'], 'post_attachment' => (! empty($data['attachment_data'])) ? 1 : 0, 'bbcode_bitfield' => $data['bbcode_bitfield'], 'bbcode_uid' => $data['bbcode_uid'], 'post_edit_locked' => $data['post_edit_locked'] )); if ($update_message) { $sql_data[POSTS_TABLE]['sql']['post_text'] = $data['message']; } break; } $topic_row = array(); // And the topic ladies and gentlemen switch ($post_mode) { case 'post': $sql_data[TOPICS_TABLE]['sql'] = array( 'topic_poster' => (int) $user->data['user_id'], 'topic_time' => $current_time, 'topic_last_view_time' => $current_time, 'forum_id' => $data['forum_id'], 'icon_id' => $data['icon_id'], 'topic_posts_approved' => ($post_visibility == ITEM_APPROVED) ? 1 : 0, 'topic_posts_softdeleted' => ($post_visibility == ITEM_DELETED) ? 1 : 0, 'topic_posts_unapproved' => ($post_visibility == ITEM_UNAPPROVED) ? 1 : 0, 'topic_visibility' => $post_visibility, 'topic_delete_user' => ($post_visibility != ITEM_APPROVED) ? (int) $user->data['user_id'] : 0, 'topic_title' => $subject, 'topic_first_poster_name' => (! $userdata['user_id'] != ANONYMOUS && $username) ? $username : (($userdata['user_id'] != ANONYMOUS) ? $userdata['username'] : ''), 'topic_first_poster_colour' => $userdata['user_colour'], 'topic_type' => $topic_type, 'topic_time_limit' => ($topic_type == POST_STICKY || $topic_type == POST_ANNOUNCE) ? ($data['topic_time_limit'] * 86400) : 0, 'topic_attachment' => (! empty($data['attachment_data'])) ? 1 : 0, 'topic_status' => (isset($data['topic_status'])) ? $data['topic_status'] : ITEM_UNLOCKED ); if (isset($poll['poll_options']) && ! empty($poll['poll_options'])) { $poll_start = ($poll['poll_start']) ? $poll['poll_start'] : $current_time; $poll_length = $poll['poll_length'] * 86400; if ($poll_length < 0) { $poll_start = $poll_start + $poll_length; if ($poll_start < 0) { $poll_start = 0; } $poll_length = 1; } $sql_data[TOPICS_TABLE]['sql'] = array_merge($sql_data[TOPICS_TABLE]['sql'], array( 'poll_title' => $poll['poll_title'], 'poll_start' => $poll_start, 'poll_max_options' => $poll['poll_max_options'], 'poll_length' => $poll_length, 'poll_vote_change' => $poll['poll_vote_change'] )); } $sql_data[USERS_TABLE]['stat'][] = "user_lastpost_time = $current_time" . (($post_visibility == ITEM_APPROVED) ? ', user_posts = user_posts + 1' : ''); if ($post_visibility == ITEM_APPROVED) { $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_approved = forum_topics_approved + 1'; $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts_approved = forum_posts_approved + 1'; } else if ($post_visibility == ITEM_UNAPPROVED) { $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_unapproved = forum_topics_unapproved + 1'; $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts_unapproved = forum_posts_unapproved + 1'; } else if ($post_visibility == ITEM_DELETED) { $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_softdeleted = forum_topics_softdeleted + 1'; $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts_softdeleted = forum_posts_softdeleted + 1'; } break; case 'reply': $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_view_time = ' . $current_time . ', topic_bumped = 0, topic_bumper = 0' . (($post_visibility == ITEM_APPROVED) ? ', topic_posts_approved = topic_posts_approved + 1' : '') . (($post_visibility == ITEM_UNAPPROVED) ? ', topic_posts_unapproved = topic_posts_unapproved + 1' : '') . (($post_visibility == ITEM_DELETED) ? ', topic_posts_softdeleted = topic_posts_softdeleted + 1' : '') . ((! empty($data['attachment_data']) || (isset($data['topic_attachment']) && $data['topic_attachment'])) ? ', topic_attachment = 1' : ''); $sql_data[USERS_TABLE]['stat'][] = "user_lastpost_time = $current_time" . ((($data['post_postcount']) && $post_visibility == ITEM_APPROVED) ? ', user_posts = user_posts + 1' : ''); if ($post_visibility == ITEM_APPROVED) { $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts_approved = forum_posts_approved + 1'; } else if ($post_visibility == ITEM_UNAPPROVED) { $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts_unapproved = forum_posts_unapproved + 1'; } else if ($post_visibility == ITEM_DELETED) { $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts_softdeleted = forum_posts_softdeleted + 1'; } break; case 'edit_topic': case 'edit_first_post': if (isset($poll['poll_options'])) { $poll_start = ($poll['poll_start'] || empty($poll['poll_options'])) ? $poll['poll_start'] : $current_time; $poll_length = $poll['poll_length'] * 86400; if ($poll_length < 0) { $poll_start = $poll_start + $poll_length; if ($poll_start < 0) { $poll_start = 0; } $poll_length = 1; } } $sql_data[TOPICS_TABLE]['sql'] = array( 'forum_id' => $data['forum_id'], 'icon_id' => $data['icon_id'], 'topic_title' => $subject, 'topic_first_poster_name' => $username, 'topic_type' => $topic_type, 'topic_time_limit' => ($topic_type == POST_STICKY || $topic_type == POST_ANNOUNCE) ? ($data['topic_time_limit'] * 86400) : 0, 'poll_title' => (isset($poll['poll_options'])) ? $poll['poll_title'] : '', 'poll_start' => (isset($poll['poll_options'])) ? $poll_start : 0, 'poll_max_options' => (isset($poll['poll_options'])) ? $poll['poll_max_options'] : 1, 'poll_length' => (isset($poll['poll_options'])) ? $poll_length : 0, 'poll_vote_change' => (isset($poll['poll_vote_change'])) ? $poll['poll_vote_change'] : 0, 'topic_last_view_time' => $current_time, 'topic_attachment' => (! empty($data['attachment_data'])) ? 1 : (isset($data['topic_attachment']) ? $data['topic_attachment'] : 0) ); break; } /** * Modify sql query data for post submitting * * @event core.submit_post_modify_sql_data * * @var array with the data for the post * @var array with the poll data for the post * @var string containing posting mode value * @var bool with the data for the posting SQL query * @var string containing post subject value * @var int containing topic type value * @var string containing post author name * @since 3.1.3-RC1 */ $vars = array( 'data', 'poll', 'post_mode', 'sql_data', 'subject', 'topic_type', 'username' ); extract($phpbb_dispatcher->trigger_event('core.submit_post_modify_sql_data', compact($vars))); // Submit new topic if ($post_mode == 'post') { $sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_data[TOPICS_TABLE]['sql']); $db->sql_query($sql); $data['topic_id'] = $db->sql_nextid(); $sql_data[POSTS_TABLE]['sql'] = array_merge($sql_data[POSTS_TABLE]['sql'], array( 'topic_id' => $data['topic_id'] )); unset($sql_data[TOPICS_TABLE]['sql']); } // Submit new post if ($post_mode == 'post' || $post_mode == 'reply') { if ($post_mode == 'reply') { $sql_data[POSTS_TABLE]['sql'] = array_merge($sql_data[POSTS_TABLE]['sql'], array( 'topic_id' => $data['topic_id'] )); } $sql = 'INSERT INTO ' . POSTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_data[POSTS_TABLE]['sql']); $db->sql_query($sql); $data['post_id'] = $db->sql_nextid(); if ($post_mode == 'post' || $post_visibility == ITEM_APPROVED) { $sql_data[TOPICS_TABLE]['sql'] = array( 'topic_last_post_id' => $data['post_id'], 'topic_last_post_time' => $current_time, 'topic_last_poster_id' => $sql_data[POSTS_TABLE]['sql']['poster_id'], 'topic_last_poster_name' => ($userdata['user_id'] == ANONYMOUS) ? $sql_data[POSTS_TABLE]['sql']['post_username'] : $userdata['username'], 'topic_last_poster_colour' => $userdata['user_colour'], 'topic_last_post_subject' => (string) $subject, ); } if ($post_mode == 'post') { $sql_data[TOPICS_TABLE]['sql']['topic_first_post_id'] = $data['post_id']; } // Update total post count and forum information if ($post_visibility == ITEM_APPROVED) { if ($post_mode == 'post') { set_config_count('num_topics', 1, true); } set_config_count('num_posts', 1, true); //TODO Name & Color $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_id = ' . $data['post_id']; $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = '" . $db->sql_escape($subject) . "'"; $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_time = ' . $current_time; $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_poster_id = ' . (int) $userdata['user_id']; $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape((!$userdata['is_registered'] && $username) ? $username : (($userdata['user_id'] != ANONYMOUS) ? $userdata['username'] : '')) . "'"; $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_colour = '" . $db->sql_escape($userdata['user_colour']) . "'"; } unset($sql_data[POSTS_TABLE]['sql']); } // Update the topics table if (isset($sql_data[TOPICS_TABLE]['sql'])) { $sql = 'UPDATE ' . TOPICS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_data[TOPICS_TABLE]['sql']) . ' WHERE topic_id = ' . $data['topic_id']; $db->sql_query($sql); unset($sql_data[TOPICS_TABLE]['sql']); } // Update the posts table if (isset($sql_data[POSTS_TABLE]['sql'])) { $sql = 'UPDATE ' . POSTS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_data[POSTS_TABLE]['sql']) . ' WHERE post_id = ' . $data['post_id']; $db->sql_query($sql); unset($sql_data[POSTS_TABLE]['sql']); } // Update Poll Tables if (isset($poll['poll_options'])) { $cur_poll_options = array(); if ($mode == 'edit') { $sql = 'SELECT * FROM ' . POLL_OPTIONS_TABLE . ' WHERE topic_id = ' . $data['topic_id'] . ' ORDER BY poll_option_id'; $result = $db->sql_query($sql); $cur_poll_options = array(); while ($row = $db->sql_fetchrow($result)) { $cur_poll_options[] = $row; } $db->sql_freeresult($result); } $sql_insert_ary = array(); for ($i = 0, $size = sizeof($poll['poll_options']); $i < $size; $i ++) { if (strlen(trim($poll['poll_options'][$i]))) { if (empty($cur_poll_options[$i])) { // If we add options we need to put them to the end to be able to preserve votes... $sql_insert_ary[] = array( 'poll_option_id' => (int) sizeof($cur_poll_options) + 1 + sizeof($sql_insert_ary), 'topic_id' => (int) $data['topic_id'], 'poll_option_text' => (string) $poll['poll_options'][$i] ); } else if ($poll['poll_options'][$i] != $cur_poll_options[$i]) { $sql = 'UPDATE ' . POLL_OPTIONS_TABLE . " SET poll_option_text = '" . $db->sql_escape($poll['poll_options'][$i]) . "' WHERE poll_option_id = " . $cur_poll_options[$i]['poll_option_id'] . ' AND topic_id = ' . $data['topic_id']; $db->sql_query($sql); } } } $db->sql_multi_insert(POLL_OPTIONS_TABLE, $sql_insert_ary); if (sizeof($poll['poll_options']) < sizeof($cur_poll_options)) { $sql = 'DELETE FROM ' . POLL_OPTIONS_TABLE . ' WHERE poll_option_id > ' . sizeof($poll['poll_options']) . ' AND topic_id = ' . $data['topic_id']; $db->sql_query($sql); } // If edited, we would need to reset votes (since options can be re-ordered above, you can't be sure if the change is for changing the text or adding an option if ($mode == 'edit' && sizeof($poll['poll_options']) != sizeof($cur_poll_options)) { $db->sql_query('DELETE FROM ' . POLL_VOTES_TABLE . ' WHERE topic_id = ' . $data['topic_id']); $db->sql_query('UPDATE ' . POLL_OPTIONS_TABLE . ' SET poll_option_total = 0 WHERE topic_id = ' . $data['topic_id']); } } // Submit Attachments if (! empty($data['attachment_data']) && $data['post_id'] && in_array($mode, array( 'post', 'reply', 'quote', 'edit' ))) { $space_taken = $files_added = 0; $orphan_rows = array(); foreach ($data['attachment_data'] as $pos => $attach_row) { $orphan_rows[(int) $attach_row['attach_id']] = array(); } if (sizeof($orphan_rows)) { $sql = 'SELECT attach_id, filesize, physical_filename FROM ' . ATTACHMENTS_TABLE . ' WHERE ' . $db->sql_in_set('attach_id', array_keys($orphan_rows)) . ' AND is_orphan = 1 AND poster_id = ' . $user->data['user_id']; $result = $db->sql_query($sql); $orphan_rows = array(); while ($row = $db->sql_fetchrow($result)) { $orphan_rows[$row['attach_id']] = $row; } $db->sql_freeresult($result); } foreach ($data['attachment_data'] as $pos => $attach_row) { if ($attach_row['is_orphan'] && ! isset($orphan_rows[$attach_row['attach_id']])) { continue; } if (! $attach_row['is_orphan']) { // update entry in db if attachment already stored in db and filespace $sql = 'UPDATE ' . ATTACHMENTS_TABLE . " SET attach_comment = '" . $db->sql_escape($attach_row['attach_comment']) . "' WHERE attach_id = " . (int) $attach_row['attach_id'] . ' AND is_orphan = 0'; $db->sql_query($sql); } else { // insert attachment into db if (! @file_exists($phpbb_root_path . $config['upload_path'] . '/' . utf8_basename($orphan_rows[$attach_row['attach_id']]['physical_filename']))) { continue; } $space_taken += $orphan_rows[$attach_row['attach_id']]['filesize']; $files_added ++; $attach_sql = array( 'post_msg_id' => $data['post_id'], 'topic_id' => $data['topic_id'], 'is_orphan' => 0, 'poster_id' => $poster_id, 'attach_comment' => $attach_row['attach_comment'] ); $sql = 'UPDATE ' . ATTACHMENTS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $attach_sql) . ' WHERE attach_id = ' . $attach_row['attach_id'] . ' AND is_orphan = 1 AND poster_id = ' . $user->data['user_id']; $db->sql_query($sql); } } if ($space_taken && $files_added) { set_config_count('upload_dir_size', $space_taken, true); set_config_count('num_files', $files_added, true); } } $first_post_has_topic_info = ($post_mode == 'edit_first_post' && (($post_visibility == ITEM_DELETED && $data['topic_posts_softdeleted'] == 1) || ($post_visibility == ITEM_UNAPPROVED && $data['topic_posts_unapproved'] == 1) || ($post_visibility == ITEM_REAPPROVE && $data['topic_posts_unapproved'] == 1) || ($post_visibility == ITEM_APPROVED && $data['topic_posts_approved'] == 1))); // Fix the post's and topic's visibility and first/last post information, when the post is edited if (($post_mode != 'post' && $post_mode != 'reply') && $data['post_visibility'] != $post_visibility) { // If the post was not approved, it could also be the starter, // so we sync the starter after approving/restoring, to ensure that the stats are correct // Same applies for the last post $is_starter = ($post_mode == 'edit_first_post' || $post_mode == 'edit_topic' || $data['post_visibility'] != ITEM_APPROVED); $is_latest = ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || $data['post_visibility'] != ITEM_APPROVED); $phpbb_content_visibility = $phpbb_container->get('content.visibility'); $phpbb_content_visibility->set_post_visibility($post_visibility, $data['post_id'], $data['topic_id'], $data['forum_id'], $userdata['user_id'], time(), '', $is_starter, $is_latest); } else if ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || $first_post_has_topic_info) { if ($post_visibility == ITEM_APPROVED || $data['topic_visibility'] == $post_visibility) { // only the subject can be changed from edit $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_post_subject = '" . $db->sql_escape($subject) . "'"; // Maybe not only the subject, but also changing anonymous usernames. ;) if ($data['poster_id'] == ANONYMOUS) { $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_poster_name = '" . $db->sql_escape($username) . "'"; } if ($post_visibility == ITEM_APPROVED) { // this does not _necessarily_ mean that we must update the info again, // it just means that we might have to $sql = 'SELECT forum_last_post_id, forum_last_post_subject FROM ' . FORUMS_TABLE . ' WHERE forum_id = ' . (int) $data['forum_id']; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); // this post is the latest post in the forum, better update if ($row['forum_last_post_id'] == $data['post_id'] && ($row['forum_last_post_subject'] !== $subject || $data['poster_id'] == ANONYMOUS)) { // the post's subject changed if ($row['forum_last_post_subject'] !== $subject) { $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = '" . $db->sql_escape($subject) . "'"; } // Update the user name if poster is anonymous... just in case a moderator changed it if ($data['poster_id'] == ANONYMOUS) { $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape($username) . "'"; } } } } } // Update forum stats $where_sql = array( POSTS_TABLE => 'post_id = ' . $data['post_id'], TOPICS_TABLE => 'topic_id = ' . $data['topic_id'], FORUMS_TABLE => 'forum_id = ' . $data['forum_id'], USERS_TABLE => 'user_id = ' . $poster_id ); foreach ($sql_data as $table => $update_ary) { if (isset($update_ary['stat']) && implode('', $update_ary['stat'])) { $sql = "UPDATE $table SET " . implode(', ', $update_ary['stat']) . ' WHERE ' . $where_sql[$table]; $db->sql_query($sql); } } // Delete topic shadows (if any exist). We do not need a shadow topic for an global announcement if ($topic_type == POST_GLOBAL) { $sql = 'DELETE FROM ' . TOPICS_TABLE . ' WHERE topic_moved_id = ' . $data['topic_id']; $db->sql_query($sql); } // Committing the transaction before updating search index $db->sql_transaction('commit'); // Delete draft if post was loaded... $draft_id = request_var('draft_loaded', 0); if ($draft_id) { $sql = 'DELETE FROM ' . DRAFTS_TABLE . " WHERE draft_id = $draft_id AND user_id = {$userdata['user_id']}"; $db->sql_query($sql); } // Index message contents if ($update_search_index && $data['enable_indexing']) { // Select the search method and do some additional checks to ensure it can actually be utilised $search_type = $config['search_type']; if (! class_exists($search_type)) { trigger_error('NO_SUCH_SEARCH_MODULE'); } $error = false; $search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user, $phpbb_dispatcher); if ($error) { trigger_error($error); } $search->index($mode, $data['post_id'], $data['message'], $subject, $poster_id, $data['forum_id']); } // Topic Notification, do not change if moderator is changing other users posts... if ($userdata['user_id'] == $poster_id) { if (! $data['notify_set'] && $data['notify']) { $sql = 'INSERT INTO ' . TOPICS_WATCH_TABLE . ' (user_id, topic_id) VALUES (' . $user->data['user_id'] . ', ' . $data['topic_id'] . ')'; $db->sql_query($sql); } else if (($config['email_enable'] || $config['jab_enable']) && $data['notify_set'] && ! $data['notify']) { $sql = 'DELETE FROM ' . TOPICS_WATCH_TABLE . ' WHERE user_id = ' . $user->data['user_id'] . ' AND topic_id = ' . $data['topic_id']; $db->sql_query($sql); } } if ($mode == 'post' || $mode == 'reply' || $mode == 'quote') { // Mark this topic as posted to markread('post', $data['forum_id'], $data['topic_id']); } // Mark this topic as read // We do not use post_time here, this is intended (post_time can have a date in the past if editing a message) markread('topic', $data['forum_id'], $data['topic_id'], time()); // if ($config['load_db_lastread'] && $userdata['is_registered']) { $sql = 'SELECT mark_time FROM ' . FORUMS_TRACK_TABLE . ' WHERE user_id = ' . $userdata['user_id'] . ' AND forum_id = ' . $data['forum_id']; $result = $db->sql_query($sql); $f_mark_time = (int) $db->sql_fetchfield('mark_time'); $db->sql_freeresult($result); } else if ($config['load_anon_lastread'] || $userdata['is_registered']) { $f_mark_time = false; } if (($config['load_db_lastread'] && $user->data['is_registered']) || $config['load_anon_lastread'] || $userdata['is_registered']) { // Update forum info $sql = 'SELECT forum_last_post_time FROM ' . FORUMS_TABLE . ' WHERE forum_id = ' . $data['forum_id']; $result = $db->sql_query($sql); $forum_last_post_time = (int) $db->sql_fetchfield('forum_last_post_time'); $db->sql_freeresult($result); update_forum_tracking_info($data['forum_id'], $forum_last_post_time, $f_mark_time, false); } // If a username was supplied or the poster is a guest, we will use the supplied username. // Doing it this way we can use "...post by guest-username..." in notifications when // "guest-username" is supplied or ommit the username if it is not. $username = ($username !== '' || ! $userdata['is_registered']) ? $username : $userdata['username']; // Send Notifications $notification_data = array_merge($data, array( 'topic_title' => (isset($data['topic_title'])) ? $data['topic_title'] : $subject, 'forum_name' => (isset($data['forum_name']) ? $data['forum_name'] : ''), 'post_username' => $username, 'poster_id' => $poster_id, 'post_text' => $data['message'], 'post_time' => $current_time, 'post_subject' => $subject )); $phpbb_notifications = $phpbb_container->get('notification_manager'); if ($post_visibility == ITEM_APPROVED) { switch ($mode) { case 'post': $phpbb_notifications->add_notifications(array( 'notification.type.quote', 'notification.type.topic' ), $notification_data); break; case 'reply': case 'quote': $phpbb_notifications->add_notifications(array( 'notification.type.quote', 'notification.type.bookmark', 'notification.type.post' ), $notification_data); break; case 'edit_topic': case 'edit_first_post': case 'edit': case 'edit_last_post': $phpbb_notifications->update_notifications(array( 'notification.type.quote', 'notification.type.bookmark', 'notification.type.topic', 'notification.type.post' ), $notification_data); break; } } else if ($post_visibility == ITEM_UNAPPROVED) { switch ($mode) { case 'post': $phpbb_notifications->add_notifications('notification.type.topic_in_queue', $notification_data); break; case 'reply': case 'quote': $phpbb_notifications->add_notifications('notification.type.post_in_queue', $notification_data); break; case 'edit_topic': case 'edit_first_post': case 'edit': case 'edit_last_post': // Nothing to do here break; } } else if ($post_visibility == ITEM_REAPPROVE) { switch ($mode) { case 'edit_topic': case 'edit_first_post': $phpbb_notifications->add_notifications('notification.type.topic_in_queue', $notification_data); // Delete the approve_post notification so we can notify the user again, // when his post got reapproved $phpbb_notifications->delete_notifications('notification.type.approve_post', $notification_data['post_id']); break; case 'edit': case 'edit_last_post': $phpbb_notifications->add_notifications('notification.type.post_in_queue', $notification_data); // Delete the approve_post notification so we can notify the user again, // when his post got reapproved $phpbb_notifications->delete_notifications('notification.type.approve_post', $notification_data['post_id']); break; case 'post': case 'reply': case 'quote': // Nothing to do here break; } } else if ($post_visibility == ITEM_DELETED) { switch ($mode) { case 'post': case 'reply': case 'quote': case 'edit_topic': case 'edit_first_post': case 'edit': case 'edit_last_post': // Nothing to do here break; } } $params = $add_anchor = ''; if ($post_visibility == ITEM_APPROVED) { $params .= '&amp;t=' . $data['topic_id']; if ($mode != 'post') { $params .= '&amp;p=' . $data['post_id']; $add_anchor = '#p' . $data['post_id']; } } else if ($mode != 'post' && $post_mode != 'edit_first_post' && $post_mode != 'edit_topic') { $params .= '&amp;t=' . $data['topic_id']; } $url = (! $params) ? "{$phpbb_root_path}viewforum.$phpEx" : "{$phpbb_root_path}viewtopic.$phpEx"; $url = append_sid($url, 'f=' . $data['forum_id'] . $params) . $add_anchor; /** * This event is used for performing actions directly after a post or topic * has been submitted. * When a new topic is posted, the topic ID is * available in the $data array. * * The only action that can be done by altering data made available to this * event is to modify the return URL ($url). * * @event core.submit_post_end * * @var string containing posting mode value * @var string containing post subject value * @var string containing post author name * @var int containing topic type value * @var array with the poll data for the post * @var array with the data for the post * @var int containing up to date post visibility * @var bool indicating if the post will be updated * @var bool indicating if the search index will be updated * @var string "Return to topic" URL * * @since 3.1.0-a3 * @change 3.1.0-RC3 Added vars mode, subject, username, topic_type, * poll, update_message, update_search_index */ $vars = array( 'mode', 'subject', 'username', 'topic_type', 'poll', 'data', 'post_visibility', 'update_message', 'update_search_index', 'url' ); extract($phpbb_dispatcher->trigger_event('core.submit_post_end', compact($vars))); return $data; }
[ "protected", "function", "submit_post", "(", "$", "mode", ",", "$", "subject", ",", "$", "username", ",", "$", "topic_type", ",", "&", "$", "poll", ",", "&", "$", "data", ",", "$", "update_message", "=", "true", ",", "$", "update_search_index", "=", "true", ")", "{", "global", "$", "db", ",", "$", "user", ",", "$", "config", ",", "$", "auth", ",", "$", "phpEx", ",", "$", "template", ",", "$", "phpbb_root_path", ",", "$", "phpbb_container", ",", "$", "phpbb_dispatcher", ";", "/**\n\t\t * Modify the data for post submitting\n\t\t *\n\t\t * @event core.modify_submit_post_data\n\t\t *\n\t\t * @var string containing posting mode value\n\t\t * @var string containing post subject value\n\t\t * @var string containing post author name\n\t\t * @var int containing topic type value\n\t\t * @var array with the poll data for the post\n\t\t * @var array with the data for the post\n\t\t * @var bool indicating if the post will be updated\n\t\t * @var bool indicating if the search index will be updated\n\t\t * @since 3.1.0-a4\n\t\t */", "$", "vars", "=", "array", "(", "'mode'", ",", "'subject'", ",", "'username'", ",", "'topic_type'", ",", "'poll'", ",", "'data'", ",", "'update_message'", ",", "'update_search_index'", ")", ";", "extract", "(", "$", "phpbb_dispatcher", "->", "trigger_event", "(", "'core.modify_submit_post_data'", ",", "compact", "(", "$", "vars", ")", ")", ")", ";", "// We do not handle erasing posts here", "if", "(", "$", "mode", "==", "'delete'", ")", "{", "return", "false", ";", "}", "// User Info", "if", "(", "$", "mode", "!=", "'edit'", "&&", "isset", "(", "$", "data", "[", "'poster_id'", "]", ")", "&&", "$", "data", "[", "'poster_id'", "]", "&&", "$", "data", "[", "'poster_id'", "]", "!=", "ANONYMOUS", "&&", "$", "data", "[", "'poster_id'", "]", "!=", "$", "user", "->", "data", "[", "'user_id'", "]", ")", "{", "$", "userdata", "=", "$", "this", "->", "get_userdata", "(", "$", "data", "[", "'poster_id'", "]", ")", ";", "}", "else", "{", "$", "userdata", "=", "array", "(", "'username'", "=>", "$", "user", "->", "data", "[", "'username'", "]", ",", "'user_colour'", "=>", "$", "user", "->", "data", "[", "'user_colour'", "]", ",", "'user_id'", "=>", "$", "user", "->", "data", "[", "'user_id'", "]", ",", "'is_registered'", "=>", "$", "user", "->", "data", "[", "'is_registered'", "]", ",", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "data", "[", "'post_time'", "]", ")", ")", "{", "$", "current_time", "=", "$", "data", "[", "'post_time'", "]", ";", "}", "else", "{", "$", "current_time", "=", "time", "(", ")", ";", "}", "if", "(", "$", "mode", "==", "'post'", ")", "{", "$", "post_mode", "=", "'post'", ";", "$", "update_message", "=", "true", ";", "}", "else", "if", "(", "$", "mode", "!=", "'edit'", ")", "{", "$", "post_mode", "=", "'reply'", ";", "$", "update_message", "=", "true", ";", "}", "else", "if", "(", "$", "mode", "==", "'edit'", ")", "{", "$", "post_mode", "=", "(", "$", "data", "[", "'topic_posts_approved'", "]", "+", "$", "data", "[", "'topic_posts_unapproved'", "]", "+", "$", "data", "[", "'topic_posts_softdeleted'", "]", "==", "1", ")", "?", "'edit_topic'", ":", "(", "(", "$", "data", "[", "'topic_first_post_id'", "]", "==", "$", "data", "[", "'post_id'", "]", ")", "?", "'edit_first_post'", ":", "(", "(", "$", "data", "[", "'topic_last_post_id'", "]", "==", "$", "data", "[", "'post_id'", "]", ")", "?", "'edit_last_post'", ":", "'edit'", ")", ")", ";", "}", "// First of all make sure the subject and topic title are having the correct length.", "// To achieve this without cutting off between special chars we convert to an array and then count the elements.", "$", "subject", "=", "truncate_string", "(", "$", "subject", ",", "120", ")", ";", "$", "data", "[", "'topic_title'", "]", "=", "truncate_string", "(", "$", "data", "[", "'topic_title'", "]", ",", "120", ")", ";", "// Collect some basic information about which tables and which rows to update/insert", "$", "sql_data", "=", "$", "topic_row", "=", "array", "(", ")", ";", "$", "poster_id", "=", "isset", "(", "$", "data", "[", "'poster_id'", "]", ")", "?", "$", "data", "[", "'poster_id'", "]", ":", "(", "int", ")", "$", "userdata", "[", "'user_id'", "]", ";", "// Retrieve some additional information if not present", "if", "(", "$", "mode", "==", "'edit'", "&&", "(", "!", "isset", "(", "$", "data", "[", "'post_visibility'", "]", ")", "||", "!", "isset", "(", "$", "data", "[", "'topic_visibility'", "]", ")", "||", "$", "data", "[", "'post_visibility'", "]", "===", "false", "||", "$", "data", "[", "'topic_visibility'", "]", "===", "false", ")", ")", "{", "$", "sql", "=", "'SELECT p.post_visibility, t.topic_type, t.topic_posts_approved, t.topic_posts_unapproved, t.topic_posts_softdeleted, t.topic_visibility\n\t\t\t\tFROM '", ".", "TOPICS_TABLE", ".", "' t, '", ".", "POSTS_TABLE", ".", "' p\n\t\t\t\tWHERE t.topic_id = p.topic_id\n\t\t\t\t\tAND p.post_id = '", ".", "$", "data", "[", "'post_id'", "]", ";", "$", "result", "=", "$", "db", "->", "sql_query", "(", "$", "sql", ")", ";", "$", "topic_row", "=", "$", "db", "->", "sql_fetchrow", "(", "$", "result", ")", ";", "$", "db", "->", "sql_freeresult", "(", "$", "result", ")", ";", "$", "data", "[", "'topic_visibility'", "]", "=", "$", "topic_row", "[", "'topic_visibility'", "]", ";", "$", "data", "[", "'post_visibility'", "]", "=", "$", "topic_row", "[", "'post_visibility'", "]", ";", "}", "// This variable indicates if the user is able to post or put into the queue", "$", "post_visibility", "=", "isset", "(", "$", "data", "[", "'post_visibility'", "]", ")", "?", "$", "data", "[", "'post_visibility'", "]", ":", "ITEM_APPROVED", ";", "// MODs/Extensions are able to force any visibility on posts", "if", "(", "isset", "(", "$", "data", "[", "'force_approved_state'", "]", ")", ")", "{", "$", "post_visibility", "=", "(", "in_array", "(", "(", "int", ")", "$", "data", "[", "'force_approved_state'", "]", ",", "array", "(", "ITEM_APPROVED", ",", "ITEM_UNAPPROVED", ",", "ITEM_DELETED", ",", "ITEM_REAPPROVE", ")", ")", ")", "?", "(", "int", ")", "$", "data", "[", "'force_approved_state'", "]", ":", "$", "post_visibility", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "'force_visibility'", "]", ")", ")", "{", "$", "post_visibility", "=", "(", "in_array", "(", "(", "int", ")", "$", "data", "[", "'force_visibility'", "]", ",", "array", "(", "ITEM_APPROVED", ",", "ITEM_UNAPPROVED", ",", "ITEM_DELETED", ",", "ITEM_REAPPROVE", ")", ")", ")", "?", "(", "int", ")", "$", "data", "[", "'force_visibility'", "]", ":", "$", "post_visibility", ";", "}", "// Start the transaction here", "$", "db", "->", "sql_transaction", "(", "'begin'", ")", ";", "// Collect Information", "switch", "(", "$", "post_mode", ")", "{", "case", "'post'", ":", "case", "'reply'", ":", "$", "sql_data", "[", "POSTS_TABLE", "]", "[", "'sql'", "]", "=", "array", "(", "'forum_id'", "=>", "$", "data", "[", "'forum_id'", "]", ",", "'poster_id'", "=>", "(", "int", ")", "$", "userdata", "[", "'user_id'", "]", ",", "'icon_id'", "=>", "$", "data", "[", "'icon_id'", "]", ",", "'poster_ip'", "=>", "$", "user", "->", "ip", ",", "'post_time'", "=>", "$", "current_time", ",", "'post_visibility'", "=>", "$", "post_visibility", ",", "'enable_bbcode'", "=>", "$", "data", "[", "'enable_bbcode'", "]", ",", "'enable_smilies'", "=>", "$", "data", "[", "'enable_smilies'", "]", ",", "'enable_magic_url'", "=>", "$", "data", "[", "'enable_urls'", "]", ",", "'enable_sig'", "=>", "$", "data", "[", "'enable_sig'", "]", ",", "'post_username'", "=>", "(", "$", "userdata", "[", "'user_id'", "]", "!=", "ANONYMOUS", ")", "?", "$", "username", ":", "''", ",", "'post_subject'", "=>", "$", "subject", ",", "'post_text'", "=>", "$", "data", "[", "'message'", "]", ",", "'post_checksum'", "=>", "$", "data", "[", "'message_md5'", "]", ",", "'post_attachment'", "=>", "(", "!", "empty", "(", "$", "data", "[", "'attachment_data'", "]", ")", ")", "?", "1", ":", "0", ",", "'bbcode_bitfield'", "=>", "$", "data", "[", "'bbcode_bitfield'", "]", ",", "'bbcode_uid'", "=>", "$", "data", "[", "'bbcode_uid'", "]", ",", "'post_postcount'", "=>", "isset", "(", "$", "data", "[", "'post_postcount'", "]", ")", "?", "$", "data", "[", "'post_postcount'", "]", ":", "1", ",", "'post_edit_locked'", "=>", "$", "data", "[", "'post_edit_locked'", "]", ")", ";", "break", ";", "case", "'edit_first_post'", ":", "case", "'edit'", ":", "case", "'edit_last_post'", ":", "case", "'edit_topic'", ":", "// If edit reason is given always display edit info", "// If editing last post then display no edit info", "// If m_edit permission then display no edit info", "// If normal edit display edit info", "// Display edit info if edit reason given or user is editing his post, which is not the last within the topic.", "if", "(", "$", "data", "[", "'post_edit_reason'", "]", "||", "(", "$", "post_mode", "==", "'edit'", "||", "$", "post_mode", "==", "'edit_first_post'", ")", ")", "{", "$", "data", "[", "'post_edit_reason'", "]", "=", "truncate_string", "(", "$", "data", "[", "'post_edit_reason'", "]", ",", "255", ",", "255", ",", "false", ")", ";", "$", "sql_data", "[", "POSTS_TABLE", "]", "[", "'sql'", "]", "=", "array", "(", "'post_edit_time'", "=>", "$", "current_time", ",", "'post_edit_reason'", "=>", "$", "data", "[", "'post_edit_reason'", "]", ",", "'post_edit_user'", "=>", "(", "int", ")", "$", "data", "[", "'post_edit_user'", "]", ")", ";", "$", "sql_data", "[", "POSTS_TABLE", "]", "[", "'stat'", "]", "[", "]", "=", "'post_edit_count = post_edit_count + 1'", ";", "}", "else", "if", "(", "!", "$", "data", "[", "'post_edit_reason'", "]", "&&", "$", "mode", "==", "'edit'", ")", "{", "$", "sql_data", "[", "POSTS_TABLE", "]", "[", "'sql'", "]", "=", "array", "(", "'post_edit_reason'", "=>", "''", ")", ";", "}", "// If the person editing this post is different to the one having posted then we will add a log entry stating the edit", "// Could be simplified by only adding to the log if the edit is not tracked - but this may confuse admins/mods", "if", "(", "$", "user", "->", "data", "[", "'user_id'", "]", "!=", "$", "poster_id", ")", "{", "$", "log_subject", "=", "(", "$", "subject", ")", "?", "$", "subject", ":", "$", "data", "[", "'topic_title'", "]", ";", "add_log", "(", "'mod'", ",", "$", "data", "[", "'forum_id'", "]", ",", "$", "data", "[", "'topic_id'", "]", ",", "'LOG_POST_EDITED'", ",", "$", "log_subject", ",", "(", "!", "empty", "(", "$", "username", ")", ")", "?", "$", "username", ":", "$", "user", "->", "lang", "[", "'GUEST'", "]", ",", "$", "data", "[", "'post_edit_reason'", "]", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "sql_data", "[", "POSTS_TABLE", "]", "[", "'sql'", "]", ")", ")", "{", "$", "sql_data", "[", "POSTS_TABLE", "]", "[", "'sql'", "]", "=", "array", "(", ")", ";", "}", "$", "sql_data", "[", "POSTS_TABLE", "]", "[", "'sql'", "]", "=", "array_merge", "(", "$", "sql_data", "[", "POSTS_TABLE", "]", "[", "'sql'", "]", ",", "array", "(", "'forum_id'", "=>", "$", "data", "[", "'forum_id'", "]", ",", "'poster_id'", "=>", "$", "data", "[", "'poster_id'", "]", ",", "'icon_id'", "=>", "$", "data", "[", "'icon_id'", "]", ",", "// We will change the visibility later", "// 'post_visibility' => $post_visibility,", "'enable_bbcode'", "=>", "$", "data", "[", "'enable_bbcode'", "]", ",", "'enable_smilies'", "=>", "$", "data", "[", "'enable_smilies'", "]", ",", "'enable_magic_url'", "=>", "$", "data", "[", "'enable_urls'", "]", ",", "'enable_sig'", "=>", "$", "data", "[", "'enable_sig'", "]", ",", "'post_username'", "=>", "(", "$", "username", "?", "$", "username", ":", "''", ")", ",", "'post_subject'", "=>", "$", "subject", ",", "'post_checksum'", "=>", "$", "data", "[", "'message_md5'", "]", ",", "'post_attachment'", "=>", "(", "!", "empty", "(", "$", "data", "[", "'attachment_data'", "]", ")", ")", "?", "1", ":", "0", ",", "'bbcode_bitfield'", "=>", "$", "data", "[", "'bbcode_bitfield'", "]", ",", "'bbcode_uid'", "=>", "$", "data", "[", "'bbcode_uid'", "]", ",", "'post_edit_locked'", "=>", "$", "data", "[", "'post_edit_locked'", "]", ")", ")", ";", "if", "(", "$", "update_message", ")", "{", "$", "sql_data", "[", "POSTS_TABLE", "]", "[", "'sql'", "]", "[", "'post_text'", "]", "=", "$", "data", "[", "'message'", "]", ";", "}", "break", ";", "}", "$", "topic_row", "=", "array", "(", ")", ";", "// And the topic ladies and gentlemen", "switch", "(", "$", "post_mode", ")", "{", "case", "'post'", ":", "$", "sql_data", "[", "TOPICS_TABLE", "]", "[", "'sql'", "]", "=", "array", "(", "'topic_poster'", "=>", "(", "int", ")", "$", "user", "->", "data", "[", "'user_id'", "]", ",", "'topic_time'", "=>", "$", "current_time", ",", "'topic_last_view_time'", "=>", "$", "current_time", ",", "'forum_id'", "=>", "$", "data", "[", "'forum_id'", "]", ",", "'icon_id'", "=>", "$", "data", "[", "'icon_id'", "]", ",", "'topic_posts_approved'", "=>", "(", "$", "post_visibility", "==", "ITEM_APPROVED", ")", "?", "1", ":", "0", ",", "'topic_posts_softdeleted'", "=>", "(", "$", "post_visibility", "==", "ITEM_DELETED", ")", "?", "1", ":", "0", ",", "'topic_posts_unapproved'", "=>", "(", "$", "post_visibility", "==", "ITEM_UNAPPROVED", ")", "?", "1", ":", "0", ",", "'topic_visibility'", "=>", "$", "post_visibility", ",", "'topic_delete_user'", "=>", "(", "$", "post_visibility", "!=", "ITEM_APPROVED", ")", "?", "(", "int", ")", "$", "user", "->", "data", "[", "'user_id'", "]", ":", "0", ",", "'topic_title'", "=>", "$", "subject", ",", "'topic_first_poster_name'", "=>", "(", "!", "$", "userdata", "[", "'user_id'", "]", "!=", "ANONYMOUS", "&&", "$", "username", ")", "?", "$", "username", ":", "(", "(", "$", "userdata", "[", "'user_id'", "]", "!=", "ANONYMOUS", ")", "?", "$", "userdata", "[", "'username'", "]", ":", "''", ")", ",", "'topic_first_poster_colour'", "=>", "$", "userdata", "[", "'user_colour'", "]", ",", "'topic_type'", "=>", "$", "topic_type", ",", "'topic_time_limit'", "=>", "(", "$", "topic_type", "==", "POST_STICKY", "||", "$", "topic_type", "==", "POST_ANNOUNCE", ")", "?", "(", "$", "data", "[", "'topic_time_limit'", "]", "*", "86400", ")", ":", "0", ",", "'topic_attachment'", "=>", "(", "!", "empty", "(", "$", "data", "[", "'attachment_data'", "]", ")", ")", "?", "1", ":", "0", ",", "'topic_status'", "=>", "(", "isset", "(", "$", "data", "[", "'topic_status'", "]", ")", ")", "?", "$", "data", "[", "'topic_status'", "]", ":", "ITEM_UNLOCKED", ")", ";", "if", "(", "isset", "(", "$", "poll", "[", "'poll_options'", "]", ")", "&&", "!", "empty", "(", "$", "poll", "[", "'poll_options'", "]", ")", ")", "{", "$", "poll_start", "=", "(", "$", "poll", "[", "'poll_start'", "]", ")", "?", "$", "poll", "[", "'poll_start'", "]", ":", "$", "current_time", ";", "$", "poll_length", "=", "$", "poll", "[", "'poll_length'", "]", "*", "86400", ";", "if", "(", "$", "poll_length", "<", "0", ")", "{", "$", "poll_start", "=", "$", "poll_start", "+", "$", "poll_length", ";", "if", "(", "$", "poll_start", "<", "0", ")", "{", "$", "poll_start", "=", "0", ";", "}", "$", "poll_length", "=", "1", ";", "}", "$", "sql_data", "[", "TOPICS_TABLE", "]", "[", "'sql'", "]", "=", "array_merge", "(", "$", "sql_data", "[", "TOPICS_TABLE", "]", "[", "'sql'", "]", ",", "array", "(", "'poll_title'", "=>", "$", "poll", "[", "'poll_title'", "]", ",", "'poll_start'", "=>", "$", "poll_start", ",", "'poll_max_options'", "=>", "$", "poll", "[", "'poll_max_options'", "]", ",", "'poll_length'", "=>", "$", "poll_length", ",", "'poll_vote_change'", "=>", "$", "poll", "[", "'poll_vote_change'", "]", ")", ")", ";", "}", "$", "sql_data", "[", "USERS_TABLE", "]", "[", "'stat'", "]", "[", "]", "=", "\"user_lastpost_time = $current_time\"", ".", "(", "(", "$", "post_visibility", "==", "ITEM_APPROVED", ")", "?", "', user_posts = user_posts + 1'", ":", "''", ")", ";", "if", "(", "$", "post_visibility", "==", "ITEM_APPROVED", ")", "{", "$", "sql_data", "[", "FORUMS_TABLE", "]", "[", "'stat'", "]", "[", "]", "=", "'forum_topics_approved = forum_topics_approved + 1'", ";", "$", "sql_data", "[", "FORUMS_TABLE", "]", "[", "'stat'", "]", "[", "]", "=", "'forum_posts_approved = forum_posts_approved + 1'", ";", "}", "else", "if", "(", "$", "post_visibility", "==", "ITEM_UNAPPROVED", ")", "{", "$", "sql_data", "[", "FORUMS_TABLE", "]", "[", "'stat'", "]", "[", "]", "=", "'forum_topics_unapproved = forum_topics_unapproved + 1'", ";", "$", "sql_data", "[", "FORUMS_TABLE", "]", "[", "'stat'", "]", "[", "]", "=", "'forum_posts_unapproved = forum_posts_unapproved + 1'", ";", "}", "else", "if", "(", "$", "post_visibility", "==", "ITEM_DELETED", ")", "{", "$", "sql_data", "[", "FORUMS_TABLE", "]", "[", "'stat'", "]", "[", "]", "=", "'forum_topics_softdeleted = forum_topics_softdeleted + 1'", ";", "$", "sql_data", "[", "FORUMS_TABLE", "]", "[", "'stat'", "]", "[", "]", "=", "'forum_posts_softdeleted = forum_posts_softdeleted + 1'", ";", "}", "break", ";", "case", "'reply'", ":", "$", "sql_data", "[", "TOPICS_TABLE", "]", "[", "'stat'", "]", "[", "]", "=", "'topic_last_view_time = '", ".", "$", "current_time", ".", "',\n\t\t\t\t\ttopic_bumped = 0,\n\t\t\t\t\ttopic_bumper = 0'", ".", "(", "(", "$", "post_visibility", "==", "ITEM_APPROVED", ")", "?", "', topic_posts_approved = topic_posts_approved + 1'", ":", "''", ")", ".", "(", "(", "$", "post_visibility", "==", "ITEM_UNAPPROVED", ")", "?", "', topic_posts_unapproved = topic_posts_unapproved + 1'", ":", "''", ")", ".", "(", "(", "$", "post_visibility", "==", "ITEM_DELETED", ")", "?", "', topic_posts_softdeleted = topic_posts_softdeleted + 1'", ":", "''", ")", ".", "(", "(", "!", "empty", "(", "$", "data", "[", "'attachment_data'", "]", ")", "||", "(", "isset", "(", "$", "data", "[", "'topic_attachment'", "]", ")", "&&", "$", "data", "[", "'topic_attachment'", "]", ")", ")", "?", "', topic_attachment = 1'", ":", "''", ")", ";", "$", "sql_data", "[", "USERS_TABLE", "]", "[", "'stat'", "]", "[", "]", "=", "\"user_lastpost_time = $current_time\"", ".", "(", "(", "(", "$", "data", "[", "'post_postcount'", "]", ")", "&&", "$", "post_visibility", "==", "ITEM_APPROVED", ")", "?", "', user_posts = user_posts + 1'", ":", "''", ")", ";", "if", "(", "$", "post_visibility", "==", "ITEM_APPROVED", ")", "{", "$", "sql_data", "[", "FORUMS_TABLE", "]", "[", "'stat'", "]", "[", "]", "=", "'forum_posts_approved = forum_posts_approved + 1'", ";", "}", "else", "if", "(", "$", "post_visibility", "==", "ITEM_UNAPPROVED", ")", "{", "$", "sql_data", "[", "FORUMS_TABLE", "]", "[", "'stat'", "]", "[", "]", "=", "'forum_posts_unapproved = forum_posts_unapproved + 1'", ";", "}", "else", "if", "(", "$", "post_visibility", "==", "ITEM_DELETED", ")", "{", "$", "sql_data", "[", "FORUMS_TABLE", "]", "[", "'stat'", "]", "[", "]", "=", "'forum_posts_softdeleted = forum_posts_softdeleted + 1'", ";", "}", "break", ";", "case", "'edit_topic'", ":", "case", "'edit_first_post'", ":", "if", "(", "isset", "(", "$", "poll", "[", "'poll_options'", "]", ")", ")", "{", "$", "poll_start", "=", "(", "$", "poll", "[", "'poll_start'", "]", "||", "empty", "(", "$", "poll", "[", "'poll_options'", "]", ")", ")", "?", "$", "poll", "[", "'poll_start'", "]", ":", "$", "current_time", ";", "$", "poll_length", "=", "$", "poll", "[", "'poll_length'", "]", "*", "86400", ";", "if", "(", "$", "poll_length", "<", "0", ")", "{", "$", "poll_start", "=", "$", "poll_start", "+", "$", "poll_length", ";", "if", "(", "$", "poll_start", "<", "0", ")", "{", "$", "poll_start", "=", "0", ";", "}", "$", "poll_length", "=", "1", ";", "}", "}", "$", "sql_data", "[", "TOPICS_TABLE", "]", "[", "'sql'", "]", "=", "array", "(", "'forum_id'", "=>", "$", "data", "[", "'forum_id'", "]", ",", "'icon_id'", "=>", "$", "data", "[", "'icon_id'", "]", ",", "'topic_title'", "=>", "$", "subject", ",", "'topic_first_poster_name'", "=>", "$", "username", ",", "'topic_type'", "=>", "$", "topic_type", ",", "'topic_time_limit'", "=>", "(", "$", "topic_type", "==", "POST_STICKY", "||", "$", "topic_type", "==", "POST_ANNOUNCE", ")", "?", "(", "$", "data", "[", "'topic_time_limit'", "]", "*", "86400", ")", ":", "0", ",", "'poll_title'", "=>", "(", "isset", "(", "$", "poll", "[", "'poll_options'", "]", ")", ")", "?", "$", "poll", "[", "'poll_title'", "]", ":", "''", ",", "'poll_start'", "=>", "(", "isset", "(", "$", "poll", "[", "'poll_options'", "]", ")", ")", "?", "$", "poll_start", ":", "0", ",", "'poll_max_options'", "=>", "(", "isset", "(", "$", "poll", "[", "'poll_options'", "]", ")", ")", "?", "$", "poll", "[", "'poll_max_options'", "]", ":", "1", ",", "'poll_length'", "=>", "(", "isset", "(", "$", "poll", "[", "'poll_options'", "]", ")", ")", "?", "$", "poll_length", ":", "0", ",", "'poll_vote_change'", "=>", "(", "isset", "(", "$", "poll", "[", "'poll_vote_change'", "]", ")", ")", "?", "$", "poll", "[", "'poll_vote_change'", "]", ":", "0", ",", "'topic_last_view_time'", "=>", "$", "current_time", ",", "'topic_attachment'", "=>", "(", "!", "empty", "(", "$", "data", "[", "'attachment_data'", "]", ")", ")", "?", "1", ":", "(", "isset", "(", "$", "data", "[", "'topic_attachment'", "]", ")", "?", "$", "data", "[", "'topic_attachment'", "]", ":", "0", ")", ")", ";", "break", ";", "}", "/**\n\t\t * Modify sql query data for post submitting\n\t\t *\n\t\t * @event core.submit_post_modify_sql_data\n\t\t *\n\t\t * @var array with the data for the post\n\t\t * @var array with the poll data for the post\n\t\t * @var string containing posting mode value\n\t\t * @var bool with the data for the posting SQL query\n\t\t * @var string containing post subject value\n\t\t * @var int containing topic type value\n\t\t * @var string containing post author name\n\t\t * @since 3.1.3-RC1\n\t\t */", "$", "vars", "=", "array", "(", "'data'", ",", "'poll'", ",", "'post_mode'", ",", "'sql_data'", ",", "'subject'", ",", "'topic_type'", ",", "'username'", ")", ";", "extract", "(", "$", "phpbb_dispatcher", "->", "trigger_event", "(", "'core.submit_post_modify_sql_data'", ",", "compact", "(", "$", "vars", ")", ")", ")", ";", "// Submit new topic", "if", "(", "$", "post_mode", "==", "'post'", ")", "{", "$", "sql", "=", "'INSERT INTO '", ".", "TOPICS_TABLE", ".", "' '", ".", "$", "db", "->", "sql_build_array", "(", "'INSERT'", ",", "$", "sql_data", "[", "TOPICS_TABLE", "]", "[", "'sql'", "]", ")", ";", "$", "db", "->", "sql_query", "(", "$", "sql", ")", ";", "$", "data", "[", "'topic_id'", "]", "=", "$", "db", "->", "sql_nextid", "(", ")", ";", "$", "sql_data", "[", "POSTS_TABLE", "]", "[", "'sql'", "]", "=", "array_merge", "(", "$", "sql_data", "[", "POSTS_TABLE", "]", "[", "'sql'", "]", ",", "array", "(", "'topic_id'", "=>", "$", "data", "[", "'topic_id'", "]", ")", ")", ";", "unset", "(", "$", "sql_data", "[", "TOPICS_TABLE", "]", "[", "'sql'", "]", ")", ";", "}", "// Submit new post", "if", "(", "$", "post_mode", "==", "'post'", "||", "$", "post_mode", "==", "'reply'", ")", "{", "if", "(", "$", "post_mode", "==", "'reply'", ")", "{", "$", "sql_data", "[", "POSTS_TABLE", "]", "[", "'sql'", "]", "=", "array_merge", "(", "$", "sql_data", "[", "POSTS_TABLE", "]", "[", "'sql'", "]", ",", "array", "(", "'topic_id'", "=>", "$", "data", "[", "'topic_id'", "]", ")", ")", ";", "}", "$", "sql", "=", "'INSERT INTO '", ".", "POSTS_TABLE", ".", "' '", ".", "$", "db", "->", "sql_build_array", "(", "'INSERT'", ",", "$", "sql_data", "[", "POSTS_TABLE", "]", "[", "'sql'", "]", ")", ";", "$", "db", "->", "sql_query", "(", "$", "sql", ")", ";", "$", "data", "[", "'post_id'", "]", "=", "$", "db", "->", "sql_nextid", "(", ")", ";", "if", "(", "$", "post_mode", "==", "'post'", "||", "$", "post_visibility", "==", "ITEM_APPROVED", ")", "{", "$", "sql_data", "[", "TOPICS_TABLE", "]", "[", "'sql'", "]", "=", "array", "(", "'topic_last_post_id'", "=>", "$", "data", "[", "'post_id'", "]", ",", "'topic_last_post_time'", "=>", "$", "current_time", ",", "'topic_last_poster_id'", "=>", "$", "sql_data", "[", "POSTS_TABLE", "]", "[", "'sql'", "]", "[", "'poster_id'", "]", ",", "'topic_last_poster_name'", "=>", "(", "$", "userdata", "[", "'user_id'", "]", "==", "ANONYMOUS", ")", "?", "$", "sql_data", "[", "POSTS_TABLE", "]", "[", "'sql'", "]", "[", "'post_username'", "]", ":", "$", "userdata", "[", "'username'", "]", ",", "'topic_last_poster_colour'", "=>", "$", "userdata", "[", "'user_colour'", "]", ",", "'topic_last_post_subject'", "=>", "(", "string", ")", "$", "subject", ",", ")", ";", "}", "if", "(", "$", "post_mode", "==", "'post'", ")", "{", "$", "sql_data", "[", "TOPICS_TABLE", "]", "[", "'sql'", "]", "[", "'topic_first_post_id'", "]", "=", "$", "data", "[", "'post_id'", "]", ";", "}", "// Update total post count and forum information", "if", "(", "$", "post_visibility", "==", "ITEM_APPROVED", ")", "{", "if", "(", "$", "post_mode", "==", "'post'", ")", "{", "set_config_count", "(", "'num_topics'", ",", "1", ",", "true", ")", ";", "}", "set_config_count", "(", "'num_posts'", ",", "1", ",", "true", ")", ";", "//TODO Name & Color", "$", "sql_data", "[", "FORUMS_TABLE", "]", "[", "'stat'", "]", "[", "]", "=", "'forum_last_post_id = '", ".", "$", "data", "[", "'post_id'", "]", ";", "$", "sql_data", "[", "FORUMS_TABLE", "]", "[", "'stat'", "]", "[", "]", "=", "\"forum_last_post_subject = '\"", ".", "$", "db", "->", "sql_escape", "(", "$", "subject", ")", ".", "\"'\"", ";", "$", "sql_data", "[", "FORUMS_TABLE", "]", "[", "'stat'", "]", "[", "]", "=", "'forum_last_post_time = '", ".", "$", "current_time", ";", "$", "sql_data", "[", "FORUMS_TABLE", "]", "[", "'stat'", "]", "[", "]", "=", "'forum_last_poster_id = '", ".", "(", "int", ")", "$", "userdata", "[", "'user_id'", "]", ";", "$", "sql_data", "[", "FORUMS_TABLE", "]", "[", "'stat'", "]", "[", "]", "=", "\"forum_last_poster_name = '\"", ".", "$", "db", "->", "sql_escape", "(", "(", "!", "$", "userdata", "[", "'is_registered'", "]", "&&", "$", "username", ")", "?", "$", "username", ":", "(", "(", "$", "userdata", "[", "'user_id'", "]", "!=", "ANONYMOUS", ")", "?", "$", "userdata", "[", "'username'", "]", ":", "''", ")", ")", ".", "\"'\"", ";", "$", "sql_data", "[", "FORUMS_TABLE", "]", "[", "'stat'", "]", "[", "]", "=", "\"forum_last_poster_colour = '\"", ".", "$", "db", "->", "sql_escape", "(", "$", "userdata", "[", "'user_colour'", "]", ")", ".", "\"'\"", ";", "}", "unset", "(", "$", "sql_data", "[", "POSTS_TABLE", "]", "[", "'sql'", "]", ")", ";", "}", "// Update the topics table", "if", "(", "isset", "(", "$", "sql_data", "[", "TOPICS_TABLE", "]", "[", "'sql'", "]", ")", ")", "{", "$", "sql", "=", "'UPDATE '", ".", "TOPICS_TABLE", ".", "'\n\t\t\t\tSET '", ".", "$", "db", "->", "sql_build_array", "(", "'UPDATE'", ",", "$", "sql_data", "[", "TOPICS_TABLE", "]", "[", "'sql'", "]", ")", ".", "'\n\t\t\t\tWHERE topic_id = '", ".", "$", "data", "[", "'topic_id'", "]", ";", "$", "db", "->", "sql_query", "(", "$", "sql", ")", ";", "unset", "(", "$", "sql_data", "[", "TOPICS_TABLE", "]", "[", "'sql'", "]", ")", ";", "}", "// Update the posts table", "if", "(", "isset", "(", "$", "sql_data", "[", "POSTS_TABLE", "]", "[", "'sql'", "]", ")", ")", "{", "$", "sql", "=", "'UPDATE '", ".", "POSTS_TABLE", ".", "'\n\t\t\t\tSET '", ".", "$", "db", "->", "sql_build_array", "(", "'UPDATE'", ",", "$", "sql_data", "[", "POSTS_TABLE", "]", "[", "'sql'", "]", ")", ".", "'\n\t\t\t\tWHERE post_id = '", ".", "$", "data", "[", "'post_id'", "]", ";", "$", "db", "->", "sql_query", "(", "$", "sql", ")", ";", "unset", "(", "$", "sql_data", "[", "POSTS_TABLE", "]", "[", "'sql'", "]", ")", ";", "}", "// Update Poll Tables", "if", "(", "isset", "(", "$", "poll", "[", "'poll_options'", "]", ")", ")", "{", "$", "cur_poll_options", "=", "array", "(", ")", ";", "if", "(", "$", "mode", "==", "'edit'", ")", "{", "$", "sql", "=", "'SELECT *\n\t\t\t\t\tFROM '", ".", "POLL_OPTIONS_TABLE", ".", "'\n\t\t\t\t\tWHERE topic_id = '", ".", "$", "data", "[", "'topic_id'", "]", ".", "'\n\t\t\t\t\tORDER BY poll_option_id'", ";", "$", "result", "=", "$", "db", "->", "sql_query", "(", "$", "sql", ")", ";", "$", "cur_poll_options", "=", "array", "(", ")", ";", "while", "(", "$", "row", "=", "$", "db", "->", "sql_fetchrow", "(", "$", "result", ")", ")", "{", "$", "cur_poll_options", "[", "]", "=", "$", "row", ";", "}", "$", "db", "->", "sql_freeresult", "(", "$", "result", ")", ";", "}", "$", "sql_insert_ary", "=", "array", "(", ")", ";", "for", "(", "$", "i", "=", "0", ",", "$", "size", "=", "sizeof", "(", "$", "poll", "[", "'poll_options'", "]", ")", ";", "$", "i", "<", "$", "size", ";", "$", "i", "++", ")", "{", "if", "(", "strlen", "(", "trim", "(", "$", "poll", "[", "'poll_options'", "]", "[", "$", "i", "]", ")", ")", ")", "{", "if", "(", "empty", "(", "$", "cur_poll_options", "[", "$", "i", "]", ")", ")", "{", "// If we add options we need to put them to the end to be able to preserve votes...", "$", "sql_insert_ary", "[", "]", "=", "array", "(", "'poll_option_id'", "=>", "(", "int", ")", "sizeof", "(", "$", "cur_poll_options", ")", "+", "1", "+", "sizeof", "(", "$", "sql_insert_ary", ")", ",", "'topic_id'", "=>", "(", "int", ")", "$", "data", "[", "'topic_id'", "]", ",", "'poll_option_text'", "=>", "(", "string", ")", "$", "poll", "[", "'poll_options'", "]", "[", "$", "i", "]", ")", ";", "}", "else", "if", "(", "$", "poll", "[", "'poll_options'", "]", "[", "$", "i", "]", "!=", "$", "cur_poll_options", "[", "$", "i", "]", ")", "{", "$", "sql", "=", "'UPDATE '", ".", "POLL_OPTIONS_TABLE", ".", "\"\n\t\t\t\t\t\tSET poll_option_text = '\"", ".", "$", "db", "->", "sql_escape", "(", "$", "poll", "[", "'poll_options'", "]", "[", "$", "i", "]", ")", ".", "\"'\n\t\t\t\t\t\tWHERE poll_option_id = \"", ".", "$", "cur_poll_options", "[", "$", "i", "]", "[", "'poll_option_id'", "]", ".", "'\n\t\t\t\t\t\tAND topic_id = '", ".", "$", "data", "[", "'topic_id'", "]", ";", "$", "db", "->", "sql_query", "(", "$", "sql", ")", ";", "}", "}", "}", "$", "db", "->", "sql_multi_insert", "(", "POLL_OPTIONS_TABLE", ",", "$", "sql_insert_ary", ")", ";", "if", "(", "sizeof", "(", "$", "poll", "[", "'poll_options'", "]", ")", "<", "sizeof", "(", "$", "cur_poll_options", ")", ")", "{", "$", "sql", "=", "'DELETE FROM '", ".", "POLL_OPTIONS_TABLE", ".", "'\n\t\t\t\t\tWHERE poll_option_id > '", ".", "sizeof", "(", "$", "poll", "[", "'poll_options'", "]", ")", ".", "'\n\t\t\t\t\t\tAND topic_id = '", ".", "$", "data", "[", "'topic_id'", "]", ";", "$", "db", "->", "sql_query", "(", "$", "sql", ")", ";", "}", "// If edited, we would need to reset votes (since options can be re-ordered above, you can't be sure if the change is for changing the text or adding an option", "if", "(", "$", "mode", "==", "'edit'", "&&", "sizeof", "(", "$", "poll", "[", "'poll_options'", "]", ")", "!=", "sizeof", "(", "$", "cur_poll_options", ")", ")", "{", "$", "db", "->", "sql_query", "(", "'DELETE FROM '", ".", "POLL_VOTES_TABLE", ".", "' WHERE topic_id = '", ".", "$", "data", "[", "'topic_id'", "]", ")", ";", "$", "db", "->", "sql_query", "(", "'UPDATE '", ".", "POLL_OPTIONS_TABLE", ".", "' SET poll_option_total = 0 WHERE topic_id = '", ".", "$", "data", "[", "'topic_id'", "]", ")", ";", "}", "}", "// Submit Attachments", "if", "(", "!", "empty", "(", "$", "data", "[", "'attachment_data'", "]", ")", "&&", "$", "data", "[", "'post_id'", "]", "&&", "in_array", "(", "$", "mode", ",", "array", "(", "'post'", ",", "'reply'", ",", "'quote'", ",", "'edit'", ")", ")", ")", "{", "$", "space_taken", "=", "$", "files_added", "=", "0", ";", "$", "orphan_rows", "=", "array", "(", ")", ";", "foreach", "(", "$", "data", "[", "'attachment_data'", "]", "as", "$", "pos", "=>", "$", "attach_row", ")", "{", "$", "orphan_rows", "[", "(", "int", ")", "$", "attach_row", "[", "'attach_id'", "]", "]", "=", "array", "(", ")", ";", "}", "if", "(", "sizeof", "(", "$", "orphan_rows", ")", ")", "{", "$", "sql", "=", "'SELECT attach_id, filesize, physical_filename\n\t\t\tFROM '", ".", "ATTACHMENTS_TABLE", ".", "'\n\t\t\t\t\tWHERE '", ".", "$", "db", "->", "sql_in_set", "(", "'attach_id'", ",", "array_keys", "(", "$", "orphan_rows", ")", ")", ".", "'\n\t\t\t\t\t\tAND is_orphan = 1\n\t\t\t\t\t\tAND poster_id = '", ".", "$", "user", "->", "data", "[", "'user_id'", "]", ";", "$", "result", "=", "$", "db", "->", "sql_query", "(", "$", "sql", ")", ";", "$", "orphan_rows", "=", "array", "(", ")", ";", "while", "(", "$", "row", "=", "$", "db", "->", "sql_fetchrow", "(", "$", "result", ")", ")", "{", "$", "orphan_rows", "[", "$", "row", "[", "'attach_id'", "]", "]", "=", "$", "row", ";", "}", "$", "db", "->", "sql_freeresult", "(", "$", "result", ")", ";", "}", "foreach", "(", "$", "data", "[", "'attachment_data'", "]", "as", "$", "pos", "=>", "$", "attach_row", ")", "{", "if", "(", "$", "attach_row", "[", "'is_orphan'", "]", "&&", "!", "isset", "(", "$", "orphan_rows", "[", "$", "attach_row", "[", "'attach_id'", "]", "]", ")", ")", "{", "continue", ";", "}", "if", "(", "!", "$", "attach_row", "[", "'is_orphan'", "]", ")", "{", "// update entry in db if attachment already stored in db and filespace", "$", "sql", "=", "'UPDATE '", ".", "ATTACHMENTS_TABLE", ".", "\"\n\t\t\t\t\t\tSET attach_comment = '\"", ".", "$", "db", "->", "sql_escape", "(", "$", "attach_row", "[", "'attach_comment'", "]", ")", ".", "\"'\n\t\t\t\t\t\tWHERE attach_id = \"", ".", "(", "int", ")", "$", "attach_row", "[", "'attach_id'", "]", ".", "'\n\t\t\t\t\t\t\tAND is_orphan = 0'", ";", "$", "db", "->", "sql_query", "(", "$", "sql", ")", ";", "}", "else", "{", "// insert attachment into db", "if", "(", "!", "@", "file_exists", "(", "$", "phpbb_root_path", ".", "$", "config", "[", "'upload_path'", "]", ".", "'/'", ".", "utf8_basename", "(", "$", "orphan_rows", "[", "$", "attach_row", "[", "'attach_id'", "]", "]", "[", "'physical_filename'", "]", ")", ")", ")", "{", "continue", ";", "}", "$", "space_taken", "+=", "$", "orphan_rows", "[", "$", "attach_row", "[", "'attach_id'", "]", "]", "[", "'filesize'", "]", ";", "$", "files_added", "++", ";", "$", "attach_sql", "=", "array", "(", "'post_msg_id'", "=>", "$", "data", "[", "'post_id'", "]", ",", "'topic_id'", "=>", "$", "data", "[", "'topic_id'", "]", ",", "'is_orphan'", "=>", "0", ",", "'poster_id'", "=>", "$", "poster_id", ",", "'attach_comment'", "=>", "$", "attach_row", "[", "'attach_comment'", "]", ")", ";", "$", "sql", "=", "'UPDATE '", ".", "ATTACHMENTS_TABLE", ".", "' SET '", ".", "$", "db", "->", "sql_build_array", "(", "'UPDATE'", ",", "$", "attach_sql", ")", ".", "'\n\t\t\t\t\t\tWHERE attach_id = '", ".", "$", "attach_row", "[", "'attach_id'", "]", ".", "'\n\t\t\t\t\t\tAND is_orphan = 1\n\t\t\t\t\t\t\tAND poster_id = '", ".", "$", "user", "->", "data", "[", "'user_id'", "]", ";", "$", "db", "->", "sql_query", "(", "$", "sql", ")", ";", "}", "}", "if", "(", "$", "space_taken", "&&", "$", "files_added", ")", "{", "set_config_count", "(", "'upload_dir_size'", ",", "$", "space_taken", ",", "true", ")", ";", "set_config_count", "(", "'num_files'", ",", "$", "files_added", ",", "true", ")", ";", "}", "}", "$", "first_post_has_topic_info", "=", "(", "$", "post_mode", "==", "'edit_first_post'", "&&", "(", "(", "$", "post_visibility", "==", "ITEM_DELETED", "&&", "$", "data", "[", "'topic_posts_softdeleted'", "]", "==", "1", ")", "||", "(", "$", "post_visibility", "==", "ITEM_UNAPPROVED", "&&", "$", "data", "[", "'topic_posts_unapproved'", "]", "==", "1", ")", "||", "(", "$", "post_visibility", "==", "ITEM_REAPPROVE", "&&", "$", "data", "[", "'topic_posts_unapproved'", "]", "==", "1", ")", "||", "(", "$", "post_visibility", "==", "ITEM_APPROVED", "&&", "$", "data", "[", "'topic_posts_approved'", "]", "==", "1", ")", ")", ")", ";", "// Fix the post's and topic's visibility and first/last post information, when the post is edited", "if", "(", "(", "$", "post_mode", "!=", "'post'", "&&", "$", "post_mode", "!=", "'reply'", ")", "&&", "$", "data", "[", "'post_visibility'", "]", "!=", "$", "post_visibility", ")", "{", "// If the post was not approved, it could also be the starter,", "// so we sync the starter after approving/restoring, to ensure that the stats are correct", "// Same applies for the last post", "$", "is_starter", "=", "(", "$", "post_mode", "==", "'edit_first_post'", "||", "$", "post_mode", "==", "'edit_topic'", "||", "$", "data", "[", "'post_visibility'", "]", "!=", "ITEM_APPROVED", ")", ";", "$", "is_latest", "=", "(", "$", "post_mode", "==", "'edit_last_post'", "||", "$", "post_mode", "==", "'edit_topic'", "||", "$", "data", "[", "'post_visibility'", "]", "!=", "ITEM_APPROVED", ")", ";", "$", "phpbb_content_visibility", "=", "$", "phpbb_container", "->", "get", "(", "'content.visibility'", ")", ";", "$", "phpbb_content_visibility", "->", "set_post_visibility", "(", "$", "post_visibility", ",", "$", "data", "[", "'post_id'", "]", ",", "$", "data", "[", "'topic_id'", "]", ",", "$", "data", "[", "'forum_id'", "]", ",", "$", "userdata", "[", "'user_id'", "]", ",", "time", "(", ")", ",", "''", ",", "$", "is_starter", ",", "$", "is_latest", ")", ";", "}", "else", "if", "(", "$", "post_mode", "==", "'edit_last_post'", "||", "$", "post_mode", "==", "'edit_topic'", "||", "$", "first_post_has_topic_info", ")", "{", "if", "(", "$", "post_visibility", "==", "ITEM_APPROVED", "||", "$", "data", "[", "'topic_visibility'", "]", "==", "$", "post_visibility", ")", "{", "// only the subject can be changed from edit", "$", "sql_data", "[", "TOPICS_TABLE", "]", "[", "'stat'", "]", "[", "]", "=", "\"topic_last_post_subject = '\"", ".", "$", "db", "->", "sql_escape", "(", "$", "subject", ")", ".", "\"'\"", ";", "// Maybe not only the subject, but also changing anonymous usernames. ;)", "if", "(", "$", "data", "[", "'poster_id'", "]", "==", "ANONYMOUS", ")", "{", "$", "sql_data", "[", "TOPICS_TABLE", "]", "[", "'stat'", "]", "[", "]", "=", "\"topic_last_poster_name = '\"", ".", "$", "db", "->", "sql_escape", "(", "$", "username", ")", ".", "\"'\"", ";", "}", "if", "(", "$", "post_visibility", "==", "ITEM_APPROVED", ")", "{", "// this does not _necessarily_ mean that we must update the info again,", "// it just means that we might have to", "$", "sql", "=", "'SELECT forum_last_post_id, forum_last_post_subject\n\t\t\t\t\t\tFROM '", ".", "FORUMS_TABLE", ".", "'\n\t\t\t\t\t\tWHERE forum_id = '", ".", "(", "int", ")", "$", "data", "[", "'forum_id'", "]", ";", "$", "result", "=", "$", "db", "->", "sql_query", "(", "$", "sql", ")", ";", "$", "row", "=", "$", "db", "->", "sql_fetchrow", "(", "$", "result", ")", ";", "$", "db", "->", "sql_freeresult", "(", "$", "result", ")", ";", "// this post is the latest post in the forum, better update", "if", "(", "$", "row", "[", "'forum_last_post_id'", "]", "==", "$", "data", "[", "'post_id'", "]", "&&", "(", "$", "row", "[", "'forum_last_post_subject'", "]", "!==", "$", "subject", "||", "$", "data", "[", "'poster_id'", "]", "==", "ANONYMOUS", ")", ")", "{", "// the post's subject changed", "if", "(", "$", "row", "[", "'forum_last_post_subject'", "]", "!==", "$", "subject", ")", "{", "$", "sql_data", "[", "FORUMS_TABLE", "]", "[", "'stat'", "]", "[", "]", "=", "\"forum_last_post_subject = '\"", ".", "$", "db", "->", "sql_escape", "(", "$", "subject", ")", ".", "\"'\"", ";", "}", "// Update the user name if poster is anonymous... just in case a moderator changed it", "if", "(", "$", "data", "[", "'poster_id'", "]", "==", "ANONYMOUS", ")", "{", "$", "sql_data", "[", "FORUMS_TABLE", "]", "[", "'stat'", "]", "[", "]", "=", "\"forum_last_poster_name = '\"", ".", "$", "db", "->", "sql_escape", "(", "$", "username", ")", ".", "\"'\"", ";", "}", "}", "}", "}", "}", "// Update forum stats", "$", "where_sql", "=", "array", "(", "POSTS_TABLE", "=>", "'post_id = '", ".", "$", "data", "[", "'post_id'", "]", ",", "TOPICS_TABLE", "=>", "'topic_id = '", ".", "$", "data", "[", "'topic_id'", "]", ",", "FORUMS_TABLE", "=>", "'forum_id = '", ".", "$", "data", "[", "'forum_id'", "]", ",", "USERS_TABLE", "=>", "'user_id = '", ".", "$", "poster_id", ")", ";", "foreach", "(", "$", "sql_data", "as", "$", "table", "=>", "$", "update_ary", ")", "{", "if", "(", "isset", "(", "$", "update_ary", "[", "'stat'", "]", ")", "&&", "implode", "(", "''", ",", "$", "update_ary", "[", "'stat'", "]", ")", ")", "{", "$", "sql", "=", "\"UPDATE $table SET \"", ".", "implode", "(", "', '", ",", "$", "update_ary", "[", "'stat'", "]", ")", ".", "' WHERE '", ".", "$", "where_sql", "[", "$", "table", "]", ";", "$", "db", "->", "sql_query", "(", "$", "sql", ")", ";", "}", "}", "// Delete topic shadows (if any exist). We do not need a shadow topic for an global announcement", "if", "(", "$", "topic_type", "==", "POST_GLOBAL", ")", "{", "$", "sql", "=", "'DELETE FROM '", ".", "TOPICS_TABLE", ".", "'\n\t\t\t\t\t\t\tWHERE topic_moved_id = '", ".", "$", "data", "[", "'topic_id'", "]", ";", "$", "db", "->", "sql_query", "(", "$", "sql", ")", ";", "}", "// Committing the transaction before updating search index", "$", "db", "->", "sql_transaction", "(", "'commit'", ")", ";", "// Delete draft if post was loaded...", "$", "draft_id", "=", "request_var", "(", "'draft_loaded'", ",", "0", ")", ";", "if", "(", "$", "draft_id", ")", "{", "$", "sql", "=", "'DELETE FROM '", ".", "DRAFTS_TABLE", ".", "\"\n\t\t\t\t\t\t\t\tWHERE draft_id = $draft_id\n\t\t\tAND user_id = {$userdata['user_id']}\"", ";", "$", "db", "->", "sql_query", "(", "$", "sql", ")", ";", "}", "// Index message contents", "if", "(", "$", "update_search_index", "&&", "$", "data", "[", "'enable_indexing'", "]", ")", "{", "// Select the search method and do some additional checks to ensure it can actually be utilised", "$", "search_type", "=", "$", "config", "[", "'search_type'", "]", ";", "if", "(", "!", "class_exists", "(", "$", "search_type", ")", ")", "{", "trigger_error", "(", "'NO_SUCH_SEARCH_MODULE'", ")", ";", "}", "$", "error", "=", "false", ";", "$", "search", "=", "new", "$", "search_type", "(", "$", "error", ",", "$", "phpbb_root_path", ",", "$", "phpEx", ",", "$", "auth", ",", "$", "config", ",", "$", "db", ",", "$", "user", ",", "$", "phpbb_dispatcher", ")", ";", "if", "(", "$", "error", ")", "{", "trigger_error", "(", "$", "error", ")", ";", "}", "$", "search", "->", "index", "(", "$", "mode", ",", "$", "data", "[", "'post_id'", "]", ",", "$", "data", "[", "'message'", "]", ",", "$", "subject", ",", "$", "poster_id", ",", "$", "data", "[", "'forum_id'", "]", ")", ";", "}", "// Topic Notification, do not change if moderator is changing other users posts...", "if", "(", "$", "userdata", "[", "'user_id'", "]", "==", "$", "poster_id", ")", "{", "if", "(", "!", "$", "data", "[", "'notify_set'", "]", "&&", "$", "data", "[", "'notify'", "]", ")", "{", "$", "sql", "=", "'INSERT INTO '", ".", "TOPICS_WATCH_TABLE", ".", "' (user_id, topic_id)\n\t\t\t\t\tVALUES ('", ".", "$", "user", "->", "data", "[", "'user_id'", "]", ".", "', '", ".", "$", "data", "[", "'topic_id'", "]", ".", "')'", ";", "$", "db", "->", "sql_query", "(", "$", "sql", ")", ";", "}", "else", "if", "(", "(", "$", "config", "[", "'email_enable'", "]", "||", "$", "config", "[", "'jab_enable'", "]", ")", "&&", "$", "data", "[", "'notify_set'", "]", "&&", "!", "$", "data", "[", "'notify'", "]", ")", "{", "$", "sql", "=", "'DELETE FROM '", ".", "TOPICS_WATCH_TABLE", ".", "'\n\t\t\t\t\tWHERE user_id = '", ".", "$", "user", "->", "data", "[", "'user_id'", "]", ".", "'\n\t\t\t\t\t\tAND topic_id = '", ".", "$", "data", "[", "'topic_id'", "]", ";", "$", "db", "->", "sql_query", "(", "$", "sql", ")", ";", "}", "}", "if", "(", "$", "mode", "==", "'post'", "||", "$", "mode", "==", "'reply'", "||", "$", "mode", "==", "'quote'", ")", "{", "// Mark this topic as posted to", "markread", "(", "'post'", ",", "$", "data", "[", "'forum_id'", "]", ",", "$", "data", "[", "'topic_id'", "]", ")", ";", "}", "// Mark this topic as read", "// We do not use post_time here, this is intended (post_time can have a date in the past if editing a message)", "markread", "(", "'topic'", ",", "$", "data", "[", "'forum_id'", "]", ",", "$", "data", "[", "'topic_id'", "]", ",", "time", "(", ")", ")", ";", "//", "if", "(", "$", "config", "[", "'load_db_lastread'", "]", "&&", "$", "userdata", "[", "'is_registered'", "]", ")", "{", "$", "sql", "=", "'SELECT mark_time\n\t\t\t\t\tFROM '", ".", "FORUMS_TRACK_TABLE", ".", "'\n\t\t\t\t\tWHERE user_id = '", ".", "$", "userdata", "[", "'user_id'", "]", ".", "'\n\t\t\t\tAND forum_id = '", ".", "$", "data", "[", "'forum_id'", "]", ";", "$", "result", "=", "$", "db", "->", "sql_query", "(", "$", "sql", ")", ";", "$", "f_mark_time", "=", "(", "int", ")", "$", "db", "->", "sql_fetchfield", "(", "'mark_time'", ")", ";", "$", "db", "->", "sql_freeresult", "(", "$", "result", ")", ";", "}", "else", "if", "(", "$", "config", "[", "'load_anon_lastread'", "]", "||", "$", "userdata", "[", "'is_registered'", "]", ")", "{", "$", "f_mark_time", "=", "false", ";", "}", "if", "(", "(", "$", "config", "[", "'load_db_lastread'", "]", "&&", "$", "user", "->", "data", "[", "'is_registered'", "]", ")", "||", "$", "config", "[", "'load_anon_lastread'", "]", "||", "$", "userdata", "[", "'is_registered'", "]", ")", "{", "// Update forum info", "$", "sql", "=", "'SELECT forum_last_post_time\n\t\t\t\tFROM '", ".", "FORUMS_TABLE", ".", "'\n\t\t\t\tWHERE forum_id = '", ".", "$", "data", "[", "'forum_id'", "]", ";", "$", "result", "=", "$", "db", "->", "sql_query", "(", "$", "sql", ")", ";", "$", "forum_last_post_time", "=", "(", "int", ")", "$", "db", "->", "sql_fetchfield", "(", "'forum_last_post_time'", ")", ";", "$", "db", "->", "sql_freeresult", "(", "$", "result", ")", ";", "update_forum_tracking_info", "(", "$", "data", "[", "'forum_id'", "]", ",", "$", "forum_last_post_time", ",", "$", "f_mark_time", ",", "false", ")", ";", "}", "// If a username was supplied or the poster is a guest, we will use the supplied username.", "// Doing it this way we can use \"...post by guest-username...\" in notifications when", "// \"guest-username\" is supplied or ommit the username if it is not.", "$", "username", "=", "(", "$", "username", "!==", "''", "||", "!", "$", "userdata", "[", "'is_registered'", "]", ")", "?", "$", "username", ":", "$", "userdata", "[", "'username'", "]", ";", "// Send Notifications", "$", "notification_data", "=", "array_merge", "(", "$", "data", ",", "array", "(", "'topic_title'", "=>", "(", "isset", "(", "$", "data", "[", "'topic_title'", "]", ")", ")", "?", "$", "data", "[", "'topic_title'", "]", ":", "$", "subject", ",", "'forum_name'", "=>", "(", "isset", "(", "$", "data", "[", "'forum_name'", "]", ")", "?", "$", "data", "[", "'forum_name'", "]", ":", "''", ")", ",", "'post_username'", "=>", "$", "username", ",", "'poster_id'", "=>", "$", "poster_id", ",", "'post_text'", "=>", "$", "data", "[", "'message'", "]", ",", "'post_time'", "=>", "$", "current_time", ",", "'post_subject'", "=>", "$", "subject", ")", ")", ";", "$", "phpbb_notifications", "=", "$", "phpbb_container", "->", "get", "(", "'notification_manager'", ")", ";", "if", "(", "$", "post_visibility", "==", "ITEM_APPROVED", ")", "{", "switch", "(", "$", "mode", ")", "{", "case", "'post'", ":", "$", "phpbb_notifications", "->", "add_notifications", "(", "array", "(", "'notification.type.quote'", ",", "'notification.type.topic'", ")", ",", "$", "notification_data", ")", ";", "break", ";", "case", "'reply'", ":", "case", "'quote'", ":", "$", "phpbb_notifications", "->", "add_notifications", "(", "array", "(", "'notification.type.quote'", ",", "'notification.type.bookmark'", ",", "'notification.type.post'", ")", ",", "$", "notification_data", ")", ";", "break", ";", "case", "'edit_topic'", ":", "case", "'edit_first_post'", ":", "case", "'edit'", ":", "case", "'edit_last_post'", ":", "$", "phpbb_notifications", "->", "update_notifications", "(", "array", "(", "'notification.type.quote'", ",", "'notification.type.bookmark'", ",", "'notification.type.topic'", ",", "'notification.type.post'", ")", ",", "$", "notification_data", ")", ";", "break", ";", "}", "}", "else", "if", "(", "$", "post_visibility", "==", "ITEM_UNAPPROVED", ")", "{", "switch", "(", "$", "mode", ")", "{", "case", "'post'", ":", "$", "phpbb_notifications", "->", "add_notifications", "(", "'notification.type.topic_in_queue'", ",", "$", "notification_data", ")", ";", "break", ";", "case", "'reply'", ":", "case", "'quote'", ":", "$", "phpbb_notifications", "->", "add_notifications", "(", "'notification.type.post_in_queue'", ",", "$", "notification_data", ")", ";", "break", ";", "case", "'edit_topic'", ":", "case", "'edit_first_post'", ":", "case", "'edit'", ":", "case", "'edit_last_post'", ":", "// Nothing to do here", "break", ";", "}", "}", "else", "if", "(", "$", "post_visibility", "==", "ITEM_REAPPROVE", ")", "{", "switch", "(", "$", "mode", ")", "{", "case", "'edit_topic'", ":", "case", "'edit_first_post'", ":", "$", "phpbb_notifications", "->", "add_notifications", "(", "'notification.type.topic_in_queue'", ",", "$", "notification_data", ")", ";", "// Delete the approve_post notification so we can notify the user again,", "// when his post got reapproved", "$", "phpbb_notifications", "->", "delete_notifications", "(", "'notification.type.approve_post'", ",", "$", "notification_data", "[", "'post_id'", "]", ")", ";", "break", ";", "case", "'edit'", ":", "case", "'edit_last_post'", ":", "$", "phpbb_notifications", "->", "add_notifications", "(", "'notification.type.post_in_queue'", ",", "$", "notification_data", ")", ";", "// Delete the approve_post notification so we can notify the user again,", "// when his post got reapproved", "$", "phpbb_notifications", "->", "delete_notifications", "(", "'notification.type.approve_post'", ",", "$", "notification_data", "[", "'post_id'", "]", ")", ";", "break", ";", "case", "'post'", ":", "case", "'reply'", ":", "case", "'quote'", ":", "// Nothing to do here", "break", ";", "}", "}", "else", "if", "(", "$", "post_visibility", "==", "ITEM_DELETED", ")", "{", "switch", "(", "$", "mode", ")", "{", "case", "'post'", ":", "case", "'reply'", ":", "case", "'quote'", ":", "case", "'edit_topic'", ":", "case", "'edit_first_post'", ":", "case", "'edit'", ":", "case", "'edit_last_post'", ":", "// Nothing to do here", "break", ";", "}", "}", "$", "params", "=", "$", "add_anchor", "=", "''", ";", "if", "(", "$", "post_visibility", "==", "ITEM_APPROVED", ")", "{", "$", "params", ".=", "'&amp;t='", ".", "$", "data", "[", "'topic_id'", "]", ";", "if", "(", "$", "mode", "!=", "'post'", ")", "{", "$", "params", ".=", "'&amp;p='", ".", "$", "data", "[", "'post_id'", "]", ";", "$", "add_anchor", "=", "'#p'", ".", "$", "data", "[", "'post_id'", "]", ";", "}", "}", "else", "if", "(", "$", "mode", "!=", "'post'", "&&", "$", "post_mode", "!=", "'edit_first_post'", "&&", "$", "post_mode", "!=", "'edit_topic'", ")", "{", "$", "params", ".=", "'&amp;t='", ".", "$", "data", "[", "'topic_id'", "]", ";", "}", "$", "url", "=", "(", "!", "$", "params", ")", "?", "\"{$phpbb_root_path}viewforum.$phpEx\"", ":", "\"{$phpbb_root_path}viewtopic.$phpEx\"", ";", "$", "url", "=", "append_sid", "(", "$", "url", ",", "'f='", ".", "$", "data", "[", "'forum_id'", "]", ".", "$", "params", ")", ".", "$", "add_anchor", ";", "/**\n\t\t * This event is used for performing actions directly after a post or topic\n\t\t * has been submitted.\n\t\t * When a new topic is posted, the topic ID is\n\t\t * available in the $data array.\n\t\t *\n\t\t * The only action that can be done by altering data made available to this\n\t\t * event is to modify the return URL ($url).\n\t\t *\n\t\t * @event core.submit_post_end\n\t\t *\n\t\t * @var string containing posting mode value\n\t\t * @var string containing post subject value\n\t\t * @var string containing post author name\n\t\t * @var int containing topic type value\n\t\t * @var array with the poll data for the post\n\t\t * @var array with the data for the post\n\t\t * @var int containing up to date post visibility\n\t\t * @var bool indicating if the post will be updated\n\t\t * @var bool indicating if the search index will be updated\n\t\t * @var string \"Return to topic\" URL\n\t\t *\n\t\t * @since 3.1.0-a3\n\t\t * @change 3.1.0-RC3 Added vars mode, subject, username, topic_type,\n\t\t * poll, update_message, update_search_index\n\t\t */", "$", "vars", "=", "array", "(", "'mode'", ",", "'subject'", ",", "'username'", ",", "'topic_type'", ",", "'poll'", ",", "'data'", ",", "'post_visibility'", ",", "'update_message'", ",", "'update_search_index'", ",", "'url'", ")", ";", "extract", "(", "$", "phpbb_dispatcher", "->", "trigger_event", "(", "'core.submit_post_end'", ",", "compact", "(", "$", "vars", ")", ")", ")", ";", "return", "$", "data", ";", "}" ]
This is currently a modified copy of the phpBB function so it allows posting as a different user and ignores some permissions.
[ "This", "is", "currently", "a", "modified", "copy", "of", "the", "phpBB", "function", "so", "it", "allows", "posting", "as", "a", "different", "user", "and", "ignores", "some", "permissions", "." ]
train
https://github.com/gn36/phpbb-oo-posting-api/blob/d0e19482a9e1e93a435c1758a66df9324145381a/src/Gn36/OoPostingApi/posting_base.php#L13-L981
php-lug/lug
src/Component/Grid/Sort/Type/SortType.php
SortType.configureOptions
public function configureOptions(OptionsResolver $resolver) { $resolver ->setRequired(['builder', 'grid', 'sort']) ->setAllowedTypes('builder', DataSourceBuilderInterface::class) ->setAllowedTypes('grid', GridInterface::class) ->setAllowedTypes('sort', SortInterface::class); }
php
public function configureOptions(OptionsResolver $resolver) { $resolver ->setRequired(['builder', 'grid', 'sort']) ->setAllowedTypes('builder', DataSourceBuilderInterface::class) ->setAllowedTypes('grid', GridInterface::class) ->setAllowedTypes('sort', SortInterface::class); }
[ "public", "function", "configureOptions", "(", "OptionsResolver", "$", "resolver", ")", "{", "$", "resolver", "->", "setRequired", "(", "[", "'builder'", ",", "'grid'", ",", "'sort'", "]", ")", "->", "setAllowedTypes", "(", "'builder'", ",", "DataSourceBuilderInterface", "::", "class", ")", "->", "setAllowedTypes", "(", "'grid'", ",", "GridInterface", "::", "class", ")", "->", "setAllowedTypes", "(", "'sort'", ",", "SortInterface", "::", "class", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Grid/Sort/Type/SortType.php#L40-L47
Daursu/xero
src/Daursu/Xero/models/Invoice.php
Invoice.getPdf
public function getPdf($id = '') { $id = $id ? : $this->attributes[$this->primary_column]; return $this->request('GET', sprintf('%s/%s', $this->getUrl(), $id), array(), "", "pdf"); }
php
public function getPdf($id = '') { $id = $id ? : $this->attributes[$this->primary_column]; return $this->request('GET', sprintf('%s/%s', $this->getUrl(), $id), array(), "", "pdf"); }
[ "public", "function", "getPdf", "(", "$", "id", "=", "''", ")", "{", "$", "id", "=", "$", "id", "?", ":", "$", "this", "->", "attributes", "[", "$", "this", "->", "primary_column", "]", ";", "return", "$", "this", "->", "request", "(", "'GET'", ",", "sprintf", "(", "'%s/%s'", ",", "$", "this", "->", "getUrl", "(", ")", ",", "$", "id", ")", ",", "array", "(", ")", ",", "\"\"", ",", "\"pdf\"", ")", ";", "}" ]
Retrieves a PDF file of an invoice @return mixed
[ "Retrieves", "a", "PDF", "file", "of", "an", "invoice" ]
train
https://github.com/Daursu/xero/blob/f6ac2b0cd3123f9667fd07927bee6725d34df4a6/src/Daursu/Xero/models/Invoice.php#L17-L21
canis-io/yii2-broadcaster
lib/models/BroadcastSubscription.php
BroadcastSubscription.prepareConfig
public function prepareConfig($event) { if (empty($this->batch_type)) { $this->batch_type = null; } if (isset($this->_configObject)) { if (!$this->configObject->validate()) { $this->addError('config', 'Invalid configuration'); $event->isValid = false; return false; } try { $attributes = $this->configObject->attributes; unset($attributes['model']); $this->config = json_encode(['class' => get_class($this->configObject), 'attributes' => $attributes]); } catch (\Exception $e) { \d($this->_configObject); exit; } } else { $this->addError('config', 'Need to provide configuration for this subscription'); $event->isValid = false; return false; } }
php
public function prepareConfig($event) { if (empty($this->batch_type)) { $this->batch_type = null; } if (isset($this->_configObject)) { if (!$this->configObject->validate()) { $this->addError('config', 'Invalid configuration'); $event->isValid = false; return false; } try { $attributes = $this->configObject->attributes; unset($attributes['model']); $this->config = json_encode(['class' => get_class($this->configObject), 'attributes' => $attributes]); } catch (\Exception $e) { \d($this->_configObject); exit; } } else { $this->addError('config', 'Need to provide configuration for this subscription'); $event->isValid = false; return false; } }
[ "public", "function", "prepareConfig", "(", "$", "event", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "batch_type", ")", ")", "{", "$", "this", "->", "batch_type", "=", "null", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "_configObject", ")", ")", "{", "if", "(", "!", "$", "this", "->", "configObject", "->", "validate", "(", ")", ")", "{", "$", "this", "->", "addError", "(", "'config'", ",", "'Invalid configuration'", ")", ";", "$", "event", "->", "isValid", "=", "false", ";", "return", "false", ";", "}", "try", "{", "$", "attributes", "=", "$", "this", "->", "configObject", "->", "attributes", ";", "unset", "(", "$", "attributes", "[", "'model'", "]", ")", ";", "$", "this", "->", "config", "=", "json_encode", "(", "[", "'class'", "=>", "get_class", "(", "$", "this", "->", "configObject", ")", ",", "'attributes'", "=>", "$", "attributes", "]", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "\\", "d", "(", "$", "this", "->", "_configObject", ")", ";", "exit", ";", "}", "}", "else", "{", "$", "this", "->", "addError", "(", "'config'", ",", "'Need to provide configuration for this subscription'", ")", ";", "$", "event", "->", "isValid", "=", "false", ";", "return", "false", ";", "}", "}" ]
[[@doctodo method_description:serializeAction]].
[ "[[" ]
train
https://github.com/canis-io/yii2-broadcaster/blob/b8d7b5b24f2d8f4fdb29132dd85df34602dcd6b1/lib/models/BroadcastSubscription.php#L63-L87
canis-io/yii2-broadcaster
lib/models/BroadcastSubscription.php
BroadcastSubscription.getConfigObject
public function getConfigObject() { if (!isset($this->_configObject) && !empty($this->config)) { $configSettings = json_decode($this->config, true); if (isset($configSettings['class'])) { $this->_configObject = Yii::createObject($configSettings); $this->_configObject->model = $this; } } return $this->_configObject; }
php
public function getConfigObject() { if (!isset($this->_configObject) && !empty($this->config)) { $configSettings = json_decode($this->config, true); if (isset($configSettings['class'])) { $this->_configObject = Yii::createObject($configSettings); $this->_configObject->model = $this; } } return $this->_configObject; }
[ "public", "function", "getConfigObject", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "_configObject", ")", "&&", "!", "empty", "(", "$", "this", "->", "config", ")", ")", "{", "$", "configSettings", "=", "json_decode", "(", "$", "this", "->", "config", ",", "true", ")", ";", "if", "(", "isset", "(", "$", "configSettings", "[", "'class'", "]", ")", ")", "{", "$", "this", "->", "_configObject", "=", "Yii", "::", "createObject", "(", "$", "configSettings", ")", ";", "$", "this", "->", "_configObject", "->", "model", "=", "$", "this", ";", "}", "}", "return", "$", "this", "->", "_configObject", ";", "}" ]
Get action object. @return [[@doctodo return_type:getActionObject]] [[@doctodo return_description:getActionObject]]
[ "Get", "action", "object", "." ]
train
https://github.com/canis-io/yii2-broadcaster/blob/b8d7b5b24f2d8f4fdb29132dd85df34602dcd6b1/lib/models/BroadcastSubscription.php#L119-L130
ekuiter/feature-php
FeaturePhp/Aspect/AspectKernel.php
AspectKernel.generateFiles
public function generateFiles($class, $target) { $files = array(); $includes = ""; $registers = ""; foreach ($this->aspects as $aspect) { $files[] = $aspect->getStoredFile(); $includes .= "require_once __DIR__ . '/" . str_replace("'", "\'", $aspect->getRelativeFileTarget($target)) . "';\n"; $registers .= ' $container->registerAspect(new ' . $aspect->getClassName() . "());\n"; } $files[] = fphp\File\TemplateFile::fromSpecification( fphp\Specification\TemplateSpecification::fromArrayAndSettings( array( "source" => "AspectKernel.php.template", "target" => $target, "rules" => array( array("assign" => "class", "to" => $class), array("assign" => "includes", "to" => trim($includes)), array("assign" => "registers", "to" => trim($registers)) ) ), fphp\Settings::inDirectory(__DIR__)) ); return $files; }
php
public function generateFiles($class, $target) { $files = array(); $includes = ""; $registers = ""; foreach ($this->aspects as $aspect) { $files[] = $aspect->getStoredFile(); $includes .= "require_once __DIR__ . '/" . str_replace("'", "\'", $aspect->getRelativeFileTarget($target)) . "';\n"; $registers .= ' $container->registerAspect(new ' . $aspect->getClassName() . "());\n"; } $files[] = fphp\File\TemplateFile::fromSpecification( fphp\Specification\TemplateSpecification::fromArrayAndSettings( array( "source" => "AspectKernel.php.template", "target" => $target, "rules" => array( array("assign" => "class", "to" => $class), array("assign" => "includes", "to" => trim($includes)), array("assign" => "registers", "to" => trim($registers)) ) ), fphp\Settings::inDirectory(__DIR__)) ); return $files; }
[ "public", "function", "generateFiles", "(", "$", "class", ",", "$", "target", ")", "{", "$", "files", "=", "array", "(", ")", ";", "$", "includes", "=", "\"\"", ";", "$", "registers", "=", "\"\"", ";", "foreach", "(", "$", "this", "->", "aspects", "as", "$", "aspect", ")", "{", "$", "files", "[", "]", "=", "$", "aspect", "->", "getStoredFile", "(", ")", ";", "$", "includes", ".=", "\"require_once __DIR__ . '/\"", ".", "str_replace", "(", "\"'\"", ",", "\"\\'\"", ",", "$", "aspect", "->", "getRelativeFileTarget", "(", "$", "target", ")", ")", ".", "\"';\\n\"", ";", "$", "registers", ".=", "' $container->registerAspect(new '", ".", "$", "aspect", "->", "getClassName", "(", ")", ".", "\"());\\n\"", ";", "}", "$", "files", "[", "]", "=", "fphp", "\\", "File", "\\", "TemplateFile", "::", "fromSpecification", "(", "fphp", "\\", "Specification", "\\", "TemplateSpecification", "::", "fromArrayAndSettings", "(", "array", "(", "\"source\"", "=>", "\"AspectKernel.php.template\"", ",", "\"target\"", "=>", "$", "target", ",", "\"rules\"", "=>", "array", "(", "array", "(", "\"assign\"", "=>", "\"class\"", ",", "\"to\"", "=>", "$", "class", ")", ",", "array", "(", "\"assign\"", "=>", "\"includes\"", ",", "\"to\"", "=>", "trim", "(", "$", "includes", ")", ")", ",", "array", "(", "\"assign\"", "=>", "\"registers\"", ",", "\"to\"", "=>", "trim", "(", "$", "registers", ")", ")", ")", ")", ",", "fphp", "\\", "Settings", "::", "inDirectory", "(", "__DIR__", ")", ")", ")", ";", "return", "$", "files", ";", "}" ]
Generates the aspect kernel's files. This includes all aspect files and the aspect kernel itself. @param string $class @param string $target
[ "Generates", "the", "aspect", "kernel", "s", "files", ".", "This", "includes", "all", "aspect", "files", "and", "the", "aspect", "kernel", "itself", "." ]
train
https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/Aspect/AspectKernel.php#L44-L69
NuclearCMS/Hierarchy
src/Builders/ModelBuilder.php
ModelBuilder.build
public function build($name, Collection $fields = null) { $path = $this->getClassFilePath($name); $tableName = source_table_name($name); $contents = view('_hierarchy::entities.model', [ 'tableName' => $tableName, 'name' => $this->getClassName($name), 'fields' => $this->makeFields($fields), 'searchableFields' => $this->makeSearchableFields($fields, $tableName), 'mutatables' => $this->makeMutatableFields($fields) ])->render(); $this->write($path, $contents); }
php
public function build($name, Collection $fields = null) { $path = $this->getClassFilePath($name); $tableName = source_table_name($name); $contents = view('_hierarchy::entities.model', [ 'tableName' => $tableName, 'name' => $this->getClassName($name), 'fields' => $this->makeFields($fields), 'searchableFields' => $this->makeSearchableFields($fields, $tableName), 'mutatables' => $this->makeMutatableFields($fields) ])->render(); $this->write($path, $contents); }
[ "public", "function", "build", "(", "$", "name", ",", "Collection", "$", "fields", "=", "null", ")", "{", "$", "path", "=", "$", "this", "->", "getClassFilePath", "(", "$", "name", ")", ";", "$", "tableName", "=", "source_table_name", "(", "$", "name", ")", ";", "$", "contents", "=", "view", "(", "'_hierarchy::entities.model'", ",", "[", "'tableName'", "=>", "$", "tableName", ",", "'name'", "=>", "$", "this", "->", "getClassName", "(", "$", "name", ")", ",", "'fields'", "=>", "$", "this", "->", "makeFields", "(", "$", "fields", ")", ",", "'searchableFields'", "=>", "$", "this", "->", "makeSearchableFields", "(", "$", "fields", ",", "$", "tableName", ")", ",", "'mutatables'", "=>", "$", "this", "->", "makeMutatableFields", "(", "$", "fields", ")", "]", ")", "->", "render", "(", ")", ";", "$", "this", "->", "write", "(", "$", "path", ",", "$", "contents", ")", ";", "}" ]
Builds a source model @param string $name @param Collection $fields
[ "Builds", "a", "source", "model" ]
train
https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Builders/ModelBuilder.php#L20-L34
NuclearCMS/Hierarchy
src/Builders/ModelBuilder.php
ModelBuilder.makeFields
protected function makeFields(Collection $fields = null) { if (is_null($fields)) { return ''; } $fields = $fields->pluck('name')->toArray(); return count($fields) ? "'" . implode("', '", $fields) . "'" : ''; }
php
protected function makeFields(Collection $fields = null) { if (is_null($fields)) { return ''; } $fields = $fields->pluck('name')->toArray(); return count($fields) ? "'" . implode("', '", $fields) . "'" : ''; }
[ "protected", "function", "makeFields", "(", "Collection", "$", "fields", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "fields", ")", ")", "{", "return", "''", ";", "}", "$", "fields", "=", "$", "fields", "->", "pluck", "(", "'name'", ")", "->", "toArray", "(", ")", ";", "return", "count", "(", "$", "fields", ")", "?", "\"'\"", ".", "implode", "(", "\"', '\"", ",", "$", "fields", ")", ".", "\"'\"", ":", "''", ";", "}" ]
Makes fields @param Collection $fields @return string
[ "Makes", "fields" ]
train
https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Builders/ModelBuilder.php#L42-L52
NuclearCMS/Hierarchy
src/Builders/ModelBuilder.php
ModelBuilder.makeSearchableFields
protected function makeSearchableFields(Collection $fields = null, $tableName) { if (is_null($fields)) { return ''; } $searchables = []; foreach ($fields as $field) { if (intval($field->search_priority) > 0) { $searchables[] = "'{$tableName}.{$field->name}' => {$field->search_priority}"; } } return implode(",", $searchables); }
php
protected function makeSearchableFields(Collection $fields = null, $tableName) { if (is_null($fields)) { return ''; } $searchables = []; foreach ($fields as $field) { if (intval($field->search_priority) > 0) { $searchables[] = "'{$tableName}.{$field->name}' => {$field->search_priority}"; } } return implode(",", $searchables); }
[ "protected", "function", "makeSearchableFields", "(", "Collection", "$", "fields", "=", "null", ",", "$", "tableName", ")", "{", "if", "(", "is_null", "(", "$", "fields", ")", ")", "{", "return", "''", ";", "}", "$", "searchables", "=", "[", "]", ";", "foreach", "(", "$", "fields", "as", "$", "field", ")", "{", "if", "(", "intval", "(", "$", "field", "->", "search_priority", ")", ">", "0", ")", "{", "$", "searchables", "[", "]", "=", "\"'{$tableName}.{$field->name}' => {$field->search_priority}\"", ";", "}", "}", "return", "implode", "(", "\",\"", ",", "$", "searchables", ")", ";", "}" ]
Makes searchable fields @param Collection $fields @param string $tableName @return string
[ "Makes", "searchable", "fields" ]
train
https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Builders/ModelBuilder.php#L61-L79
NuclearCMS/Hierarchy
src/Builders/ModelBuilder.php
ModelBuilder.makeMutatableFields
protected function makeMutatableFields(Collection $fields = null) { if (is_null($fields)) { return ''; } $mutatables = []; foreach ($fields as $field) { if (in_array($field->type, ['document', 'gallery', 'markdown', 'node', 'node_collection'])) { $mutatables[] = "'{$field->name}' => '{$field->type}'"; } } return implode(",", $mutatables); }
php
protected function makeMutatableFields(Collection $fields = null) { if (is_null($fields)) { return ''; } $mutatables = []; foreach ($fields as $field) { if (in_array($field->type, ['document', 'gallery', 'markdown', 'node', 'node_collection'])) { $mutatables[] = "'{$field->name}' => '{$field->type}'"; } } return implode(",", $mutatables); }
[ "protected", "function", "makeMutatableFields", "(", "Collection", "$", "fields", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "fields", ")", ")", "{", "return", "''", ";", "}", "$", "mutatables", "=", "[", "]", ";", "foreach", "(", "$", "fields", "as", "$", "field", ")", "{", "if", "(", "in_array", "(", "$", "field", "->", "type", ",", "[", "'document'", ",", "'gallery'", ",", "'markdown'", ",", "'node'", ",", "'node_collection'", "]", ")", ")", "{", "$", "mutatables", "[", "]", "=", "\"'{$field->name}' => '{$field->type}'\"", ";", "}", "}", "return", "implode", "(", "\",\"", ",", "$", "mutatables", ")", ";", "}" ]
Makes mutatable fields @param Collection $fields @return string
[ "Makes", "mutatable", "fields" ]
train
https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Builders/ModelBuilder.php#L87-L105
expectation-php/expect
src/matcher/TruthyMatcher.php
TruthyMatcher.match
public function match($actual) { $this->actual = $actual; if (is_bool($this->actual)) { return $this->actual !== false; } return isset($this->actual); }
php
public function match($actual) { $this->actual = $actual; if (is_bool($this->actual)) { return $this->actual !== false; } return isset($this->actual); }
[ "public", "function", "match", "(", "$", "actual", ")", "{", "$", "this", "->", "actual", "=", "$", "actual", ";", "if", "(", "is_bool", "(", "$", "this", "->", "actual", ")", ")", "{", "return", "$", "this", "->", "actual", "!==", "false", ";", "}", "return", "isset", "(", "$", "this", "->", "actual", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/expectation-php/expect/blob/1a32c5af37f3dc8dabe4e8eedeeb21aea16ce139/src/matcher/TruthyMatcher.php#L28-L37
tttptd/laravel-responder
src/Traits/RespondsWithJson.php
RespondsWithJson.errorResponse
public function errorResponse(string $errorCode = null, int $statusCode = null, $message = null):JsonResponse { return app(Responder::class)->error($errorCode, $statusCode, $message); }
php
public function errorResponse(string $errorCode = null, int $statusCode = null, $message = null):JsonResponse { return app(Responder::class)->error($errorCode, $statusCode, $message); }
[ "public", "function", "errorResponse", "(", "string", "$", "errorCode", "=", "null", ",", "int", "$", "statusCode", "=", "null", ",", "$", "message", "=", "null", ")", ":", "JsonResponse", "{", "return", "app", "(", "Responder", "::", "class", ")", "->", "error", "(", "$", "errorCode", ",", "$", "statusCode", ",", "$", "message", ")", ";", "}" ]
Generate an error JSON response. @param string|null $errorCode @param int|null $statusCode @param mixed $message @return JsonResponse
[ "Generate", "an", "error", "JSON", "response", "." ]
train
https://github.com/tttptd/laravel-responder/blob/0e4a32701f0de755c1f1af458045829e1bd6caf6/src/Traits/RespondsWithJson.php#L27-L30
tttptd/laravel-responder
src/Traits/RespondsWithJson.php
RespondsWithJson.successResponse
public function successResponse($data = null, $statusCode = null, array $meta = []):JsonResponse { return app(Responder::class)->success($data, $statusCode, $meta); }
php
public function successResponse($data = null, $statusCode = null, array $meta = []):JsonResponse { return app(Responder::class)->success($data, $statusCode, $meta); }
[ "public", "function", "successResponse", "(", "$", "data", "=", "null", ",", "$", "statusCode", "=", "null", ",", "array", "$", "meta", "=", "[", "]", ")", ":", "JsonResponse", "{", "return", "app", "(", "Responder", "::", "class", ")", "->", "success", "(", "$", "data", ",", "$", "statusCode", ",", "$", "meta", ")", ";", "}" ]
Generate a successful JSON response. @param mixed|null $data @param int|null $statusCode @param array $meta @return \Illuminate\Http\JsonResponse
[ "Generate", "a", "successful", "JSON", "response", "." ]
train
https://github.com/tttptd/laravel-responder/blob/0e4a32701f0de755c1f1af458045829e1bd6caf6/src/Traits/RespondsWithJson.php#L40-L43
tttptd/laravel-responder
src/Traits/RespondsWithJson.php
RespondsWithJson.transform
public function transform($data = null, $transformer = null):SuccessResponseBuilder { return app(Responder::class)->transform($data, $transformer); }
php
public function transform($data = null, $transformer = null):SuccessResponseBuilder { return app(Responder::class)->transform($data, $transformer); }
[ "public", "function", "transform", "(", "$", "data", "=", "null", ",", "$", "transformer", "=", "null", ")", ":", "SuccessResponseBuilder", "{", "return", "app", "(", "Responder", "::", "class", ")", "->", "transform", "(", "$", "data", ",", "$", "transformer", ")", ";", "}" ]
Transform the data and return a success response builder. @param mixed|null $data @param callable|string|null $transformer @return \Flugg\Responder\Http\SuccessResponse
[ "Transform", "the", "data", "and", "return", "a", "success", "response", "builder", "." ]
train
https://github.com/tttptd/laravel-responder/blob/0e4a32701f0de755c1f1af458045829e1bd6caf6/src/Traits/RespondsWithJson.php#L52-L55
artscorestudio/document-bundle
Form/Factory/FormFactory.php
FormFactory.createForm
public function createForm(array $options = array()) { $options = array_merge(array('validation_groups' => $this->validationGroups), $options); return $this->formFactory->createNamed($this->name, $this->type, null, $options); }
php
public function createForm(array $options = array()) { $options = array_merge(array('validation_groups' => $this->validationGroups), $options); return $this->formFactory->createNamed($this->name, $this->type, null, $options); }
[ "public", "function", "createForm", "(", "array", "$", "options", "=", "array", "(", ")", ")", "{", "$", "options", "=", "array_merge", "(", "array", "(", "'validation_groups'", "=>", "$", "this", "->", "validationGroups", ")", ",", "$", "options", ")", ";", "return", "$", "this", "->", "formFactory", "->", "createNamed", "(", "$", "this", "->", "name", ",", "$", "this", "->", "type", ",", "null", ",", "$", "options", ")", ";", "}" ]
{@inheritDoc} @see \ASF\DocumentBundle\Form\Factory\FormFactoryInterface::createForm()
[ "{" ]
train
https://github.com/artscorestudio/document-bundle/blob/3aceab0f75de8f7dd0fad0d0db83d7940bf565c8/Form/Factory/FormFactory.php#L60-L65
kusanagi/katana-sdk-php7
src/Component/Component.php
Component.run
public function run(): bool { if ($this->startup) { $this->logger->debug('Calling startup callback'); call_user_func($this->startup, $this); } $actions = implode(', ', array_keys($this->callbacks)); $this->logger->info("Component running with callbacks for $actions"); $this->executor->execute( $this->apiFactory, $this->input, $this->callbacks, $this->error ); if ($this->shutdown) { $this->logger->debug('Calling shutdown callback'); call_user_func($this->shutdown, $this); } return true; }
php
public function run(): bool { if ($this->startup) { $this->logger->debug('Calling startup callback'); call_user_func($this->startup, $this); } $actions = implode(', ', array_keys($this->callbacks)); $this->logger->info("Component running with callbacks for $actions"); $this->executor->execute( $this->apiFactory, $this->input, $this->callbacks, $this->error ); if ($this->shutdown) { $this->logger->debug('Calling shutdown callback'); call_user_func($this->shutdown, $this); } return true; }
[ "public", "function", "run", "(", ")", ":", "bool", "{", "if", "(", "$", "this", "->", "startup", ")", "{", "$", "this", "->", "logger", "->", "debug", "(", "'Calling startup callback'", ")", ";", "call_user_func", "(", "$", "this", "->", "startup", ",", "$", "this", ")", ";", "}", "$", "actions", "=", "implode", "(", "', '", ",", "array_keys", "(", "$", "this", "->", "callbacks", ")", ")", ";", "$", "this", "->", "logger", "->", "info", "(", "\"Component running with callbacks for $actions\"", ")", ";", "$", "this", "->", "executor", "->", "execute", "(", "$", "this", "->", "apiFactory", ",", "$", "this", "->", "input", ",", "$", "this", "->", "callbacks", ",", "$", "this", "->", "error", ")", ";", "if", "(", "$", "this", "->", "shutdown", ")", "{", "$", "this", "->", "logger", "->", "debug", "(", "'Calling shutdown callback'", ")", ";", "call_user_func", "(", "$", "this", "->", "shutdown", ",", "$", "this", ")", ";", "}", "return", "true", ";", "}" ]
Run the SDK. @return bool
[ "Run", "the", "SDK", "." ]
train
https://github.com/kusanagi/katana-sdk-php7/blob/91e7860a1852c3ce79a7034f8c36f41840e69e1f/src/Component/Component.php#L131-L153