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
hametuha/wpametu
src/WPametu/API/QueryHighJack.php
QueryHighJack.rewrite_rules_array
public function rewrite_rules_array( array $rules ){ if( !empty($this->rewrites) ){ $rules = array_merge($this->rewrites, $rules); } return $rules; }
php
public function rewrite_rules_array( array $rules ){ if( !empty($this->rewrites) ){ $rules = array_merge($this->rewrites, $rules); } return $rules; }
[ "public", "function", "rewrite_rules_array", "(", "array", "$", "rules", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "rewrites", ")", ")", "{", "$", "rules", "=", "array_merge", "(", "$", "this", "->", "rewrites", ",", "$", "rules", ")", ";", "}", "return", "$", "rules", ";", "}" ]
Register rewrite rules @param array $rules @return array
[ "Register", "rewrite", "rules" ]
train
https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/API/QueryHighJack.php#L71-L76
hametuha/wpametu
src/WPametu/API/QueryHighJack.php
QueryHighJack.detect_title
final public function detect_title( \WP_Query &$wp_query ){ if( $wp_query->is_main_query() && $this->is_valid_query($wp_query) ){ add_filter('wp_title', [$this, 'wp_title'], 10, 3); } }
php
final public function detect_title( \WP_Query &$wp_query ){ if( $wp_query->is_main_query() && $this->is_valid_query($wp_query) ){ add_filter('wp_title', [$this, 'wp_title'], 10, 3); } }
[ "final", "public", "function", "detect_title", "(", "\\", "WP_Query", "&", "$", "wp_query", ")", "{", "if", "(", "$", "wp_query", "->", "is_main_query", "(", ")", "&&", "$", "this", "->", "is_valid_query", "(", "$", "wp_query", ")", ")", "{", "add_filter", "(", "'wp_title'", ",", "[", "$", "this", ",", "'wp_title'", "]", ",", "10", ",", "3", ")", ";", "}", "}" ]
Add wp_title filter if required @param \WP_Query $wp_query
[ "Add", "wp_title", "filter", "if", "required" ]
train
https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/API/QueryHighJack.php#L83-L87
hametuha/wpametu
src/WPametu/API/QueryHighJack.php
QueryHighJack.add_meta_query
protected function add_meta_query( \WP_Query &$wp_query, array $meta_query ){ $old_query = (array) $wp_query->get('meta_query'); array_push($old_query, $meta_query); $wp_query->set('meta_query', $old_query); }
php
protected function add_meta_query( \WP_Query &$wp_query, array $meta_query ){ $old_query = (array) $wp_query->get('meta_query'); array_push($old_query, $meta_query); $wp_query->set('meta_query', $old_query); }
[ "protected", "function", "add_meta_query", "(", "\\", "WP_Query", "&", "$", "wp_query", ",", "array", "$", "meta_query", ")", "{", "$", "old_query", "=", "(", "array", ")", "$", "wp_query", "->", "get", "(", "'meta_query'", ")", ";", "array_push", "(", "$", "old_query", ",", "$", "meta_query", ")", ";", "$", "wp_query", "->", "set", "(", "'meta_query'", ",", "$", "old_query", ")", ";", "}" ]
Add meta query @param \WP_Query $wp_query @param array $meta_query
[ "Add", "meta", "query" ]
train
https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/API/QueryHighJack.php#L226-L230
technote-space/wordpress-plugin-base
src/classes/models/lib/loader/controller/admin.php
Admin.plugin_action_links
private function plugin_action_links( $links ) { $link = $this->get_view( 'admin/include/action_links', [ 'url' => menu_page_url( $this->get_menu_slug(), false ), ] ); array_unshift( $links, $link ); return $links; }
php
private function plugin_action_links( $links ) { $link = $this->get_view( 'admin/include/action_links', [ 'url' => menu_page_url( $this->get_menu_slug(), false ), ] ); array_unshift( $links, $link ); return $links; }
[ "private", "function", "plugin_action_links", "(", "$", "links", ")", "{", "$", "link", "=", "$", "this", "->", "get_view", "(", "'admin/include/action_links'", ",", "[", "'url'", "=>", "menu_page_url", "(", "$", "this", "->", "get_menu_slug", "(", ")", ",", "false", ")", ",", "]", ")", ";", "array_unshift", "(", "$", "links", ",", "$", "link", ")", ";", "return", "$", "links", ";", "}" ]
@param $links @return array
[ "@param", "$links" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/loader/controller/admin.php#L250-L257
technote-space/wordpress-plugin-base
src/classes/models/lib/loader/controller/admin.php
Admin.load
private function load() { if ( isset( $this->page ) ) { if ( $this->app->user_can( $this->page->get_capability() ) ) { $this->get_view( 'admin/include/layout', [ 'page' => $this->page, 'slug' => $this->page->get_page_slug(), ], true ); } else { $this->get_view( 'admin/include/error', [ 'message' => 'Forbidden.' ], true ); } } else { $this->get_view( 'admin/include/error', [ 'message' => 'Page not found.' ], true ); } }
php
private function load() { if ( isset( $this->page ) ) { if ( $this->app->user_can( $this->page->get_capability() ) ) { $this->get_view( 'admin/include/layout', [ 'page' => $this->page, 'slug' => $this->page->get_page_slug(), ], true ); } else { $this->get_view( 'admin/include/error', [ 'message' => 'Forbidden.' ], true ); } } else { $this->get_view( 'admin/include/error', [ 'message' => 'Page not found.' ], true ); } }
[ "private", "function", "load", "(", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "page", ")", ")", "{", "if", "(", "$", "this", "->", "app", "->", "user_can", "(", "$", "this", "->", "page", "->", "get_capability", "(", ")", ")", ")", "{", "$", "this", "->", "get_view", "(", "'admin/include/layout'", ",", "[", "'page'", "=>", "$", "this", "->", "page", ",", "'slug'", "=>", "$", "this", "->", "page", "->", "get_page_slug", "(", ")", ",", "]", ",", "true", ")", ";", "}", "else", "{", "$", "this", "->", "get_view", "(", "'admin/include/error'", ",", "[", "'message'", "=>", "'Forbidden.'", "]", ",", "true", ")", ";", "}", "}", "else", "{", "$", "this", "->", "get_view", "(", "'admin/include/error'", ",", "[", "'message'", "=>", "'Page not found.'", "]", ",", "true", ")", ";", "}", "}" ]
load
[ "load" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/loader/controller/admin.php#L293-L306
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo/Data.php
Dwoo_Data.clear
public function clear($name = null) { if ($name === null) { $this->data = array(); } elseif (is_array($name)) { foreach ($name as $index) unset($this->data[$index]); } else { unset($this->data[$name]); } }
php
public function clear($name = null) { if ($name === null) { $this->data = array(); } elseif (is_array($name)) { foreach ($name as $index) unset($this->data[$index]); } else { unset($this->data[$name]); } }
[ "public", "function", "clear", "(", "$", "name", "=", "null", ")", "{", "if", "(", "$", "name", "===", "null", ")", "{", "$", "this", "->", "data", "=", "array", "(", ")", ";", "}", "elseif", "(", "is_array", "(", "$", "name", ")", ")", "{", "foreach", "(", "$", "name", "as", "$", "index", ")", "unset", "(", "$", "this", "->", "data", "[", "$", "index", "]", ")", ";", "}", "else", "{", "unset", "(", "$", "this", "->", "data", "[", "$", "name", "]", ")", ";", "}", "}" ]
clears a the entire data or only the given key @param array|string $name clears only one value if you give a name, multiple values if you give an array of names, or the entire data if left null
[ "clears", "a", "the", "entire", "data", "or", "only", "the", "given", "key" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Data.php#L43-L53
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo/Data.php
Dwoo_Data.mergeData
public function mergeData(array $data) { $args = func_get_args(); while (list(,$v) = each($args)) { if (is_array($v)) { $this->data = array_merge($this->data, $v); } } }
php
public function mergeData(array $data) { $args = func_get_args(); while (list(,$v) = each($args)) { if (is_array($v)) { $this->data = array_merge($this->data, $v); } } }
[ "public", "function", "mergeData", "(", "array", "$", "data", ")", "{", "$", "args", "=", "func_get_args", "(", ")", ";", "while", "(", "list", "(", ",", "$", "v", ")", "=", "each", "(", "$", "args", ")", ")", "{", "if", "(", "is_array", "(", "$", "v", ")", ")", "{", "$", "this", "->", "data", "=", "array_merge", "(", "$", "this", "->", "data", ",", "$", "v", ")", ";", "}", "}", "}" ]
merges the given array(s) with the current data with array_merge @param array $data the array to merge @param array $data2 $data3 ... other arrays to merge, optional, etc.
[ "merges", "the", "given", "array", "(", "s", ")", "with", "the", "current", "data", "with", "array_merge" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Data.php#L71-L79
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo/Data.php
Dwoo_Data.assign
public function assign($name, $val = null) { if (is_array($name)) { reset($name); while (list($k,$v) = each($name)) $this->data[$k] = $v; } else { $this->data[$name] = $val; } }
php
public function assign($name, $val = null) { if (is_array($name)) { reset($name); while (list($k,$v) = each($name)) $this->data[$k] = $v; } else { $this->data[$name] = $val; } }
[ "public", "function", "assign", "(", "$", "name", ",", "$", "val", "=", "null", ")", "{", "if", "(", "is_array", "(", "$", "name", ")", ")", "{", "reset", "(", "$", "name", ")", ";", "while", "(", "list", "(", "$", "k", ",", "$", "v", ")", "=", "each", "(", "$", "name", ")", ")", "$", "this", "->", "data", "[", "$", "k", "]", "=", "$", "v", ";", "}", "else", "{", "$", "this", "->", "data", "[", "$", "name", "]", "=", "$", "val", ";", "}", "}" ]
assigns a value or an array of values to the data object @param array|string $name an associative array of multiple (index=>value) or a string that is the index to use, i.e. a value assigned to "foo" will be accessible in the template through {$foo} @param mixed $val the value to assign, or null if $name was an array
[ "assigns", "a", "value", "or", "an", "array", "of", "values", "to", "the", "data", "object" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Data.php#L89-L98
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/implementations/expression_pgsql.php
ezcQueryExpressionPgsql.subString
public function subString( $value, $from, $len = null ) { $value = $this->getIdentifier( $value ); if ( $len === null ) { $len = $this->getIdentifier( $len ); return "substr( {$value}, {$from} )"; } else { return "substr( {$value}, {$from}, {$len} )"; } }
php
public function subString( $value, $from, $len = null ) { $value = $this->getIdentifier( $value ); if ( $len === null ) { $len = $this->getIdentifier( $len ); return "substr( {$value}, {$from} )"; } else { return "substr( {$value}, {$from}, {$len} )"; } }
[ "public", "function", "subString", "(", "$", "value", ",", "$", "from", ",", "$", "len", "=", "null", ")", "{", "$", "value", "=", "$", "this", "->", "getIdentifier", "(", "$", "value", ")", ";", "if", "(", "$", "len", "===", "null", ")", "{", "$", "len", "=", "$", "this", "->", "getIdentifier", "(", "$", "len", ")", ";", "return", "\"substr( {$value}, {$from} )\"", ";", "}", "else", "{", "return", "\"substr( {$value}, {$from}, {$len} )\"", ";", "}", "}" ]
Returns part of a string. Note: Not SQL92, but common functionality. @param string $value the target $value the string or the string column. @param int $from extract from this characeter. @param int $len extract this amount of characters. @return string sql that extracts part of a string.
[ "Returns", "part", "of", "a", "string", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/implementations/expression_pgsql.php#L83-L95
kusanagi/katana-sdk-php7
src/Api/Factory/ServiceApiFactory.php
ServiceApiFactory.build
public function build( $action, array $data, CliInput $input, Mapping $mapping ) { $context = new ZMQContext(); $socket = new ZMQSocket($context, ZMQ::SOCKET_REQ); $socket->setSockOpt(ZMQ::SOCKOPT_LINGER, 0); if ($input->getMapping() === 'compact') { $transportMapper = new CompactTransportMapper(); $runtimeCallMapper = new CompactRuntimeCallMapper($transportMapper); } else { $transportMapper = new ExtendedTransportMapper(); $runtimeCallMapper = new ExtendedRuntimeCallMapper($transportMapper); } $caller = new ZeroMQRuntimeCaller( new MessagePackSerializer(), new CompactTransportMapper(), $socket, $runtimeCallMapper, new Timer() ); $transport = $this->mapper->getTransport($data); return new ActionApi( $this->logger->getRequestLogger($transport->getMeta()->getId()), $this->component, $mapping, dirname(realpath($_SERVER['SCRIPT_FILENAME'])), $input->getName(), $input->getVersion(), $input->getFrameworkVersion(), $input->getVariables(), $input->isDebug(), $action, $caller, $transport, new TypeCatalog(), $this->mapper->getParams($data) ); }
php
public function build( $action, array $data, CliInput $input, Mapping $mapping ) { $context = new ZMQContext(); $socket = new ZMQSocket($context, ZMQ::SOCKET_REQ); $socket->setSockOpt(ZMQ::SOCKOPT_LINGER, 0); if ($input->getMapping() === 'compact') { $transportMapper = new CompactTransportMapper(); $runtimeCallMapper = new CompactRuntimeCallMapper($transportMapper); } else { $transportMapper = new ExtendedTransportMapper(); $runtimeCallMapper = new ExtendedRuntimeCallMapper($transportMapper); } $caller = new ZeroMQRuntimeCaller( new MessagePackSerializer(), new CompactTransportMapper(), $socket, $runtimeCallMapper, new Timer() ); $transport = $this->mapper->getTransport($data); return new ActionApi( $this->logger->getRequestLogger($transport->getMeta()->getId()), $this->component, $mapping, dirname(realpath($_SERVER['SCRIPT_FILENAME'])), $input->getName(), $input->getVersion(), $input->getFrameworkVersion(), $input->getVariables(), $input->isDebug(), $action, $caller, $transport, new TypeCatalog(), $this->mapper->getParams($data) ); }
[ "public", "function", "build", "(", "$", "action", ",", "array", "$", "data", ",", "CliInput", "$", "input", ",", "Mapping", "$", "mapping", ")", "{", "$", "context", "=", "new", "ZMQContext", "(", ")", ";", "$", "socket", "=", "new", "ZMQSocket", "(", "$", "context", ",", "ZMQ", "::", "SOCKET_REQ", ")", ";", "$", "socket", "->", "setSockOpt", "(", "ZMQ", "::", "SOCKOPT_LINGER", ",", "0", ")", ";", "if", "(", "$", "input", "->", "getMapping", "(", ")", "===", "'compact'", ")", "{", "$", "transportMapper", "=", "new", "CompactTransportMapper", "(", ")", ";", "$", "runtimeCallMapper", "=", "new", "CompactRuntimeCallMapper", "(", "$", "transportMapper", ")", ";", "}", "else", "{", "$", "transportMapper", "=", "new", "ExtendedTransportMapper", "(", ")", ";", "$", "runtimeCallMapper", "=", "new", "ExtendedRuntimeCallMapper", "(", "$", "transportMapper", ")", ";", "}", "$", "caller", "=", "new", "ZeroMQRuntimeCaller", "(", "new", "MessagePackSerializer", "(", ")", ",", "new", "CompactTransportMapper", "(", ")", ",", "$", "socket", ",", "$", "runtimeCallMapper", ",", "new", "Timer", "(", ")", ")", ";", "$", "transport", "=", "$", "this", "->", "mapper", "->", "getTransport", "(", "$", "data", ")", ";", "return", "new", "ActionApi", "(", "$", "this", "->", "logger", "->", "getRequestLogger", "(", "$", "transport", "->", "getMeta", "(", ")", "->", "getId", "(", ")", ")", ",", "$", "this", "->", "component", ",", "$", "mapping", ",", "dirname", "(", "realpath", "(", "$", "_SERVER", "[", "'SCRIPT_FILENAME'", "]", ")", ")", ",", "$", "input", "->", "getName", "(", ")", ",", "$", "input", "->", "getVersion", "(", ")", ",", "$", "input", "->", "getFrameworkVersion", "(", ")", ",", "$", "input", "->", "getVariables", "(", ")", ",", "$", "input", "->", "isDebug", "(", ")", ",", "$", "action", ",", "$", "caller", ",", "$", "transport", ",", "new", "TypeCatalog", "(", ")", ",", "$", "this", "->", "mapper", "->", "getParams", "(", "$", "data", ")", ")", ";", "}" ]
Build an Action Api class instance @param string $action @param array $data @param CliInput $input @param Mapping $mapping @return ActionApi
[ "Build", "an", "Action", "Api", "class", "instance" ]
train
https://github.com/kusanagi/katana-sdk-php7/blob/91e7860a1852c3ce79a7034f8c36f41840e69e1f/src/Api/Factory/ServiceApiFactory.php#L47-L90
artscorestudio/document-bundle
Repository/PostRepository.php
PostRepository.getLastVersion
public function getLastVersion($post_id) { $qb = $this->createQueryBuilder('p'); $qb->where('p.original=:post_id') ->orderBy('p.createdAt', 'DESC') ->setParameter(':post_id', $post_id); $result = $qb->getQuery()->setMaxResults(1)->getResult(Query::HYDRATE_OBJECT); if ( is_null($result) ) { $qb2 = $this->createQueryBuilder('p'); $qb2->where('p.id=:post_id')->setParameter(':post_id', $post_id); $result = $qb->getQuery()->getResult(Query::HYDRATE_OBJECT); } return $result; }
php
public function getLastVersion($post_id) { $qb = $this->createQueryBuilder('p'); $qb->where('p.original=:post_id') ->orderBy('p.createdAt', 'DESC') ->setParameter(':post_id', $post_id); $result = $qb->getQuery()->setMaxResults(1)->getResult(Query::HYDRATE_OBJECT); if ( is_null($result) ) { $qb2 = $this->createQueryBuilder('p'); $qb2->where('p.id=:post_id')->setParameter(':post_id', $post_id); $result = $qb->getQuery()->getResult(Query::HYDRATE_OBJECT); } return $result; }
[ "public", "function", "getLastVersion", "(", "$", "post_id", ")", "{", "$", "qb", "=", "$", "this", "->", "createQueryBuilder", "(", "'p'", ")", ";", "$", "qb", "->", "where", "(", "'p.original=:post_id'", ")", "->", "orderBy", "(", "'p.createdAt'", ",", "'DESC'", ")", "->", "setParameter", "(", "':post_id'", ",", "$", "post_id", ")", ";", "$", "result", "=", "$", "qb", "->", "getQuery", "(", ")", "->", "setMaxResults", "(", "1", ")", "->", "getResult", "(", "Query", "::", "HYDRATE_OBJECT", ")", ";", "if", "(", "is_null", "(", "$", "result", ")", ")", "{", "$", "qb2", "=", "$", "this", "->", "createQueryBuilder", "(", "'p'", ")", ";", "$", "qb2", "->", "where", "(", "'p.id=:post_id'", ")", "->", "setParameter", "(", "':post_id'", ",", "$", "post_id", ")", ";", "$", "result", "=", "$", "qb", "->", "getQuery", "(", ")", "->", "getResult", "(", "Query", "::", "HYDRATE_OBJECT", ")", ";", "}", "return", "$", "result", ";", "}" ]
Get last version for a post @param integer $id AsfDocumentBundle:Page ID
[ "Get", "last", "version", "for", "a", "post" ]
train
https://github.com/artscorestudio/document-bundle/blob/3aceab0f75de8f7dd0fad0d0db83d7940bf565c8/Repository/PostRepository.php#L29-L47
artscorestudio/document-bundle
Repository/PostRepository.php
PostRepository.getAllLastVersion
public function getAllLastVersion() { $qb = $this->createQueryBuilder('p'); $qb->where('p.original IS NULL AND p.state=:state') ->setParameter(':state', DocumentModel::STATE_PUBLISHED); $result = $qb->getQuery()->getResult(); $return = array(); foreach($result as $original) { $return[] = $this->getLastVersion($original->getId()); } return $return; }
php
public function getAllLastVersion() { $qb = $this->createQueryBuilder('p'); $qb->where('p.original IS NULL AND p.state=:state') ->setParameter(':state', DocumentModel::STATE_PUBLISHED); $result = $qb->getQuery()->getResult(); $return = array(); foreach($result as $original) { $return[] = $this->getLastVersion($original->getId()); } return $return; }
[ "public", "function", "getAllLastVersion", "(", ")", "{", "$", "qb", "=", "$", "this", "->", "createQueryBuilder", "(", "'p'", ")", ";", "$", "qb", "->", "where", "(", "'p.original IS NULL AND p.state=:state'", ")", "->", "setParameter", "(", "':state'", ",", "DocumentModel", "::", "STATE_PUBLISHED", ")", ";", "$", "result", "=", "$", "qb", "->", "getQuery", "(", ")", "->", "getResult", "(", ")", ";", "$", "return", "=", "array", "(", ")", ";", "foreach", "(", "$", "result", "as", "$", "original", ")", "{", "$", "return", "[", "]", "=", "$", "this", "->", "getLastVersion", "(", "$", "original", "->", "getId", "(", ")", ")", ";", "}", "return", "$", "return", ";", "}" ]
Get all posts in their last version
[ "Get", "all", "posts", "in", "their", "last", "version" ]
train
https://github.com/artscorestudio/document-bundle/blob/3aceab0f75de8f7dd0fad0d0db83d7940bf565c8/Repository/PostRepository.php#L52-L64
WasabiLib/Mail
src/Mail.php
Mail.send
public function send() { if($this->message->getBody()==null){ throw new InvalidArgumentException(sprintf( 'Provided body is not valid. It should be one of "%s". %s provided', implode('", "', ['string', 'Zend\Mime\Part', 'Zend\Mime\Message','Zend\View\Model\ViewModel']), is_object($this->message->getBody()) ? get_class($this->message->getBody()) : gettype($this->message->getBody()) )); } else { $this->attachFiles(); $this->transporter->send($this->message); } }
php
public function send() { if($this->message->getBody()==null){ throw new InvalidArgumentException(sprintf( 'Provided body is not valid. It should be one of "%s". %s provided', implode('", "', ['string', 'Zend\Mime\Part', 'Zend\Mime\Message','Zend\View\Model\ViewModel']), is_object($this->message->getBody()) ? get_class($this->message->getBody()) : gettype($this->message->getBody()) )); } else { $this->attachFiles(); $this->transporter->send($this->message); } }
[ "public", "function", "send", "(", ")", "{", "if", "(", "$", "this", "->", "message", "->", "getBody", "(", ")", "==", "null", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'Provided body is not valid. It should be one of \"%s\". %s provided'", ",", "implode", "(", "'\", \"'", ",", "[", "'string'", ",", "'Zend\\Mime\\Part'", ",", "'Zend\\Mime\\Message'", ",", "'Zend\\View\\Model\\ViewModel'", "]", ")", ",", "is_object", "(", "$", "this", "->", "message", "->", "getBody", "(", ")", ")", "?", "get_class", "(", "$", "this", "->", "message", "->", "getBody", "(", ")", ")", ":", "gettype", "(", "$", "this", "->", "message", "->", "getBody", "(", ")", ")", ")", ")", ";", "}", "else", "{", "$", "this", "->", "attachFiles", "(", ")", ";", "$", "this", "->", "transporter", "->", "send", "(", "$", "this", "->", "message", ")", ";", "}", "}" ]
Sends the email.
[ "Sends", "the", "email", "." ]
train
https://github.com/WasabiLib/Mail/blob/5e6a1de480d500e380e5ecfbf633d40f87e9c8e9/src/Mail.php#L208-L220
WasabiLib/Mail
src/Mail.php
Mail.attachFiles
private function attachFiles(){ if (count($this->attachments) === 0) { return; } // Get old message parts $mimeMessage = $this->message->getBody(); if (is_string($mimeMessage)) { $originalBodyPart = new Mime\Part($mimeMessage); $originalBodyPart->type = $mimeMessage != strip_tags($mimeMessage) ? Mime\Mime::TYPE_HTML : Mime\Mime::TYPE_TEXT; // A Mime\Part body will be wraped into a Mime\Message, ensuring we handle a Mime\Message after this point $this->setBody($originalBodyPart); $mimeMessage = $this->message->getBody();; } $oldParts = $mimeMessage->getParts(); // Generate a new Mime\Part for each attachment $attachmentParts = []; $info = new \finfo(FILEINFO_MIME_TYPE); foreach ($this->attachments as $key => $attachment) { if (! is_file($attachment)) { continue; // If checked file is not valid, continue to the next } // If the key is a string, use it as the attachment name $basename = is_string($key) ? $key : basename($attachment); $part = new Mime\Part(fopen($attachment, 'r')); $part->id = $basename; $part->filename = $basename; $part->type = $info->file($attachment); $part->encoding = Mime\Mime::ENCODING_BASE64; $part->disposition = Mime\Mime::DISPOSITION_ATTACHMENT; $attachmentParts[] = $part; } $body = new Mime\Message(); $body->setParts(array_merge($oldParts, $attachmentParts)); $this->message->setBody($body); }
php
private function attachFiles(){ if (count($this->attachments) === 0) { return; } // Get old message parts $mimeMessage = $this->message->getBody(); if (is_string($mimeMessage)) { $originalBodyPart = new Mime\Part($mimeMessage); $originalBodyPart->type = $mimeMessage != strip_tags($mimeMessage) ? Mime\Mime::TYPE_HTML : Mime\Mime::TYPE_TEXT; // A Mime\Part body will be wraped into a Mime\Message, ensuring we handle a Mime\Message after this point $this->setBody($originalBodyPart); $mimeMessage = $this->message->getBody();; } $oldParts = $mimeMessage->getParts(); // Generate a new Mime\Part for each attachment $attachmentParts = []; $info = new \finfo(FILEINFO_MIME_TYPE); foreach ($this->attachments as $key => $attachment) { if (! is_file($attachment)) { continue; // If checked file is not valid, continue to the next } // If the key is a string, use it as the attachment name $basename = is_string($key) ? $key : basename($attachment); $part = new Mime\Part(fopen($attachment, 'r')); $part->id = $basename; $part->filename = $basename; $part->type = $info->file($attachment); $part->encoding = Mime\Mime::ENCODING_BASE64; $part->disposition = Mime\Mime::DISPOSITION_ATTACHMENT; $attachmentParts[] = $part; } $body = new Mime\Message(); $body->setParts(array_merge($oldParts, $attachmentParts)); $this->message->setBody($body); }
[ "private", "function", "attachFiles", "(", ")", "{", "if", "(", "count", "(", "$", "this", "->", "attachments", ")", "===", "0", ")", "{", "return", ";", "}", "// Get old message parts", "$", "mimeMessage", "=", "$", "this", "->", "message", "->", "getBody", "(", ")", ";", "if", "(", "is_string", "(", "$", "mimeMessage", ")", ")", "{", "$", "originalBodyPart", "=", "new", "Mime", "\\", "Part", "(", "$", "mimeMessage", ")", ";", "$", "originalBodyPart", "->", "type", "=", "$", "mimeMessage", "!=", "strip_tags", "(", "$", "mimeMessage", ")", "?", "Mime", "\\", "Mime", "::", "TYPE_HTML", ":", "Mime", "\\", "Mime", "::", "TYPE_TEXT", ";", "// A Mime\\Part body will be wraped into a Mime\\Message, ensuring we handle a Mime\\Message after this point", "$", "this", "->", "setBody", "(", "$", "originalBodyPart", ")", ";", "$", "mimeMessage", "=", "$", "this", "->", "message", "->", "getBody", "(", ")", ";", ";", "}", "$", "oldParts", "=", "$", "mimeMessage", "->", "getParts", "(", ")", ";", "// Generate a new Mime\\Part for each attachment", "$", "attachmentParts", "=", "[", "]", ";", "$", "info", "=", "new", "\\", "finfo", "(", "FILEINFO_MIME_TYPE", ")", ";", "foreach", "(", "$", "this", "->", "attachments", "as", "$", "key", "=>", "$", "attachment", ")", "{", "if", "(", "!", "is_file", "(", "$", "attachment", ")", ")", "{", "continue", ";", "// If checked file is not valid, continue to the next", "}", "// If the key is a string, use it as the attachment name", "$", "basename", "=", "is_string", "(", "$", "key", ")", "?", "$", "key", ":", "basename", "(", "$", "attachment", ")", ";", "$", "part", "=", "new", "Mime", "\\", "Part", "(", "fopen", "(", "$", "attachment", ",", "'r'", ")", ")", ";", "$", "part", "->", "id", "=", "$", "basename", ";", "$", "part", "->", "filename", "=", "$", "basename", ";", "$", "part", "->", "type", "=", "$", "info", "->", "file", "(", "$", "attachment", ")", ";", "$", "part", "->", "encoding", "=", "Mime", "\\", "Mime", "::", "ENCODING_BASE64", ";", "$", "part", "->", "disposition", "=", "Mime", "\\", "Mime", "::", "DISPOSITION_ATTACHMENT", ";", "$", "attachmentParts", "[", "]", "=", "$", "part", ";", "}", "$", "body", "=", "new", "Mime", "\\", "Message", "(", ")", ";", "$", "body", "->", "setParts", "(", "array_merge", "(", "$", "oldParts", ",", "$", "attachmentParts", ")", ")", ";", "$", "this", "->", "message", "->", "setBody", "(", "$", "body", ")", ";", "}" ]
Attaches files to the message if any
[ "Attaches", "files", "to", "the", "message", "if", "any" ]
train
https://github.com/WasabiLib/Mail/blob/5e6a1de480d500e380e5ecfbf633d40f87e9c8e9/src/Mail.php#L234-L270
barrelstrength/craftnet-php
src/CraftnetClient.php
CraftnetClient.post
public function post($endpoint, array $options = []) { $jsonValues = []; if (isset($options['json'])) { $jsonValues = $options['json']; } return $this->httpClient->request('POST', 'https://api.craftcms.com/v1/'.$endpoint, [ 'auth' => $this->setAuth(), 'json' => $jsonValues ]); }
php
public function post($endpoint, array $options = []) { $jsonValues = []; if (isset($options['json'])) { $jsonValues = $options['json']; } return $this->httpClient->request('POST', 'https://api.craftcms.com/v1/'.$endpoint, [ 'auth' => $this->setAuth(), 'json' => $jsonValues ]); }
[ "public", "function", "post", "(", "$", "endpoint", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "jsonValues", "=", "[", "]", ";", "if", "(", "isset", "(", "$", "options", "[", "'json'", "]", ")", ")", "{", "$", "jsonValues", "=", "$", "options", "[", "'json'", "]", ";", "}", "return", "$", "this", "->", "httpClient", "->", "request", "(", "'POST'", ",", "'https://api.craftcms.com/v1/'", ".", "$", "endpoint", ",", "[", "'auth'", "=>", "$", "this", "->", "setAuth", "(", ")", ",", "'json'", "=>", "$", "jsonValues", "]", ")", ";", "}" ]
Sends a POST request to the Craftnet API @param $endpoint @param array $options @return mixed|\Psr\Http\Message\ResponseInterface @throws \GuzzleHttp\Exception\GuzzleException
[ "Sends", "a", "POST", "request", "to", "the", "Craftnet", "API" ]
train
https://github.com/barrelstrength/craftnet-php/blob/90c9767b6bef6078bc062b3bfcdde38b24c843fc/src/CraftnetClient.php#L98-L110
technote-space/wordpress-plugin-base
src/classes/models/lib/option.php
Option.reload_options
public function reload_options() { if ( $this->_suspend_reload ) { return; } $this->_options = wp_parse_args( $this->get_option(), [] ); $this->unescape_options(); }
php
public function reload_options() { if ( $this->_suspend_reload ) { return; } $this->_options = wp_parse_args( $this->get_option(), [] ); $this->unescape_options(); }
[ "public", "function", "reload_options", "(", ")", "{", "if", "(", "$", "this", "->", "_suspend_reload", ")", "{", "return", ";", "}", "$", "this", "->", "_options", "=", "wp_parse_args", "(", "$", "this", "->", "get_option", "(", ")", ",", "[", "]", ")", ";", "$", "this", "->", "unescape_options", "(", ")", ";", "}" ]
reload options
[ "reload", "options" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/option.php#L56-L64
technote-space/wordpress-plugin-base
src/classes/models/lib/option.php
Option.unescape_options
private function unescape_options() { foreach ( $this->_options as $key => $value ) { if ( is_string( $value ) ) { $this->_options[ $key ] = stripslashes( htmlspecialchars_decode( $this->_options[ $key ] ) ); } } }
php
private function unescape_options() { foreach ( $this->_options as $key => $value ) { if ( is_string( $value ) ) { $this->_options[ $key ] = stripslashes( htmlspecialchars_decode( $this->_options[ $key ] ) ); } } }
[ "private", "function", "unescape_options", "(", ")", "{", "foreach", "(", "$", "this", "->", "_options", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_string", "(", "$", "value", ")", ")", "{", "$", "this", "->", "_options", "[", "$", "key", "]", "=", "stripslashes", "(", "htmlspecialchars_decode", "(", "$", "this", "->", "_options", "[", "$", "key", "]", ")", ")", ";", "}", "}", "}" ]
unescape options
[ "unescape", "options" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/option.php#L90-L96
technote-space/wordpress-plugin-base
src/classes/models/lib/option.php
Option.get
public function get( $key, $default = '' ) { if ( array_key_exists( $key, $this->_options ) ) { return $this->apply_filters( 'get_option', $this->_options[ $key ], $key, $default ); } return $this->apply_filters( 'get_option', $default, $key, $default ); }
php
public function get( $key, $default = '' ) { if ( array_key_exists( $key, $this->_options ) ) { return $this->apply_filters( 'get_option', $this->_options[ $key ], $key, $default ); } return $this->apply_filters( 'get_option', $default, $key, $default ); }
[ "public", "function", "get", "(", "$", "key", ",", "$", "default", "=", "''", ")", "{", "if", "(", "array_key_exists", "(", "$", "key", ",", "$", "this", "->", "_options", ")", ")", "{", "return", "$", "this", "->", "apply_filters", "(", "'get_option'", ",", "$", "this", "->", "_options", "[", "$", "key", "]", ",", "$", "key", ",", "$", "default", ")", ";", "}", "return", "$", "this", "->", "apply_filters", "(", "'get_option'", ",", "$", "default", ",", "$", "key", ",", "$", "default", ")", ";", "}" ]
@param string $key @param string $default @return mixed
[ "@param", "string", "$key", "@param", "string", "$default" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/option.php#L104-L110
technote-space/wordpress-plugin-base
src/classes/models/lib/option.php
Option.set
public function set( $key, $value ) { $this->reload_options(); $suspend_reload = $this->_suspend_reload; $prev = isset( $this->_options[ $key ] ) ? $this->_options[ $key ] : null; $this->_options[ $key ] = $value; if ( $prev !== $value ) { $this->_suspend_reload = true; $this->do_action( 'changed_option', $key, $value, $prev ); $this->_suspend_reload = $suspend_reload; } return $this->save(); }
php
public function set( $key, $value ) { $this->reload_options(); $suspend_reload = $this->_suspend_reload; $prev = isset( $this->_options[ $key ] ) ? $this->_options[ $key ] : null; $this->_options[ $key ] = $value; if ( $prev !== $value ) { $this->_suspend_reload = true; $this->do_action( 'changed_option', $key, $value, $prev ); $this->_suspend_reload = $suspend_reload; } return $this->save(); }
[ "public", "function", "set", "(", "$", "key", ",", "$", "value", ")", "{", "$", "this", "->", "reload_options", "(", ")", ";", "$", "suspend_reload", "=", "$", "this", "->", "_suspend_reload", ";", "$", "prev", "=", "isset", "(", "$", "this", "->", "_options", "[", "$", "key", "]", ")", "?", "$", "this", "->", "_options", "[", "$", "key", "]", ":", "null", ";", "$", "this", "->", "_options", "[", "$", "key", "]", "=", "$", "value", ";", "if", "(", "$", "prev", "!==", "$", "value", ")", "{", "$", "this", "->", "_suspend_reload", "=", "true", ";", "$", "this", "->", "do_action", "(", "'changed_option'", ",", "$", "key", ",", "$", "value", ",", "$", "prev", ")", ";", "$", "this", "->", "_suspend_reload", "=", "$", "suspend_reload", ";", "}", "return", "$", "this", "->", "save", "(", ")", ";", "}" ]
@param string $key @param mixed $value @return bool
[ "@param", "string", "$key", "@param", "mixed", "$value" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/option.php#L118-L130
technote-space/wordpress-plugin-base
src/classes/models/lib/option.php
Option.delete
public function delete( $key ) { $this->reload_options(); $suspend_reload = $this->_suspend_reload; if ( array_key_exists( $key, $this->_options ) ) { $prev = $this->_options[ $key ]; unset( $this->_options[ $key ] ); $this->_suspend_reload = true; $this->do_action( 'deleted_option', $key, $prev ); $this->_suspend_reload = $suspend_reload; return $this->save(); } return true; }
php
public function delete( $key ) { $this->reload_options(); $suspend_reload = $this->_suspend_reload; if ( array_key_exists( $key, $this->_options ) ) { $prev = $this->_options[ $key ]; unset( $this->_options[ $key ] ); $this->_suspend_reload = true; $this->do_action( 'deleted_option', $key, $prev ); $this->_suspend_reload = $suspend_reload; return $this->save(); } return true; }
[ "public", "function", "delete", "(", "$", "key", ")", "{", "$", "this", "->", "reload_options", "(", ")", ";", "$", "suspend_reload", "=", "$", "this", "->", "_suspend_reload", ";", "if", "(", "array_key_exists", "(", "$", "key", ",", "$", "this", "->", "_options", ")", ")", "{", "$", "prev", "=", "$", "this", "->", "_options", "[", "$", "key", "]", ";", "unset", "(", "$", "this", "->", "_options", "[", "$", "key", "]", ")", ";", "$", "this", "->", "_suspend_reload", "=", "true", ";", "$", "this", "->", "do_action", "(", "'deleted_option'", ",", "$", "key", ",", "$", "prev", ")", ";", "$", "this", "->", "_suspend_reload", "=", "$", "suspend_reload", ";", "return", "$", "this", "->", "save", "(", ")", ";", "}", "return", "true", ";", "}" ]
@param string $key @return bool
[ "@param", "string", "$key" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/option.php#L137-L151
technote-space/wordpress-plugin-base
src/classes/models/lib/option.php
Option.set_post_value
public function set_post_value( $key, $default = null ) { if ( ! isset( $_POST[ $key ] ) && ! isset( $default ) ) { return false; } $result = $this->set( $key, isset( $_POST[ $key ] ) ? $_POST[ $key ] : $default ); $this->delete_hook_cache( preg_replace( '/^' . preg_quote( $this->get_filter_prefix(), '/' ) . '/', '', $key ) ); return $result; }
php
public function set_post_value( $key, $default = null ) { if ( ! isset( $_POST[ $key ] ) && ! isset( $default ) ) { return false; } $result = $this->set( $key, isset( $_POST[ $key ] ) ? $_POST[ $key ] : $default ); $this->delete_hook_cache( preg_replace( '/^' . preg_quote( $this->get_filter_prefix(), '/' ) . '/', '', $key ) ); return $result; }
[ "public", "function", "set_post_value", "(", "$", "key", ",", "$", "default", "=", "null", ")", "{", "if", "(", "!", "isset", "(", "$", "_POST", "[", "$", "key", "]", ")", "&&", "!", "isset", "(", "$", "default", ")", ")", "{", "return", "false", ";", "}", "$", "result", "=", "$", "this", "->", "set", "(", "$", "key", ",", "isset", "(", "$", "_POST", "[", "$", "key", "]", ")", "?", "$", "_POST", "[", "$", "key", "]", ":", "$", "default", ")", ";", "$", "this", "->", "delete_hook_cache", "(", "preg_replace", "(", "'/^'", ".", "preg_quote", "(", "$", "this", "->", "get_filter_prefix", "(", ")", ",", "'/'", ")", ".", "'/'", ",", "''", ",", "$", "key", ")", ")", ";", "return", "$", "result", ";", "}" ]
@param string $key @param mixed $default @return bool
[ "@param", "string", "$key", "@param", "mixed", "$default" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/option.php#L159-L167
petrica/php-statsd-system
Config/ConfigLoader.php
ConfigLoader.load
public function load() { if (file_exists($this->filepath) && ($contents = file_get_contents($this->filepath))) { $yaml = new Parser(); $config = $yaml->parse($contents); if (null === $config) { $config = array(); } $processor = new Processor(); $configDefinition = new ConfigDefinition(); $processedConfiguration = $processor->processConfiguration( $configDefinition, $config ); if (empty($processedConfiguration)) { throw new Exception( 'You need to specify at least one gaguge in the configuration file' ); } return $processedConfiguration; } else { throw new \RuntimeException(sprintf('Configuration file does not exist or is not accessible %s', $this->filepath)); } }
php
public function load() { if (file_exists($this->filepath) && ($contents = file_get_contents($this->filepath))) { $yaml = new Parser(); $config = $yaml->parse($contents); if (null === $config) { $config = array(); } $processor = new Processor(); $configDefinition = new ConfigDefinition(); $processedConfiguration = $processor->processConfiguration( $configDefinition, $config ); if (empty($processedConfiguration)) { throw new Exception( 'You need to specify at least one gaguge in the configuration file' ); } return $processedConfiguration; } else { throw new \RuntimeException(sprintf('Configuration file does not exist or is not accessible %s', $this->filepath)); } }
[ "public", "function", "load", "(", ")", "{", "if", "(", "file_exists", "(", "$", "this", "->", "filepath", ")", "&&", "(", "$", "contents", "=", "file_get_contents", "(", "$", "this", "->", "filepath", ")", ")", ")", "{", "$", "yaml", "=", "new", "Parser", "(", ")", ";", "$", "config", "=", "$", "yaml", "->", "parse", "(", "$", "contents", ")", ";", "if", "(", "null", "===", "$", "config", ")", "{", "$", "config", "=", "array", "(", ")", ";", "}", "$", "processor", "=", "new", "Processor", "(", ")", ";", "$", "configDefinition", "=", "new", "ConfigDefinition", "(", ")", ";", "$", "processedConfiguration", "=", "$", "processor", "->", "processConfiguration", "(", "$", "configDefinition", ",", "$", "config", ")", ";", "if", "(", "empty", "(", "$", "processedConfiguration", ")", ")", "{", "throw", "new", "Exception", "(", "'You need to specify at least one gaguge in the configuration file'", ")", ";", "}", "return", "$", "processedConfiguration", ";", "}", "else", "{", "throw", "new", "\\", "RuntimeException", "(", "sprintf", "(", "'Configuration file does not exist or is not accessible %s'", ",", "$", "this", "->", "filepath", ")", ")", ";", "}", "}" ]
Process configuration and make sure the configuration format is as expected @return array
[ "Process", "configuration", "and", "make", "sure", "the", "configuration", "format", "is", "as", "expected" ]
train
https://github.com/petrica/php-statsd-system/blob/c476be3514a631a605737888bb8f6eb096789c9d/Config/ConfigLoader.php#L36-L66
oroinc/OroLayoutComponent
Util/BlockUtils.php
BlockUtils.registerPlugin
public static function registerPlugin(BlockView $view, $pluginName) { $optionsArray = $view->vars['block_prefixes']; array_splice( $optionsArray, -1, 1, [$pluginName, end($optionsArray)] ); $view->vars['block_prefixes'] = $optionsArray; }
php
public static function registerPlugin(BlockView $view, $pluginName) { $optionsArray = $view->vars['block_prefixes']; array_splice( $optionsArray, -1, 1, [$pluginName, end($optionsArray)] ); $view->vars['block_prefixes'] = $optionsArray; }
[ "public", "static", "function", "registerPlugin", "(", "BlockView", "$", "view", ",", "$", "pluginName", ")", "{", "$", "optionsArray", "=", "$", "view", "->", "vars", "[", "'block_prefixes'", "]", ";", "array_splice", "(", "$", "optionsArray", ",", "-", "1", ",", "1", ",", "[", "$", "pluginName", ",", "end", "(", "$", "optionsArray", ")", "]", ")", ";", "$", "view", "->", "vars", "[", "'block_prefixes'", "]", "=", "$", "optionsArray", ";", "}" ]
Registers the plugin for the block type. You can use this method to add the additional block prefix that allow you to create an additional template for existing block type. IMPORTANT: This method should be called in finishView of your block type extension because the 'block_prefixes' array is not filled in buildView yet. @param BlockView $view @param string $pluginName
[ "Registers", "the", "plugin", "for", "the", "block", "type", ".", "You", "can", "use", "this", "method", "to", "add", "the", "additional", "block", "prefix", "that", "allow", "you", "to", "create", "an", "additional", "template", "for", "existing", "block", "type", "." ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/Util/BlockUtils.php#L22-L32
oroinc/OroLayoutComponent
Util/BlockUtils.php
BlockUtils.normalizeTransValue
public static function normalizeTransValue($text, $parameters = null) { if (is_string($text) && !empty($text)) { $text = ['label' => $text]; } if (!empty($parameters) && is_array($text) && !isset($text['parameters'])) { $text['parameters'] = $parameters; } return $text; }
php
public static function normalizeTransValue($text, $parameters = null) { if (is_string($text) && !empty($text)) { $text = ['label' => $text]; } if (!empty($parameters) && is_array($text) && !isset($text['parameters'])) { $text['parameters'] = $parameters; } return $text; }
[ "public", "static", "function", "normalizeTransValue", "(", "$", "text", ",", "$", "parameters", "=", "null", ")", "{", "if", "(", "is_string", "(", "$", "text", ")", "&&", "!", "empty", "(", "$", "text", ")", ")", "{", "$", "text", "=", "[", "'label'", "=>", "$", "text", "]", ";", "}", "if", "(", "!", "empty", "(", "$", "parameters", ")", "&&", "is_array", "(", "$", "text", ")", "&&", "!", "isset", "(", "$", "text", "[", "'parameters'", "]", ")", ")", "{", "$", "text", "[", "'parameters'", "]", "=", "$", "parameters", ";", "}", "return", "$", "text", ";", "}" ]
Normalizes the given value to the format that can be translated by a renderer. @param string|array $text The text to be translated @param array|null $parameters The parameters @return array
[ "Normalizes", "the", "given", "value", "to", "the", "format", "that", "can", "be", "translated", "by", "a", "renderer", "." ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/Util/BlockUtils.php#L42-L52
oroinc/OroLayoutComponent
Util/BlockUtils.php
BlockUtils.processUrl
public static function processUrl(BlockView $view, Options $options, $required = false, $prefix = null) { $pathName = null !== $prefix ? $prefix . '_path' : 'path'; $routeName = null !== $prefix ? $prefix . '_route_name' : 'route_name'; if ($options->isExistsAndNotEmpty($pathName)) { $view->vars[$pathName] = $options[$pathName]; } elseif ($options->isExistsAndNotEmpty($routeName)) { $view->vars[$routeName] = $options[$routeName]; $routeParamName = null !== $prefix ? $prefix . '_route_parameters' : 'route_parameters'; $view->vars[$routeParamName] = isset($options[$routeParamName]) ? $options[$routeParamName] : []; } elseif ($required) { throw new MissingOptionsException( sprintf('Either "%s" or "%s" must be set.', $pathName, $routeName) ); } }
php
public static function processUrl(BlockView $view, Options $options, $required = false, $prefix = null) { $pathName = null !== $prefix ? $prefix . '_path' : 'path'; $routeName = null !== $prefix ? $prefix . '_route_name' : 'route_name'; if ($options->isExistsAndNotEmpty($pathName)) { $view->vars[$pathName] = $options[$pathName]; } elseif ($options->isExistsAndNotEmpty($routeName)) { $view->vars[$routeName] = $options[$routeName]; $routeParamName = null !== $prefix ? $prefix . '_route_parameters' : 'route_parameters'; $view->vars[$routeParamName] = isset($options[$routeParamName]) ? $options[$routeParamName] : []; } elseif ($required) { throw new MissingOptionsException( sprintf('Either "%s" or "%s" must be set.', $pathName, $routeName) ); } }
[ "public", "static", "function", "processUrl", "(", "BlockView", "$", "view", ",", "Options", "$", "options", ",", "$", "required", "=", "false", ",", "$", "prefix", "=", "null", ")", "{", "$", "pathName", "=", "null", "!==", "$", "prefix", "?", "$", "prefix", ".", "'_path'", ":", "'path'", ";", "$", "routeName", "=", "null", "!==", "$", "prefix", "?", "$", "prefix", ".", "'_route_name'", ":", "'route_name'", ";", "if", "(", "$", "options", "->", "isExistsAndNotEmpty", "(", "$", "pathName", ")", ")", "{", "$", "view", "->", "vars", "[", "$", "pathName", "]", "=", "$", "options", "[", "$", "pathName", "]", ";", "}", "elseif", "(", "$", "options", "->", "isExistsAndNotEmpty", "(", "$", "routeName", ")", ")", "{", "$", "view", "->", "vars", "[", "$", "routeName", "]", "=", "$", "options", "[", "$", "routeName", "]", ";", "$", "routeParamName", "=", "null", "!==", "$", "prefix", "?", "$", "prefix", ".", "'_route_parameters'", ":", "'route_parameters'", ";", "$", "view", "->", "vars", "[", "$", "routeParamName", "]", "=", "isset", "(", "$", "options", "[", "$", "routeParamName", "]", ")", "?", "$", "options", "[", "$", "routeParamName", "]", ":", "[", "]", ";", "}", "elseif", "(", "$", "required", ")", "{", "throw", "new", "MissingOptionsException", "(", "sprintf", "(", "'Either \"%s\" or \"%s\" must be set.'", ",", "$", "pathName", ",", "$", "routeName", ")", ")", ";", "}", "}" ]
Gets the url related options and pass them to the block view. @param BlockView $view The block view @param Options $options The block options @param boolean $required Specifies whether the url related options are mandatory @param string|null $prefix The prefix for the url related options @SuppressWarnings(PHPMD.NPathComplexity)
[ "Gets", "the", "url", "related", "options", "and", "pass", "them", "to", "the", "block", "view", "." ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/Util/BlockUtils.php#L64-L82
php-lug/lug
src/Component/Grid/Model/Builder/GridBuilder.php
GridBuilder.build
public function build(array $config) { $config = $this->prepareConfig($config); return new Grid( $this->buildResource($config), $this->buildColumns($config), $this->buildFilters($config), $this->buildSorts($config), $this->buildGlobalActions($config), $this->buildColumnActions($config), $this->buildBatches($config), $this->buildData($config), $this->buildOptions($config) ); }
php
public function build(array $config) { $config = $this->prepareConfig($config); return new Grid( $this->buildResource($config), $this->buildColumns($config), $this->buildFilters($config), $this->buildSorts($config), $this->buildGlobalActions($config), $this->buildColumnActions($config), $this->buildBatches($config), $this->buildData($config), $this->buildOptions($config) ); }
[ "public", "function", "build", "(", "array", "$", "config", ")", "{", "$", "config", "=", "$", "this", "->", "prepareConfig", "(", "$", "config", ")", ";", "return", "new", "Grid", "(", "$", "this", "->", "buildResource", "(", "$", "config", ")", ",", "$", "this", "->", "buildColumns", "(", "$", "config", ")", ",", "$", "this", "->", "buildFilters", "(", "$", "config", ")", ",", "$", "this", "->", "buildSorts", "(", "$", "config", ")", ",", "$", "this", "->", "buildGlobalActions", "(", "$", "config", ")", ",", "$", "this", "->", "buildColumnActions", "(", "$", "config", ")", ",", "$", "this", "->", "buildBatches", "(", "$", "config", ")", ",", "$", "this", "->", "buildData", "(", "$", "config", ")", ",", "$", "this", "->", "buildOptions", "(", "$", "config", ")", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Grid/Model/Builder/GridBuilder.php#L77-L92
php-lug/lug
src/Component/Grid/Model/Builder/GridBuilder.php
GridBuilder.buildColumns
protected function buildColumns(array $config) { $columns = []; foreach (isset($config['columns']) ? $config['columns'] : [] as $name => $column) { $column = $this->buildColumn(array_merge(['name' => $name], $column), $config); $columns[$column->getName()] = $column; } return $columns; }
php
protected function buildColumns(array $config) { $columns = []; foreach (isset($config['columns']) ? $config['columns'] : [] as $name => $column) { $column = $this->buildColumn(array_merge(['name' => $name], $column), $config); $columns[$column->getName()] = $column; } return $columns; }
[ "protected", "function", "buildColumns", "(", "array", "$", "config", ")", "{", "$", "columns", "=", "[", "]", ";", "foreach", "(", "isset", "(", "$", "config", "[", "'columns'", "]", ")", "?", "$", "config", "[", "'columns'", "]", ":", "[", "]", "as", "$", "name", "=>", "$", "column", ")", "{", "$", "column", "=", "$", "this", "->", "buildColumn", "(", "array_merge", "(", "[", "'name'", "=>", "$", "name", "]", ",", "$", "column", ")", ",", "$", "config", ")", ";", "$", "columns", "[", "$", "column", "->", "getName", "(", ")", "]", "=", "$", "column", ";", "}", "return", "$", "columns", ";", "}" ]
@param mixed[] $config @return ColumnInterface[]
[ "@param", "mixed", "[]", "$config" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Grid/Model/Builder/GridBuilder.php#L113-L123
php-lug/lug
src/Component/Grid/Model/Builder/GridBuilder.php
GridBuilder.buildColumn
protected function buildColumn(array $config, array $parentConfig) { return $this->columnBuilder->build($this->prepareConfig($config, $parentConfig)); }
php
protected function buildColumn(array $config, array $parentConfig) { return $this->columnBuilder->build($this->prepareConfig($config, $parentConfig)); }
[ "protected", "function", "buildColumn", "(", "array", "$", "config", ",", "array", "$", "parentConfig", ")", "{", "return", "$", "this", "->", "columnBuilder", "->", "build", "(", "$", "this", "->", "prepareConfig", "(", "$", "config", ",", "$", "parentConfig", ")", ")", ";", "}" ]
@param mixed[] $config @param mixed[] $parentConfig @return ColumnInterface
[ "@param", "mixed", "[]", "$config", "@param", "mixed", "[]", "$parentConfig" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Grid/Model/Builder/GridBuilder.php#L131-L134
php-lug/lug
src/Component/Grid/Model/Builder/GridBuilder.php
GridBuilder.buildFilters
protected function buildFilters(array $config) { $filters = []; foreach ((isset($config['filters']) ? $config['filters'] : []) as $name => $filter) { $filter = $this->buildFilter(array_merge(['name' => $name], $filter), $config); $filters[$filter->getName()] = $filter; } return $filters; }
php
protected function buildFilters(array $config) { $filters = []; foreach ((isset($config['filters']) ? $config['filters'] : []) as $name => $filter) { $filter = $this->buildFilter(array_merge(['name' => $name], $filter), $config); $filters[$filter->getName()] = $filter; } return $filters; }
[ "protected", "function", "buildFilters", "(", "array", "$", "config", ")", "{", "$", "filters", "=", "[", "]", ";", "foreach", "(", "(", "isset", "(", "$", "config", "[", "'filters'", "]", ")", "?", "$", "config", "[", "'filters'", "]", ":", "[", "]", ")", "as", "$", "name", "=>", "$", "filter", ")", "{", "$", "filter", "=", "$", "this", "->", "buildFilter", "(", "array_merge", "(", "[", "'name'", "=>", "$", "name", "]", ",", "$", "filter", ")", ",", "$", "config", ")", ";", "$", "filters", "[", "$", "filter", "->", "getName", "(", ")", "]", "=", "$", "filter", ";", "}", "return", "$", "filters", ";", "}" ]
@param mixed[] $config @return FilterInterface[]
[ "@param", "mixed", "[]", "$config" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Grid/Model/Builder/GridBuilder.php#L141-L151
php-lug/lug
src/Component/Grid/Model/Builder/GridBuilder.php
GridBuilder.buildFilter
protected function buildFilter(array $config, array $parentConfig) { return $this->filterBuilder->build($this->prepareConfig($config, $parentConfig)); }
php
protected function buildFilter(array $config, array $parentConfig) { return $this->filterBuilder->build($this->prepareConfig($config, $parentConfig)); }
[ "protected", "function", "buildFilter", "(", "array", "$", "config", ",", "array", "$", "parentConfig", ")", "{", "return", "$", "this", "->", "filterBuilder", "->", "build", "(", "$", "this", "->", "prepareConfig", "(", "$", "config", ",", "$", "parentConfig", ")", ")", ";", "}" ]
@param mixed[] $config @param mixed[] $parentConfig @return FilterInterface
[ "@param", "mixed", "[]", "$config", "@param", "mixed", "[]", "$parentConfig" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Grid/Model/Builder/GridBuilder.php#L159-L162
php-lug/lug
src/Component/Grid/Model/Builder/GridBuilder.php
GridBuilder.buildSorts
protected function buildSorts(array $config) { $sorts = []; foreach ((isset($config['sorts']) ? $config['sorts'] : []) as $name => $sort) { $sort = $this->buildSort(array_merge(['name' => $name], $sort), $config); $sorts[$sort->getName()] = $sort; } return $sorts; }
php
protected function buildSorts(array $config) { $sorts = []; foreach ((isset($config['sorts']) ? $config['sorts'] : []) as $name => $sort) { $sort = $this->buildSort(array_merge(['name' => $name], $sort), $config); $sorts[$sort->getName()] = $sort; } return $sorts; }
[ "protected", "function", "buildSorts", "(", "array", "$", "config", ")", "{", "$", "sorts", "=", "[", "]", ";", "foreach", "(", "(", "isset", "(", "$", "config", "[", "'sorts'", "]", ")", "?", "$", "config", "[", "'sorts'", "]", ":", "[", "]", ")", "as", "$", "name", "=>", "$", "sort", ")", "{", "$", "sort", "=", "$", "this", "->", "buildSort", "(", "array_merge", "(", "[", "'name'", "=>", "$", "name", "]", ",", "$", "sort", ")", ",", "$", "config", ")", ";", "$", "sorts", "[", "$", "sort", "->", "getName", "(", ")", "]", "=", "$", "sort", ";", "}", "return", "$", "sorts", ";", "}" ]
@param mixed[] $config @return SortInterface[]
[ "@param", "mixed", "[]", "$config" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Grid/Model/Builder/GridBuilder.php#L169-L179
php-lug/lug
src/Component/Grid/Model/Builder/GridBuilder.php
GridBuilder.buildSort
protected function buildSort(array $config, array $parentConfig) { return $this->sortBuilder->build($this->prepareConfig($config, $parentConfig)); }
php
protected function buildSort(array $config, array $parentConfig) { return $this->sortBuilder->build($this->prepareConfig($config, $parentConfig)); }
[ "protected", "function", "buildSort", "(", "array", "$", "config", ",", "array", "$", "parentConfig", ")", "{", "return", "$", "this", "->", "sortBuilder", "->", "build", "(", "$", "this", "->", "prepareConfig", "(", "$", "config", ",", "$", "parentConfig", ")", ")", ";", "}" ]
@param mixed[] $config @param mixed[] $parentConfig @return SortInterface
[ "@param", "mixed", "[]", "$config", "@param", "mixed", "[]", "$parentConfig" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Grid/Model/Builder/GridBuilder.php#L187-L190
php-lug/lug
src/Component/Grid/Model/Builder/GridBuilder.php
GridBuilder.buildGlobalActions
protected function buildGlobalActions(array $config) { $globalActions = []; foreach ((isset($config['global_actions']) ? $config['global_actions'] : []) as $name => $action) { $action = $this->buildGlobalAction(array_merge(['name' => $name], $action), $config); $globalActions[$action->getName()] = $action; } return $globalActions; }
php
protected function buildGlobalActions(array $config) { $globalActions = []; foreach ((isset($config['global_actions']) ? $config['global_actions'] : []) as $name => $action) { $action = $this->buildGlobalAction(array_merge(['name' => $name], $action), $config); $globalActions[$action->getName()] = $action; } return $globalActions; }
[ "protected", "function", "buildGlobalActions", "(", "array", "$", "config", ")", "{", "$", "globalActions", "=", "[", "]", ";", "foreach", "(", "(", "isset", "(", "$", "config", "[", "'global_actions'", "]", ")", "?", "$", "config", "[", "'global_actions'", "]", ":", "[", "]", ")", "as", "$", "name", "=>", "$", "action", ")", "{", "$", "action", "=", "$", "this", "->", "buildGlobalAction", "(", "array_merge", "(", "[", "'name'", "=>", "$", "name", "]", ",", "$", "action", ")", ",", "$", "config", ")", ";", "$", "globalActions", "[", "$", "action", "->", "getName", "(", ")", "]", "=", "$", "action", ";", "}", "return", "$", "globalActions", ";", "}" ]
@param mixed[] $config @return ActionInterface[]
[ "@param", "mixed", "[]", "$config" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Grid/Model/Builder/GridBuilder.php#L197-L207
php-lug/lug
src/Component/Grid/Model/Builder/GridBuilder.php
GridBuilder.buildGlobalAction
protected function buildGlobalAction(array $config, array $parentConfig) { return $this->actionBuilder->build($this->prepareConfig($config, $parentConfig)); }
php
protected function buildGlobalAction(array $config, array $parentConfig) { return $this->actionBuilder->build($this->prepareConfig($config, $parentConfig)); }
[ "protected", "function", "buildGlobalAction", "(", "array", "$", "config", ",", "array", "$", "parentConfig", ")", "{", "return", "$", "this", "->", "actionBuilder", "->", "build", "(", "$", "this", "->", "prepareConfig", "(", "$", "config", ",", "$", "parentConfig", ")", ")", ";", "}" ]
@param mixed[] $config @param mixed[] $parentConfig @return ActionInterface
[ "@param", "mixed", "[]", "$config", "@param", "mixed", "[]", "$parentConfig" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Grid/Model/Builder/GridBuilder.php#L215-L218
php-lug/lug
src/Component/Grid/Model/Builder/GridBuilder.php
GridBuilder.buildColumnActions
protected function buildColumnActions(array $config) { $columnActions = []; foreach ((isset($config['column_actions']) ? $config['column_actions'] : []) as $name => $action) { $action = $this->buildColumnAction(array_merge(['name' => $name], $action), $config); $columnActions[$action->getName()] = $action; } return $columnActions; }
php
protected function buildColumnActions(array $config) { $columnActions = []; foreach ((isset($config['column_actions']) ? $config['column_actions'] : []) as $name => $action) { $action = $this->buildColumnAction(array_merge(['name' => $name], $action), $config); $columnActions[$action->getName()] = $action; } return $columnActions; }
[ "protected", "function", "buildColumnActions", "(", "array", "$", "config", ")", "{", "$", "columnActions", "=", "[", "]", ";", "foreach", "(", "(", "isset", "(", "$", "config", "[", "'column_actions'", "]", ")", "?", "$", "config", "[", "'column_actions'", "]", ":", "[", "]", ")", "as", "$", "name", "=>", "$", "action", ")", "{", "$", "action", "=", "$", "this", "->", "buildColumnAction", "(", "array_merge", "(", "[", "'name'", "=>", "$", "name", "]", ",", "$", "action", ")", ",", "$", "config", ")", ";", "$", "columnActions", "[", "$", "action", "->", "getName", "(", ")", "]", "=", "$", "action", ";", "}", "return", "$", "columnActions", ";", "}" ]
@param mixed[] $config @return ActionInterface[]
[ "@param", "mixed", "[]", "$config" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Grid/Model/Builder/GridBuilder.php#L225-L235
php-lug/lug
src/Component/Grid/Model/Builder/GridBuilder.php
GridBuilder.buildColumnAction
protected function buildColumnAction(array $config, array $parentConfig) { return $this->actionBuilder->build($this->prepareConfig($config, $parentConfig)); }
php
protected function buildColumnAction(array $config, array $parentConfig) { return $this->actionBuilder->build($this->prepareConfig($config, $parentConfig)); }
[ "protected", "function", "buildColumnAction", "(", "array", "$", "config", ",", "array", "$", "parentConfig", ")", "{", "return", "$", "this", "->", "actionBuilder", "->", "build", "(", "$", "this", "->", "prepareConfig", "(", "$", "config", ",", "$", "parentConfig", ")", ")", ";", "}" ]
@param mixed[] $config @param mixed[] $parentConfig @return ActionInterface
[ "@param", "mixed", "[]", "$config", "@param", "mixed", "[]", "$parentConfig" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Grid/Model/Builder/GridBuilder.php#L243-L246
php-lug/lug
src/Component/Grid/Model/Builder/GridBuilder.php
GridBuilder.buildBatches
protected function buildBatches(array $config) { $batches = []; foreach ((isset($config['batches']) ? $config['batches'] : []) as $name => $batch) { $batch = $this->buildBatch(array_merge(['name' => $name], $batch), $config); $batches[$batch->getName()] = $batch; } return $batches; }
php
protected function buildBatches(array $config) { $batches = []; foreach ((isset($config['batches']) ? $config['batches'] : []) as $name => $batch) { $batch = $this->buildBatch(array_merge(['name' => $name], $batch), $config); $batches[$batch->getName()] = $batch; } return $batches; }
[ "protected", "function", "buildBatches", "(", "array", "$", "config", ")", "{", "$", "batches", "=", "[", "]", ";", "foreach", "(", "(", "isset", "(", "$", "config", "[", "'batches'", "]", ")", "?", "$", "config", "[", "'batches'", "]", ":", "[", "]", ")", "as", "$", "name", "=>", "$", "batch", ")", "{", "$", "batch", "=", "$", "this", "->", "buildBatch", "(", "array_merge", "(", "[", "'name'", "=>", "$", "name", "]", ",", "$", "batch", ")", ",", "$", "config", ")", ";", "$", "batches", "[", "$", "batch", "->", "getName", "(", ")", "]", "=", "$", "batch", ";", "}", "return", "$", "batches", ";", "}" ]
@param mixed[] $config @return BatchInterface[]
[ "@param", "mixed", "[]", "$config" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Grid/Model/Builder/GridBuilder.php#L253-L263
php-lug/lug
src/Component/Grid/Model/Builder/GridBuilder.php
GridBuilder.buildBatch
protected function buildBatch(array $config, array $parentConfig) { return $this->batchBuilder->build($this->prepareConfig($config, $parentConfig)); }
php
protected function buildBatch(array $config, array $parentConfig) { return $this->batchBuilder->build($this->prepareConfig($config, $parentConfig)); }
[ "protected", "function", "buildBatch", "(", "array", "$", "config", ",", "array", "$", "parentConfig", ")", "{", "return", "$", "this", "->", "batchBuilder", "->", "build", "(", "$", "this", "->", "prepareConfig", "(", "$", "config", ",", "$", "parentConfig", ")", ")", ";", "}" ]
@param mixed[] $config @param mixed[] $parentConfig @return BatchInterface
[ "@param", "mixed", "[]", "$config", "@param", "mixed", "[]", "$parentConfig" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Grid/Model/Builder/GridBuilder.php#L271-L274
songshenzong/log
src/Bridge/SwiftMailer/SwiftMailCollector.php
SwiftMailCollector.formatTo
protected function formatTo($to) { if (!$to) { return ''; } $f = []; foreach ($to as $k => $v) { $f[] = (empty($v) ? '' : "$v ") . "<$k>"; } return implode(', ', $f); }
php
protected function formatTo($to) { if (!$to) { return ''; } $f = []; foreach ($to as $k => $v) { $f[] = (empty($v) ? '' : "$v ") . "<$k>"; } return implode(', ', $f); }
[ "protected", "function", "formatTo", "(", "$", "to", ")", "{", "if", "(", "!", "$", "to", ")", "{", "return", "''", ";", "}", "$", "f", "=", "[", "]", ";", "foreach", "(", "$", "to", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "f", "[", "]", "=", "(", "empty", "(", "$", "v", ")", "?", "''", ":", "\"$v \"", ")", ".", "\"<$k>\"", ";", "}", "return", "implode", "(", "', '", ",", "$", "f", ")", ";", "}" ]
@param $to @return string
[ "@param", "$to" ]
train
https://github.com/songshenzong/log/blob/b1e01f7994da47737866eabf82367490eab17c46/src/Bridge/SwiftMailer/SwiftMailCollector.php#L64-L75
simialbi/yii2-simialbi-base
widgets/InputWidget.php
InputWidget.init
public function init() { if (!isset($this->options['id'])) { $this->options['id'] = $this->hasModel() ? Html::getInputId($this->model, $this->attribute) : $this->getId(); } parent::init(); }
php
public function init() { if (!isset($this->options['id'])) { $this->options['id'] = $this->hasModel() ? Html::getInputId($this->model, $this->attribute) : $this->getId(); } parent::init(); }
[ "public", "function", "init", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "options", "[", "'id'", "]", ")", ")", "{", "$", "this", "->", "options", "[", "'id'", "]", "=", "$", "this", "->", "hasModel", "(", ")", "?", "Html", "::", "getInputId", "(", "$", "this", "->", "model", ",", "$", "this", "->", "attribute", ")", ":", "$", "this", "->", "getId", "(", ")", ";", "}", "parent", "::", "init", "(", ")", ";", "}" ]
{@inheritdoc} @throws \yii\base\InvalidConfigException
[ "{" ]
train
https://github.com/simialbi/yii2-simialbi-base/blob/f68d3ee64f52c6dfb0aa31ffc14f5ced5aabdbb7/widgets/InputWidget.php#L42-L47
simialbi/yii2-simialbi-base
widgets/InputWidget.php
InputWidget.registerPlugin
protected function registerPlugin($pluginName = null) { $view = $this->view; $className = static::className(); $assetClassName = $className."Asset"; if (empty($pluginName)) { $pluginName = strtolower(StringHelper::basename($className)); } if (class_exists($assetClassName)) { /** * @var \simialbi\yii2\web\AssetBundle $assetClassName */ $assetClassName::register($view); } $id = $this->options['id']; if ($this->clientOptions !== false) { $options = empty($this->clientOptions) ? '' : Json::htmlEncode($this->clientOptions); $js = "jQuery('#$id').$pluginName($options);"; $view->registerJs($js); } $this->registerClientEvents(); }
php
protected function registerPlugin($pluginName = null) { $view = $this->view; $className = static::className(); $assetClassName = $className."Asset"; if (empty($pluginName)) { $pluginName = strtolower(StringHelper::basename($className)); } if (class_exists($assetClassName)) { /** * @var \simialbi\yii2\web\AssetBundle $assetClassName */ $assetClassName::register($view); } $id = $this->options['id']; if ($this->clientOptions !== false) { $options = empty($this->clientOptions) ? '' : Json::htmlEncode($this->clientOptions); $js = "jQuery('#$id').$pluginName($options);"; $view->registerJs($js); } $this->registerClientEvents(); }
[ "protected", "function", "registerPlugin", "(", "$", "pluginName", "=", "null", ")", "{", "$", "view", "=", "$", "this", "->", "view", ";", "$", "className", "=", "static", "::", "className", "(", ")", ";", "$", "assetClassName", "=", "$", "className", ".", "\"Asset\"", ";", "if", "(", "empty", "(", "$", "pluginName", ")", ")", "{", "$", "pluginName", "=", "strtolower", "(", "StringHelper", "::", "basename", "(", "$", "className", ")", ")", ";", "}", "if", "(", "class_exists", "(", "$", "assetClassName", ")", ")", "{", "/**\n\t\t\t * @var \\simialbi\\yii2\\web\\AssetBundle $assetClassName\n\t\t\t */", "$", "assetClassName", "::", "register", "(", "$", "view", ")", ";", "}", "$", "id", "=", "$", "this", "->", "options", "[", "'id'", "]", ";", "if", "(", "$", "this", "->", "clientOptions", "!==", "false", ")", "{", "$", "options", "=", "empty", "(", "$", "this", "->", "clientOptions", ")", "?", "''", ":", "Json", "::", "htmlEncode", "(", "$", "this", "->", "clientOptions", ")", ";", "$", "js", "=", "\"jQuery('#$id').$pluginName($options);\"", ";", "$", "view", "->", "registerJs", "(", "$", "js", ")", ";", "}", "$", "this", "->", "registerClientEvents", "(", ")", ";", "}" ]
Registers a specific plugin and the related events @param string $pluginName optional plugin name
[ "Registers", "a", "specific", "plugin", "and", "the", "related", "events" ]
train
https://github.com/simialbi/yii2-simialbi-base/blob/f68d3ee64f52c6dfb0aa31ffc14f5ced5aabdbb7/widgets/InputWidget.php#L54-L78
simialbi/yii2-simialbi-base
widgets/InputWidget.php
InputWidget.registerClientEvents
protected function registerClientEvents() { if (!empty($this->clientEvents)) { $id = $this->options['id']; $js = []; foreach ($this->clientEvents as $event => $handler) { $js[] = "jQuery('#$id').on('$event', $handler);"; } $this->view->registerJs(implode("\n", $js)); } }
php
protected function registerClientEvents() { if (!empty($this->clientEvents)) { $id = $this->options['id']; $js = []; foreach ($this->clientEvents as $event => $handler) { $js[] = "jQuery('#$id').on('$event', $handler);"; } $this->view->registerJs(implode("\n", $js)); } }
[ "protected", "function", "registerClientEvents", "(", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "clientEvents", ")", ")", "{", "$", "id", "=", "$", "this", "->", "options", "[", "'id'", "]", ";", "$", "js", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "clientEvents", "as", "$", "event", "=>", "$", "handler", ")", "{", "$", "js", "[", "]", "=", "\"jQuery('#$id').on('$event', $handler);\"", ";", "}", "$", "this", "->", "view", "->", "registerJs", "(", "implode", "(", "\"\\n\"", ",", "$", "js", ")", ")", ";", "}", "}" ]
Registers JS event handlers that are listed in [[clientEvents]].
[ "Registers", "JS", "event", "handlers", "that", "are", "listed", "in", "[[", "clientEvents", "]]", "." ]
train
https://github.com/simialbi/yii2-simialbi-base/blob/f68d3ee64f52c6dfb0aa31ffc14f5ced5aabdbb7/widgets/InputWidget.php#L83-L92
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php
Dwoo_Compiler.removePreProcessor
public function removePreProcessor($callback) { if (($index = array_search($callback, $this->processors['pre'], true)) !== false) { unset($this->processors['pre'][$index]); } elseif (($index = array_search('Dwoo_Processor_'.str_replace('Dwoo_Processor_', '', $callback), $this->processors['pre'], true)) !== false) { unset($this->processors['pre'][$index]); } else { $class = 'Dwoo_Processor_' . str_replace('Dwoo_Processor_', '', $callback); foreach ($this->processors['pre'] as $index=>$proc) { if (is_array($proc) && ($proc[0] instanceof $class) || (isset($proc['class']) && $proc['class'] == $class)) { unset($this->processors['pre'][$index]); break; } } } }
php
public function removePreProcessor($callback) { if (($index = array_search($callback, $this->processors['pre'], true)) !== false) { unset($this->processors['pre'][$index]); } elseif (($index = array_search('Dwoo_Processor_'.str_replace('Dwoo_Processor_', '', $callback), $this->processors['pre'], true)) !== false) { unset($this->processors['pre'][$index]); } else { $class = 'Dwoo_Processor_' . str_replace('Dwoo_Processor_', '', $callback); foreach ($this->processors['pre'] as $index=>$proc) { if (is_array($proc) && ($proc[0] instanceof $class) || (isset($proc['class']) && $proc['class'] == $class)) { unset($this->processors['pre'][$index]); break; } } } }
[ "public", "function", "removePreProcessor", "(", "$", "callback", ")", "{", "if", "(", "(", "$", "index", "=", "array_search", "(", "$", "callback", ",", "$", "this", "->", "processors", "[", "'pre'", "]", ",", "true", ")", ")", "!==", "false", ")", "{", "unset", "(", "$", "this", "->", "processors", "[", "'pre'", "]", "[", "$", "index", "]", ")", ";", "}", "elseif", "(", "(", "$", "index", "=", "array_search", "(", "'Dwoo_Processor_'", ".", "str_replace", "(", "'Dwoo_Processor_'", ",", "''", ",", "$", "callback", ")", ",", "$", "this", "->", "processors", "[", "'pre'", "]", ",", "true", ")", ")", "!==", "false", ")", "{", "unset", "(", "$", "this", "->", "processors", "[", "'pre'", "]", "[", "$", "index", "]", ")", ";", "}", "else", "{", "$", "class", "=", "'Dwoo_Processor_'", ".", "str_replace", "(", "'Dwoo_Processor_'", ",", "''", ",", "$", "callback", ")", ";", "foreach", "(", "$", "this", "->", "processors", "[", "'pre'", "]", "as", "$", "index", "=>", "$", "proc", ")", "{", "if", "(", "is_array", "(", "$", "proc", ")", "&&", "(", "$", "proc", "[", "0", "]", "instanceof", "$", "class", ")", "||", "(", "isset", "(", "$", "proc", "[", "'class'", "]", ")", "&&", "$", "proc", "[", "'class'", "]", "==", "$", "class", ")", ")", "{", "unset", "(", "$", "this", "->", "processors", "[", "'pre'", "]", "[", "$", "index", "]", ")", ";", "break", ";", "}", "}", "}", "}" ]
removes a preprocessor from the compiler @param mixed $callback either a valid callback to the preprocessor or a simple name if it was autoloaded
[ "removes", "a", "preprocessor", "from", "the", "compiler" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php#L380-L395
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php
Dwoo_Compiler.addPostProcessor
public function addPostProcessor($callback, $autoload = false) { if ($autoload) { $name = str_replace('Dwoo_Processor_', '', $callback); $class = 'Dwoo_Processor_'.$name; if (class_exists($class, false)) { $callback = array(new $class($this), 'process'); } elseif (function_exists($class)) { $callback = $class; } else { $callback = array('autoload'=>true, 'class'=>$class, 'name'=>$name); } $this->processors['post'][] = $callback; } else { $this->processors['post'][] = $callback; } }
php
public function addPostProcessor($callback, $autoload = false) { if ($autoload) { $name = str_replace('Dwoo_Processor_', '', $callback); $class = 'Dwoo_Processor_'.$name; if (class_exists($class, false)) { $callback = array(new $class($this), 'process'); } elseif (function_exists($class)) { $callback = $class; } else { $callback = array('autoload'=>true, 'class'=>$class, 'name'=>$name); } $this->processors['post'][] = $callback; } else { $this->processors['post'][] = $callback; } }
[ "public", "function", "addPostProcessor", "(", "$", "callback", ",", "$", "autoload", "=", "false", ")", "{", "if", "(", "$", "autoload", ")", "{", "$", "name", "=", "str_replace", "(", "'Dwoo_Processor_'", ",", "''", ",", "$", "callback", ")", ";", "$", "class", "=", "'Dwoo_Processor_'", ".", "$", "name", ";", "if", "(", "class_exists", "(", "$", "class", ",", "false", ")", ")", "{", "$", "callback", "=", "array", "(", "new", "$", "class", "(", "$", "this", ")", ",", "'process'", ")", ";", "}", "elseif", "(", "function_exists", "(", "$", "class", ")", ")", "{", "$", "callback", "=", "$", "class", ";", "}", "else", "{", "$", "callback", "=", "array", "(", "'autoload'", "=>", "true", ",", "'class'", "=>", "$", "class", ",", "'name'", "=>", "$", "name", ")", ";", "}", "$", "this", "->", "processors", "[", "'post'", "]", "[", "]", "=", "$", "callback", ";", "}", "else", "{", "$", "this", "->", "processors", "[", "'post'", "]", "[", "]", "=", "$", "callback", ";", "}", "}" ]
adds a postprocessor to the compiler, it will be called before the template is compiled @param mixed $callback either a valid callback to the postprocessor or a simple name if the autoload is set to true @param bool $autoload if set to true, the postprocessor is auto-loaded from one of the plugin directories, else you must provide a valid callback
[ "adds", "a", "postprocessor", "to", "the", "compiler", "it", "will", "be", "called", "before", "the", "template", "is", "compiled" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php#L404-L422
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php
Dwoo_Compiler.loadProcessor
protected function loadProcessor($class, $name) { if (!class_exists($class, false) && !function_exists($class)) { try { $this->dwoo->getLoader()->loadPlugin($name); } catch (Dwoo_Exception $e) { throw new Dwoo_Exception('Processor '.$name.' could not be found in your plugin directories, please ensure it is in a file named '.$name.'.php in the plugin directory'); } } if (class_exists($class, false)) { return array(new $class($this), 'process'); } if (function_exists($class)) { return $class; } throw new Dwoo_Exception('Wrong processor name, when using autoload the processor must be in one of your plugin dir as "name.php" containg a class or function named "Dwoo_Processor_name"'); }
php
protected function loadProcessor($class, $name) { if (!class_exists($class, false) && !function_exists($class)) { try { $this->dwoo->getLoader()->loadPlugin($name); } catch (Dwoo_Exception $e) { throw new Dwoo_Exception('Processor '.$name.' could not be found in your plugin directories, please ensure it is in a file named '.$name.'.php in the plugin directory'); } } if (class_exists($class, false)) { return array(new $class($this), 'process'); } if (function_exists($class)) { return $class; } throw new Dwoo_Exception('Wrong processor name, when using autoload the processor must be in one of your plugin dir as "name.php" containg a class or function named "Dwoo_Processor_name"'); }
[ "protected", "function", "loadProcessor", "(", "$", "class", ",", "$", "name", ")", "{", "if", "(", "!", "class_exists", "(", "$", "class", ",", "false", ")", "&&", "!", "function_exists", "(", "$", "class", ")", ")", "{", "try", "{", "$", "this", "->", "dwoo", "->", "getLoader", "(", ")", "->", "loadPlugin", "(", "$", "name", ")", ";", "}", "catch", "(", "Dwoo_Exception", "$", "e", ")", "{", "throw", "new", "Dwoo_Exception", "(", "'Processor '", ".", "$", "name", ".", "' could not be found in your plugin directories, please ensure it is in a file named '", ".", "$", "name", ".", "'.php in the plugin directory'", ")", ";", "}", "}", "if", "(", "class_exists", "(", "$", "class", ",", "false", ")", ")", "{", "return", "array", "(", "new", "$", "class", "(", "$", "this", ")", ",", "'process'", ")", ";", "}", "if", "(", "function_exists", "(", "$", "class", ")", ")", "{", "return", "$", "class", ";", "}", "throw", "new", "Dwoo_Exception", "(", "'Wrong processor name, when using autoload the processor must be in one of your plugin dir as \"name.php\" containg a class or function named \"Dwoo_Processor_name\"'", ")", ";", "}" ]
internal function to autoload processors at runtime if required @param string $class the class/function name @param string $name the plugin name (without Dwoo_Plugin_ prefix)
[ "internal", "function", "to", "autoload", "processors", "at", "runtime", "if", "required" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php#L452-L471
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php
Dwoo_Compiler.compile
public function compile(Dwoo $dwoo, Dwoo_ITemplate $template) { // init vars $tpl = $template->getSource(); $ptr = 0; $this->dwoo = $dwoo; $this->template = $template; $this->templateSource =& $tpl; $this->pointer =& $ptr; while (true) { // if pointer is at the beginning, reset everything, that allows a plugin to externally reset the compiler if everything must be reparsed if ($ptr===0) { // resets variables $this->usedPlugins = array(); $this->data = array(); $this->scope =& $this->data; $this->scopeTree = array(); $this->stack = array(); $this->line = 1; $this->templatePlugins = array(); // add top level block $compiled = $this->addBlock('topLevelBlock', array(), 0); $this->stack[0]['buffer'] = ''; if ($this->debug) echo 'COMPILER INIT<br />'; if ($this->debug) echo 'PROCESSING PREPROCESSORS ('.count($this->processors['pre']).')<br>'; // runs preprocessors foreach ($this->processors['pre'] as $preProc) { if (is_array($preProc) && isset($preProc['autoload'])) { $preProc = $this->loadProcessor($preProc['class'], $preProc['name']); } if (is_array($preProc) && $preProc[0] instanceof Dwoo_Processor) { $tpl = call_user_func($preProc, $tpl); } else { $tpl = call_user_func($preProc, $this, $tpl); } } unset($preProc); // show template source if debug if ($this->debug) echo '<pre>'.print_r(htmlentities($tpl), true).'</pre><hr />'; // strips php tags if required by the security policy if ($this->securityPolicy !== null) { $search = array('{<\?php.*?\?>}'); if (ini_get('short_open_tags')) { $search = array('{<\?.*?\?>}', '{<%.*?%>}'); } switch($this->securityPolicy->getPhpHandling()) { case Dwoo_Security_Policy::PHP_ALLOW: break; case Dwoo_Security_Policy::PHP_ENCODE: $tpl = preg_replace_callback($search, array($this, 'phpTagEncodingHelper'), $tpl); break; case Dwoo_Security_Policy::PHP_REMOVE: $tpl = preg_replace($search, '', $tpl); } } } $pos = strpos($tpl, $this->ld, $ptr); if ($pos === false) { $this->push(substr($tpl, $ptr), 0); break; } elseif (substr($tpl, $pos-1, 1) === '\\' && substr($tpl, $pos-2, 1) !== '\\') { $this->push(substr($tpl, $ptr, $pos-$ptr-1) . $this->ld); $ptr = $pos+strlen($this->ld); } elseif (preg_match('/^'.$this->ldr . ($this->allowLooseOpenings ? '\s*' : '') . 'literal' . ($this->allowLooseOpenings ? '\s*' : '') . $this->rdr.'/s', substr($tpl, $pos), $litOpen)) { if (!preg_match('/'.$this->ldr . ($this->allowLooseOpenings ? '\s*' : '') . '\/literal' . ($this->allowLooseOpenings ? '\s*' : '') . $this->rdr.'/s', $tpl, $litClose, PREG_OFFSET_CAPTURE, $pos)) { throw new Dwoo_Compilation_Exception($this, 'The {literal} blocks must be closed explicitly with {/literal}'); } $endpos = $litClose[0][1]; $this->push(substr($tpl, $ptr, $pos-$ptr) . substr($tpl, $pos + strlen($litOpen[0]), $endpos-$pos-strlen($litOpen[0]))); $ptr = $endpos+strlen($litClose[0][0]); } else { if (substr($tpl, $pos-2, 1) === '\\' && substr($tpl, $pos-1, 1) === '\\') { $this->push(substr($tpl, $ptr, $pos-$ptr-1)); $ptr = $pos; } $this->push(substr($tpl, $ptr, $pos-$ptr)); $ptr = $pos; $pos += strlen($this->ld); if ($this->allowLooseOpenings) { while (substr($tpl, $pos, 1) === ' ') { $pos+=1; } } else { if (substr($tpl, $pos, 1) === ' ' || substr($tpl, $pos, 1) === "\r" || substr($tpl, $pos, 1) === "\n" || substr($tpl, $pos, 1) === "\t") { $ptr = $pos; $this->push($this->ld); continue; } } // check that there is an end tag present if (strpos($tpl, $this->rd, $pos) === false) { throw new Dwoo_Compilation_Exception($this, 'A template tag was not closed, started with "'.substr($tpl, $ptr, 30).'"'); } $ptr += strlen($this->ld); $subptr = $ptr; while (true) { $parsed = $this->parse($tpl, $subptr, null, false, 'root', $subptr); // reload loop if the compiler was reset if ($ptr === 0) { continue 2; } $len = $subptr - $ptr; $this->push($parsed, substr_count(substr($tpl, $ptr, $len), "\n")); $ptr += $len; if ($parsed === false) { break; } } // adds additional line breaks between php closing and opening tags because the php parser removes those if there is just a single line break if (substr($this->curBlock['buffer'], -2) === '?>' && preg_match('{^(([\r\n])([\r\n]?))}', substr($tpl, $ptr, 3), $m)) { if ($m[3] === '') { $ptr+=1; $this->push($m[1].$m[1], 1); } else { $ptr+=2; $this->push($m[1]."\n", 2); } } } } $compiled .= $this->removeBlock('topLevelBlock'); if ($this->debug) echo 'PROCESSING POSTPROCESSORS<br>'; foreach ($this->processors['post'] as $postProc) { if (is_array($postProc) && isset($postProc['autoload'])) { $postProc = $this->loadProcessor($postProc['class'], $postProc['name']); } if (is_array($postProc) && $postProc[0] instanceof Dwoo_Processor) { $compiled = call_user_func($postProc, $compiled); } else { $compiled = call_user_func($postProc, $this, $compiled); } } unset($postProc); if ($this->debug) echo 'COMPILATION COMPLETE : MEM USAGE : '.memory_get_usage().'<br>'; $output = "<?php\n/* template head */\n"; // build plugin preloader foreach ($this->usedPlugins as $plugin=>$type) { if ($type & Dwoo::CUSTOM_PLUGIN) { continue; } switch($type) { case Dwoo::BLOCK_PLUGIN: case Dwoo::CLASS_PLUGIN: $output .= "if (class_exists('Dwoo_Plugin_$plugin', false)===false)\n\t\$this->getLoader()->loadPlugin('$plugin');\n"; break; case Dwoo::FUNC_PLUGIN: $output .= "if (function_exists('Dwoo_Plugin_$plugin')===false)\n\t\$this->getLoader()->loadPlugin('$plugin');\n"; break; case Dwoo::SMARTY_MODIFIER: $output .= "if (function_exists('smarty_modifier_$plugin')===false)\n\t\$this->getLoader()->loadPlugin('$plugin');\n"; break; case Dwoo::SMARTY_FUNCTION: $output .= "if (function_exists('smarty_function_$plugin')===false)\n\t\$this->getLoader()->loadPlugin('$plugin');\n"; break; case Dwoo::SMARTY_BLOCK: $output .= "if (function_exists('smarty_block_$plugin')===false)\n\t\$this->getLoader()->loadPlugin('$plugin');\n"; break; case Dwoo::PROXY_PLUGIN: $output .= $this->getDwoo()->getPluginProxy()->getPreloader($plugin); break; default: throw new Dwoo_Compilation_Exception($this, 'Type error for '.$plugin.' with type'.$type); } } foreach ($this->templatePlugins as $function => $attr) { if (isset($attr['called']) && $attr['called'] === true && !isset($attr['checked'])) { $this->resolveSubTemplateDependencies($function); } } foreach ($this->templatePlugins as $function) { if (isset($function['called']) && $function['called'] === true) { $output .= $function['body'].PHP_EOL; } } $output .= $compiled."\n?>"; $output = preg_replace('/(?<!;|\}|\*\/|\n|\{)(\s*'.preg_quote(self::PHP_CLOSE, '/') . preg_quote(self::PHP_OPEN, '/').')/', ";\n", $output); $output = str_replace(self::PHP_CLOSE . self::PHP_OPEN, "\n", $output); // handle <?xml tag at the beginning $output = preg_replace('#(/\* template body \*/ \?>\s*)<\?xml#is', '$1<?php echo \'<?xml\'; ?>', $output); if ($this->debug) { echo '<hr><pre>'; $lines = preg_split('{\r\n|\n|<br />}', highlight_string(($output), true)); array_shift($lines); foreach ($lines as $i=>$line) { echo ($i+1).'. '.$line."\r\n"; } } if ($this->debug) echo '<hr></pre></pre>'; $this->template = $this->dwoo = null; $tpl = null; return $output; }
php
public function compile(Dwoo $dwoo, Dwoo_ITemplate $template) { // init vars $tpl = $template->getSource(); $ptr = 0; $this->dwoo = $dwoo; $this->template = $template; $this->templateSource =& $tpl; $this->pointer =& $ptr; while (true) { // if pointer is at the beginning, reset everything, that allows a plugin to externally reset the compiler if everything must be reparsed if ($ptr===0) { // resets variables $this->usedPlugins = array(); $this->data = array(); $this->scope =& $this->data; $this->scopeTree = array(); $this->stack = array(); $this->line = 1; $this->templatePlugins = array(); // add top level block $compiled = $this->addBlock('topLevelBlock', array(), 0); $this->stack[0]['buffer'] = ''; if ($this->debug) echo 'COMPILER INIT<br />'; if ($this->debug) echo 'PROCESSING PREPROCESSORS ('.count($this->processors['pre']).')<br>'; // runs preprocessors foreach ($this->processors['pre'] as $preProc) { if (is_array($preProc) && isset($preProc['autoload'])) { $preProc = $this->loadProcessor($preProc['class'], $preProc['name']); } if (is_array($preProc) && $preProc[0] instanceof Dwoo_Processor) { $tpl = call_user_func($preProc, $tpl); } else { $tpl = call_user_func($preProc, $this, $tpl); } } unset($preProc); // show template source if debug if ($this->debug) echo '<pre>'.print_r(htmlentities($tpl), true).'</pre><hr />'; // strips php tags if required by the security policy if ($this->securityPolicy !== null) { $search = array('{<\?php.*?\?>}'); if (ini_get('short_open_tags')) { $search = array('{<\?.*?\?>}', '{<%.*?%>}'); } switch($this->securityPolicy->getPhpHandling()) { case Dwoo_Security_Policy::PHP_ALLOW: break; case Dwoo_Security_Policy::PHP_ENCODE: $tpl = preg_replace_callback($search, array($this, 'phpTagEncodingHelper'), $tpl); break; case Dwoo_Security_Policy::PHP_REMOVE: $tpl = preg_replace($search, '', $tpl); } } } $pos = strpos($tpl, $this->ld, $ptr); if ($pos === false) { $this->push(substr($tpl, $ptr), 0); break; } elseif (substr($tpl, $pos-1, 1) === '\\' && substr($tpl, $pos-2, 1) !== '\\') { $this->push(substr($tpl, $ptr, $pos-$ptr-1) . $this->ld); $ptr = $pos+strlen($this->ld); } elseif (preg_match('/^'.$this->ldr . ($this->allowLooseOpenings ? '\s*' : '') . 'literal' . ($this->allowLooseOpenings ? '\s*' : '') . $this->rdr.'/s', substr($tpl, $pos), $litOpen)) { if (!preg_match('/'.$this->ldr . ($this->allowLooseOpenings ? '\s*' : '') . '\/literal' . ($this->allowLooseOpenings ? '\s*' : '') . $this->rdr.'/s', $tpl, $litClose, PREG_OFFSET_CAPTURE, $pos)) { throw new Dwoo_Compilation_Exception($this, 'The {literal} blocks must be closed explicitly with {/literal}'); } $endpos = $litClose[0][1]; $this->push(substr($tpl, $ptr, $pos-$ptr) . substr($tpl, $pos + strlen($litOpen[0]), $endpos-$pos-strlen($litOpen[0]))); $ptr = $endpos+strlen($litClose[0][0]); } else { if (substr($tpl, $pos-2, 1) === '\\' && substr($tpl, $pos-1, 1) === '\\') { $this->push(substr($tpl, $ptr, $pos-$ptr-1)); $ptr = $pos; } $this->push(substr($tpl, $ptr, $pos-$ptr)); $ptr = $pos; $pos += strlen($this->ld); if ($this->allowLooseOpenings) { while (substr($tpl, $pos, 1) === ' ') { $pos+=1; } } else { if (substr($tpl, $pos, 1) === ' ' || substr($tpl, $pos, 1) === "\r" || substr($tpl, $pos, 1) === "\n" || substr($tpl, $pos, 1) === "\t") { $ptr = $pos; $this->push($this->ld); continue; } } // check that there is an end tag present if (strpos($tpl, $this->rd, $pos) === false) { throw new Dwoo_Compilation_Exception($this, 'A template tag was not closed, started with "'.substr($tpl, $ptr, 30).'"'); } $ptr += strlen($this->ld); $subptr = $ptr; while (true) { $parsed = $this->parse($tpl, $subptr, null, false, 'root', $subptr); // reload loop if the compiler was reset if ($ptr === 0) { continue 2; } $len = $subptr - $ptr; $this->push($parsed, substr_count(substr($tpl, $ptr, $len), "\n")); $ptr += $len; if ($parsed === false) { break; } } // adds additional line breaks between php closing and opening tags because the php parser removes those if there is just a single line break if (substr($this->curBlock['buffer'], -2) === '?>' && preg_match('{^(([\r\n])([\r\n]?))}', substr($tpl, $ptr, 3), $m)) { if ($m[3] === '') { $ptr+=1; $this->push($m[1].$m[1], 1); } else { $ptr+=2; $this->push($m[1]."\n", 2); } } } } $compiled .= $this->removeBlock('topLevelBlock'); if ($this->debug) echo 'PROCESSING POSTPROCESSORS<br>'; foreach ($this->processors['post'] as $postProc) { if (is_array($postProc) && isset($postProc['autoload'])) { $postProc = $this->loadProcessor($postProc['class'], $postProc['name']); } if (is_array($postProc) && $postProc[0] instanceof Dwoo_Processor) { $compiled = call_user_func($postProc, $compiled); } else { $compiled = call_user_func($postProc, $this, $compiled); } } unset($postProc); if ($this->debug) echo 'COMPILATION COMPLETE : MEM USAGE : '.memory_get_usage().'<br>'; $output = "<?php\n/* template head */\n"; // build plugin preloader foreach ($this->usedPlugins as $plugin=>$type) { if ($type & Dwoo::CUSTOM_PLUGIN) { continue; } switch($type) { case Dwoo::BLOCK_PLUGIN: case Dwoo::CLASS_PLUGIN: $output .= "if (class_exists('Dwoo_Plugin_$plugin', false)===false)\n\t\$this->getLoader()->loadPlugin('$plugin');\n"; break; case Dwoo::FUNC_PLUGIN: $output .= "if (function_exists('Dwoo_Plugin_$plugin')===false)\n\t\$this->getLoader()->loadPlugin('$plugin');\n"; break; case Dwoo::SMARTY_MODIFIER: $output .= "if (function_exists('smarty_modifier_$plugin')===false)\n\t\$this->getLoader()->loadPlugin('$plugin');\n"; break; case Dwoo::SMARTY_FUNCTION: $output .= "if (function_exists('smarty_function_$plugin')===false)\n\t\$this->getLoader()->loadPlugin('$plugin');\n"; break; case Dwoo::SMARTY_BLOCK: $output .= "if (function_exists('smarty_block_$plugin')===false)\n\t\$this->getLoader()->loadPlugin('$plugin');\n"; break; case Dwoo::PROXY_PLUGIN: $output .= $this->getDwoo()->getPluginProxy()->getPreloader($plugin); break; default: throw new Dwoo_Compilation_Exception($this, 'Type error for '.$plugin.' with type'.$type); } } foreach ($this->templatePlugins as $function => $attr) { if (isset($attr['called']) && $attr['called'] === true && !isset($attr['checked'])) { $this->resolveSubTemplateDependencies($function); } } foreach ($this->templatePlugins as $function) { if (isset($function['called']) && $function['called'] === true) { $output .= $function['body'].PHP_EOL; } } $output .= $compiled."\n?>"; $output = preg_replace('/(?<!;|\}|\*\/|\n|\{)(\s*'.preg_quote(self::PHP_CLOSE, '/') . preg_quote(self::PHP_OPEN, '/').')/', ";\n", $output); $output = str_replace(self::PHP_CLOSE . self::PHP_OPEN, "\n", $output); // handle <?xml tag at the beginning $output = preg_replace('#(/\* template body \*/ \?>\s*)<\?xml#is', '$1<?php echo \'<?xml\'; ?>', $output); if ($this->debug) { echo '<hr><pre>'; $lines = preg_split('{\r\n|\n|<br />}', highlight_string(($output), true)); array_shift($lines); foreach ($lines as $i=>$line) { echo ($i+1).'. '.$line."\r\n"; } } if ($this->debug) echo '<hr></pre></pre>'; $this->template = $this->dwoo = null; $tpl = null; return $output; }
[ "public", "function", "compile", "(", "Dwoo", "$", "dwoo", ",", "Dwoo_ITemplate", "$", "template", ")", "{", "// init vars", "$", "tpl", "=", "$", "template", "->", "getSource", "(", ")", ";", "$", "ptr", "=", "0", ";", "$", "this", "->", "dwoo", "=", "$", "dwoo", ";", "$", "this", "->", "template", "=", "$", "template", ";", "$", "this", "->", "templateSource", "=", "&", "$", "tpl", ";", "$", "this", "->", "pointer", "=", "&", "$", "ptr", ";", "while", "(", "true", ")", "{", "// if pointer is at the beginning, reset everything, that allows a plugin to externally reset the compiler if everything must be reparsed", "if", "(", "$", "ptr", "===", "0", ")", "{", "// resets variables", "$", "this", "->", "usedPlugins", "=", "array", "(", ")", ";", "$", "this", "->", "data", "=", "array", "(", ")", ";", "$", "this", "->", "scope", "=", "&", "$", "this", "->", "data", ";", "$", "this", "->", "scopeTree", "=", "array", "(", ")", ";", "$", "this", "->", "stack", "=", "array", "(", ")", ";", "$", "this", "->", "line", "=", "1", ";", "$", "this", "->", "templatePlugins", "=", "array", "(", ")", ";", "// add top level block", "$", "compiled", "=", "$", "this", "->", "addBlock", "(", "'topLevelBlock'", ",", "array", "(", ")", ",", "0", ")", ";", "$", "this", "->", "stack", "[", "0", "]", "[", "'buffer'", "]", "=", "''", ";", "if", "(", "$", "this", "->", "debug", ")", "echo", "'COMPILER INIT<br />'", ";", "if", "(", "$", "this", "->", "debug", ")", "echo", "'PROCESSING PREPROCESSORS ('", ".", "count", "(", "$", "this", "->", "processors", "[", "'pre'", "]", ")", ".", "')<br>'", ";", "// runs preprocessors", "foreach", "(", "$", "this", "->", "processors", "[", "'pre'", "]", "as", "$", "preProc", ")", "{", "if", "(", "is_array", "(", "$", "preProc", ")", "&&", "isset", "(", "$", "preProc", "[", "'autoload'", "]", ")", ")", "{", "$", "preProc", "=", "$", "this", "->", "loadProcessor", "(", "$", "preProc", "[", "'class'", "]", ",", "$", "preProc", "[", "'name'", "]", ")", ";", "}", "if", "(", "is_array", "(", "$", "preProc", ")", "&&", "$", "preProc", "[", "0", "]", "instanceof", "Dwoo_Processor", ")", "{", "$", "tpl", "=", "call_user_func", "(", "$", "preProc", ",", "$", "tpl", ")", ";", "}", "else", "{", "$", "tpl", "=", "call_user_func", "(", "$", "preProc", ",", "$", "this", ",", "$", "tpl", ")", ";", "}", "}", "unset", "(", "$", "preProc", ")", ";", "// show template source if debug", "if", "(", "$", "this", "->", "debug", ")", "echo", "'<pre>'", ".", "print_r", "(", "htmlentities", "(", "$", "tpl", ")", ",", "true", ")", ".", "'</pre><hr />'", ";", "// strips php tags if required by the security policy", "if", "(", "$", "this", "->", "securityPolicy", "!==", "null", ")", "{", "$", "search", "=", "array", "(", "'{<\\?php.*?\\?>}'", ")", ";", "if", "(", "ini_get", "(", "'short_open_tags'", ")", ")", "{", "$", "search", "=", "array", "(", "'{<\\?.*?\\?>}'", ",", "'{<%.*?%>}'", ")", ";", "}", "switch", "(", "$", "this", "->", "securityPolicy", "->", "getPhpHandling", "(", ")", ")", "{", "case", "Dwoo_Security_Policy", "::", "PHP_ALLOW", ":", "break", ";", "case", "Dwoo_Security_Policy", "::", "PHP_ENCODE", ":", "$", "tpl", "=", "preg_replace_callback", "(", "$", "search", ",", "array", "(", "$", "this", ",", "'phpTagEncodingHelper'", ")", ",", "$", "tpl", ")", ";", "break", ";", "case", "Dwoo_Security_Policy", "::", "PHP_REMOVE", ":", "$", "tpl", "=", "preg_replace", "(", "$", "search", ",", "''", ",", "$", "tpl", ")", ";", "}", "}", "}", "$", "pos", "=", "strpos", "(", "$", "tpl", ",", "$", "this", "->", "ld", ",", "$", "ptr", ")", ";", "if", "(", "$", "pos", "===", "false", ")", "{", "$", "this", "->", "push", "(", "substr", "(", "$", "tpl", ",", "$", "ptr", ")", ",", "0", ")", ";", "break", ";", "}", "elseif", "(", "substr", "(", "$", "tpl", ",", "$", "pos", "-", "1", ",", "1", ")", "===", "'\\\\'", "&&", "substr", "(", "$", "tpl", ",", "$", "pos", "-", "2", ",", "1", ")", "!==", "'\\\\'", ")", "{", "$", "this", "->", "push", "(", "substr", "(", "$", "tpl", ",", "$", "ptr", ",", "$", "pos", "-", "$", "ptr", "-", "1", ")", ".", "$", "this", "->", "ld", ")", ";", "$", "ptr", "=", "$", "pos", "+", "strlen", "(", "$", "this", "->", "ld", ")", ";", "}", "elseif", "(", "preg_match", "(", "'/^'", ".", "$", "this", "->", "ldr", ".", "(", "$", "this", "->", "allowLooseOpenings", "?", "'\\s*'", ":", "''", ")", ".", "'literal'", ".", "(", "$", "this", "->", "allowLooseOpenings", "?", "'\\s*'", ":", "''", ")", ".", "$", "this", "->", "rdr", ".", "'/s'", ",", "substr", "(", "$", "tpl", ",", "$", "pos", ")", ",", "$", "litOpen", ")", ")", "{", "if", "(", "!", "preg_match", "(", "'/'", ".", "$", "this", "->", "ldr", ".", "(", "$", "this", "->", "allowLooseOpenings", "?", "'\\s*'", ":", "''", ")", ".", "'\\/literal'", ".", "(", "$", "this", "->", "allowLooseOpenings", "?", "'\\s*'", ":", "''", ")", ".", "$", "this", "->", "rdr", ".", "'/s'", ",", "$", "tpl", ",", "$", "litClose", ",", "PREG_OFFSET_CAPTURE", ",", "$", "pos", ")", ")", "{", "throw", "new", "Dwoo_Compilation_Exception", "(", "$", "this", ",", "'The {literal} blocks must be closed explicitly with {/literal}'", ")", ";", "}", "$", "endpos", "=", "$", "litClose", "[", "0", "]", "[", "1", "]", ";", "$", "this", "->", "push", "(", "substr", "(", "$", "tpl", ",", "$", "ptr", ",", "$", "pos", "-", "$", "ptr", ")", ".", "substr", "(", "$", "tpl", ",", "$", "pos", "+", "strlen", "(", "$", "litOpen", "[", "0", "]", ")", ",", "$", "endpos", "-", "$", "pos", "-", "strlen", "(", "$", "litOpen", "[", "0", "]", ")", ")", ")", ";", "$", "ptr", "=", "$", "endpos", "+", "strlen", "(", "$", "litClose", "[", "0", "]", "[", "0", "]", ")", ";", "}", "else", "{", "if", "(", "substr", "(", "$", "tpl", ",", "$", "pos", "-", "2", ",", "1", ")", "===", "'\\\\'", "&&", "substr", "(", "$", "tpl", ",", "$", "pos", "-", "1", ",", "1", ")", "===", "'\\\\'", ")", "{", "$", "this", "->", "push", "(", "substr", "(", "$", "tpl", ",", "$", "ptr", ",", "$", "pos", "-", "$", "ptr", "-", "1", ")", ")", ";", "$", "ptr", "=", "$", "pos", ";", "}", "$", "this", "->", "push", "(", "substr", "(", "$", "tpl", ",", "$", "ptr", ",", "$", "pos", "-", "$", "ptr", ")", ")", ";", "$", "ptr", "=", "$", "pos", ";", "$", "pos", "+=", "strlen", "(", "$", "this", "->", "ld", ")", ";", "if", "(", "$", "this", "->", "allowLooseOpenings", ")", "{", "while", "(", "substr", "(", "$", "tpl", ",", "$", "pos", ",", "1", ")", "===", "' '", ")", "{", "$", "pos", "+=", "1", ";", "}", "}", "else", "{", "if", "(", "substr", "(", "$", "tpl", ",", "$", "pos", ",", "1", ")", "===", "' '", "||", "substr", "(", "$", "tpl", ",", "$", "pos", ",", "1", ")", "===", "\"\\r\"", "||", "substr", "(", "$", "tpl", ",", "$", "pos", ",", "1", ")", "===", "\"\\n\"", "||", "substr", "(", "$", "tpl", ",", "$", "pos", ",", "1", ")", "===", "\"\\t\"", ")", "{", "$", "ptr", "=", "$", "pos", ";", "$", "this", "->", "push", "(", "$", "this", "->", "ld", ")", ";", "continue", ";", "}", "}", "// check that there is an end tag present", "if", "(", "strpos", "(", "$", "tpl", ",", "$", "this", "->", "rd", ",", "$", "pos", ")", "===", "false", ")", "{", "throw", "new", "Dwoo_Compilation_Exception", "(", "$", "this", ",", "'A template tag was not closed, started with \"'", ".", "substr", "(", "$", "tpl", ",", "$", "ptr", ",", "30", ")", ".", "'\"'", ")", ";", "}", "$", "ptr", "+=", "strlen", "(", "$", "this", "->", "ld", ")", ";", "$", "subptr", "=", "$", "ptr", ";", "while", "(", "true", ")", "{", "$", "parsed", "=", "$", "this", "->", "parse", "(", "$", "tpl", ",", "$", "subptr", ",", "null", ",", "false", ",", "'root'", ",", "$", "subptr", ")", ";", "// reload loop if the compiler was reset", "if", "(", "$", "ptr", "===", "0", ")", "{", "continue", "2", ";", "}", "$", "len", "=", "$", "subptr", "-", "$", "ptr", ";", "$", "this", "->", "push", "(", "$", "parsed", ",", "substr_count", "(", "substr", "(", "$", "tpl", ",", "$", "ptr", ",", "$", "len", ")", ",", "\"\\n\"", ")", ")", ";", "$", "ptr", "+=", "$", "len", ";", "if", "(", "$", "parsed", "===", "false", ")", "{", "break", ";", "}", "}", "// adds additional line breaks between php closing and opening tags because the php parser removes those if there is just a single line break", "if", "(", "substr", "(", "$", "this", "->", "curBlock", "[", "'buffer'", "]", ",", "-", "2", ")", "===", "'?>'", "&&", "preg_match", "(", "'{^(([\\r\\n])([\\r\\n]?))}'", ",", "substr", "(", "$", "tpl", ",", "$", "ptr", ",", "3", ")", ",", "$", "m", ")", ")", "{", "if", "(", "$", "m", "[", "3", "]", "===", "''", ")", "{", "$", "ptr", "+=", "1", ";", "$", "this", "->", "push", "(", "$", "m", "[", "1", "]", ".", "$", "m", "[", "1", "]", ",", "1", ")", ";", "}", "else", "{", "$", "ptr", "+=", "2", ";", "$", "this", "->", "push", "(", "$", "m", "[", "1", "]", ".", "\"\\n\"", ",", "2", ")", ";", "}", "}", "}", "}", "$", "compiled", ".=", "$", "this", "->", "removeBlock", "(", "'topLevelBlock'", ")", ";", "if", "(", "$", "this", "->", "debug", ")", "echo", "'PROCESSING POSTPROCESSORS<br>'", ";", "foreach", "(", "$", "this", "->", "processors", "[", "'post'", "]", "as", "$", "postProc", ")", "{", "if", "(", "is_array", "(", "$", "postProc", ")", "&&", "isset", "(", "$", "postProc", "[", "'autoload'", "]", ")", ")", "{", "$", "postProc", "=", "$", "this", "->", "loadProcessor", "(", "$", "postProc", "[", "'class'", "]", ",", "$", "postProc", "[", "'name'", "]", ")", ";", "}", "if", "(", "is_array", "(", "$", "postProc", ")", "&&", "$", "postProc", "[", "0", "]", "instanceof", "Dwoo_Processor", ")", "{", "$", "compiled", "=", "call_user_func", "(", "$", "postProc", ",", "$", "compiled", ")", ";", "}", "else", "{", "$", "compiled", "=", "call_user_func", "(", "$", "postProc", ",", "$", "this", ",", "$", "compiled", ")", ";", "}", "}", "unset", "(", "$", "postProc", ")", ";", "if", "(", "$", "this", "->", "debug", ")", "echo", "'COMPILATION COMPLETE : MEM USAGE : '", ".", "memory_get_usage", "(", ")", ".", "'<br>'", ";", "$", "output", "=", "\"<?php\\n/* template head */\\n\"", ";", "// build plugin preloader", "foreach", "(", "$", "this", "->", "usedPlugins", "as", "$", "plugin", "=>", "$", "type", ")", "{", "if", "(", "$", "type", "&", "Dwoo", "::", "CUSTOM_PLUGIN", ")", "{", "continue", ";", "}", "switch", "(", "$", "type", ")", "{", "case", "Dwoo", "::", "BLOCK_PLUGIN", ":", "case", "Dwoo", "::", "CLASS_PLUGIN", ":", "$", "output", ".=", "\"if (class_exists('Dwoo_Plugin_$plugin', false)===false)\\n\\t\\$this->getLoader()->loadPlugin('$plugin');\\n\"", ";", "break", ";", "case", "Dwoo", "::", "FUNC_PLUGIN", ":", "$", "output", ".=", "\"if (function_exists('Dwoo_Plugin_$plugin')===false)\\n\\t\\$this->getLoader()->loadPlugin('$plugin');\\n\"", ";", "break", ";", "case", "Dwoo", "::", "SMARTY_MODIFIER", ":", "$", "output", ".=", "\"if (function_exists('smarty_modifier_$plugin')===false)\\n\\t\\$this->getLoader()->loadPlugin('$plugin');\\n\"", ";", "break", ";", "case", "Dwoo", "::", "SMARTY_FUNCTION", ":", "$", "output", ".=", "\"if (function_exists('smarty_function_$plugin')===false)\\n\\t\\$this->getLoader()->loadPlugin('$plugin');\\n\"", ";", "break", ";", "case", "Dwoo", "::", "SMARTY_BLOCK", ":", "$", "output", ".=", "\"if (function_exists('smarty_block_$plugin')===false)\\n\\t\\$this->getLoader()->loadPlugin('$plugin');\\n\"", ";", "break", ";", "case", "Dwoo", "::", "PROXY_PLUGIN", ":", "$", "output", ".=", "$", "this", "->", "getDwoo", "(", ")", "->", "getPluginProxy", "(", ")", "->", "getPreloader", "(", "$", "plugin", ")", ";", "break", ";", "default", ":", "throw", "new", "Dwoo_Compilation_Exception", "(", "$", "this", ",", "'Type error for '", ".", "$", "plugin", ".", "' with type'", ".", "$", "type", ")", ";", "}", "}", "foreach", "(", "$", "this", "->", "templatePlugins", "as", "$", "function", "=>", "$", "attr", ")", "{", "if", "(", "isset", "(", "$", "attr", "[", "'called'", "]", ")", "&&", "$", "attr", "[", "'called'", "]", "===", "true", "&&", "!", "isset", "(", "$", "attr", "[", "'checked'", "]", ")", ")", "{", "$", "this", "->", "resolveSubTemplateDependencies", "(", "$", "function", ")", ";", "}", "}", "foreach", "(", "$", "this", "->", "templatePlugins", "as", "$", "function", ")", "{", "if", "(", "isset", "(", "$", "function", "[", "'called'", "]", ")", "&&", "$", "function", "[", "'called'", "]", "===", "true", ")", "{", "$", "output", ".=", "$", "function", "[", "'body'", "]", ".", "PHP_EOL", ";", "}", "}", "$", "output", ".=", "$", "compiled", ".", "\"\\n?>\"", ";", "$", "output", "=", "preg_replace", "(", "'/(?<!;|\\}|\\*\\/|\\n|\\{)(\\s*'", ".", "preg_quote", "(", "self", "::", "PHP_CLOSE", ",", "'/'", ")", ".", "preg_quote", "(", "self", "::", "PHP_OPEN", ",", "'/'", ")", ".", "')/'", ",", "\";\\n\"", ",", "$", "output", ")", ";", "$", "output", "=", "str_replace", "(", "self", "::", "PHP_CLOSE", ".", "self", "::", "PHP_OPEN", ",", "\"\\n\"", ",", "$", "output", ")", ";", "// handle <?xml tag at the beginning", "$", "output", "=", "preg_replace", "(", "'#(/\\* template body \\*/ \\?>\\s*)<\\?xml#is'", ",", "'$1<?php echo \\'<?xml\\'; ?>'", ",", "$", "output", ")", ";", "if", "(", "$", "this", "->", "debug", ")", "{", "echo", "'<hr><pre>'", ";", "$", "lines", "=", "preg_split", "(", "'{\\r\\n|\\n|<br />}'", ",", "highlight_string", "(", "(", "$", "output", ")", ",", "true", ")", ")", ";", "array_shift", "(", "$", "lines", ")", ";", "foreach", "(", "$", "lines", "as", "$", "i", "=>", "$", "line", ")", "{", "echo", "(", "$", "i", "+", "1", ")", ".", "'. '", ".", "$", "line", ".", "\"\\r\\n\"", ";", "}", "}", "if", "(", "$", "this", "->", "debug", ")", "echo", "'<hr></pre></pre>'", ";", "$", "this", "->", "template", "=", "$", "this", "->", "dwoo", "=", "null", ";", "$", "tpl", "=", "null", ";", "return", "$", "output", ";", "}" ]
compiles the provided string down to php code @param string $tpl the template to compile @return string a compiled php string
[ "compiles", "the", "provided", "string", "down", "to", "php", "code" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php#L682-L909
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php
Dwoo_Compiler.resolveSubTemplateDependencies
protected function resolveSubTemplateDependencies($function) { $body = $this->templatePlugins[$function]['body']; foreach ($this->templatePlugins as $func => $attr) { if ($func !== $function && !isset($attr['called']) && strpos($body, 'Dwoo_Plugin_'.$func) !== false) { $this->templatePlugins[$func]['called'] = true; $this->resolveSubTemplateDependencies($func); } } $this->templatePlugins[$function]['checked'] = true; }
php
protected function resolveSubTemplateDependencies($function) { $body = $this->templatePlugins[$function]['body']; foreach ($this->templatePlugins as $func => $attr) { if ($func !== $function && !isset($attr['called']) && strpos($body, 'Dwoo_Plugin_'.$func) !== false) { $this->templatePlugins[$func]['called'] = true; $this->resolveSubTemplateDependencies($func); } } $this->templatePlugins[$function]['checked'] = true; }
[ "protected", "function", "resolveSubTemplateDependencies", "(", "$", "function", ")", "{", "$", "body", "=", "$", "this", "->", "templatePlugins", "[", "$", "function", "]", "[", "'body'", "]", ";", "foreach", "(", "$", "this", "->", "templatePlugins", "as", "$", "func", "=>", "$", "attr", ")", "{", "if", "(", "$", "func", "!==", "$", "function", "&&", "!", "isset", "(", "$", "attr", "[", "'called'", "]", ")", "&&", "strpos", "(", "$", "body", ",", "'Dwoo_Plugin_'", ".", "$", "func", ")", "!==", "false", ")", "{", "$", "this", "->", "templatePlugins", "[", "$", "func", "]", "[", "'called'", "]", "=", "true", ";", "$", "this", "->", "resolveSubTemplateDependencies", "(", "$", "func", ")", ";", "}", "}", "$", "this", "->", "templatePlugins", "[", "$", "function", "]", "[", "'checked'", "]", "=", "true", ";", "}" ]
checks what sub-templates are used in every sub-template so that we're sure they are all compiled @param string $function the sub-template name
[ "checks", "what", "sub", "-", "templates", "are", "used", "in", "every", "sub", "-", "template", "so", "that", "we", "re", "sure", "they", "are", "all", "compiled" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php#L916-L926
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php
Dwoo_Compiler.setScope
public function setScope($scope, $absolute = false) { $old = $this->scopeTree; if ($scope===null) { unset($this->scope); $this->scope = null; } if (is_array($scope)===false) { $scope = explode('.', $scope); } if ($absolute===true) { $this->scope =& $this->data; $this->scopeTree = array(); } while (($bit = array_shift($scope)) !== null) { if ($bit === '_parent' || $bit === '_') { array_pop($this->scopeTree); reset($this->scopeTree); $this->scope =& $this->data; $cnt = count($this->scopeTree); for ($i=0;$i<$cnt;$i++) $this->scope =& $this->scope[$this->scopeTree[$i]]; } elseif ($bit === '_root' || $bit === '__') { $this->scope =& $this->data; $this->scopeTree = array(); } elseif (isset($this->scope[$bit])) { $this->scope =& $this->scope[$bit]; $this->scopeTree[] = $bit; } else { $this->scope[$bit] = array(); $this->scope =& $this->scope[$bit]; $this->scopeTree[] = $bit; } } return $old; }
php
public function setScope($scope, $absolute = false) { $old = $this->scopeTree; if ($scope===null) { unset($this->scope); $this->scope = null; } if (is_array($scope)===false) { $scope = explode('.', $scope); } if ($absolute===true) { $this->scope =& $this->data; $this->scopeTree = array(); } while (($bit = array_shift($scope)) !== null) { if ($bit === '_parent' || $bit === '_') { array_pop($this->scopeTree); reset($this->scopeTree); $this->scope =& $this->data; $cnt = count($this->scopeTree); for ($i=0;$i<$cnt;$i++) $this->scope =& $this->scope[$this->scopeTree[$i]]; } elseif ($bit === '_root' || $bit === '__') { $this->scope =& $this->data; $this->scopeTree = array(); } elseif (isset($this->scope[$bit])) { $this->scope =& $this->scope[$bit]; $this->scopeTree[] = $bit; } else { $this->scope[$bit] = array(); $this->scope =& $this->scope[$bit]; $this->scopeTree[] = $bit; } } return $old; }
[ "public", "function", "setScope", "(", "$", "scope", ",", "$", "absolute", "=", "false", ")", "{", "$", "old", "=", "$", "this", "->", "scopeTree", ";", "if", "(", "$", "scope", "===", "null", ")", "{", "unset", "(", "$", "this", "->", "scope", ")", ";", "$", "this", "->", "scope", "=", "null", ";", "}", "if", "(", "is_array", "(", "$", "scope", ")", "===", "false", ")", "{", "$", "scope", "=", "explode", "(", "'.'", ",", "$", "scope", ")", ";", "}", "if", "(", "$", "absolute", "===", "true", ")", "{", "$", "this", "->", "scope", "=", "&", "$", "this", "->", "data", ";", "$", "this", "->", "scopeTree", "=", "array", "(", ")", ";", "}", "while", "(", "(", "$", "bit", "=", "array_shift", "(", "$", "scope", ")", ")", "!==", "null", ")", "{", "if", "(", "$", "bit", "===", "'_parent'", "||", "$", "bit", "===", "'_'", ")", "{", "array_pop", "(", "$", "this", "->", "scopeTree", ")", ";", "reset", "(", "$", "this", "->", "scopeTree", ")", ";", "$", "this", "->", "scope", "=", "&", "$", "this", "->", "data", ";", "$", "cnt", "=", "count", "(", "$", "this", "->", "scopeTree", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "cnt", ";", "$", "i", "++", ")", "$", "this", "->", "scope", "=", "&", "$", "this", "->", "scope", "[", "$", "this", "->", "scopeTree", "[", "$", "i", "]", "]", ";", "}", "elseif", "(", "$", "bit", "===", "'_root'", "||", "$", "bit", "===", "'__'", ")", "{", "$", "this", "->", "scope", "=", "&", "$", "this", "->", "data", ";", "$", "this", "->", "scopeTree", "=", "array", "(", ")", ";", "}", "elseif", "(", "isset", "(", "$", "this", "->", "scope", "[", "$", "bit", "]", ")", ")", "{", "$", "this", "->", "scope", "=", "&", "$", "this", "->", "scope", "[", "$", "bit", "]", ";", "$", "this", "->", "scopeTree", "[", "]", "=", "$", "bit", ";", "}", "else", "{", "$", "this", "->", "scope", "[", "$", "bit", "]", "=", "array", "(", ")", ";", "$", "this", "->", "scope", "=", "&", "$", "this", "->", "scope", "[", "$", "bit", "]", ";", "$", "this", "->", "scopeTree", "[", "]", "=", "$", "bit", ";", "}", "}", "return", "$", "old", ";", "}" ]
sets the scope set to null if the scope becomes "unstable" (i.e. too variable or unknown) so that variables are compiled in a more evaluative way than just $this->scope['key'] @param mixed $scope a string i.e. "level1.level2" or an array i.e. array("level1", "level2") @param bool $absolute if true, the scope is set from the top level scope and not from the current scope @return array the current scope tree
[ "sets", "the", "scope" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php#L964-L1004
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php
Dwoo_Compiler.addBlock
public function addBlock($type, array $params, $paramtype) { $class = 'Dwoo_Plugin_'.$type; if (class_exists($class, false) === false) { $this->dwoo->getLoader()->loadPlugin($type); } $params = $this->mapParams($params, array($class, 'init'), $paramtype); $this->stack[] = array('type' => $type, 'params' => $params, 'custom' => false, 'class' => $class, 'buffer' => null); $this->curBlock =& $this->stack[count($this->stack)-1]; return call_user_func(array($class,'preProcessing'), $this, $params, '', '', $type); }
php
public function addBlock($type, array $params, $paramtype) { $class = 'Dwoo_Plugin_'.$type; if (class_exists($class, false) === false) { $this->dwoo->getLoader()->loadPlugin($type); } $params = $this->mapParams($params, array($class, 'init'), $paramtype); $this->stack[] = array('type' => $type, 'params' => $params, 'custom' => false, 'class' => $class, 'buffer' => null); $this->curBlock =& $this->stack[count($this->stack)-1]; return call_user_func(array($class,'preProcessing'), $this, $params, '', '', $type); }
[ "public", "function", "addBlock", "(", "$", "type", ",", "array", "$", "params", ",", "$", "paramtype", ")", "{", "$", "class", "=", "'Dwoo_Plugin_'", ".", "$", "type", ";", "if", "(", "class_exists", "(", "$", "class", ",", "false", ")", "===", "false", ")", "{", "$", "this", "->", "dwoo", "->", "getLoader", "(", ")", "->", "loadPlugin", "(", "$", "type", ")", ";", "}", "$", "params", "=", "$", "this", "->", "mapParams", "(", "$", "params", ",", "array", "(", "$", "class", ",", "'init'", ")", ",", "$", "paramtype", ")", ";", "$", "this", "->", "stack", "[", "]", "=", "array", "(", "'type'", "=>", "$", "type", ",", "'params'", "=>", "$", "params", ",", "'custom'", "=>", "false", ",", "'class'", "=>", "$", "class", ",", "'buffer'", "=>", "null", ")", ";", "$", "this", "->", "curBlock", "=", "&", "$", "this", "->", "stack", "[", "count", "(", "$", "this", "->", "stack", ")", "-", "1", "]", ";", "return", "call_user_func", "(", "array", "(", "$", "class", ",", "'preProcessing'", ")", ",", "$", "this", ",", "$", "params", ",", "''", ",", "''", ",", "$", "type", ")", ";", "}" ]
adds a block to the top of the block stack @param string $type block type (name) @param array $params the parameters array @param int $paramtype the parameters type (see mapParams), 0, 1 or 2 @return string the preProcessing() method's output
[ "adds", "a", "block", "to", "the", "top", "of", "the", "block", "stack" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php#L1014-L1026
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php
Dwoo_Compiler.injectBlock
public function injectBlock($type, array $params) { $class = 'Dwoo_Plugin_'.$type; if (class_exists($class, false) === false) { $this->dwoo->getLoader()->loadPlugin($type); } $this->stack[] = array('type' => $type, 'params' => $params, 'custom' => false, 'class' => $class, 'buffer' => null); $this->curBlock =& $this->stack[count($this->stack)-1]; }
php
public function injectBlock($type, array $params) { $class = 'Dwoo_Plugin_'.$type; if (class_exists($class, false) === false) { $this->dwoo->getLoader()->loadPlugin($type); } $this->stack[] = array('type' => $type, 'params' => $params, 'custom' => false, 'class' => $class, 'buffer' => null); $this->curBlock =& $this->stack[count($this->stack)-1]; }
[ "public", "function", "injectBlock", "(", "$", "type", ",", "array", "$", "params", ")", "{", "$", "class", "=", "'Dwoo_Plugin_'", ".", "$", "type", ";", "if", "(", "class_exists", "(", "$", "class", ",", "false", ")", "===", "false", ")", "{", "$", "this", "->", "dwoo", "->", "getLoader", "(", ")", "->", "loadPlugin", "(", "$", "type", ")", ";", "}", "$", "this", "->", "stack", "[", "]", "=", "array", "(", "'type'", "=>", "$", "type", ",", "'params'", "=>", "$", "params", ",", "'custom'", "=>", "false", ",", "'class'", "=>", "$", "class", ",", "'buffer'", "=>", "null", ")", ";", "$", "this", "->", "curBlock", "=", "&", "$", "this", "->", "stack", "[", "count", "(", "$", "this", "->", "stack", ")", "-", "1", "]", ";", "}" ]
injects a block at the top of the plugin stack without calling its preProcessing method used by {else} blocks to re-add themselves after having closed everything up to their parent @param string $type block type (name) @param array $params parameters array
[ "injects", "a", "block", "at", "the", "top", "of", "the", "plugin", "stack", "without", "calling", "its", "preProcessing", "method" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php#L1060-L1068
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php
Dwoo_Compiler.removeBlock
public function removeBlock($type) { $output = ''; $pluginType = $this->getPluginType($type); if ($pluginType & Dwoo::SMARTY_BLOCK) { $type = 'smartyinterface'; } while (true) { while ($top = array_pop($this->stack)) { if ($top['custom']) { $class = $top['class']; } else { $class = 'Dwoo_Plugin_'.$top['type']; } if (count($this->stack)) { $this->curBlock =& $this->stack[count($this->stack)-1]; $this->push(call_user_func(array($class, 'postProcessing'), $this, $top['params'], '', '', $top['buffer']), 0); } else { $null = null; $this->curBlock =& $null; $output = call_user_func(array($class, 'postProcessing'), $this, $top['params'], '', '', $top['buffer']); } if ($top['type'] === $type) { break 2; } } throw new Dwoo_Compilation_Exception($this, 'Syntax malformation, a block of type "'.$type.'" was closed but was not opened'); break; } return $output; }
php
public function removeBlock($type) { $output = ''; $pluginType = $this->getPluginType($type); if ($pluginType & Dwoo::SMARTY_BLOCK) { $type = 'smartyinterface'; } while (true) { while ($top = array_pop($this->stack)) { if ($top['custom']) { $class = $top['class']; } else { $class = 'Dwoo_Plugin_'.$top['type']; } if (count($this->stack)) { $this->curBlock =& $this->stack[count($this->stack)-1]; $this->push(call_user_func(array($class, 'postProcessing'), $this, $top['params'], '', '', $top['buffer']), 0); } else { $null = null; $this->curBlock =& $null; $output = call_user_func(array($class, 'postProcessing'), $this, $top['params'], '', '', $top['buffer']); } if ($top['type'] === $type) { break 2; } } throw new Dwoo_Compilation_Exception($this, 'Syntax malformation, a block of type "'.$type.'" was closed but was not opened'); break; } return $output; }
[ "public", "function", "removeBlock", "(", "$", "type", ")", "{", "$", "output", "=", "''", ";", "$", "pluginType", "=", "$", "this", "->", "getPluginType", "(", "$", "type", ")", ";", "if", "(", "$", "pluginType", "&", "Dwoo", "::", "SMARTY_BLOCK", ")", "{", "$", "type", "=", "'smartyinterface'", ";", "}", "while", "(", "true", ")", "{", "while", "(", "$", "top", "=", "array_pop", "(", "$", "this", "->", "stack", ")", ")", "{", "if", "(", "$", "top", "[", "'custom'", "]", ")", "{", "$", "class", "=", "$", "top", "[", "'class'", "]", ";", "}", "else", "{", "$", "class", "=", "'Dwoo_Plugin_'", ".", "$", "top", "[", "'type'", "]", ";", "}", "if", "(", "count", "(", "$", "this", "->", "stack", ")", ")", "{", "$", "this", "->", "curBlock", "=", "&", "$", "this", "->", "stack", "[", "count", "(", "$", "this", "->", "stack", ")", "-", "1", "]", ";", "$", "this", "->", "push", "(", "call_user_func", "(", "array", "(", "$", "class", ",", "'postProcessing'", ")", ",", "$", "this", ",", "$", "top", "[", "'params'", "]", ",", "''", ",", "''", ",", "$", "top", "[", "'buffer'", "]", ")", ",", "0", ")", ";", "}", "else", "{", "$", "null", "=", "null", ";", "$", "this", "->", "curBlock", "=", "&", "$", "null", ";", "$", "output", "=", "call_user_func", "(", "array", "(", "$", "class", ",", "'postProcessing'", ")", ",", "$", "this", ",", "$", "top", "[", "'params'", "]", ",", "''", ",", "''", ",", "$", "top", "[", "'buffer'", "]", ")", ";", "}", "if", "(", "$", "top", "[", "'type'", "]", "===", "$", "type", ")", "{", "break", "2", ";", "}", "}", "throw", "new", "Dwoo_Compilation_Exception", "(", "$", "this", ",", "'Syntax malformation, a block of type \"'", ".", "$", "type", ".", "'\" was closed but was not opened'", ")", ";", "break", ";", "}", "return", "$", "output", ";", "}" ]
removes the closest-to-top block of the given type and all other blocks encountered while going down the block stack @param string $type block type (name) @return string the output of all postProcessing() method's return values of the closed blocks
[ "removes", "the", "closest", "-", "to", "-", "top", "block", "of", "the", "given", "type", "and", "all", "other", "blocks", "encountered", "while", "going", "down", "the", "block", "stack" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php#L1077-L1111
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php
Dwoo_Compiler.&
public function &findBlock($type, $closeAlong = false) { if ($closeAlong===true) { while ($b = end($this->stack)) { if ($b['type']===$type) { return $this->stack[key($this->stack)]; } $this->push($this->removeTopBlock(), 0); } } else { end($this->stack); while ($b = current($this->stack)) { if ($b['type']===$type) { return $this->stack[key($this->stack)]; } prev($this->stack); } } throw new Dwoo_Compilation_Exception($this, 'A parent block of type "'.$type.'" is required and can not be found'); }
php
public function &findBlock($type, $closeAlong = false) { if ($closeAlong===true) { while ($b = end($this->stack)) { if ($b['type']===$type) { return $this->stack[key($this->stack)]; } $this->push($this->removeTopBlock(), 0); } } else { end($this->stack); while ($b = current($this->stack)) { if ($b['type']===$type) { return $this->stack[key($this->stack)]; } prev($this->stack); } } throw new Dwoo_Compilation_Exception($this, 'A parent block of type "'.$type.'" is required and can not be found'); }
[ "public", "function", "&", "findBlock", "(", "$", "type", ",", "$", "closeAlong", "=", "false", ")", "{", "if", "(", "$", "closeAlong", "===", "true", ")", "{", "while", "(", "$", "b", "=", "end", "(", "$", "this", "->", "stack", ")", ")", "{", "if", "(", "$", "b", "[", "'type'", "]", "===", "$", "type", ")", "{", "return", "$", "this", "->", "stack", "[", "key", "(", "$", "this", "->", "stack", ")", "]", ";", "}", "$", "this", "->", "push", "(", "$", "this", "->", "removeTopBlock", "(", ")", ",", "0", ")", ";", "}", "}", "else", "{", "end", "(", "$", "this", "->", "stack", ")", ";", "while", "(", "$", "b", "=", "current", "(", "$", "this", "->", "stack", ")", ")", "{", "if", "(", "$", "b", "[", "'type'", "]", "===", "$", "type", ")", "{", "return", "$", "this", "->", "stack", "[", "key", "(", "$", "this", "->", "stack", ")", "]", ";", "}", "prev", "(", "$", "this", "->", "stack", ")", ";", "}", "}", "throw", "new", "Dwoo_Compilation_Exception", "(", "$", "this", ",", "'A parent block of type \"'", ".", "$", "type", ".", "'\" is required and can not be found'", ")", ";", "}" ]
returns a reference to the first block of the given type encountered and optionally closes all blocks until it finds it this is mainly used by {else} plugins to close everything that was opened between their parent and themselves @param string $type the block type (name) @param bool $closeAlong whether to close all blocks encountered while going down the block stack or not @return &array the array is as such: array('type'=>pluginName, 'params'=>parameter array, 'custom'=>bool defining whether it's a custom plugin or not, for internal use)
[ "returns", "a", "reference", "to", "the", "first", "block", "of", "the", "given", "type", "encountered", "and", "optionally", "closes", "all", "blocks", "until", "it", "finds", "it" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php#L1125-L1145
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php
Dwoo_Compiler.removeTopBlock
public function removeTopBlock() { $o = array_pop($this->stack); if ($o === null) { throw new Dwoo_Compilation_Exception($this, 'Syntax malformation, a block of unknown type was closed but was not opened.'); } if ($o['custom']) { $class = $o['class']; } else { $class = 'Dwoo_Plugin_'.$o['type']; } $this->curBlock =& $this->stack[count($this->stack)-1]; return call_user_func(array($class, 'postProcessing'), $this, $o['params'], '', '', $o['buffer']); }
php
public function removeTopBlock() { $o = array_pop($this->stack); if ($o === null) { throw new Dwoo_Compilation_Exception($this, 'Syntax malformation, a block of unknown type was closed but was not opened.'); } if ($o['custom']) { $class = $o['class']; } else { $class = 'Dwoo_Plugin_'.$o['type']; } $this->curBlock =& $this->stack[count($this->stack)-1]; return call_user_func(array($class, 'postProcessing'), $this, $o['params'], '', '', $o['buffer']); }
[ "public", "function", "removeTopBlock", "(", ")", "{", "$", "o", "=", "array_pop", "(", "$", "this", "->", "stack", ")", ";", "if", "(", "$", "o", "===", "null", ")", "{", "throw", "new", "Dwoo_Compilation_Exception", "(", "$", "this", ",", "'Syntax malformation, a block of unknown type was closed but was not opened.'", ")", ";", "}", "if", "(", "$", "o", "[", "'custom'", "]", ")", "{", "$", "class", "=", "$", "o", "[", "'class'", "]", ";", "}", "else", "{", "$", "class", "=", "'Dwoo_Plugin_'", ".", "$", "o", "[", "'type'", "]", ";", "}", "$", "this", "->", "curBlock", "=", "&", "$", "this", "->", "stack", "[", "count", "(", "$", "this", "->", "stack", ")", "-", "1", "]", ";", "return", "call_user_func", "(", "array", "(", "$", "class", ",", "'postProcessing'", ")", ",", "$", "this", ",", "$", "o", "[", "'params'", "]", ",", "''", ",", "''", ",", "$", "o", "[", "'buffer'", "]", ")", ";", "}" ]
removes the block at the top of the stack and calls its postProcessing() method @return string the postProcessing() method's output
[ "removes", "the", "block", "at", "the", "top", "of", "the", "stack", "and", "calls", "its", "postProcessing", "()", "method" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php#L1163-L1178
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php
Dwoo_Compiler.parseFunction
protected function parseFunction($in, $from, $to, $parsingParams = false, $curBlock='', &$pointer = null) { $cmdstr = substr($in, $from, $to-$from); preg_match('/^([a-z][a-z0-9_]*(?:::[a-z][a-z0-9_]*)?)(\s*'.$this->rdr.'|\s*;)?/i', $cmdstr, $match); if (empty($match[1])) { throw new Dwoo_Compilation_Exception($this, 'Parse error, invalid function name : '.substr($cmdstr, 0, 15)); } $func = $match[1]; if (!empty($match[2])) { $cmdstr = $match[1]; } if ($this->debug) echo 'FUNC FOUND ('.$func.')<br />'; $paramsep = ''; if (is_array($parsingParams) || $curBlock != 'root') { $paramspos = strpos($cmdstr, '('); $paramsep = ')'; } elseif(preg_match_all('#[a-z0-9_]+(\s*\(|\s+[^(])#i', $cmdstr, $match, PREG_OFFSET_CAPTURE)) { $paramspos = $match[1][0][1]; $paramsep = substr($match[1][0][0], -1) === '(' ? ')':''; if($paramsep === ')') { $paramspos += strlen($match[1][0][0]) - 1; if(substr($cmdstr, 0, 2) === 'if' || substr($cmdstr, 0, 6) === 'elseif') { $paramsep = ''; if(strlen($match[1][0][0]) > 1) { $paramspos--; } } } } else { $paramspos = false; } $state = 0; if ($paramspos === false) { $params = array(); if ($curBlock !== 'root') { return $this->parseOthers($in, $from, $to, $parsingParams, $curBlock, $pointer); } } else { if ($curBlock === 'condition') { // load if plugin $this->getPluginType('if'); if (Dwoo_Plugin_if::replaceKeywords(array($func), $this) !== array($func)) { return $this->parseOthers($in, $from, $to, $parsingParams, $curBlock, $pointer); } } $whitespace = strlen(substr($cmdstr, strlen($func), $paramspos-strlen($func))); $paramstr = substr($cmdstr, $paramspos+1); if (substr($paramstr, -1, 1) === $paramsep) { $paramstr = substr($paramstr, 0, -1); } if (strlen($paramstr)===0) { $params = array(); $paramstr = ''; } else { $ptr = 0; $params = array(); if ($func === 'empty') { $params = $this->parseVar($paramstr, $ptr, strlen($paramstr), $params, 'root', $ptr); } else { while ($ptr < strlen($paramstr)) { while (true) { if ($ptr >= strlen($paramstr)) { break 2; } if ($func !== 'if' && $func !== 'elseif' && $paramstr[$ptr] === ')') { if ($this->debug) echo 'PARAM PARSING ENDED, ")" FOUND, POINTER AT '.$ptr.'<br/>'; break 2; } elseif ($paramstr[$ptr] === ';') { $ptr++; if ($this->debug) echo 'PARAM PARSING ENDED, ";" FOUND, POINTER AT '.$ptr.'<br/>'; break 2; } elseif ($func !== 'if' && $func !== 'elseif' && $paramstr[$ptr] === '/') { if ($this->debug) echo 'PARAM PARSING ENDED, "/" FOUND, POINTER AT '.$ptr.'<br/>'; break 2; } elseif (substr($paramstr, $ptr, strlen($this->rd)) === $this->rd) { if ($this->debug) echo 'PARAM PARSING ENDED, RIGHT DELIMITER FOUND, POINTER AT '.$ptr.'<br/>'; break 2; } if ($paramstr[$ptr] === ' ' || $paramstr[$ptr] === ',' || $paramstr[$ptr] === "\r" || $paramstr[$ptr] === "\n" || $paramstr[$ptr] === "\t") { $ptr++; } else { break; } } if ($this->debug) echo 'FUNC START PARAM PARSING WITH POINTER AT '.$ptr.'<br/>'; if ($func === 'if' || $func === 'elseif' || $func === 'tif') { $params = $this->parse($paramstr, $ptr, strlen($paramstr), $params, 'condition', $ptr); } else { $params = $this->parse($paramstr, $ptr, strlen($paramstr), $params, 'function', $ptr); } if ($this->debug) echo 'PARAM PARSED, POINTER AT '.$ptr.' ('.substr($paramstr, $ptr-1, 3).')<br/>'; } } $paramstr = substr($paramstr, 0, $ptr); $state = 0; foreach ($params as $k=>$p) { if (is_array($p) && is_array($p[1])) { $state |= 2; } else { if (($state & 2) && preg_match('#^(["\'])(.+?)\1$#', $p[0], $m)) { $params[$k] = array($m[2], array('true', 'true')); } else { if ($state & 2) { throw new Dwoo_Compilation_Exception($this, 'You can not use an unnamed parameter after a named one'); } $state |= 1; } } } } } if ($pointer !== null) { $pointer += (isset($paramstr) ? strlen($paramstr) : 0) + (')' === $paramsep ? 2 : ($paramspos === false ? 0 : 1)) + strlen($func) + (isset($whitespace) ? $whitespace : 0); if ($this->debug) echo 'FUNC ADDS '.((isset($paramstr) ? strlen($paramstr) : 0) + (')' === $paramsep ? 2 : ($paramspos === false ? 0 : 1)) + strlen($func)).' TO POINTER<br/>'; } if ($curBlock === 'method' || $func === 'do' || strstr($func, '::') !== false) { $pluginType = Dwoo::NATIVE_PLUGIN; } else { $pluginType = $this->getPluginType($func); } // blocks if ($pluginType & Dwoo::BLOCK_PLUGIN) { if ($curBlock !== 'root' || is_array($parsingParams)) { throw new Dwoo_Compilation_Exception($this, 'Block plugins can not be used as other plugin\'s arguments'); } if ($pluginType & Dwoo::CUSTOM_PLUGIN) { return $this->addCustomBlock($func, $params, $state); } else { return $this->addBlock($func, $params, $state); } } elseif ($pluginType & Dwoo::SMARTY_BLOCK) { if ($curBlock !== 'root' || is_array($parsingParams)) { throw new Dwoo_Compilation_Exception($this, 'Block plugins can not be used as other plugin\'s arguments'); } if ($state & 2) { array_unshift($params, array('__functype', array($pluginType, $pluginType))); array_unshift($params, array('__funcname', array($func, $func))); } else { array_unshift($params, array($pluginType, $pluginType)); array_unshift($params, array($func, $func)); } return $this->addBlock('smartyinterface', $params, $state); } // funcs if ($pluginType & Dwoo::NATIVE_PLUGIN || $pluginType & Dwoo::SMARTY_FUNCTION || $pluginType & Dwoo::SMARTY_BLOCK) { $params = $this->mapParams($params, null, $state); } elseif ($pluginType & Dwoo::CLASS_PLUGIN) { if ($pluginType & Dwoo::CUSTOM_PLUGIN) { $params = $this->mapParams($params, array($this->customPlugins[$func]['class'], $this->customPlugins[$func]['function']), $state); } else { $params = $this->mapParams($params, array('Dwoo_Plugin_'.$func, ($pluginType & Dwoo::COMPILABLE_PLUGIN) ? 'compile' : 'process'), $state); } } elseif ($pluginType & Dwoo::FUNC_PLUGIN) { if ($pluginType & Dwoo::CUSTOM_PLUGIN) { $params = $this->mapParams($params, $this->customPlugins[$func]['callback'], $state); } else { $params = $this->mapParams($params, 'Dwoo_Plugin_'.$func.(($pluginType & Dwoo::COMPILABLE_PLUGIN) ? '_compile' : ''), $state); } } elseif ($pluginType & Dwoo::SMARTY_MODIFIER) { $output = 'smarty_modifier_'.$func.'('.implode(', ', $params).')'; } elseif ($pluginType & Dwoo::PROXY_PLUGIN) { $params = $this->mapParams($params, $this->getDwoo()->getPluginProxy()->getCallback($func), $state); } elseif ($pluginType & Dwoo::TEMPLATE_PLUGIN) { // transforms the parameter array from (x=>array('paramname'=>array(values))) to (paramname=>array(values)) $map = array(); foreach ($this->templatePlugins[$func]['params'] as $param=>$defValue) { if ($param == 'rest') { $param = '*'; } $hasDefault = $defValue !== null; if ($defValue === 'null') { $defValue = null; } elseif ($defValue === 'false') { $defValue = false; } elseif ($defValue === 'true') { $defValue = true; } elseif (preg_match('#^([\'"]).*?\1$#', $defValue)) { $defValue = substr($defValue, 1, -1); } $map[] = array($param, $hasDefault, $defValue); } $params = $this->mapParams($params, null, $state, $map); } // only keep php-syntax-safe values for non-block plugins foreach ($params as &$p) { $p = $p[0]; } if ($pluginType & Dwoo::NATIVE_PLUGIN) { if ($func === 'do') { if (isset($params['*'])) { $output = implode(';', $params['*']).';'; } else { $output = ''; } if (is_array($parsingParams) || $curBlock !== 'root') { throw new Dwoo_Compilation_Exception($this, 'Do can not be used inside another function or block'); } else { return self::PHP_OPEN.$output.self::PHP_CLOSE; } } else { if (isset($params['*'])) { $output = $func.'('.implode(', ', $params['*']).')'; } else { $output = $func.'()'; } } } elseif ($pluginType & Dwoo::FUNC_PLUGIN) { if ($pluginType & Dwoo::COMPILABLE_PLUGIN) { if ($pluginType & Dwoo::CUSTOM_PLUGIN) { $funcCompiler = $this->customPlugins[$func]['callback']; } else { $funcCompiler = 'Dwoo_Plugin_'.$func.'_compile'; } array_unshift($params, $this); $output = call_user_func_array($funcCompiler, $params); } else { array_unshift($params, '$this'); $params = self::implode_r($params); if ($pluginType & Dwoo::CUSTOM_PLUGIN) { $callback = $this->customPlugins[$func]['callback']; $output = 'call_user_func(\''.$callback.'\', '.$params.')'; } else { $output = 'Dwoo_Plugin_'.$func.'('.$params.')'; } } } elseif ($pluginType & Dwoo::CLASS_PLUGIN) { if ($pluginType & Dwoo::COMPILABLE_PLUGIN) { if ($pluginType & Dwoo::CUSTOM_PLUGIN) { $callback = $this->customPlugins[$func]['callback']; if (!is_array($callback)) { if (!method_exists($callback, 'compile')) { throw new Dwoo_Exception('Custom plugin '.$func.' must implement the "compile" method to be compilable, or you should provide a full callback to the method to use'); } if (($ref = new ReflectionMethod($callback, 'compile')) && $ref->isStatic()) { $funcCompiler = array($callback, 'compile'); } else { $funcCompiler = array(new $callback, 'compile'); } } else { $funcCompiler = $callback; } } else { $funcCompiler = array('Dwoo_Plugin_'.$func, 'compile'); array_unshift($params, $this); } $output = call_user_func_array($funcCompiler, $params); } else { $params = self::implode_r($params); if ($pluginType & Dwoo::CUSTOM_PLUGIN) { $callback = $this->customPlugins[$func]['callback']; if (!is_array($callback)) { if (!method_exists($callback, 'process')) { throw new Dwoo_Exception('Custom plugin '.$func.' must implement the "process" method to be usable, or you should provide a full callback to the method to use'); } if (($ref = new ReflectionMethod($callback, 'process')) && $ref->isStatic()) { $output = 'call_user_func(array(\''.$callback.'\', \'process\'), '.$params.')'; } else { $output = 'call_user_func(array($this->getObjectPlugin(\''.$callback.'\'), \'process\'), '.$params.')'; } } elseif (is_object($callback[0])) { $output = 'call_user_func(array($this->plugins[\''.$func.'\'][\'callback\'][0], \''.$callback[1].'\'), '.$params.')'; } elseif (($ref = new ReflectionMethod($callback[0], $callback[1])) && $ref->isStatic()) { $output = 'call_user_func(array(\''.$callback[0].'\', \''.$callback[1].'\'), '.$params.')'; } else { $output = 'call_user_func(array($this->getObjectPlugin(\''.$callback[0].'\'), \''.$callback[1].'\'), '.$params.')'; } if (empty($params)) { $output = substr($output, 0, -3).')'; } } else { $output = '$this->classCall(\''.$func.'\', array('.$params.'))'; } } } elseif ($pluginType & Dwoo::PROXY_PLUGIN) { $output = call_user_func(array($this->dwoo->getPluginProxy(), 'getCode'), $func, $params); } elseif ($pluginType & Dwoo::SMARTY_FUNCTION) { if (isset($params['*'])) { $params = self::implode_r($params['*'], true); } else { $params = ''; } if ($pluginType & Dwoo::CUSTOM_PLUGIN) { $callback = $this->customPlugins[$func]['callback']; if (is_array($callback)) { if (is_object($callback[0])) { $output = 'call_user_func_array(array($this->plugins[\''.$func.'\'][\'callback\'][0], \''.$callback[1].'\'), array(array('.$params.'), $this))'; } else { $output = 'call_user_func_array(array(\''.$callback[0].'\', \''.$callback[1].'\'), array(array('.$params.'), $this))'; } } else { $output = $callback.'(array('.$params.'), $this)'; } } else { $output = 'smarty_function_'.$func.'(array('.$params.'), $this)'; } } elseif ($pluginType & Dwoo::TEMPLATE_PLUGIN) { array_unshift($params, '$this'); $params = self::implode_r($params); $output = 'Dwoo_Plugin_'.$func.'_'.$this->templatePlugins[$func]['uuid'].'('.$params.')'; $this->templatePlugins[$func]['called'] = true; } if (is_array($parsingParams)) { $parsingParams[] = array($output, $output); return $parsingParams; } elseif ($curBlock === 'namedparam') { return array($output, $output); } else { return $output; } }
php
protected function parseFunction($in, $from, $to, $parsingParams = false, $curBlock='', &$pointer = null) { $cmdstr = substr($in, $from, $to-$from); preg_match('/^([a-z][a-z0-9_]*(?:::[a-z][a-z0-9_]*)?)(\s*'.$this->rdr.'|\s*;)?/i', $cmdstr, $match); if (empty($match[1])) { throw new Dwoo_Compilation_Exception($this, 'Parse error, invalid function name : '.substr($cmdstr, 0, 15)); } $func = $match[1]; if (!empty($match[2])) { $cmdstr = $match[1]; } if ($this->debug) echo 'FUNC FOUND ('.$func.')<br />'; $paramsep = ''; if (is_array($parsingParams) || $curBlock != 'root') { $paramspos = strpos($cmdstr, '('); $paramsep = ')'; } elseif(preg_match_all('#[a-z0-9_]+(\s*\(|\s+[^(])#i', $cmdstr, $match, PREG_OFFSET_CAPTURE)) { $paramspos = $match[1][0][1]; $paramsep = substr($match[1][0][0], -1) === '(' ? ')':''; if($paramsep === ')') { $paramspos += strlen($match[1][0][0]) - 1; if(substr($cmdstr, 0, 2) === 'if' || substr($cmdstr, 0, 6) === 'elseif') { $paramsep = ''; if(strlen($match[1][0][0]) > 1) { $paramspos--; } } } } else { $paramspos = false; } $state = 0; if ($paramspos === false) { $params = array(); if ($curBlock !== 'root') { return $this->parseOthers($in, $from, $to, $parsingParams, $curBlock, $pointer); } } else { if ($curBlock === 'condition') { // load if plugin $this->getPluginType('if'); if (Dwoo_Plugin_if::replaceKeywords(array($func), $this) !== array($func)) { return $this->parseOthers($in, $from, $to, $parsingParams, $curBlock, $pointer); } } $whitespace = strlen(substr($cmdstr, strlen($func), $paramspos-strlen($func))); $paramstr = substr($cmdstr, $paramspos+1); if (substr($paramstr, -1, 1) === $paramsep) { $paramstr = substr($paramstr, 0, -1); } if (strlen($paramstr)===0) { $params = array(); $paramstr = ''; } else { $ptr = 0; $params = array(); if ($func === 'empty') { $params = $this->parseVar($paramstr, $ptr, strlen($paramstr), $params, 'root', $ptr); } else { while ($ptr < strlen($paramstr)) { while (true) { if ($ptr >= strlen($paramstr)) { break 2; } if ($func !== 'if' && $func !== 'elseif' && $paramstr[$ptr] === ')') { if ($this->debug) echo 'PARAM PARSING ENDED, ")" FOUND, POINTER AT '.$ptr.'<br/>'; break 2; } elseif ($paramstr[$ptr] === ';') { $ptr++; if ($this->debug) echo 'PARAM PARSING ENDED, ";" FOUND, POINTER AT '.$ptr.'<br/>'; break 2; } elseif ($func !== 'if' && $func !== 'elseif' && $paramstr[$ptr] === '/') { if ($this->debug) echo 'PARAM PARSING ENDED, "/" FOUND, POINTER AT '.$ptr.'<br/>'; break 2; } elseif (substr($paramstr, $ptr, strlen($this->rd)) === $this->rd) { if ($this->debug) echo 'PARAM PARSING ENDED, RIGHT DELIMITER FOUND, POINTER AT '.$ptr.'<br/>'; break 2; } if ($paramstr[$ptr] === ' ' || $paramstr[$ptr] === ',' || $paramstr[$ptr] === "\r" || $paramstr[$ptr] === "\n" || $paramstr[$ptr] === "\t") { $ptr++; } else { break; } } if ($this->debug) echo 'FUNC START PARAM PARSING WITH POINTER AT '.$ptr.'<br/>'; if ($func === 'if' || $func === 'elseif' || $func === 'tif') { $params = $this->parse($paramstr, $ptr, strlen($paramstr), $params, 'condition', $ptr); } else { $params = $this->parse($paramstr, $ptr, strlen($paramstr), $params, 'function', $ptr); } if ($this->debug) echo 'PARAM PARSED, POINTER AT '.$ptr.' ('.substr($paramstr, $ptr-1, 3).')<br/>'; } } $paramstr = substr($paramstr, 0, $ptr); $state = 0; foreach ($params as $k=>$p) { if (is_array($p) && is_array($p[1])) { $state |= 2; } else { if (($state & 2) && preg_match('#^(["\'])(.+?)\1$#', $p[0], $m)) { $params[$k] = array($m[2], array('true', 'true')); } else { if ($state & 2) { throw new Dwoo_Compilation_Exception($this, 'You can not use an unnamed parameter after a named one'); } $state |= 1; } } } } } if ($pointer !== null) { $pointer += (isset($paramstr) ? strlen($paramstr) : 0) + (')' === $paramsep ? 2 : ($paramspos === false ? 0 : 1)) + strlen($func) + (isset($whitespace) ? $whitespace : 0); if ($this->debug) echo 'FUNC ADDS '.((isset($paramstr) ? strlen($paramstr) : 0) + (')' === $paramsep ? 2 : ($paramspos === false ? 0 : 1)) + strlen($func)).' TO POINTER<br/>'; } if ($curBlock === 'method' || $func === 'do' || strstr($func, '::') !== false) { $pluginType = Dwoo::NATIVE_PLUGIN; } else { $pluginType = $this->getPluginType($func); } // blocks if ($pluginType & Dwoo::BLOCK_PLUGIN) { if ($curBlock !== 'root' || is_array($parsingParams)) { throw new Dwoo_Compilation_Exception($this, 'Block plugins can not be used as other plugin\'s arguments'); } if ($pluginType & Dwoo::CUSTOM_PLUGIN) { return $this->addCustomBlock($func, $params, $state); } else { return $this->addBlock($func, $params, $state); } } elseif ($pluginType & Dwoo::SMARTY_BLOCK) { if ($curBlock !== 'root' || is_array($parsingParams)) { throw new Dwoo_Compilation_Exception($this, 'Block plugins can not be used as other plugin\'s arguments'); } if ($state & 2) { array_unshift($params, array('__functype', array($pluginType, $pluginType))); array_unshift($params, array('__funcname', array($func, $func))); } else { array_unshift($params, array($pluginType, $pluginType)); array_unshift($params, array($func, $func)); } return $this->addBlock('smartyinterface', $params, $state); } // funcs if ($pluginType & Dwoo::NATIVE_PLUGIN || $pluginType & Dwoo::SMARTY_FUNCTION || $pluginType & Dwoo::SMARTY_BLOCK) { $params = $this->mapParams($params, null, $state); } elseif ($pluginType & Dwoo::CLASS_PLUGIN) { if ($pluginType & Dwoo::CUSTOM_PLUGIN) { $params = $this->mapParams($params, array($this->customPlugins[$func]['class'], $this->customPlugins[$func]['function']), $state); } else { $params = $this->mapParams($params, array('Dwoo_Plugin_'.$func, ($pluginType & Dwoo::COMPILABLE_PLUGIN) ? 'compile' : 'process'), $state); } } elseif ($pluginType & Dwoo::FUNC_PLUGIN) { if ($pluginType & Dwoo::CUSTOM_PLUGIN) { $params = $this->mapParams($params, $this->customPlugins[$func]['callback'], $state); } else { $params = $this->mapParams($params, 'Dwoo_Plugin_'.$func.(($pluginType & Dwoo::COMPILABLE_PLUGIN) ? '_compile' : ''), $state); } } elseif ($pluginType & Dwoo::SMARTY_MODIFIER) { $output = 'smarty_modifier_'.$func.'('.implode(', ', $params).')'; } elseif ($pluginType & Dwoo::PROXY_PLUGIN) { $params = $this->mapParams($params, $this->getDwoo()->getPluginProxy()->getCallback($func), $state); } elseif ($pluginType & Dwoo::TEMPLATE_PLUGIN) { // transforms the parameter array from (x=>array('paramname'=>array(values))) to (paramname=>array(values)) $map = array(); foreach ($this->templatePlugins[$func]['params'] as $param=>$defValue) { if ($param == 'rest') { $param = '*'; } $hasDefault = $defValue !== null; if ($defValue === 'null') { $defValue = null; } elseif ($defValue === 'false') { $defValue = false; } elseif ($defValue === 'true') { $defValue = true; } elseif (preg_match('#^([\'"]).*?\1$#', $defValue)) { $defValue = substr($defValue, 1, -1); } $map[] = array($param, $hasDefault, $defValue); } $params = $this->mapParams($params, null, $state, $map); } // only keep php-syntax-safe values for non-block plugins foreach ($params as &$p) { $p = $p[0]; } if ($pluginType & Dwoo::NATIVE_PLUGIN) { if ($func === 'do') { if (isset($params['*'])) { $output = implode(';', $params['*']).';'; } else { $output = ''; } if (is_array($parsingParams) || $curBlock !== 'root') { throw new Dwoo_Compilation_Exception($this, 'Do can not be used inside another function or block'); } else { return self::PHP_OPEN.$output.self::PHP_CLOSE; } } else { if (isset($params['*'])) { $output = $func.'('.implode(', ', $params['*']).')'; } else { $output = $func.'()'; } } } elseif ($pluginType & Dwoo::FUNC_PLUGIN) { if ($pluginType & Dwoo::COMPILABLE_PLUGIN) { if ($pluginType & Dwoo::CUSTOM_PLUGIN) { $funcCompiler = $this->customPlugins[$func]['callback']; } else { $funcCompiler = 'Dwoo_Plugin_'.$func.'_compile'; } array_unshift($params, $this); $output = call_user_func_array($funcCompiler, $params); } else { array_unshift($params, '$this'); $params = self::implode_r($params); if ($pluginType & Dwoo::CUSTOM_PLUGIN) { $callback = $this->customPlugins[$func]['callback']; $output = 'call_user_func(\''.$callback.'\', '.$params.')'; } else { $output = 'Dwoo_Plugin_'.$func.'('.$params.')'; } } } elseif ($pluginType & Dwoo::CLASS_PLUGIN) { if ($pluginType & Dwoo::COMPILABLE_PLUGIN) { if ($pluginType & Dwoo::CUSTOM_PLUGIN) { $callback = $this->customPlugins[$func]['callback']; if (!is_array($callback)) { if (!method_exists($callback, 'compile')) { throw new Dwoo_Exception('Custom plugin '.$func.' must implement the "compile" method to be compilable, or you should provide a full callback to the method to use'); } if (($ref = new ReflectionMethod($callback, 'compile')) && $ref->isStatic()) { $funcCompiler = array($callback, 'compile'); } else { $funcCompiler = array(new $callback, 'compile'); } } else { $funcCompiler = $callback; } } else { $funcCompiler = array('Dwoo_Plugin_'.$func, 'compile'); array_unshift($params, $this); } $output = call_user_func_array($funcCompiler, $params); } else { $params = self::implode_r($params); if ($pluginType & Dwoo::CUSTOM_PLUGIN) { $callback = $this->customPlugins[$func]['callback']; if (!is_array($callback)) { if (!method_exists($callback, 'process')) { throw new Dwoo_Exception('Custom plugin '.$func.' must implement the "process" method to be usable, or you should provide a full callback to the method to use'); } if (($ref = new ReflectionMethod($callback, 'process')) && $ref->isStatic()) { $output = 'call_user_func(array(\''.$callback.'\', \'process\'), '.$params.')'; } else { $output = 'call_user_func(array($this->getObjectPlugin(\''.$callback.'\'), \'process\'), '.$params.')'; } } elseif (is_object($callback[0])) { $output = 'call_user_func(array($this->plugins[\''.$func.'\'][\'callback\'][0], \''.$callback[1].'\'), '.$params.')'; } elseif (($ref = new ReflectionMethod($callback[0], $callback[1])) && $ref->isStatic()) { $output = 'call_user_func(array(\''.$callback[0].'\', \''.$callback[1].'\'), '.$params.')'; } else { $output = 'call_user_func(array($this->getObjectPlugin(\''.$callback[0].'\'), \''.$callback[1].'\'), '.$params.')'; } if (empty($params)) { $output = substr($output, 0, -3).')'; } } else { $output = '$this->classCall(\''.$func.'\', array('.$params.'))'; } } } elseif ($pluginType & Dwoo::PROXY_PLUGIN) { $output = call_user_func(array($this->dwoo->getPluginProxy(), 'getCode'), $func, $params); } elseif ($pluginType & Dwoo::SMARTY_FUNCTION) { if (isset($params['*'])) { $params = self::implode_r($params['*'], true); } else { $params = ''; } if ($pluginType & Dwoo::CUSTOM_PLUGIN) { $callback = $this->customPlugins[$func]['callback']; if (is_array($callback)) { if (is_object($callback[0])) { $output = 'call_user_func_array(array($this->plugins[\''.$func.'\'][\'callback\'][0], \''.$callback[1].'\'), array(array('.$params.'), $this))'; } else { $output = 'call_user_func_array(array(\''.$callback[0].'\', \''.$callback[1].'\'), array(array('.$params.'), $this))'; } } else { $output = $callback.'(array('.$params.'), $this)'; } } else { $output = 'smarty_function_'.$func.'(array('.$params.'), $this)'; } } elseif ($pluginType & Dwoo::TEMPLATE_PLUGIN) { array_unshift($params, '$this'); $params = self::implode_r($params); $output = 'Dwoo_Plugin_'.$func.'_'.$this->templatePlugins[$func]['uuid'].'('.$params.')'; $this->templatePlugins[$func]['called'] = true; } if (is_array($parsingParams)) { $parsingParams[] = array($output, $output); return $parsingParams; } elseif ($curBlock === 'namedparam') { return array($output, $output); } else { return $output; } }
[ "protected", "function", "parseFunction", "(", "$", "in", ",", "$", "from", ",", "$", "to", ",", "$", "parsingParams", "=", "false", ",", "$", "curBlock", "=", "''", ",", "&", "$", "pointer", "=", "null", ")", "{", "$", "cmdstr", "=", "substr", "(", "$", "in", ",", "$", "from", ",", "$", "to", "-", "$", "from", ")", ";", "preg_match", "(", "'/^([a-z][a-z0-9_]*(?:::[a-z][a-z0-9_]*)?)(\\s*'", ".", "$", "this", "->", "rdr", ".", "'|\\s*;)?/i'", ",", "$", "cmdstr", ",", "$", "match", ")", ";", "if", "(", "empty", "(", "$", "match", "[", "1", "]", ")", ")", "{", "throw", "new", "Dwoo_Compilation_Exception", "(", "$", "this", ",", "'Parse error, invalid function name : '", ".", "substr", "(", "$", "cmdstr", ",", "0", ",", "15", ")", ")", ";", "}", "$", "func", "=", "$", "match", "[", "1", "]", ";", "if", "(", "!", "empty", "(", "$", "match", "[", "2", "]", ")", ")", "{", "$", "cmdstr", "=", "$", "match", "[", "1", "]", ";", "}", "if", "(", "$", "this", "->", "debug", ")", "echo", "'FUNC FOUND ('", ".", "$", "func", ".", "')<br />'", ";", "$", "paramsep", "=", "''", ";", "if", "(", "is_array", "(", "$", "parsingParams", ")", "||", "$", "curBlock", "!=", "'root'", ")", "{", "$", "paramspos", "=", "strpos", "(", "$", "cmdstr", ",", "'('", ")", ";", "$", "paramsep", "=", "')'", ";", "}", "elseif", "(", "preg_match_all", "(", "'#[a-z0-9_]+(\\s*\\(|\\s+[^(])#i'", ",", "$", "cmdstr", ",", "$", "match", ",", "PREG_OFFSET_CAPTURE", ")", ")", "{", "$", "paramspos", "=", "$", "match", "[", "1", "]", "[", "0", "]", "[", "1", "]", ";", "$", "paramsep", "=", "substr", "(", "$", "match", "[", "1", "]", "[", "0", "]", "[", "0", "]", ",", "-", "1", ")", "===", "'('", "?", "')'", ":", "''", ";", "if", "(", "$", "paramsep", "===", "')'", ")", "{", "$", "paramspos", "+=", "strlen", "(", "$", "match", "[", "1", "]", "[", "0", "]", "[", "0", "]", ")", "-", "1", ";", "if", "(", "substr", "(", "$", "cmdstr", ",", "0", ",", "2", ")", "===", "'if'", "||", "substr", "(", "$", "cmdstr", ",", "0", ",", "6", ")", "===", "'elseif'", ")", "{", "$", "paramsep", "=", "''", ";", "if", "(", "strlen", "(", "$", "match", "[", "1", "]", "[", "0", "]", "[", "0", "]", ")", ">", "1", ")", "{", "$", "paramspos", "--", ";", "}", "}", "}", "}", "else", "{", "$", "paramspos", "=", "false", ";", "}", "$", "state", "=", "0", ";", "if", "(", "$", "paramspos", "===", "false", ")", "{", "$", "params", "=", "array", "(", ")", ";", "if", "(", "$", "curBlock", "!==", "'root'", ")", "{", "return", "$", "this", "->", "parseOthers", "(", "$", "in", ",", "$", "from", ",", "$", "to", ",", "$", "parsingParams", ",", "$", "curBlock", ",", "$", "pointer", ")", ";", "}", "}", "else", "{", "if", "(", "$", "curBlock", "===", "'condition'", ")", "{", "// load if plugin", "$", "this", "->", "getPluginType", "(", "'if'", ")", ";", "if", "(", "Dwoo_Plugin_if", "::", "replaceKeywords", "(", "array", "(", "$", "func", ")", ",", "$", "this", ")", "!==", "array", "(", "$", "func", ")", ")", "{", "return", "$", "this", "->", "parseOthers", "(", "$", "in", ",", "$", "from", ",", "$", "to", ",", "$", "parsingParams", ",", "$", "curBlock", ",", "$", "pointer", ")", ";", "}", "}", "$", "whitespace", "=", "strlen", "(", "substr", "(", "$", "cmdstr", ",", "strlen", "(", "$", "func", ")", ",", "$", "paramspos", "-", "strlen", "(", "$", "func", ")", ")", ")", ";", "$", "paramstr", "=", "substr", "(", "$", "cmdstr", ",", "$", "paramspos", "+", "1", ")", ";", "if", "(", "substr", "(", "$", "paramstr", ",", "-", "1", ",", "1", ")", "===", "$", "paramsep", ")", "{", "$", "paramstr", "=", "substr", "(", "$", "paramstr", ",", "0", ",", "-", "1", ")", ";", "}", "if", "(", "strlen", "(", "$", "paramstr", ")", "===", "0", ")", "{", "$", "params", "=", "array", "(", ")", ";", "$", "paramstr", "=", "''", ";", "}", "else", "{", "$", "ptr", "=", "0", ";", "$", "params", "=", "array", "(", ")", ";", "if", "(", "$", "func", "===", "'empty'", ")", "{", "$", "params", "=", "$", "this", "->", "parseVar", "(", "$", "paramstr", ",", "$", "ptr", ",", "strlen", "(", "$", "paramstr", ")", ",", "$", "params", ",", "'root'", ",", "$", "ptr", ")", ";", "}", "else", "{", "while", "(", "$", "ptr", "<", "strlen", "(", "$", "paramstr", ")", ")", "{", "while", "(", "true", ")", "{", "if", "(", "$", "ptr", ">=", "strlen", "(", "$", "paramstr", ")", ")", "{", "break", "2", ";", "}", "if", "(", "$", "func", "!==", "'if'", "&&", "$", "func", "!==", "'elseif'", "&&", "$", "paramstr", "[", "$", "ptr", "]", "===", "')'", ")", "{", "if", "(", "$", "this", "->", "debug", ")", "echo", "'PARAM PARSING ENDED, \")\" FOUND, POINTER AT '", ".", "$", "ptr", ".", "'<br/>'", ";", "break", "2", ";", "}", "elseif", "(", "$", "paramstr", "[", "$", "ptr", "]", "===", "';'", ")", "{", "$", "ptr", "++", ";", "if", "(", "$", "this", "->", "debug", ")", "echo", "'PARAM PARSING ENDED, \";\" FOUND, POINTER AT '", ".", "$", "ptr", ".", "'<br/>'", ";", "break", "2", ";", "}", "elseif", "(", "$", "func", "!==", "'if'", "&&", "$", "func", "!==", "'elseif'", "&&", "$", "paramstr", "[", "$", "ptr", "]", "===", "'/'", ")", "{", "if", "(", "$", "this", "->", "debug", ")", "echo", "'PARAM PARSING ENDED, \"/\" FOUND, POINTER AT '", ".", "$", "ptr", ".", "'<br/>'", ";", "break", "2", ";", "}", "elseif", "(", "substr", "(", "$", "paramstr", ",", "$", "ptr", ",", "strlen", "(", "$", "this", "->", "rd", ")", ")", "===", "$", "this", "->", "rd", ")", "{", "if", "(", "$", "this", "->", "debug", ")", "echo", "'PARAM PARSING ENDED, RIGHT DELIMITER FOUND, POINTER AT '", ".", "$", "ptr", ".", "'<br/>'", ";", "break", "2", ";", "}", "if", "(", "$", "paramstr", "[", "$", "ptr", "]", "===", "' '", "||", "$", "paramstr", "[", "$", "ptr", "]", "===", "','", "||", "$", "paramstr", "[", "$", "ptr", "]", "===", "\"\\r\"", "||", "$", "paramstr", "[", "$", "ptr", "]", "===", "\"\\n\"", "||", "$", "paramstr", "[", "$", "ptr", "]", "===", "\"\\t\"", ")", "{", "$", "ptr", "++", ";", "}", "else", "{", "break", ";", "}", "}", "if", "(", "$", "this", "->", "debug", ")", "echo", "'FUNC START PARAM PARSING WITH POINTER AT '", ".", "$", "ptr", ".", "'<br/>'", ";", "if", "(", "$", "func", "===", "'if'", "||", "$", "func", "===", "'elseif'", "||", "$", "func", "===", "'tif'", ")", "{", "$", "params", "=", "$", "this", "->", "parse", "(", "$", "paramstr", ",", "$", "ptr", ",", "strlen", "(", "$", "paramstr", ")", ",", "$", "params", ",", "'condition'", ",", "$", "ptr", ")", ";", "}", "else", "{", "$", "params", "=", "$", "this", "->", "parse", "(", "$", "paramstr", ",", "$", "ptr", ",", "strlen", "(", "$", "paramstr", ")", ",", "$", "params", ",", "'function'", ",", "$", "ptr", ")", ";", "}", "if", "(", "$", "this", "->", "debug", ")", "echo", "'PARAM PARSED, POINTER AT '", ".", "$", "ptr", ".", "' ('", ".", "substr", "(", "$", "paramstr", ",", "$", "ptr", "-", "1", ",", "3", ")", ".", "')<br/>'", ";", "}", "}", "$", "paramstr", "=", "substr", "(", "$", "paramstr", ",", "0", ",", "$", "ptr", ")", ";", "$", "state", "=", "0", ";", "foreach", "(", "$", "params", "as", "$", "k", "=>", "$", "p", ")", "{", "if", "(", "is_array", "(", "$", "p", ")", "&&", "is_array", "(", "$", "p", "[", "1", "]", ")", ")", "{", "$", "state", "|=", "2", ";", "}", "else", "{", "if", "(", "(", "$", "state", "&", "2", ")", "&&", "preg_match", "(", "'#^([\"\\'])(.+?)\\1$#'", ",", "$", "p", "[", "0", "]", ",", "$", "m", ")", ")", "{", "$", "params", "[", "$", "k", "]", "=", "array", "(", "$", "m", "[", "2", "]", ",", "array", "(", "'true'", ",", "'true'", ")", ")", ";", "}", "else", "{", "if", "(", "$", "state", "&", "2", ")", "{", "throw", "new", "Dwoo_Compilation_Exception", "(", "$", "this", ",", "'You can not use an unnamed parameter after a named one'", ")", ";", "}", "$", "state", "|=", "1", ";", "}", "}", "}", "}", "}", "if", "(", "$", "pointer", "!==", "null", ")", "{", "$", "pointer", "+=", "(", "isset", "(", "$", "paramstr", ")", "?", "strlen", "(", "$", "paramstr", ")", ":", "0", ")", "+", "(", "')'", "===", "$", "paramsep", "?", "2", ":", "(", "$", "paramspos", "===", "false", "?", "0", ":", "1", ")", ")", "+", "strlen", "(", "$", "func", ")", "+", "(", "isset", "(", "$", "whitespace", ")", "?", "$", "whitespace", ":", "0", ")", ";", "if", "(", "$", "this", "->", "debug", ")", "echo", "'FUNC ADDS '", ".", "(", "(", "isset", "(", "$", "paramstr", ")", "?", "strlen", "(", "$", "paramstr", ")", ":", "0", ")", "+", "(", "')'", "===", "$", "paramsep", "?", "2", ":", "(", "$", "paramspos", "===", "false", "?", "0", ":", "1", ")", ")", "+", "strlen", "(", "$", "func", ")", ")", ".", "' TO POINTER<br/>'", ";", "}", "if", "(", "$", "curBlock", "===", "'method'", "||", "$", "func", "===", "'do'", "||", "strstr", "(", "$", "func", ",", "'::'", ")", "!==", "false", ")", "{", "$", "pluginType", "=", "Dwoo", "::", "NATIVE_PLUGIN", ";", "}", "else", "{", "$", "pluginType", "=", "$", "this", "->", "getPluginType", "(", "$", "func", ")", ";", "}", "// blocks", "if", "(", "$", "pluginType", "&", "Dwoo", "::", "BLOCK_PLUGIN", ")", "{", "if", "(", "$", "curBlock", "!==", "'root'", "||", "is_array", "(", "$", "parsingParams", ")", ")", "{", "throw", "new", "Dwoo_Compilation_Exception", "(", "$", "this", ",", "'Block plugins can not be used as other plugin\\'s arguments'", ")", ";", "}", "if", "(", "$", "pluginType", "&", "Dwoo", "::", "CUSTOM_PLUGIN", ")", "{", "return", "$", "this", "->", "addCustomBlock", "(", "$", "func", ",", "$", "params", ",", "$", "state", ")", ";", "}", "else", "{", "return", "$", "this", "->", "addBlock", "(", "$", "func", ",", "$", "params", ",", "$", "state", ")", ";", "}", "}", "elseif", "(", "$", "pluginType", "&", "Dwoo", "::", "SMARTY_BLOCK", ")", "{", "if", "(", "$", "curBlock", "!==", "'root'", "||", "is_array", "(", "$", "parsingParams", ")", ")", "{", "throw", "new", "Dwoo_Compilation_Exception", "(", "$", "this", ",", "'Block plugins can not be used as other plugin\\'s arguments'", ")", ";", "}", "if", "(", "$", "state", "&", "2", ")", "{", "array_unshift", "(", "$", "params", ",", "array", "(", "'__functype'", ",", "array", "(", "$", "pluginType", ",", "$", "pluginType", ")", ")", ")", ";", "array_unshift", "(", "$", "params", ",", "array", "(", "'__funcname'", ",", "array", "(", "$", "func", ",", "$", "func", ")", ")", ")", ";", "}", "else", "{", "array_unshift", "(", "$", "params", ",", "array", "(", "$", "pluginType", ",", "$", "pluginType", ")", ")", ";", "array_unshift", "(", "$", "params", ",", "array", "(", "$", "func", ",", "$", "func", ")", ")", ";", "}", "return", "$", "this", "->", "addBlock", "(", "'smartyinterface'", ",", "$", "params", ",", "$", "state", ")", ";", "}", "// funcs", "if", "(", "$", "pluginType", "&", "Dwoo", "::", "NATIVE_PLUGIN", "||", "$", "pluginType", "&", "Dwoo", "::", "SMARTY_FUNCTION", "||", "$", "pluginType", "&", "Dwoo", "::", "SMARTY_BLOCK", ")", "{", "$", "params", "=", "$", "this", "->", "mapParams", "(", "$", "params", ",", "null", ",", "$", "state", ")", ";", "}", "elseif", "(", "$", "pluginType", "&", "Dwoo", "::", "CLASS_PLUGIN", ")", "{", "if", "(", "$", "pluginType", "&", "Dwoo", "::", "CUSTOM_PLUGIN", ")", "{", "$", "params", "=", "$", "this", "->", "mapParams", "(", "$", "params", ",", "array", "(", "$", "this", "->", "customPlugins", "[", "$", "func", "]", "[", "'class'", "]", ",", "$", "this", "->", "customPlugins", "[", "$", "func", "]", "[", "'function'", "]", ")", ",", "$", "state", ")", ";", "}", "else", "{", "$", "params", "=", "$", "this", "->", "mapParams", "(", "$", "params", ",", "array", "(", "'Dwoo_Plugin_'", ".", "$", "func", ",", "(", "$", "pluginType", "&", "Dwoo", "::", "COMPILABLE_PLUGIN", ")", "?", "'compile'", ":", "'process'", ")", ",", "$", "state", ")", ";", "}", "}", "elseif", "(", "$", "pluginType", "&", "Dwoo", "::", "FUNC_PLUGIN", ")", "{", "if", "(", "$", "pluginType", "&", "Dwoo", "::", "CUSTOM_PLUGIN", ")", "{", "$", "params", "=", "$", "this", "->", "mapParams", "(", "$", "params", ",", "$", "this", "->", "customPlugins", "[", "$", "func", "]", "[", "'callback'", "]", ",", "$", "state", ")", ";", "}", "else", "{", "$", "params", "=", "$", "this", "->", "mapParams", "(", "$", "params", ",", "'Dwoo_Plugin_'", ".", "$", "func", ".", "(", "(", "$", "pluginType", "&", "Dwoo", "::", "COMPILABLE_PLUGIN", ")", "?", "'_compile'", ":", "''", ")", ",", "$", "state", ")", ";", "}", "}", "elseif", "(", "$", "pluginType", "&", "Dwoo", "::", "SMARTY_MODIFIER", ")", "{", "$", "output", "=", "'smarty_modifier_'", ".", "$", "func", ".", "'('", ".", "implode", "(", "', '", ",", "$", "params", ")", ".", "')'", ";", "}", "elseif", "(", "$", "pluginType", "&", "Dwoo", "::", "PROXY_PLUGIN", ")", "{", "$", "params", "=", "$", "this", "->", "mapParams", "(", "$", "params", ",", "$", "this", "->", "getDwoo", "(", ")", "->", "getPluginProxy", "(", ")", "->", "getCallback", "(", "$", "func", ")", ",", "$", "state", ")", ";", "}", "elseif", "(", "$", "pluginType", "&", "Dwoo", "::", "TEMPLATE_PLUGIN", ")", "{", "// transforms the parameter array from (x=>array('paramname'=>array(values))) to (paramname=>array(values))", "$", "map", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "templatePlugins", "[", "$", "func", "]", "[", "'params'", "]", "as", "$", "param", "=>", "$", "defValue", ")", "{", "if", "(", "$", "param", "==", "'rest'", ")", "{", "$", "param", "=", "'*'", ";", "}", "$", "hasDefault", "=", "$", "defValue", "!==", "null", ";", "if", "(", "$", "defValue", "===", "'null'", ")", "{", "$", "defValue", "=", "null", ";", "}", "elseif", "(", "$", "defValue", "===", "'false'", ")", "{", "$", "defValue", "=", "false", ";", "}", "elseif", "(", "$", "defValue", "===", "'true'", ")", "{", "$", "defValue", "=", "true", ";", "}", "elseif", "(", "preg_match", "(", "'#^([\\'\"]).*?\\1$#'", ",", "$", "defValue", ")", ")", "{", "$", "defValue", "=", "substr", "(", "$", "defValue", ",", "1", ",", "-", "1", ")", ";", "}", "$", "map", "[", "]", "=", "array", "(", "$", "param", ",", "$", "hasDefault", ",", "$", "defValue", ")", ";", "}", "$", "params", "=", "$", "this", "->", "mapParams", "(", "$", "params", ",", "null", ",", "$", "state", ",", "$", "map", ")", ";", "}", "// only keep php-syntax-safe values for non-block plugins", "foreach", "(", "$", "params", "as", "&", "$", "p", ")", "{", "$", "p", "=", "$", "p", "[", "0", "]", ";", "}", "if", "(", "$", "pluginType", "&", "Dwoo", "::", "NATIVE_PLUGIN", ")", "{", "if", "(", "$", "func", "===", "'do'", ")", "{", "if", "(", "isset", "(", "$", "params", "[", "'*'", "]", ")", ")", "{", "$", "output", "=", "implode", "(", "';'", ",", "$", "params", "[", "'*'", "]", ")", ".", "';'", ";", "}", "else", "{", "$", "output", "=", "''", ";", "}", "if", "(", "is_array", "(", "$", "parsingParams", ")", "||", "$", "curBlock", "!==", "'root'", ")", "{", "throw", "new", "Dwoo_Compilation_Exception", "(", "$", "this", ",", "'Do can not be used inside another function or block'", ")", ";", "}", "else", "{", "return", "self", "::", "PHP_OPEN", ".", "$", "output", ".", "self", "::", "PHP_CLOSE", ";", "}", "}", "else", "{", "if", "(", "isset", "(", "$", "params", "[", "'*'", "]", ")", ")", "{", "$", "output", "=", "$", "func", ".", "'('", ".", "implode", "(", "', '", ",", "$", "params", "[", "'*'", "]", ")", ".", "')'", ";", "}", "else", "{", "$", "output", "=", "$", "func", ".", "'()'", ";", "}", "}", "}", "elseif", "(", "$", "pluginType", "&", "Dwoo", "::", "FUNC_PLUGIN", ")", "{", "if", "(", "$", "pluginType", "&", "Dwoo", "::", "COMPILABLE_PLUGIN", ")", "{", "if", "(", "$", "pluginType", "&", "Dwoo", "::", "CUSTOM_PLUGIN", ")", "{", "$", "funcCompiler", "=", "$", "this", "->", "customPlugins", "[", "$", "func", "]", "[", "'callback'", "]", ";", "}", "else", "{", "$", "funcCompiler", "=", "'Dwoo_Plugin_'", ".", "$", "func", ".", "'_compile'", ";", "}", "array_unshift", "(", "$", "params", ",", "$", "this", ")", ";", "$", "output", "=", "call_user_func_array", "(", "$", "funcCompiler", ",", "$", "params", ")", ";", "}", "else", "{", "array_unshift", "(", "$", "params", ",", "'$this'", ")", ";", "$", "params", "=", "self", "::", "implode_r", "(", "$", "params", ")", ";", "if", "(", "$", "pluginType", "&", "Dwoo", "::", "CUSTOM_PLUGIN", ")", "{", "$", "callback", "=", "$", "this", "->", "customPlugins", "[", "$", "func", "]", "[", "'callback'", "]", ";", "$", "output", "=", "'call_user_func(\\''", ".", "$", "callback", ".", "'\\', '", ".", "$", "params", ".", "')'", ";", "}", "else", "{", "$", "output", "=", "'Dwoo_Plugin_'", ".", "$", "func", ".", "'('", ".", "$", "params", ".", "')'", ";", "}", "}", "}", "elseif", "(", "$", "pluginType", "&", "Dwoo", "::", "CLASS_PLUGIN", ")", "{", "if", "(", "$", "pluginType", "&", "Dwoo", "::", "COMPILABLE_PLUGIN", ")", "{", "if", "(", "$", "pluginType", "&", "Dwoo", "::", "CUSTOM_PLUGIN", ")", "{", "$", "callback", "=", "$", "this", "->", "customPlugins", "[", "$", "func", "]", "[", "'callback'", "]", ";", "if", "(", "!", "is_array", "(", "$", "callback", ")", ")", "{", "if", "(", "!", "method_exists", "(", "$", "callback", ",", "'compile'", ")", ")", "{", "throw", "new", "Dwoo_Exception", "(", "'Custom plugin '", ".", "$", "func", ".", "' must implement the \"compile\" method to be compilable, or you should provide a full callback to the method to use'", ")", ";", "}", "if", "(", "(", "$", "ref", "=", "new", "ReflectionMethod", "(", "$", "callback", ",", "'compile'", ")", ")", "&&", "$", "ref", "->", "isStatic", "(", ")", ")", "{", "$", "funcCompiler", "=", "array", "(", "$", "callback", ",", "'compile'", ")", ";", "}", "else", "{", "$", "funcCompiler", "=", "array", "(", "new", "$", "callback", ",", "'compile'", ")", ";", "}", "}", "else", "{", "$", "funcCompiler", "=", "$", "callback", ";", "}", "}", "else", "{", "$", "funcCompiler", "=", "array", "(", "'Dwoo_Plugin_'", ".", "$", "func", ",", "'compile'", ")", ";", "array_unshift", "(", "$", "params", ",", "$", "this", ")", ";", "}", "$", "output", "=", "call_user_func_array", "(", "$", "funcCompiler", ",", "$", "params", ")", ";", "}", "else", "{", "$", "params", "=", "self", "::", "implode_r", "(", "$", "params", ")", ";", "if", "(", "$", "pluginType", "&", "Dwoo", "::", "CUSTOM_PLUGIN", ")", "{", "$", "callback", "=", "$", "this", "->", "customPlugins", "[", "$", "func", "]", "[", "'callback'", "]", ";", "if", "(", "!", "is_array", "(", "$", "callback", ")", ")", "{", "if", "(", "!", "method_exists", "(", "$", "callback", ",", "'process'", ")", ")", "{", "throw", "new", "Dwoo_Exception", "(", "'Custom plugin '", ".", "$", "func", ".", "' must implement the \"process\" method to be usable, or you should provide a full callback to the method to use'", ")", ";", "}", "if", "(", "(", "$", "ref", "=", "new", "ReflectionMethod", "(", "$", "callback", ",", "'process'", ")", ")", "&&", "$", "ref", "->", "isStatic", "(", ")", ")", "{", "$", "output", "=", "'call_user_func(array(\\''", ".", "$", "callback", ".", "'\\', \\'process\\'), '", ".", "$", "params", ".", "')'", ";", "}", "else", "{", "$", "output", "=", "'call_user_func(array($this->getObjectPlugin(\\''", ".", "$", "callback", ".", "'\\'), \\'process\\'), '", ".", "$", "params", ".", "')'", ";", "}", "}", "elseif", "(", "is_object", "(", "$", "callback", "[", "0", "]", ")", ")", "{", "$", "output", "=", "'call_user_func(array($this->plugins[\\''", ".", "$", "func", ".", "'\\'][\\'callback\\'][0], \\''", ".", "$", "callback", "[", "1", "]", ".", "'\\'), '", ".", "$", "params", ".", "')'", ";", "}", "elseif", "(", "(", "$", "ref", "=", "new", "ReflectionMethod", "(", "$", "callback", "[", "0", "]", ",", "$", "callback", "[", "1", "]", ")", ")", "&&", "$", "ref", "->", "isStatic", "(", ")", ")", "{", "$", "output", "=", "'call_user_func(array(\\''", ".", "$", "callback", "[", "0", "]", ".", "'\\', \\''", ".", "$", "callback", "[", "1", "]", ".", "'\\'), '", ".", "$", "params", ".", "')'", ";", "}", "else", "{", "$", "output", "=", "'call_user_func(array($this->getObjectPlugin(\\''", ".", "$", "callback", "[", "0", "]", ".", "'\\'), \\''", ".", "$", "callback", "[", "1", "]", ".", "'\\'), '", ".", "$", "params", ".", "')'", ";", "}", "if", "(", "empty", "(", "$", "params", ")", ")", "{", "$", "output", "=", "substr", "(", "$", "output", ",", "0", ",", "-", "3", ")", ".", "')'", ";", "}", "}", "else", "{", "$", "output", "=", "'$this->classCall(\\''", ".", "$", "func", ".", "'\\', array('", ".", "$", "params", ".", "'))'", ";", "}", "}", "}", "elseif", "(", "$", "pluginType", "&", "Dwoo", "::", "PROXY_PLUGIN", ")", "{", "$", "output", "=", "call_user_func", "(", "array", "(", "$", "this", "->", "dwoo", "->", "getPluginProxy", "(", ")", ",", "'getCode'", ")", ",", "$", "func", ",", "$", "params", ")", ";", "}", "elseif", "(", "$", "pluginType", "&", "Dwoo", "::", "SMARTY_FUNCTION", ")", "{", "if", "(", "isset", "(", "$", "params", "[", "'*'", "]", ")", ")", "{", "$", "params", "=", "self", "::", "implode_r", "(", "$", "params", "[", "'*'", "]", ",", "true", ")", ";", "}", "else", "{", "$", "params", "=", "''", ";", "}", "if", "(", "$", "pluginType", "&", "Dwoo", "::", "CUSTOM_PLUGIN", ")", "{", "$", "callback", "=", "$", "this", "->", "customPlugins", "[", "$", "func", "]", "[", "'callback'", "]", ";", "if", "(", "is_array", "(", "$", "callback", ")", ")", "{", "if", "(", "is_object", "(", "$", "callback", "[", "0", "]", ")", ")", "{", "$", "output", "=", "'call_user_func_array(array($this->plugins[\\''", ".", "$", "func", ".", "'\\'][\\'callback\\'][0], \\''", ".", "$", "callback", "[", "1", "]", ".", "'\\'), array(array('", ".", "$", "params", ".", "'), $this))'", ";", "}", "else", "{", "$", "output", "=", "'call_user_func_array(array(\\''", ".", "$", "callback", "[", "0", "]", ".", "'\\', \\''", ".", "$", "callback", "[", "1", "]", ".", "'\\'), array(array('", ".", "$", "params", ".", "'), $this))'", ";", "}", "}", "else", "{", "$", "output", "=", "$", "callback", ".", "'(array('", ".", "$", "params", ".", "'), $this)'", ";", "}", "}", "else", "{", "$", "output", "=", "'smarty_function_'", ".", "$", "func", ".", "'(array('", ".", "$", "params", ".", "'), $this)'", ";", "}", "}", "elseif", "(", "$", "pluginType", "&", "Dwoo", "::", "TEMPLATE_PLUGIN", ")", "{", "array_unshift", "(", "$", "params", ",", "'$this'", ")", ";", "$", "params", "=", "self", "::", "implode_r", "(", "$", "params", ")", ";", "$", "output", "=", "'Dwoo_Plugin_'", ".", "$", "func", ".", "'_'", ".", "$", "this", "->", "templatePlugins", "[", "$", "func", "]", "[", "'uuid'", "]", ".", "'('", ".", "$", "params", ".", "')'", ";", "$", "this", "->", "templatePlugins", "[", "$", "func", "]", "[", "'called'", "]", "=", "true", ";", "}", "if", "(", "is_array", "(", "$", "parsingParams", ")", ")", "{", "$", "parsingParams", "[", "]", "=", "array", "(", "$", "output", ",", "$", "output", ")", ";", "return", "$", "parsingParams", ";", "}", "elseif", "(", "$", "curBlock", "===", "'namedparam'", ")", "{", "return", "array", "(", "$", "output", ",", "$", "output", ")", ";", "}", "else", "{", "return", "$", "output", ";", "}", "}" ]
parses a function call @param string $in the string within which we must parse something @param int $from the starting offset of the parsed area @param int $to the ending offset of the parsed area @param mixed $parsingParams must be an array if we are parsing a function or modifier's parameters, or false by default @param string $curBlock the current parser-block being processed @param mixed $pointer a reference to a pointer that will be increased by the amount of characters parsed, or null by default @return string parsed values
[ "parses", "a", "function", "call" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php#L1534-L1870
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php
Dwoo_Compiler.parseString
protected function parseString($in, $from, $to, $parsingParams = false, $curBlock='', &$pointer = null) { $substr = substr($in, $from, $to-$from); $first = $substr[0]; if ($this->debug) echo 'STRING FOUND (in '.htmlentities(substr($in, $from, min($to-$from, 50))).(($to-$from) > 50 ? '...':'').')<br />'; $strend = false; $o = $from+1; while ($strend === false) { $strend = strpos($in, $first, $o); if ($strend === false) { throw new Dwoo_Compilation_Exception($this, 'Unfinished string, started with '.substr($in, $from, $to-$from)); } if (substr($in, $strend-1, 1) === '\\') { $o = $strend+1; $strend = false; } } if ($this->debug) echo 'STRING DELIMITED: '.substr($in, $from, $strend+1-$from).'<br/>'; $srcOutput = substr($in, $from, $strend+1-$from); if ($pointer !== null) { $pointer += strlen($srcOutput); } $output = $this->replaceStringVars($srcOutput, $first); // handle modifiers if ($curBlock !== 'modifier' && preg_match('#^((?:\|(?:@?[a-z0-9_]+(?::.*)*))+)#i', substr($substr, $strend+1-$from), $match)) { $modstr = $match[1]; if ($curBlock === 'root' && substr($modstr, -1) === '}') { $modstr = substr($modstr, 0, -1); } $modstr = str_replace('\\'.$first, $first, $modstr); $ptr = 0; $output = $this->replaceModifiers(array(null, null, $output, $modstr), 'string', $ptr); $strend += $ptr; if ($pointer !== null) { $pointer += $ptr; } $srcOutput .= substr($substr, $strend+1-$from, $ptr); } if (is_array($parsingParams)) { $parsingParams[] = array($output, substr($srcOutput, 1, -1)); return $parsingParams; } elseif ($curBlock === 'namedparam') { return array($output, substr($srcOutput, 1, -1)); } else { return $output; } }
php
protected function parseString($in, $from, $to, $parsingParams = false, $curBlock='', &$pointer = null) { $substr = substr($in, $from, $to-$from); $first = $substr[0]; if ($this->debug) echo 'STRING FOUND (in '.htmlentities(substr($in, $from, min($to-$from, 50))).(($to-$from) > 50 ? '...':'').')<br />'; $strend = false; $o = $from+1; while ($strend === false) { $strend = strpos($in, $first, $o); if ($strend === false) { throw new Dwoo_Compilation_Exception($this, 'Unfinished string, started with '.substr($in, $from, $to-$from)); } if (substr($in, $strend-1, 1) === '\\') { $o = $strend+1; $strend = false; } } if ($this->debug) echo 'STRING DELIMITED: '.substr($in, $from, $strend+1-$from).'<br/>'; $srcOutput = substr($in, $from, $strend+1-$from); if ($pointer !== null) { $pointer += strlen($srcOutput); } $output = $this->replaceStringVars($srcOutput, $first); // handle modifiers if ($curBlock !== 'modifier' && preg_match('#^((?:\|(?:@?[a-z0-9_]+(?::.*)*))+)#i', substr($substr, $strend+1-$from), $match)) { $modstr = $match[1]; if ($curBlock === 'root' && substr($modstr, -1) === '}') { $modstr = substr($modstr, 0, -1); } $modstr = str_replace('\\'.$first, $first, $modstr); $ptr = 0; $output = $this->replaceModifiers(array(null, null, $output, $modstr), 'string', $ptr); $strend += $ptr; if ($pointer !== null) { $pointer += $ptr; } $srcOutput .= substr($substr, $strend+1-$from, $ptr); } if (is_array($parsingParams)) { $parsingParams[] = array($output, substr($srcOutput, 1, -1)); return $parsingParams; } elseif ($curBlock === 'namedparam') { return array($output, substr($srcOutput, 1, -1)); } else { return $output; } }
[ "protected", "function", "parseString", "(", "$", "in", ",", "$", "from", ",", "$", "to", ",", "$", "parsingParams", "=", "false", ",", "$", "curBlock", "=", "''", ",", "&", "$", "pointer", "=", "null", ")", "{", "$", "substr", "=", "substr", "(", "$", "in", ",", "$", "from", ",", "$", "to", "-", "$", "from", ")", ";", "$", "first", "=", "$", "substr", "[", "0", "]", ";", "if", "(", "$", "this", "->", "debug", ")", "echo", "'STRING FOUND (in '", ".", "htmlentities", "(", "substr", "(", "$", "in", ",", "$", "from", ",", "min", "(", "$", "to", "-", "$", "from", ",", "50", ")", ")", ")", ".", "(", "(", "$", "to", "-", "$", "from", ")", ">", "50", "?", "'...'", ":", "''", ")", ".", "')<br />'", ";", "$", "strend", "=", "false", ";", "$", "o", "=", "$", "from", "+", "1", ";", "while", "(", "$", "strend", "===", "false", ")", "{", "$", "strend", "=", "strpos", "(", "$", "in", ",", "$", "first", ",", "$", "o", ")", ";", "if", "(", "$", "strend", "===", "false", ")", "{", "throw", "new", "Dwoo_Compilation_Exception", "(", "$", "this", ",", "'Unfinished string, started with '", ".", "substr", "(", "$", "in", ",", "$", "from", ",", "$", "to", "-", "$", "from", ")", ")", ";", "}", "if", "(", "substr", "(", "$", "in", ",", "$", "strend", "-", "1", ",", "1", ")", "===", "'\\\\'", ")", "{", "$", "o", "=", "$", "strend", "+", "1", ";", "$", "strend", "=", "false", ";", "}", "}", "if", "(", "$", "this", "->", "debug", ")", "echo", "'STRING DELIMITED: '", ".", "substr", "(", "$", "in", ",", "$", "from", ",", "$", "strend", "+", "1", "-", "$", "from", ")", ".", "'<br/>'", ";", "$", "srcOutput", "=", "substr", "(", "$", "in", ",", "$", "from", ",", "$", "strend", "+", "1", "-", "$", "from", ")", ";", "if", "(", "$", "pointer", "!==", "null", ")", "{", "$", "pointer", "+=", "strlen", "(", "$", "srcOutput", ")", ";", "}", "$", "output", "=", "$", "this", "->", "replaceStringVars", "(", "$", "srcOutput", ",", "$", "first", ")", ";", "// handle modifiers", "if", "(", "$", "curBlock", "!==", "'modifier'", "&&", "preg_match", "(", "'#^((?:\\|(?:@?[a-z0-9_]+(?::.*)*))+)#i'", ",", "substr", "(", "$", "substr", ",", "$", "strend", "+", "1", "-", "$", "from", ")", ",", "$", "match", ")", ")", "{", "$", "modstr", "=", "$", "match", "[", "1", "]", ";", "if", "(", "$", "curBlock", "===", "'root'", "&&", "substr", "(", "$", "modstr", ",", "-", "1", ")", "===", "'}'", ")", "{", "$", "modstr", "=", "substr", "(", "$", "modstr", ",", "0", ",", "-", "1", ")", ";", "}", "$", "modstr", "=", "str_replace", "(", "'\\\\'", ".", "$", "first", ",", "$", "first", ",", "$", "modstr", ")", ";", "$", "ptr", "=", "0", ";", "$", "output", "=", "$", "this", "->", "replaceModifiers", "(", "array", "(", "null", ",", "null", ",", "$", "output", ",", "$", "modstr", ")", ",", "'string'", ",", "$", "ptr", ")", ";", "$", "strend", "+=", "$", "ptr", ";", "if", "(", "$", "pointer", "!==", "null", ")", "{", "$", "pointer", "+=", "$", "ptr", ";", "}", "$", "srcOutput", ".=", "substr", "(", "$", "substr", ",", "$", "strend", "+", "1", "-", "$", "from", ",", "$", "ptr", ")", ";", "}", "if", "(", "is_array", "(", "$", "parsingParams", ")", ")", "{", "$", "parsingParams", "[", "]", "=", "array", "(", "$", "output", ",", "substr", "(", "$", "srcOutput", ",", "1", ",", "-", "1", ")", ")", ";", "return", "$", "parsingParams", ";", "}", "elseif", "(", "$", "curBlock", "===", "'namedparam'", ")", "{", "return", "array", "(", "$", "output", ",", "substr", "(", "$", "srcOutput", ",", "1", ",", "-", "1", ")", ")", ";", "}", "else", "{", "return", "$", "output", ";", "}", "}" ]
parses a string @param string $in the string within which we must parse something @param int $from the starting offset of the parsed area @param int $to the ending offset of the parsed area @param mixed $parsingParams must be an array if we are parsing a function or modifier's parameters, or false by default @param string $curBlock the current parser-block being processed @param mixed $pointer a reference to a pointer that will be increased by the amount of characters parsed, or null by default @return string parsed values
[ "parses", "a", "string" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php#L1883-L1937
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php
Dwoo_Compiler.parseConst
protected function parseConst($in, $from, $to, $parsingParams = false, $curBlock='', &$pointer = null) { $substr = substr($in, $from, $to-$from); if ($this->debug) { echo 'CONST FOUND : '.$substr.'<br />'; } if (!preg_match('#^%([a-z0-9_:]+)#i', $substr, $m)) { throw new Dwoo_Compilation_Exception($this, 'Invalid constant'); } if ($pointer !== null) { $pointer += strlen($m[0]); } $output = $this->parseConstKey($m[1], $curBlock); if (is_array($parsingParams)) { $parsingParams[] = array($output, $m[1]); return $parsingParams; } elseif ($curBlock === 'namedparam') { return array($output, $m[1]); } else { return $output; } }
php
protected function parseConst($in, $from, $to, $parsingParams = false, $curBlock='', &$pointer = null) { $substr = substr($in, $from, $to-$from); if ($this->debug) { echo 'CONST FOUND : '.$substr.'<br />'; } if (!preg_match('#^%([a-z0-9_:]+)#i', $substr, $m)) { throw new Dwoo_Compilation_Exception($this, 'Invalid constant'); } if ($pointer !== null) { $pointer += strlen($m[0]); } $output = $this->parseConstKey($m[1], $curBlock); if (is_array($parsingParams)) { $parsingParams[] = array($output, $m[1]); return $parsingParams; } elseif ($curBlock === 'namedparam') { return array($output, $m[1]); } else { return $output; } }
[ "protected", "function", "parseConst", "(", "$", "in", ",", "$", "from", ",", "$", "to", ",", "$", "parsingParams", "=", "false", ",", "$", "curBlock", "=", "''", ",", "&", "$", "pointer", "=", "null", ")", "{", "$", "substr", "=", "substr", "(", "$", "in", ",", "$", "from", ",", "$", "to", "-", "$", "from", ")", ";", "if", "(", "$", "this", "->", "debug", ")", "{", "echo", "'CONST FOUND : '", ".", "$", "substr", ".", "'<br />'", ";", "}", "if", "(", "!", "preg_match", "(", "'#^%([a-z0-9_:]+)#i'", ",", "$", "substr", ",", "$", "m", ")", ")", "{", "throw", "new", "Dwoo_Compilation_Exception", "(", "$", "this", ",", "'Invalid constant'", ")", ";", "}", "if", "(", "$", "pointer", "!==", "null", ")", "{", "$", "pointer", "+=", "strlen", "(", "$", "m", "[", "0", "]", ")", ";", "}", "$", "output", "=", "$", "this", "->", "parseConstKey", "(", "$", "m", "[", "1", "]", ",", "$", "curBlock", ")", ";", "if", "(", "is_array", "(", "$", "parsingParams", ")", ")", "{", "$", "parsingParams", "[", "]", "=", "array", "(", "$", "output", ",", "$", "m", "[", "1", "]", ")", ";", "return", "$", "parsingParams", ";", "}", "elseif", "(", "$", "curBlock", "===", "'namedparam'", ")", "{", "return", "array", "(", "$", "output", ",", "$", "m", "[", "1", "]", ")", ";", "}", "else", "{", "return", "$", "output", ";", "}", "}" ]
parses a constant @param string $in the string within which we must parse something @param int $from the starting offset of the parsed area @param int $to the ending offset of the parsed area @param mixed $parsingParams must be an array if we are parsing a function or modifier's parameters, or false by default @param string $curBlock the current parser-block being processed @param mixed $pointer a reference to a pointer that will be increased by the amount of characters parsed, or null by default @return string parsed values
[ "parses", "a", "constant" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php#L1950-L1976
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php
Dwoo_Compiler.parseConstKey
protected function parseConstKey($key, $curBlock) { if ($this->securityPolicy !== null && $this->securityPolicy->getConstantHandling() === Dwoo_Security_Policy::CONST_DISALLOW) { return 'null'; } if ($curBlock !== 'root') { $output = '(defined("'.$key.'") ? '.$key.' : null)'; } else { $output = $key; } return $output; }
php
protected function parseConstKey($key, $curBlock) { if ($this->securityPolicy !== null && $this->securityPolicy->getConstantHandling() === Dwoo_Security_Policy::CONST_DISALLOW) { return 'null'; } if ($curBlock !== 'root') { $output = '(defined("'.$key.'") ? '.$key.' : null)'; } else { $output = $key; } return $output; }
[ "protected", "function", "parseConstKey", "(", "$", "key", ",", "$", "curBlock", ")", "{", "if", "(", "$", "this", "->", "securityPolicy", "!==", "null", "&&", "$", "this", "->", "securityPolicy", "->", "getConstantHandling", "(", ")", "===", "Dwoo_Security_Policy", "::", "CONST_DISALLOW", ")", "{", "return", "'null'", ";", "}", "if", "(", "$", "curBlock", "!==", "'root'", ")", "{", "$", "output", "=", "'(defined(\"'", ".", "$", "key", ".", "'\") ? '", ".", "$", "key", ".", "' : null)'", ";", "}", "else", "{", "$", "output", "=", "$", "key", ";", "}", "return", "$", "output", ";", "}" ]
parses a constant @param string $key the constant to parse @param string $curBlock the current parser-block being processed @return string parsed constant
[ "parses", "a", "constant" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php#L1985-L1998
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php
Dwoo_Compiler.parseMethodCall
protected function parseMethodCall($output, $methodCall, $curBlock, &$pointer) { $ptr = 0; $len = strlen($methodCall); while ($ptr < $len) { if (strpos($methodCall, '->', $ptr) === $ptr) { $ptr += 2; } if (in_array($methodCall[$ptr], array(';', '/', ' ', "\t", "\r", "\n", ')', '+', '*', '%', '=', '-', '|')) || substr($methodCall, $ptr, strlen($this->rd)) === $this->rd) { // break char found break; } if(!preg_match('/^([a-z0-9_]+)(\(.*?\))?/i', substr($methodCall, $ptr), $methMatch)) { throw new Dwoo_Compilation_Exception($this, 'Invalid method name : '.substr($methodCall, $ptr, 20)); } if (empty($methMatch[2])) { // property if ($curBlock === 'root') { $output .= '->'.$methMatch[1]; } else { $output = '(($tmp = '.$output.') ? $tmp->'.$methMatch[1].' : null)'; } $ptr += strlen($methMatch[1]); } else { // method if (substr($methMatch[2], 0, 2) === '()') { $parsedCall = '->'.$methMatch[1].'()'; $ptr += strlen($methMatch[1]) + 2; } else { $parsedCall = '->'.$this->parseFunction($methodCall, $ptr, strlen($methodCall), false, 'method', $ptr); } if ($curBlock === 'root') { $output .= $parsedCall; } else { $output = '(($tmp = '.$output.') ? $tmp'.$parsedCall.' : null)'; } } } $pointer += $ptr; return $output; }
php
protected function parseMethodCall($output, $methodCall, $curBlock, &$pointer) { $ptr = 0; $len = strlen($methodCall); while ($ptr < $len) { if (strpos($methodCall, '->', $ptr) === $ptr) { $ptr += 2; } if (in_array($methodCall[$ptr], array(';', '/', ' ', "\t", "\r", "\n", ')', '+', '*', '%', '=', '-', '|')) || substr($methodCall, $ptr, strlen($this->rd)) === $this->rd) { // break char found break; } if(!preg_match('/^([a-z0-9_]+)(\(.*?\))?/i', substr($methodCall, $ptr), $methMatch)) { throw new Dwoo_Compilation_Exception($this, 'Invalid method name : '.substr($methodCall, $ptr, 20)); } if (empty($methMatch[2])) { // property if ($curBlock === 'root') { $output .= '->'.$methMatch[1]; } else { $output = '(($tmp = '.$output.') ? $tmp->'.$methMatch[1].' : null)'; } $ptr += strlen($methMatch[1]); } else { // method if (substr($methMatch[2], 0, 2) === '()') { $parsedCall = '->'.$methMatch[1].'()'; $ptr += strlen($methMatch[1]) + 2; } else { $parsedCall = '->'.$this->parseFunction($methodCall, $ptr, strlen($methodCall), false, 'method', $ptr); } if ($curBlock === 'root') { $output .= $parsedCall; } else { $output = '(($tmp = '.$output.') ? $tmp'.$parsedCall.' : null)'; } } } $pointer += $ptr; return $output; }
[ "protected", "function", "parseMethodCall", "(", "$", "output", ",", "$", "methodCall", ",", "$", "curBlock", ",", "&", "$", "pointer", ")", "{", "$", "ptr", "=", "0", ";", "$", "len", "=", "strlen", "(", "$", "methodCall", ")", ";", "while", "(", "$", "ptr", "<", "$", "len", ")", "{", "if", "(", "strpos", "(", "$", "methodCall", ",", "'->'", ",", "$", "ptr", ")", "===", "$", "ptr", ")", "{", "$", "ptr", "+=", "2", ";", "}", "if", "(", "in_array", "(", "$", "methodCall", "[", "$", "ptr", "]", ",", "array", "(", "';'", ",", "'/'", ",", "' '", ",", "\"\\t\"", ",", "\"\\r\"", ",", "\"\\n\"", ",", "')'", ",", "'+'", ",", "'*'", ",", "'%'", ",", "'='", ",", "'-'", ",", "'|'", ")", ")", "||", "substr", "(", "$", "methodCall", ",", "$", "ptr", ",", "strlen", "(", "$", "this", "->", "rd", ")", ")", "===", "$", "this", "->", "rd", ")", "{", "// break char found", "break", ";", "}", "if", "(", "!", "preg_match", "(", "'/^([a-z0-9_]+)(\\(.*?\\))?/i'", ",", "substr", "(", "$", "methodCall", ",", "$", "ptr", ")", ",", "$", "methMatch", ")", ")", "{", "throw", "new", "Dwoo_Compilation_Exception", "(", "$", "this", ",", "'Invalid method name : '", ".", "substr", "(", "$", "methodCall", ",", "$", "ptr", ",", "20", ")", ")", ";", "}", "if", "(", "empty", "(", "$", "methMatch", "[", "2", "]", ")", ")", "{", "// property", "if", "(", "$", "curBlock", "===", "'root'", ")", "{", "$", "output", ".=", "'->'", ".", "$", "methMatch", "[", "1", "]", ";", "}", "else", "{", "$", "output", "=", "'(($tmp = '", ".", "$", "output", ".", "') ? $tmp->'", ".", "$", "methMatch", "[", "1", "]", ".", "' : null)'", ";", "}", "$", "ptr", "+=", "strlen", "(", "$", "methMatch", "[", "1", "]", ")", ";", "}", "else", "{", "// method", "if", "(", "substr", "(", "$", "methMatch", "[", "2", "]", ",", "0", ",", "2", ")", "===", "'()'", ")", "{", "$", "parsedCall", "=", "'->'", ".", "$", "methMatch", "[", "1", "]", ".", "'()'", ";", "$", "ptr", "+=", "strlen", "(", "$", "methMatch", "[", "1", "]", ")", "+", "2", ";", "}", "else", "{", "$", "parsedCall", "=", "'->'", ".", "$", "this", "->", "parseFunction", "(", "$", "methodCall", ",", "$", "ptr", ",", "strlen", "(", "$", "methodCall", ")", ",", "false", ",", "'method'", ",", "$", "ptr", ")", ";", "}", "if", "(", "$", "curBlock", "===", "'root'", ")", "{", "$", "output", ".=", "$", "parsedCall", ";", "}", "else", "{", "$", "output", "=", "'(($tmp = '", ".", "$", "output", ".", "') ? $tmp'", ".", "$", "parsedCall", ".", "' : null)'", ";", "}", "}", "}", "$", "pointer", "+=", "$", "ptr", ";", "return", "$", "output", ";", "}" ]
parses any number of chained method calls/property reads @param string $output the variable or whatever upon which the method are called @param string $methodCall method call source, starting at "->" @param string $curBlock the current parser-block being processed @param int $pointer a reference to a pointer that will be increased by the amount of characters parsed @return string parsed call(s)/read(s)
[ "parses", "any", "number", "of", "chained", "method", "calls", "/", "property", "reads" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php#L2217-L2262
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php
Dwoo_Compiler.parseOthers
protected function parseOthers($in, $from, $to, $parsingParams = false, $curBlock='', &$pointer = null) { $first = $in[$from]; $substr = substr($in, $from, $to-$from); $end = strlen($substr); if ($curBlock === 'condition') { $breakChars = array('(', ')', ' ', '||', '&&', '|', '&', '>=', '<=', '===', '==', '=', '!==', '!=', '<<', '<', '>>', '>', '^', '~', ',', '+', '-', '*', '/', '%', '!', '?', ':', $this->rd, ';'); } elseif ($curBlock === 'modifier') { $breakChars = array(' ', ',', ')', ':', '|', "\r", "\n", "\t", ";", $this->rd); } elseif ($curBlock === 'expression') { $breakChars = array('/', '%', '+', '-', '*', ' ', ',', ')', "\r", "\n", "\t", ";", $this->rd); } else { $breakChars = array(' ', ',', ')', "\r", "\n", "\t", ";", $this->rd); } $breaker = false; while (list($k,$char) = each($breakChars)) { $test = strpos($substr, $char); if ($test !== false && $test < $end) { $end = $test; $breaker = $k; } } if ($curBlock === 'condition') { if ($end === 0 && $breaker !== false) { $end = strlen($breakChars[$breaker]); } } if ($end !== false) { $substr = substr($substr, 0, $end); } if ($pointer !== null) { $pointer += strlen($substr); } $src = $substr; $substr = trim($substr); if (strtolower($substr) === 'false' || strtolower($substr) === 'no' || strtolower($substr) === 'off') { if ($this->debug) echo 'BOOLEAN(FALSE) PARSED<br />'; $substr = 'false'; } elseif (strtolower($substr) === 'true' || strtolower($substr) === 'yes' || strtolower($substr) === 'on') { if ($this->debug) echo 'BOOLEAN(TRUE) PARSED<br />'; $substr = 'true'; } elseif ($substr === 'null' || $substr === 'NULL') { if ($this->debug) echo 'NULL PARSED<br />'; $substr = 'null'; } elseif (is_numeric($substr)) { $substr = (float) $substr; if ((int) $substr == $substr) { $substr = (int) $substr; } if ($this->debug) echo 'NUMBER ('.$substr.') PARSED<br />'; } elseif (preg_match('{^-?(\d+|\d*(\.\d+))\s*([/*%+-]\s*-?(\d+|\d*(\.\d+)))+$}', $substr)) { if ($this->debug) echo 'SIMPLE MATH PARSED<br />'; $substr = '('.$substr.')'; } elseif ($curBlock === 'condition' && array_search($substr, $breakChars, true) !== false) { if ($this->debug) echo 'BREAKCHAR ('.$substr.') PARSED<br />'; //$substr = '"'.$substr.'"'; } else { $substr = $this->replaceStringVars('\''.str_replace('\'', '\\\'', $substr).'\'', '\'', $curBlock); if ($this->debug) echo 'BLABBER ('.$substr.') CASTED AS STRING<br />'; } if (is_array($parsingParams)) { $parsingParams[] = array($substr, $src); return $parsingParams; } elseif ($curBlock === 'namedparam') { return array($substr, $src); } elseif ($curBlock === 'expression') { return $substr; } else { throw new Exception('Something went wrong'); } }
php
protected function parseOthers($in, $from, $to, $parsingParams = false, $curBlock='', &$pointer = null) { $first = $in[$from]; $substr = substr($in, $from, $to-$from); $end = strlen($substr); if ($curBlock === 'condition') { $breakChars = array('(', ')', ' ', '||', '&&', '|', '&', '>=', '<=', '===', '==', '=', '!==', '!=', '<<', '<', '>>', '>', '^', '~', ',', '+', '-', '*', '/', '%', '!', '?', ':', $this->rd, ';'); } elseif ($curBlock === 'modifier') { $breakChars = array(' ', ',', ')', ':', '|', "\r", "\n", "\t", ";", $this->rd); } elseif ($curBlock === 'expression') { $breakChars = array('/', '%', '+', '-', '*', ' ', ',', ')', "\r", "\n", "\t", ";", $this->rd); } else { $breakChars = array(' ', ',', ')', "\r", "\n", "\t", ";", $this->rd); } $breaker = false; while (list($k,$char) = each($breakChars)) { $test = strpos($substr, $char); if ($test !== false && $test < $end) { $end = $test; $breaker = $k; } } if ($curBlock === 'condition') { if ($end === 0 && $breaker !== false) { $end = strlen($breakChars[$breaker]); } } if ($end !== false) { $substr = substr($substr, 0, $end); } if ($pointer !== null) { $pointer += strlen($substr); } $src = $substr; $substr = trim($substr); if (strtolower($substr) === 'false' || strtolower($substr) === 'no' || strtolower($substr) === 'off') { if ($this->debug) echo 'BOOLEAN(FALSE) PARSED<br />'; $substr = 'false'; } elseif (strtolower($substr) === 'true' || strtolower($substr) === 'yes' || strtolower($substr) === 'on') { if ($this->debug) echo 'BOOLEAN(TRUE) PARSED<br />'; $substr = 'true'; } elseif ($substr === 'null' || $substr === 'NULL') { if ($this->debug) echo 'NULL PARSED<br />'; $substr = 'null'; } elseif (is_numeric($substr)) { $substr = (float) $substr; if ((int) $substr == $substr) { $substr = (int) $substr; } if ($this->debug) echo 'NUMBER ('.$substr.') PARSED<br />'; } elseif (preg_match('{^-?(\d+|\d*(\.\d+))\s*([/*%+-]\s*-?(\d+|\d*(\.\d+)))+$}', $substr)) { if ($this->debug) echo 'SIMPLE MATH PARSED<br />'; $substr = '('.$substr.')'; } elseif ($curBlock === 'condition' && array_search($substr, $breakChars, true) !== false) { if ($this->debug) echo 'BREAKCHAR ('.$substr.') PARSED<br />'; //$substr = '"'.$substr.'"'; } else { $substr = $this->replaceStringVars('\''.str_replace('\'', '\\\'', $substr).'\'', '\'', $curBlock); if ($this->debug) echo 'BLABBER ('.$substr.') CASTED AS STRING<br />'; } if (is_array($parsingParams)) { $parsingParams[] = array($substr, $src); return $parsingParams; } elseif ($curBlock === 'namedparam') { return array($substr, $src); } elseif ($curBlock === 'expression') { return $substr; } else { throw new Exception('Something went wrong'); } }
[ "protected", "function", "parseOthers", "(", "$", "in", ",", "$", "from", ",", "$", "to", ",", "$", "parsingParams", "=", "false", ",", "$", "curBlock", "=", "''", ",", "&", "$", "pointer", "=", "null", ")", "{", "$", "first", "=", "$", "in", "[", "$", "from", "]", ";", "$", "substr", "=", "substr", "(", "$", "in", ",", "$", "from", ",", "$", "to", "-", "$", "from", ")", ";", "$", "end", "=", "strlen", "(", "$", "substr", ")", ";", "if", "(", "$", "curBlock", "===", "'condition'", ")", "{", "$", "breakChars", "=", "array", "(", "'('", ",", "')'", ",", "' '", ",", "'||'", ",", "'&&'", ",", "'|'", ",", "'&'", ",", "'>='", ",", "'<='", ",", "'==='", ",", "'=='", ",", "'='", ",", "'!=='", ",", "'!='", ",", "'<<'", ",", "'<'", ",", "'>>'", ",", "'>'", ",", "'^'", ",", "'~'", ",", "','", ",", "'+'", ",", "'-'", ",", "'*'", ",", "'/'", ",", "'%'", ",", "'!'", ",", "'?'", ",", "':'", ",", "$", "this", "->", "rd", ",", "';'", ")", ";", "}", "elseif", "(", "$", "curBlock", "===", "'modifier'", ")", "{", "$", "breakChars", "=", "array", "(", "' '", ",", "','", ",", "')'", ",", "':'", ",", "'|'", ",", "\"\\r\"", ",", "\"\\n\"", ",", "\"\\t\"", ",", "\";\"", ",", "$", "this", "->", "rd", ")", ";", "}", "elseif", "(", "$", "curBlock", "===", "'expression'", ")", "{", "$", "breakChars", "=", "array", "(", "'/'", ",", "'%'", ",", "'+'", ",", "'-'", ",", "'*'", ",", "' '", ",", "','", ",", "')'", ",", "\"\\r\"", ",", "\"\\n\"", ",", "\"\\t\"", ",", "\";\"", ",", "$", "this", "->", "rd", ")", ";", "}", "else", "{", "$", "breakChars", "=", "array", "(", "' '", ",", "','", ",", "')'", ",", "\"\\r\"", ",", "\"\\n\"", ",", "\"\\t\"", ",", "\";\"", ",", "$", "this", "->", "rd", ")", ";", "}", "$", "breaker", "=", "false", ";", "while", "(", "list", "(", "$", "k", ",", "$", "char", ")", "=", "each", "(", "$", "breakChars", ")", ")", "{", "$", "test", "=", "strpos", "(", "$", "substr", ",", "$", "char", ")", ";", "if", "(", "$", "test", "!==", "false", "&&", "$", "test", "<", "$", "end", ")", "{", "$", "end", "=", "$", "test", ";", "$", "breaker", "=", "$", "k", ";", "}", "}", "if", "(", "$", "curBlock", "===", "'condition'", ")", "{", "if", "(", "$", "end", "===", "0", "&&", "$", "breaker", "!==", "false", ")", "{", "$", "end", "=", "strlen", "(", "$", "breakChars", "[", "$", "breaker", "]", ")", ";", "}", "}", "if", "(", "$", "end", "!==", "false", ")", "{", "$", "substr", "=", "substr", "(", "$", "substr", ",", "0", ",", "$", "end", ")", ";", "}", "if", "(", "$", "pointer", "!==", "null", ")", "{", "$", "pointer", "+=", "strlen", "(", "$", "substr", ")", ";", "}", "$", "src", "=", "$", "substr", ";", "$", "substr", "=", "trim", "(", "$", "substr", ")", ";", "if", "(", "strtolower", "(", "$", "substr", ")", "===", "'false'", "||", "strtolower", "(", "$", "substr", ")", "===", "'no'", "||", "strtolower", "(", "$", "substr", ")", "===", "'off'", ")", "{", "if", "(", "$", "this", "->", "debug", ")", "echo", "'BOOLEAN(FALSE) PARSED<br />'", ";", "$", "substr", "=", "'false'", ";", "}", "elseif", "(", "strtolower", "(", "$", "substr", ")", "===", "'true'", "||", "strtolower", "(", "$", "substr", ")", "===", "'yes'", "||", "strtolower", "(", "$", "substr", ")", "===", "'on'", ")", "{", "if", "(", "$", "this", "->", "debug", ")", "echo", "'BOOLEAN(TRUE) PARSED<br />'", ";", "$", "substr", "=", "'true'", ";", "}", "elseif", "(", "$", "substr", "===", "'null'", "||", "$", "substr", "===", "'NULL'", ")", "{", "if", "(", "$", "this", "->", "debug", ")", "echo", "'NULL PARSED<br />'", ";", "$", "substr", "=", "'null'", ";", "}", "elseif", "(", "is_numeric", "(", "$", "substr", ")", ")", "{", "$", "substr", "=", "(", "float", ")", "$", "substr", ";", "if", "(", "(", "int", ")", "$", "substr", "==", "$", "substr", ")", "{", "$", "substr", "=", "(", "int", ")", "$", "substr", ";", "}", "if", "(", "$", "this", "->", "debug", ")", "echo", "'NUMBER ('", ".", "$", "substr", ".", "') PARSED<br />'", ";", "}", "elseif", "(", "preg_match", "(", "'{^-?(\\d+|\\d*(\\.\\d+))\\s*([/*%+-]\\s*-?(\\d+|\\d*(\\.\\d+)))+$}'", ",", "$", "substr", ")", ")", "{", "if", "(", "$", "this", "->", "debug", ")", "echo", "'SIMPLE MATH PARSED<br />'", ";", "$", "substr", "=", "'('", ".", "$", "substr", ".", "')'", ";", "}", "elseif", "(", "$", "curBlock", "===", "'condition'", "&&", "array_search", "(", "$", "substr", ",", "$", "breakChars", ",", "true", ")", "!==", "false", ")", "{", "if", "(", "$", "this", "->", "debug", ")", "echo", "'BREAKCHAR ('", ".", "$", "substr", ".", "') PARSED<br />'", ";", "//$substr = '\"'.$substr.'\"';", "}", "else", "{", "$", "substr", "=", "$", "this", "->", "replaceStringVars", "(", "'\\''", ".", "str_replace", "(", "'\\''", ",", "'\\\\\\''", ",", "$", "substr", ")", ".", "'\\''", ",", "'\\''", ",", "$", "curBlock", ")", ";", "if", "(", "$", "this", "->", "debug", ")", "echo", "'BLABBER ('", ".", "$", "substr", ".", "') CASTED AS STRING<br />'", ";", "}", "if", "(", "is_array", "(", "$", "parsingParams", ")", ")", "{", "$", "parsingParams", "[", "]", "=", "array", "(", "$", "substr", ",", "$", "src", ")", ";", "return", "$", "parsingParams", ";", "}", "elseif", "(", "$", "curBlock", "===", "'namedparam'", ")", "{", "return", "array", "(", "$", "substr", ",", "$", "src", ")", ";", "}", "elseif", "(", "$", "curBlock", "===", "'expression'", ")", "{", "return", "$", "substr", ";", "}", "else", "{", "throw", "new", "Exception", "(", "'Something went wrong'", ")", ";", "}", "}" ]
parses various constants, operators or non-quoted strings @param string $in the string within which we must parse something @param int $from the starting offset of the parsed area @param int $to the ending offset of the parsed area @param mixed $parsingParams must be an array if we are parsing a function or modifier's parameters, or false by default @param string $curBlock the current parser-block being processed @param mixed $pointer a reference to a pointer that will be increased by the amount of characters parsed, or null by default @return string parsed values
[ "parses", "various", "constants", "operators", "or", "non", "-", "quoted", "strings" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php#L2455-L2535
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php
Dwoo_Compiler.replaceStringVars
protected function replaceStringVars($string, $first, $curBlock='') { $pos = 0; if ($this->debug) echo 'STRING VAR REPLACEMENT : '.$string.'<br>'; // replace vars while (($pos = strpos($string, '$', $pos)) !== false) { $prev = substr($string, $pos-1, 1); if ($prev === '\\') { $pos++; continue; } $var = $this->parse($string, $pos, null, false, ($curBlock === 'modifier' ? 'modifier' : ($prev === '`' ? 'delimited_string':'string'))); $len = $var[0]; $var = $this->parse(str_replace('\\'.$first, $first, $string), $pos, null, false, ($curBlock === 'modifier' ? 'modifier' : ($prev === '`' ? 'delimited_string':'string'))); if ($prev === '`' && substr($string, $pos+$len, 1) === '`') { $string = substr_replace($string, $first.'.'.$var[1].'.'.$first, $pos-1, $len+2); } else { $string = substr_replace($string, $first.'.'.$var[1].'.'.$first, $pos, $len); } $pos += strlen($var[1]) + 2; if ($this->debug) echo 'STRING VAR REPLACEMENT DONE : '.$string.'<br>'; } // handle modifiers // TODO Obsolete? $string = preg_replace_callback('#("|\')\.(.+?)\.\1((?:\|(?:@?[a-z0-9_]+(?:(?::("|\').+?\4|:[^`]*))*))+)#i', array($this, 'replaceModifiers'), $string); // replace escaped dollar operators by unescaped ones if required if ($first==="'") { $string = str_replace('\\$', '$', $string); } return $string; }
php
protected function replaceStringVars($string, $first, $curBlock='') { $pos = 0; if ($this->debug) echo 'STRING VAR REPLACEMENT : '.$string.'<br>'; // replace vars while (($pos = strpos($string, '$', $pos)) !== false) { $prev = substr($string, $pos-1, 1); if ($prev === '\\') { $pos++; continue; } $var = $this->parse($string, $pos, null, false, ($curBlock === 'modifier' ? 'modifier' : ($prev === '`' ? 'delimited_string':'string'))); $len = $var[0]; $var = $this->parse(str_replace('\\'.$first, $first, $string), $pos, null, false, ($curBlock === 'modifier' ? 'modifier' : ($prev === '`' ? 'delimited_string':'string'))); if ($prev === '`' && substr($string, $pos+$len, 1) === '`') { $string = substr_replace($string, $first.'.'.$var[1].'.'.$first, $pos-1, $len+2); } else { $string = substr_replace($string, $first.'.'.$var[1].'.'.$first, $pos, $len); } $pos += strlen($var[1]) + 2; if ($this->debug) echo 'STRING VAR REPLACEMENT DONE : '.$string.'<br>'; } // handle modifiers // TODO Obsolete? $string = preg_replace_callback('#("|\')\.(.+?)\.\1((?:\|(?:@?[a-z0-9_]+(?:(?::("|\').+?\4|:[^`]*))*))+)#i', array($this, 'replaceModifiers'), $string); // replace escaped dollar operators by unescaped ones if required if ($first==="'") { $string = str_replace('\\$', '$', $string); } return $string; }
[ "protected", "function", "replaceStringVars", "(", "$", "string", ",", "$", "first", ",", "$", "curBlock", "=", "''", ")", "{", "$", "pos", "=", "0", ";", "if", "(", "$", "this", "->", "debug", ")", "echo", "'STRING VAR REPLACEMENT : '", ".", "$", "string", ".", "'<br>'", ";", "// replace vars", "while", "(", "(", "$", "pos", "=", "strpos", "(", "$", "string", ",", "'$'", ",", "$", "pos", ")", ")", "!==", "false", ")", "{", "$", "prev", "=", "substr", "(", "$", "string", ",", "$", "pos", "-", "1", ",", "1", ")", ";", "if", "(", "$", "prev", "===", "'\\\\'", ")", "{", "$", "pos", "++", ";", "continue", ";", "}", "$", "var", "=", "$", "this", "->", "parse", "(", "$", "string", ",", "$", "pos", ",", "null", ",", "false", ",", "(", "$", "curBlock", "===", "'modifier'", "?", "'modifier'", ":", "(", "$", "prev", "===", "'`'", "?", "'delimited_string'", ":", "'string'", ")", ")", ")", ";", "$", "len", "=", "$", "var", "[", "0", "]", ";", "$", "var", "=", "$", "this", "->", "parse", "(", "str_replace", "(", "'\\\\'", ".", "$", "first", ",", "$", "first", ",", "$", "string", ")", ",", "$", "pos", ",", "null", ",", "false", ",", "(", "$", "curBlock", "===", "'modifier'", "?", "'modifier'", ":", "(", "$", "prev", "===", "'`'", "?", "'delimited_string'", ":", "'string'", ")", ")", ")", ";", "if", "(", "$", "prev", "===", "'`'", "&&", "substr", "(", "$", "string", ",", "$", "pos", "+", "$", "len", ",", "1", ")", "===", "'`'", ")", "{", "$", "string", "=", "substr_replace", "(", "$", "string", ",", "$", "first", ".", "'.'", ".", "$", "var", "[", "1", "]", ".", "'.'", ".", "$", "first", ",", "$", "pos", "-", "1", ",", "$", "len", "+", "2", ")", ";", "}", "else", "{", "$", "string", "=", "substr_replace", "(", "$", "string", ",", "$", "first", ".", "'.'", ".", "$", "var", "[", "1", "]", ".", "'.'", ".", "$", "first", ",", "$", "pos", ",", "$", "len", ")", ";", "}", "$", "pos", "+=", "strlen", "(", "$", "var", "[", "1", "]", ")", "+", "2", ";", "if", "(", "$", "this", "->", "debug", ")", "echo", "'STRING VAR REPLACEMENT DONE : '", ".", "$", "string", ".", "'<br>'", ";", "}", "// handle modifiers", "// TODO Obsolete?", "$", "string", "=", "preg_replace_callback", "(", "'#(\"|\\')\\.(.+?)\\.\\1((?:\\|(?:@?[a-z0-9_]+(?:(?::(\"|\\').+?\\4|:[^`]*))*))+)#i'", ",", "array", "(", "$", "this", ",", "'replaceModifiers'", ")", ",", "$", "string", ")", ";", "// replace escaped dollar operators by unescaped ones if required", "if", "(", "$", "first", "===", "\"'\"", ")", "{", "$", "string", "=", "str_replace", "(", "'\\\\$'", ",", "'$'", ",", "$", "string", ")", ";", "}", "return", "$", "string", ";", "}" ]
replaces variables within a parsed string @param string $string the parsed string @param string $first the first character parsed in the string, which is the string delimiter (' or ") @param string $curBlock the current parser-block being processed @return string the original string with variables replaced
[ "replaces", "variables", "within", "a", "parsed", "string" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php#L2545-L2580
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php
Dwoo_Compiler.replaceModifiers
protected function replaceModifiers(array $m, $curBlock = null, &$pointer = null) { if ($this->debug) echo 'PARSING MODIFIERS : '.$m[3].'<br />'; if ($pointer !== null) { $pointer += strlen($m[3]); } // remove first pipe $cmdstrsrc = substr($m[3], 1); // remove last quote if present if (substr($cmdstrsrc, -1, 1) === $m[1]) { $cmdstrsrc = substr($cmdstrsrc, 0, -1); $add = $m[1]; } $output = $m[2]; $continue = true; while (strlen($cmdstrsrc) > 0 && $continue) { if ($cmdstrsrc[0] === '|') { $cmdstrsrc = substr($cmdstrsrc, 1); continue; } if ($cmdstrsrc[0] === ' ' || $cmdstrsrc[0] === ';' || substr($cmdstrsrc, 0, strlen($this->rd)) === $this->rd) { if ($this->debug) echo 'MODIFIER PARSING ENDED, RIGHT DELIMITER or ";" FOUND<br/>'; $continue = false; if ($pointer !== null) { $pointer -= strlen($cmdstrsrc); } break; } $cmdstr = $cmdstrsrc; $paramsep = ':'; if (!preg_match('/^(@{0,2}[a-z][a-z0-9_]*)(:)?/i', $cmdstr, $match)) { throw new Dwoo_Compilation_Exception($this, 'Invalid modifier name, started with : '.substr($cmdstr, 0, 10)); } $paramspos = !empty($match[2]) ? strlen($match[1]) : false; $func = $match[1]; $state = 0; if ($paramspos === false) { $cmdstrsrc = substr($cmdstrsrc, strlen($func)); $params = array(); if ($this->debug) echo 'MODIFIER ('.$func.') CALLED WITH NO PARAMS<br/>'; } else { $paramstr = substr($cmdstr, $paramspos+1); if (substr($paramstr, -1, 1) === $paramsep) { $paramstr = substr($paramstr, 0, -1); } $ptr = 0; $params = array(); while ($ptr < strlen($paramstr)) { if ($this->debug) echo 'MODIFIER ('.$func.') START PARAM PARSING WITH POINTER AT '.$ptr.'<br/>'; if ($this->debug) echo $paramstr.'--'.$ptr.'--'.strlen($paramstr).'--modifier<br/>'; $params = $this->parse($paramstr, $ptr, strlen($paramstr), $params, 'modifier', $ptr); if ($this->debug) echo 'PARAM PARSED, POINTER AT '.$ptr.'<br/>'; if ($ptr >= strlen($paramstr)) { if ($this->debug) echo 'PARAM PARSING ENDED, PARAM STRING CONSUMED<br/>'; break; } if ($paramstr[$ptr] === ' ' || $paramstr[$ptr] === '|' || $paramstr[$ptr] === ';' || substr($paramstr, $ptr, strlen($this->rd)) === $this->rd) { if ($this->debug) echo 'PARAM PARSING ENDED, " ", "|", RIGHT DELIMITER or ";" FOUND, POINTER AT '.$ptr.'<br/>'; if ($paramstr[$ptr] !== '|') { $continue = false; if ($pointer !== null) { $pointer -= strlen($paramstr) - $ptr; } } $ptr++; break; } if ($ptr < strlen($paramstr) && $paramstr[$ptr] === ':') { $ptr++; } } $cmdstrsrc = substr($cmdstrsrc, strlen($func)+1+$ptr); $paramstr = substr($paramstr, 0, $ptr); foreach ($params as $k=>$p) { if (is_array($p) && is_array($p[1])) { $state |= 2; } else { if (($state & 2) && preg_match('#^(["\'])(.+?)\1$#', $p[0], $m)) { $params[$k] = array($m[2], array('true', 'true')); } else { if ($state & 2) { throw new Dwoo_Compilation_Exception($this, 'You can not use an unnamed parameter after a named one'); } $state |= 1; } } } } // check if we must use array_map with this plugin or not $mapped = false; if (substr($func, 0, 1) === '@') { $func = substr($func, 1); $mapped = true; } $pluginType = $this->getPluginType($func); if ($state & 2) { array_unshift($params, array('value', array($output, $output))); } else { array_unshift($params, array($output, $output)); } if ($pluginType & Dwoo::NATIVE_PLUGIN) { $params = $this->mapParams($params, null, $state); $params = $params['*'][0]; $params = self::implode_r($params); if ($mapped) { $output = '$this->arrayMap(\''.$func.'\', array('.$params.'))'; } else { $output = $func.'('.$params.')'; } } elseif ($pluginType & Dwoo::PROXY_PLUGIN) { $params = $this->mapParams($params, $this->getDwoo()->getPluginProxy()->getCallback($func), $state); foreach ($params as &$p) $p = $p[0]; $output = call_user_func(array($this->dwoo->getPluginProxy(), 'getCode'), $func, $params); } elseif ($pluginType & Dwoo::SMARTY_MODIFIER) { $params = $this->mapParams($params, null, $state); $params = $params['*'][0]; $params = self::implode_r($params); if ($pluginType & Dwoo::CUSTOM_PLUGIN) { $callback = $this->customPlugins[$func]['callback']; if (is_array($callback)) { if (is_object($callback[0])) { $output = ($mapped ? '$this->arrayMap' : 'call_user_func_array').'(array($this->plugins[\''.$func.'\'][\'callback\'][0], \''.$callback[1].'\'), array('.$params.'))'; } else { $output = ($mapped ? '$this->arrayMap' : 'call_user_func_array').'(array(\''.$callback[0].'\', \''.$callback[1].'\'), array('.$params.'))'; } } elseif ($mapped) { $output = '$this->arrayMap(\''.$callback.'\', array('.$params.'))'; } else { $output = $callback.'('.$params.')'; } } elseif ($mapped) { $output = '$this->arrayMap(\'smarty_modifier_'.$func.'\', array('.$params.'))'; } else { $output = 'smarty_modifier_'.$func.'('.$params.')'; } } else { if ($pluginType & Dwoo::CUSTOM_PLUGIN) { $callback = $this->customPlugins[$func]['callback']; $pluginName = $callback; } else { $pluginName = 'Dwoo_Plugin_'.$func; if ($pluginType & Dwoo::CLASS_PLUGIN) { $callback = array($pluginName, ($pluginType & Dwoo::COMPILABLE_PLUGIN) ? 'compile' : 'process'); } else { $callback = $pluginName . (($pluginType & Dwoo::COMPILABLE_PLUGIN) ? '_compile' : ''); } } $params = $this->mapParams($params, $callback, $state); foreach ($params as &$p) $p = $p[0]; if ($pluginType & Dwoo::FUNC_PLUGIN) { if ($pluginType & Dwoo::COMPILABLE_PLUGIN) { if ($mapped) { throw new Dwoo_Compilation_Exception($this, 'The @ operator can not be used on compiled plugins.'); } if ($pluginType & Dwoo::CUSTOM_PLUGIN) { $funcCompiler = $this->customPlugins[$func]['callback']; } else { $funcCompiler = 'Dwoo_Plugin_'.$func.'_compile'; } array_unshift($params, $this); $output = call_user_func_array($funcCompiler, $params); } else { array_unshift($params, '$this'); $params = self::implode_r($params); if ($mapped) { $output = '$this->arrayMap(\''.$pluginName.'\', array('.$params.'))'; } else { $output = $pluginName.'('.$params.')'; } } } else { if ($pluginType & Dwoo::COMPILABLE_PLUGIN) { if ($mapped) { throw new Dwoo_Compilation_Exception($this, 'The @ operator can not be used on compiled plugins.'); } if ($pluginType & Dwoo::CUSTOM_PLUGIN) { $callback = $this->customPlugins[$func]['callback']; if (!is_array($callback)) { if (!method_exists($callback, 'compile')) { throw new Dwoo_Exception('Custom plugin '.$func.' must implement the "compile" method to be compilable, or you should provide a full callback to the method to use'); } if (($ref = new ReflectionMethod($callback, 'compile')) && $ref->isStatic()) { $funcCompiler = array($callback, 'compile'); } else { $funcCompiler = array(new $callback, 'compile'); } } else { $funcCompiler = $callback; } } else { $funcCompiler = array('Dwoo_Plugin_'.$func, 'compile'); array_unshift($params, $this); } $output = call_user_func_array($funcCompiler, $params); } else { $params = self::implode_r($params); if ($pluginType & Dwoo::CUSTOM_PLUGIN) { if (is_object($callback[0])) { $output = ($mapped ? '$this->arrayMap' : 'call_user_func_array').'(array($this->plugins[\''.$func.'\'][\'callback\'][0], \''.$callback[1].'\'), array('.$params.'))'; } else { $output = ($mapped ? '$this->arrayMap' : 'call_user_func_array').'(array(\''.$callback[0].'\', \''.$callback[1].'\'), array('.$params.'))'; } } elseif ($mapped) { $output = '$this->arrayMap(array($this->getObjectPlugin(\'Dwoo_Plugin_'.$func.'\'), \'process\'), array('.$params.'))'; } else { $output = '$this->classCall(\''.$func.'\', array('.$params.'))'; } } } } } if ($curBlock === 'var' || $m[1] === null) { return $output; } elseif ($curBlock === 'string' || $curBlock === 'root') { return $m[1].'.'.$output.'.'.$m[1].(isset($add)?$add:null); } }
php
protected function replaceModifiers(array $m, $curBlock = null, &$pointer = null) { if ($this->debug) echo 'PARSING MODIFIERS : '.$m[3].'<br />'; if ($pointer !== null) { $pointer += strlen($m[3]); } // remove first pipe $cmdstrsrc = substr($m[3], 1); // remove last quote if present if (substr($cmdstrsrc, -1, 1) === $m[1]) { $cmdstrsrc = substr($cmdstrsrc, 0, -1); $add = $m[1]; } $output = $m[2]; $continue = true; while (strlen($cmdstrsrc) > 0 && $continue) { if ($cmdstrsrc[0] === '|') { $cmdstrsrc = substr($cmdstrsrc, 1); continue; } if ($cmdstrsrc[0] === ' ' || $cmdstrsrc[0] === ';' || substr($cmdstrsrc, 0, strlen($this->rd)) === $this->rd) { if ($this->debug) echo 'MODIFIER PARSING ENDED, RIGHT DELIMITER or ";" FOUND<br/>'; $continue = false; if ($pointer !== null) { $pointer -= strlen($cmdstrsrc); } break; } $cmdstr = $cmdstrsrc; $paramsep = ':'; if (!preg_match('/^(@{0,2}[a-z][a-z0-9_]*)(:)?/i', $cmdstr, $match)) { throw new Dwoo_Compilation_Exception($this, 'Invalid modifier name, started with : '.substr($cmdstr, 0, 10)); } $paramspos = !empty($match[2]) ? strlen($match[1]) : false; $func = $match[1]; $state = 0; if ($paramspos === false) { $cmdstrsrc = substr($cmdstrsrc, strlen($func)); $params = array(); if ($this->debug) echo 'MODIFIER ('.$func.') CALLED WITH NO PARAMS<br/>'; } else { $paramstr = substr($cmdstr, $paramspos+1); if (substr($paramstr, -1, 1) === $paramsep) { $paramstr = substr($paramstr, 0, -1); } $ptr = 0; $params = array(); while ($ptr < strlen($paramstr)) { if ($this->debug) echo 'MODIFIER ('.$func.') START PARAM PARSING WITH POINTER AT '.$ptr.'<br/>'; if ($this->debug) echo $paramstr.'--'.$ptr.'--'.strlen($paramstr).'--modifier<br/>'; $params = $this->parse($paramstr, $ptr, strlen($paramstr), $params, 'modifier', $ptr); if ($this->debug) echo 'PARAM PARSED, POINTER AT '.$ptr.'<br/>'; if ($ptr >= strlen($paramstr)) { if ($this->debug) echo 'PARAM PARSING ENDED, PARAM STRING CONSUMED<br/>'; break; } if ($paramstr[$ptr] === ' ' || $paramstr[$ptr] === '|' || $paramstr[$ptr] === ';' || substr($paramstr, $ptr, strlen($this->rd)) === $this->rd) { if ($this->debug) echo 'PARAM PARSING ENDED, " ", "|", RIGHT DELIMITER or ";" FOUND, POINTER AT '.$ptr.'<br/>'; if ($paramstr[$ptr] !== '|') { $continue = false; if ($pointer !== null) { $pointer -= strlen($paramstr) - $ptr; } } $ptr++; break; } if ($ptr < strlen($paramstr) && $paramstr[$ptr] === ':') { $ptr++; } } $cmdstrsrc = substr($cmdstrsrc, strlen($func)+1+$ptr); $paramstr = substr($paramstr, 0, $ptr); foreach ($params as $k=>$p) { if (is_array($p) && is_array($p[1])) { $state |= 2; } else { if (($state & 2) && preg_match('#^(["\'])(.+?)\1$#', $p[0], $m)) { $params[$k] = array($m[2], array('true', 'true')); } else { if ($state & 2) { throw new Dwoo_Compilation_Exception($this, 'You can not use an unnamed parameter after a named one'); } $state |= 1; } } } } // check if we must use array_map with this plugin or not $mapped = false; if (substr($func, 0, 1) === '@') { $func = substr($func, 1); $mapped = true; } $pluginType = $this->getPluginType($func); if ($state & 2) { array_unshift($params, array('value', array($output, $output))); } else { array_unshift($params, array($output, $output)); } if ($pluginType & Dwoo::NATIVE_PLUGIN) { $params = $this->mapParams($params, null, $state); $params = $params['*'][0]; $params = self::implode_r($params); if ($mapped) { $output = '$this->arrayMap(\''.$func.'\', array('.$params.'))'; } else { $output = $func.'('.$params.')'; } } elseif ($pluginType & Dwoo::PROXY_PLUGIN) { $params = $this->mapParams($params, $this->getDwoo()->getPluginProxy()->getCallback($func), $state); foreach ($params as &$p) $p = $p[0]; $output = call_user_func(array($this->dwoo->getPluginProxy(), 'getCode'), $func, $params); } elseif ($pluginType & Dwoo::SMARTY_MODIFIER) { $params = $this->mapParams($params, null, $state); $params = $params['*'][0]; $params = self::implode_r($params); if ($pluginType & Dwoo::CUSTOM_PLUGIN) { $callback = $this->customPlugins[$func]['callback']; if (is_array($callback)) { if (is_object($callback[0])) { $output = ($mapped ? '$this->arrayMap' : 'call_user_func_array').'(array($this->plugins[\''.$func.'\'][\'callback\'][0], \''.$callback[1].'\'), array('.$params.'))'; } else { $output = ($mapped ? '$this->arrayMap' : 'call_user_func_array').'(array(\''.$callback[0].'\', \''.$callback[1].'\'), array('.$params.'))'; } } elseif ($mapped) { $output = '$this->arrayMap(\''.$callback.'\', array('.$params.'))'; } else { $output = $callback.'('.$params.')'; } } elseif ($mapped) { $output = '$this->arrayMap(\'smarty_modifier_'.$func.'\', array('.$params.'))'; } else { $output = 'smarty_modifier_'.$func.'('.$params.')'; } } else { if ($pluginType & Dwoo::CUSTOM_PLUGIN) { $callback = $this->customPlugins[$func]['callback']; $pluginName = $callback; } else { $pluginName = 'Dwoo_Plugin_'.$func; if ($pluginType & Dwoo::CLASS_PLUGIN) { $callback = array($pluginName, ($pluginType & Dwoo::COMPILABLE_PLUGIN) ? 'compile' : 'process'); } else { $callback = $pluginName . (($pluginType & Dwoo::COMPILABLE_PLUGIN) ? '_compile' : ''); } } $params = $this->mapParams($params, $callback, $state); foreach ($params as &$p) $p = $p[0]; if ($pluginType & Dwoo::FUNC_PLUGIN) { if ($pluginType & Dwoo::COMPILABLE_PLUGIN) { if ($mapped) { throw new Dwoo_Compilation_Exception($this, 'The @ operator can not be used on compiled plugins.'); } if ($pluginType & Dwoo::CUSTOM_PLUGIN) { $funcCompiler = $this->customPlugins[$func]['callback']; } else { $funcCompiler = 'Dwoo_Plugin_'.$func.'_compile'; } array_unshift($params, $this); $output = call_user_func_array($funcCompiler, $params); } else { array_unshift($params, '$this'); $params = self::implode_r($params); if ($mapped) { $output = '$this->arrayMap(\''.$pluginName.'\', array('.$params.'))'; } else { $output = $pluginName.'('.$params.')'; } } } else { if ($pluginType & Dwoo::COMPILABLE_PLUGIN) { if ($mapped) { throw new Dwoo_Compilation_Exception($this, 'The @ operator can not be used on compiled plugins.'); } if ($pluginType & Dwoo::CUSTOM_PLUGIN) { $callback = $this->customPlugins[$func]['callback']; if (!is_array($callback)) { if (!method_exists($callback, 'compile')) { throw new Dwoo_Exception('Custom plugin '.$func.' must implement the "compile" method to be compilable, or you should provide a full callback to the method to use'); } if (($ref = new ReflectionMethod($callback, 'compile')) && $ref->isStatic()) { $funcCompiler = array($callback, 'compile'); } else { $funcCompiler = array(new $callback, 'compile'); } } else { $funcCompiler = $callback; } } else { $funcCompiler = array('Dwoo_Plugin_'.$func, 'compile'); array_unshift($params, $this); } $output = call_user_func_array($funcCompiler, $params); } else { $params = self::implode_r($params); if ($pluginType & Dwoo::CUSTOM_PLUGIN) { if (is_object($callback[0])) { $output = ($mapped ? '$this->arrayMap' : 'call_user_func_array').'(array($this->plugins[\''.$func.'\'][\'callback\'][0], \''.$callback[1].'\'), array('.$params.'))'; } else { $output = ($mapped ? '$this->arrayMap' : 'call_user_func_array').'(array(\''.$callback[0].'\', \''.$callback[1].'\'), array('.$params.'))'; } } elseif ($mapped) { $output = '$this->arrayMap(array($this->getObjectPlugin(\'Dwoo_Plugin_'.$func.'\'), \'process\'), array('.$params.'))'; } else { $output = '$this->classCall(\''.$func.'\', array('.$params.'))'; } } } } } if ($curBlock === 'var' || $m[1] === null) { return $output; } elseif ($curBlock === 'string' || $curBlock === 'root') { return $m[1].'.'.$output.'.'.$m[1].(isset($add)?$add:null); } }
[ "protected", "function", "replaceModifiers", "(", "array", "$", "m", ",", "$", "curBlock", "=", "null", ",", "&", "$", "pointer", "=", "null", ")", "{", "if", "(", "$", "this", "->", "debug", ")", "echo", "'PARSING MODIFIERS : '", ".", "$", "m", "[", "3", "]", ".", "'<br />'", ";", "if", "(", "$", "pointer", "!==", "null", ")", "{", "$", "pointer", "+=", "strlen", "(", "$", "m", "[", "3", "]", ")", ";", "}", "// remove first pipe", "$", "cmdstrsrc", "=", "substr", "(", "$", "m", "[", "3", "]", ",", "1", ")", ";", "// remove last quote if present", "if", "(", "substr", "(", "$", "cmdstrsrc", ",", "-", "1", ",", "1", ")", "===", "$", "m", "[", "1", "]", ")", "{", "$", "cmdstrsrc", "=", "substr", "(", "$", "cmdstrsrc", ",", "0", ",", "-", "1", ")", ";", "$", "add", "=", "$", "m", "[", "1", "]", ";", "}", "$", "output", "=", "$", "m", "[", "2", "]", ";", "$", "continue", "=", "true", ";", "while", "(", "strlen", "(", "$", "cmdstrsrc", ")", ">", "0", "&&", "$", "continue", ")", "{", "if", "(", "$", "cmdstrsrc", "[", "0", "]", "===", "'|'", ")", "{", "$", "cmdstrsrc", "=", "substr", "(", "$", "cmdstrsrc", ",", "1", ")", ";", "continue", ";", "}", "if", "(", "$", "cmdstrsrc", "[", "0", "]", "===", "' '", "||", "$", "cmdstrsrc", "[", "0", "]", "===", "';'", "||", "substr", "(", "$", "cmdstrsrc", ",", "0", ",", "strlen", "(", "$", "this", "->", "rd", ")", ")", "===", "$", "this", "->", "rd", ")", "{", "if", "(", "$", "this", "->", "debug", ")", "echo", "'MODIFIER PARSING ENDED, RIGHT DELIMITER or \";\" FOUND<br/>'", ";", "$", "continue", "=", "false", ";", "if", "(", "$", "pointer", "!==", "null", ")", "{", "$", "pointer", "-=", "strlen", "(", "$", "cmdstrsrc", ")", ";", "}", "break", ";", "}", "$", "cmdstr", "=", "$", "cmdstrsrc", ";", "$", "paramsep", "=", "':'", ";", "if", "(", "!", "preg_match", "(", "'/^(@{0,2}[a-z][a-z0-9_]*)(:)?/i'", ",", "$", "cmdstr", ",", "$", "match", ")", ")", "{", "throw", "new", "Dwoo_Compilation_Exception", "(", "$", "this", ",", "'Invalid modifier name, started with : '", ".", "substr", "(", "$", "cmdstr", ",", "0", ",", "10", ")", ")", ";", "}", "$", "paramspos", "=", "!", "empty", "(", "$", "match", "[", "2", "]", ")", "?", "strlen", "(", "$", "match", "[", "1", "]", ")", ":", "false", ";", "$", "func", "=", "$", "match", "[", "1", "]", ";", "$", "state", "=", "0", ";", "if", "(", "$", "paramspos", "===", "false", ")", "{", "$", "cmdstrsrc", "=", "substr", "(", "$", "cmdstrsrc", ",", "strlen", "(", "$", "func", ")", ")", ";", "$", "params", "=", "array", "(", ")", ";", "if", "(", "$", "this", "->", "debug", ")", "echo", "'MODIFIER ('", ".", "$", "func", ".", "') CALLED WITH NO PARAMS<br/>'", ";", "}", "else", "{", "$", "paramstr", "=", "substr", "(", "$", "cmdstr", ",", "$", "paramspos", "+", "1", ")", ";", "if", "(", "substr", "(", "$", "paramstr", ",", "-", "1", ",", "1", ")", "===", "$", "paramsep", ")", "{", "$", "paramstr", "=", "substr", "(", "$", "paramstr", ",", "0", ",", "-", "1", ")", ";", "}", "$", "ptr", "=", "0", ";", "$", "params", "=", "array", "(", ")", ";", "while", "(", "$", "ptr", "<", "strlen", "(", "$", "paramstr", ")", ")", "{", "if", "(", "$", "this", "->", "debug", ")", "echo", "'MODIFIER ('", ".", "$", "func", ".", "') START PARAM PARSING WITH POINTER AT '", ".", "$", "ptr", ".", "'<br/>'", ";", "if", "(", "$", "this", "->", "debug", ")", "echo", "$", "paramstr", ".", "'--'", ".", "$", "ptr", ".", "'--'", ".", "strlen", "(", "$", "paramstr", ")", ".", "'--modifier<br/>'", ";", "$", "params", "=", "$", "this", "->", "parse", "(", "$", "paramstr", ",", "$", "ptr", ",", "strlen", "(", "$", "paramstr", ")", ",", "$", "params", ",", "'modifier'", ",", "$", "ptr", ")", ";", "if", "(", "$", "this", "->", "debug", ")", "echo", "'PARAM PARSED, POINTER AT '", ".", "$", "ptr", ".", "'<br/>'", ";", "if", "(", "$", "ptr", ">=", "strlen", "(", "$", "paramstr", ")", ")", "{", "if", "(", "$", "this", "->", "debug", ")", "echo", "'PARAM PARSING ENDED, PARAM STRING CONSUMED<br/>'", ";", "break", ";", "}", "if", "(", "$", "paramstr", "[", "$", "ptr", "]", "===", "' '", "||", "$", "paramstr", "[", "$", "ptr", "]", "===", "'|'", "||", "$", "paramstr", "[", "$", "ptr", "]", "===", "';'", "||", "substr", "(", "$", "paramstr", ",", "$", "ptr", ",", "strlen", "(", "$", "this", "->", "rd", ")", ")", "===", "$", "this", "->", "rd", ")", "{", "if", "(", "$", "this", "->", "debug", ")", "echo", "'PARAM PARSING ENDED, \" \", \"|\", RIGHT DELIMITER or \";\" FOUND, POINTER AT '", ".", "$", "ptr", ".", "'<br/>'", ";", "if", "(", "$", "paramstr", "[", "$", "ptr", "]", "!==", "'|'", ")", "{", "$", "continue", "=", "false", ";", "if", "(", "$", "pointer", "!==", "null", ")", "{", "$", "pointer", "-=", "strlen", "(", "$", "paramstr", ")", "-", "$", "ptr", ";", "}", "}", "$", "ptr", "++", ";", "break", ";", "}", "if", "(", "$", "ptr", "<", "strlen", "(", "$", "paramstr", ")", "&&", "$", "paramstr", "[", "$", "ptr", "]", "===", "':'", ")", "{", "$", "ptr", "++", ";", "}", "}", "$", "cmdstrsrc", "=", "substr", "(", "$", "cmdstrsrc", ",", "strlen", "(", "$", "func", ")", "+", "1", "+", "$", "ptr", ")", ";", "$", "paramstr", "=", "substr", "(", "$", "paramstr", ",", "0", ",", "$", "ptr", ")", ";", "foreach", "(", "$", "params", "as", "$", "k", "=>", "$", "p", ")", "{", "if", "(", "is_array", "(", "$", "p", ")", "&&", "is_array", "(", "$", "p", "[", "1", "]", ")", ")", "{", "$", "state", "|=", "2", ";", "}", "else", "{", "if", "(", "(", "$", "state", "&", "2", ")", "&&", "preg_match", "(", "'#^([\"\\'])(.+?)\\1$#'", ",", "$", "p", "[", "0", "]", ",", "$", "m", ")", ")", "{", "$", "params", "[", "$", "k", "]", "=", "array", "(", "$", "m", "[", "2", "]", ",", "array", "(", "'true'", ",", "'true'", ")", ")", ";", "}", "else", "{", "if", "(", "$", "state", "&", "2", ")", "{", "throw", "new", "Dwoo_Compilation_Exception", "(", "$", "this", ",", "'You can not use an unnamed parameter after a named one'", ")", ";", "}", "$", "state", "|=", "1", ";", "}", "}", "}", "}", "// check if we must use array_map with this plugin or not", "$", "mapped", "=", "false", ";", "if", "(", "substr", "(", "$", "func", ",", "0", ",", "1", ")", "===", "'@'", ")", "{", "$", "func", "=", "substr", "(", "$", "func", ",", "1", ")", ";", "$", "mapped", "=", "true", ";", "}", "$", "pluginType", "=", "$", "this", "->", "getPluginType", "(", "$", "func", ")", ";", "if", "(", "$", "state", "&", "2", ")", "{", "array_unshift", "(", "$", "params", ",", "array", "(", "'value'", ",", "array", "(", "$", "output", ",", "$", "output", ")", ")", ")", ";", "}", "else", "{", "array_unshift", "(", "$", "params", ",", "array", "(", "$", "output", ",", "$", "output", ")", ")", ";", "}", "if", "(", "$", "pluginType", "&", "Dwoo", "::", "NATIVE_PLUGIN", ")", "{", "$", "params", "=", "$", "this", "->", "mapParams", "(", "$", "params", ",", "null", ",", "$", "state", ")", ";", "$", "params", "=", "$", "params", "[", "'*'", "]", "[", "0", "]", ";", "$", "params", "=", "self", "::", "implode_r", "(", "$", "params", ")", ";", "if", "(", "$", "mapped", ")", "{", "$", "output", "=", "'$this->arrayMap(\\''", ".", "$", "func", ".", "'\\', array('", ".", "$", "params", ".", "'))'", ";", "}", "else", "{", "$", "output", "=", "$", "func", ".", "'('", ".", "$", "params", ".", "')'", ";", "}", "}", "elseif", "(", "$", "pluginType", "&", "Dwoo", "::", "PROXY_PLUGIN", ")", "{", "$", "params", "=", "$", "this", "->", "mapParams", "(", "$", "params", ",", "$", "this", "->", "getDwoo", "(", ")", "->", "getPluginProxy", "(", ")", "->", "getCallback", "(", "$", "func", ")", ",", "$", "state", ")", ";", "foreach", "(", "$", "params", "as", "&", "$", "p", ")", "$", "p", "=", "$", "p", "[", "0", "]", ";", "$", "output", "=", "call_user_func", "(", "array", "(", "$", "this", "->", "dwoo", "->", "getPluginProxy", "(", ")", ",", "'getCode'", ")", ",", "$", "func", ",", "$", "params", ")", ";", "}", "elseif", "(", "$", "pluginType", "&", "Dwoo", "::", "SMARTY_MODIFIER", ")", "{", "$", "params", "=", "$", "this", "->", "mapParams", "(", "$", "params", ",", "null", ",", "$", "state", ")", ";", "$", "params", "=", "$", "params", "[", "'*'", "]", "[", "0", "]", ";", "$", "params", "=", "self", "::", "implode_r", "(", "$", "params", ")", ";", "if", "(", "$", "pluginType", "&", "Dwoo", "::", "CUSTOM_PLUGIN", ")", "{", "$", "callback", "=", "$", "this", "->", "customPlugins", "[", "$", "func", "]", "[", "'callback'", "]", ";", "if", "(", "is_array", "(", "$", "callback", ")", ")", "{", "if", "(", "is_object", "(", "$", "callback", "[", "0", "]", ")", ")", "{", "$", "output", "=", "(", "$", "mapped", "?", "'$this->arrayMap'", ":", "'call_user_func_array'", ")", ".", "'(array($this->plugins[\\''", ".", "$", "func", ".", "'\\'][\\'callback\\'][0], \\''", ".", "$", "callback", "[", "1", "]", ".", "'\\'), array('", ".", "$", "params", ".", "'))'", ";", "}", "else", "{", "$", "output", "=", "(", "$", "mapped", "?", "'$this->arrayMap'", ":", "'call_user_func_array'", ")", ".", "'(array(\\''", ".", "$", "callback", "[", "0", "]", ".", "'\\', \\''", ".", "$", "callback", "[", "1", "]", ".", "'\\'), array('", ".", "$", "params", ".", "'))'", ";", "}", "}", "elseif", "(", "$", "mapped", ")", "{", "$", "output", "=", "'$this->arrayMap(\\''", ".", "$", "callback", ".", "'\\', array('", ".", "$", "params", ".", "'))'", ";", "}", "else", "{", "$", "output", "=", "$", "callback", ".", "'('", ".", "$", "params", ".", "')'", ";", "}", "}", "elseif", "(", "$", "mapped", ")", "{", "$", "output", "=", "'$this->arrayMap(\\'smarty_modifier_'", ".", "$", "func", ".", "'\\', array('", ".", "$", "params", ".", "'))'", ";", "}", "else", "{", "$", "output", "=", "'smarty_modifier_'", ".", "$", "func", ".", "'('", ".", "$", "params", ".", "')'", ";", "}", "}", "else", "{", "if", "(", "$", "pluginType", "&", "Dwoo", "::", "CUSTOM_PLUGIN", ")", "{", "$", "callback", "=", "$", "this", "->", "customPlugins", "[", "$", "func", "]", "[", "'callback'", "]", ";", "$", "pluginName", "=", "$", "callback", ";", "}", "else", "{", "$", "pluginName", "=", "'Dwoo_Plugin_'", ".", "$", "func", ";", "if", "(", "$", "pluginType", "&", "Dwoo", "::", "CLASS_PLUGIN", ")", "{", "$", "callback", "=", "array", "(", "$", "pluginName", ",", "(", "$", "pluginType", "&", "Dwoo", "::", "COMPILABLE_PLUGIN", ")", "?", "'compile'", ":", "'process'", ")", ";", "}", "else", "{", "$", "callback", "=", "$", "pluginName", ".", "(", "(", "$", "pluginType", "&", "Dwoo", "::", "COMPILABLE_PLUGIN", ")", "?", "'_compile'", ":", "''", ")", ";", "}", "}", "$", "params", "=", "$", "this", "->", "mapParams", "(", "$", "params", ",", "$", "callback", ",", "$", "state", ")", ";", "foreach", "(", "$", "params", "as", "&", "$", "p", ")", "$", "p", "=", "$", "p", "[", "0", "]", ";", "if", "(", "$", "pluginType", "&", "Dwoo", "::", "FUNC_PLUGIN", ")", "{", "if", "(", "$", "pluginType", "&", "Dwoo", "::", "COMPILABLE_PLUGIN", ")", "{", "if", "(", "$", "mapped", ")", "{", "throw", "new", "Dwoo_Compilation_Exception", "(", "$", "this", ",", "'The @ operator can not be used on compiled plugins.'", ")", ";", "}", "if", "(", "$", "pluginType", "&", "Dwoo", "::", "CUSTOM_PLUGIN", ")", "{", "$", "funcCompiler", "=", "$", "this", "->", "customPlugins", "[", "$", "func", "]", "[", "'callback'", "]", ";", "}", "else", "{", "$", "funcCompiler", "=", "'Dwoo_Plugin_'", ".", "$", "func", ".", "'_compile'", ";", "}", "array_unshift", "(", "$", "params", ",", "$", "this", ")", ";", "$", "output", "=", "call_user_func_array", "(", "$", "funcCompiler", ",", "$", "params", ")", ";", "}", "else", "{", "array_unshift", "(", "$", "params", ",", "'$this'", ")", ";", "$", "params", "=", "self", "::", "implode_r", "(", "$", "params", ")", ";", "if", "(", "$", "mapped", ")", "{", "$", "output", "=", "'$this->arrayMap(\\''", ".", "$", "pluginName", ".", "'\\', array('", ".", "$", "params", ".", "'))'", ";", "}", "else", "{", "$", "output", "=", "$", "pluginName", ".", "'('", ".", "$", "params", ".", "')'", ";", "}", "}", "}", "else", "{", "if", "(", "$", "pluginType", "&", "Dwoo", "::", "COMPILABLE_PLUGIN", ")", "{", "if", "(", "$", "mapped", ")", "{", "throw", "new", "Dwoo_Compilation_Exception", "(", "$", "this", ",", "'The @ operator can not be used on compiled plugins.'", ")", ";", "}", "if", "(", "$", "pluginType", "&", "Dwoo", "::", "CUSTOM_PLUGIN", ")", "{", "$", "callback", "=", "$", "this", "->", "customPlugins", "[", "$", "func", "]", "[", "'callback'", "]", ";", "if", "(", "!", "is_array", "(", "$", "callback", ")", ")", "{", "if", "(", "!", "method_exists", "(", "$", "callback", ",", "'compile'", ")", ")", "{", "throw", "new", "Dwoo_Exception", "(", "'Custom plugin '", ".", "$", "func", ".", "' must implement the \"compile\" method to be compilable, or you should provide a full callback to the method to use'", ")", ";", "}", "if", "(", "(", "$", "ref", "=", "new", "ReflectionMethod", "(", "$", "callback", ",", "'compile'", ")", ")", "&&", "$", "ref", "->", "isStatic", "(", ")", ")", "{", "$", "funcCompiler", "=", "array", "(", "$", "callback", ",", "'compile'", ")", ";", "}", "else", "{", "$", "funcCompiler", "=", "array", "(", "new", "$", "callback", ",", "'compile'", ")", ";", "}", "}", "else", "{", "$", "funcCompiler", "=", "$", "callback", ";", "}", "}", "else", "{", "$", "funcCompiler", "=", "array", "(", "'Dwoo_Plugin_'", ".", "$", "func", ",", "'compile'", ")", ";", "array_unshift", "(", "$", "params", ",", "$", "this", ")", ";", "}", "$", "output", "=", "call_user_func_array", "(", "$", "funcCompiler", ",", "$", "params", ")", ";", "}", "else", "{", "$", "params", "=", "self", "::", "implode_r", "(", "$", "params", ")", ";", "if", "(", "$", "pluginType", "&", "Dwoo", "::", "CUSTOM_PLUGIN", ")", "{", "if", "(", "is_object", "(", "$", "callback", "[", "0", "]", ")", ")", "{", "$", "output", "=", "(", "$", "mapped", "?", "'$this->arrayMap'", ":", "'call_user_func_array'", ")", ".", "'(array($this->plugins[\\''", ".", "$", "func", ".", "'\\'][\\'callback\\'][0], \\''", ".", "$", "callback", "[", "1", "]", ".", "'\\'), array('", ".", "$", "params", ".", "'))'", ";", "}", "else", "{", "$", "output", "=", "(", "$", "mapped", "?", "'$this->arrayMap'", ":", "'call_user_func_array'", ")", ".", "'(array(\\''", ".", "$", "callback", "[", "0", "]", ".", "'\\', \\''", ".", "$", "callback", "[", "1", "]", ".", "'\\'), array('", ".", "$", "params", ".", "'))'", ";", "}", "}", "elseif", "(", "$", "mapped", ")", "{", "$", "output", "=", "'$this->arrayMap(array($this->getObjectPlugin(\\'Dwoo_Plugin_'", ".", "$", "func", ".", "'\\'), \\'process\\'), array('", ".", "$", "params", ".", "'))'", ";", "}", "else", "{", "$", "output", "=", "'$this->classCall(\\''", ".", "$", "func", ".", "'\\', array('", ".", "$", "params", ".", "'))'", ";", "}", "}", "}", "}", "}", "if", "(", "$", "curBlock", "===", "'var'", "||", "$", "m", "[", "1", "]", "===", "null", ")", "{", "return", "$", "output", ";", "}", "elseif", "(", "$", "curBlock", "===", "'string'", "||", "$", "curBlock", "===", "'root'", ")", "{", "return", "$", "m", "[", "1", "]", ".", "'.'", ".", "$", "output", ".", "'.'", ".", "$", "m", "[", "1", "]", ".", "(", "isset", "(", "$", "add", ")", "?", "$", "add", ":", "null", ")", ";", "}", "}" ]
replaces the modifiers applied to a string or a variable @param array $m the regex matches that must be array(1=>"double or single quotes enclosing a string, when applicable", 2=>"the string or var", 3=>"the modifiers matched") @param string $curBlock the current parser-block being processed @return string the input enclosed with various function calls according to the modifiers found
[ "replaces", "the", "modifiers", "applied", "to", "a", "string", "or", "a", "variable" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php#L2589-L2830
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php
Dwoo_Compiler.getPluginType
protected function getPluginType($name) { $pluginType = -1; if (($this->securityPolicy === null && (function_exists($name) || strtolower($name) === 'isset' || strtolower($name) === 'empty')) || ($this->securityPolicy !== null && in_array(strtolower($name), $this->securityPolicy->getAllowedPhpFunctions()) !== false)) { $phpFunc = true; } while ($pluginType <= 0) { if (isset($this->templatePlugins[$name])) { $pluginType = Dwoo::TEMPLATE_PLUGIN | Dwoo::COMPILABLE_PLUGIN; } elseif (isset($this->customPlugins[$name])) { $pluginType = $this->customPlugins[$name]['type'] | Dwoo::CUSTOM_PLUGIN; } elseif (class_exists('Dwoo_Plugin_'.$name, false) !== false) { if (is_subclass_of('Dwoo_Plugin_'.$name, 'Dwoo_Block_Plugin')) { $pluginType = Dwoo::BLOCK_PLUGIN; } else { $pluginType = Dwoo::CLASS_PLUGIN; } $interfaces = class_implements('Dwoo_Plugin_'.$name, false); if (in_array('Dwoo_ICompilable', $interfaces) !== false || in_array('Dwoo_ICompilable_Block', $interfaces) !== false) { $pluginType |= Dwoo::COMPILABLE_PLUGIN; } } elseif (function_exists('Dwoo_Plugin_'.$name) !== false) { $pluginType = Dwoo::FUNC_PLUGIN; } elseif (function_exists('Dwoo_Plugin_'.$name.'_compile')) { $pluginType = Dwoo::FUNC_PLUGIN | Dwoo::COMPILABLE_PLUGIN; } elseif (function_exists('smarty_modifier_'.$name) !== false) { $pluginType = Dwoo::SMARTY_MODIFIER; } elseif (function_exists('smarty_function_'.$name) !== false) { $pluginType = Dwoo::SMARTY_FUNCTION; } elseif (function_exists('smarty_block_'.$name) !== false) { $pluginType = Dwoo::SMARTY_BLOCK; } else { if ($pluginType===-1) { try { $this->dwoo->getLoader()->loadPlugin($name, isset($phpFunc)===false); } catch (Exception $e) { if (isset($phpFunc)) { $pluginType = Dwoo::NATIVE_PLUGIN; } elseif (is_object($this->dwoo->getPluginProxy()) && $this->dwoo->getPluginProxy()->handles($name)) { $pluginType = Dwoo::PROXY_PLUGIN; break; } else { throw $e; } } } else { throw new Dwoo_Exception('Plugin "'.$name.'" could not be found'); } $pluginType++; } } if (($pluginType & Dwoo::COMPILABLE_PLUGIN) === 0 && ($pluginType & Dwoo::NATIVE_PLUGIN) === 0 && ($pluginType & Dwoo::PROXY_PLUGIN) === 0) { $this->addUsedPlugin($name, $pluginType); } return $pluginType; }
php
protected function getPluginType($name) { $pluginType = -1; if (($this->securityPolicy === null && (function_exists($name) || strtolower($name) === 'isset' || strtolower($name) === 'empty')) || ($this->securityPolicy !== null && in_array(strtolower($name), $this->securityPolicy->getAllowedPhpFunctions()) !== false)) { $phpFunc = true; } while ($pluginType <= 0) { if (isset($this->templatePlugins[$name])) { $pluginType = Dwoo::TEMPLATE_PLUGIN | Dwoo::COMPILABLE_PLUGIN; } elseif (isset($this->customPlugins[$name])) { $pluginType = $this->customPlugins[$name]['type'] | Dwoo::CUSTOM_PLUGIN; } elseif (class_exists('Dwoo_Plugin_'.$name, false) !== false) { if (is_subclass_of('Dwoo_Plugin_'.$name, 'Dwoo_Block_Plugin')) { $pluginType = Dwoo::BLOCK_PLUGIN; } else { $pluginType = Dwoo::CLASS_PLUGIN; } $interfaces = class_implements('Dwoo_Plugin_'.$name, false); if (in_array('Dwoo_ICompilable', $interfaces) !== false || in_array('Dwoo_ICompilable_Block', $interfaces) !== false) { $pluginType |= Dwoo::COMPILABLE_PLUGIN; } } elseif (function_exists('Dwoo_Plugin_'.$name) !== false) { $pluginType = Dwoo::FUNC_PLUGIN; } elseif (function_exists('Dwoo_Plugin_'.$name.'_compile')) { $pluginType = Dwoo::FUNC_PLUGIN | Dwoo::COMPILABLE_PLUGIN; } elseif (function_exists('smarty_modifier_'.$name) !== false) { $pluginType = Dwoo::SMARTY_MODIFIER; } elseif (function_exists('smarty_function_'.$name) !== false) { $pluginType = Dwoo::SMARTY_FUNCTION; } elseif (function_exists('smarty_block_'.$name) !== false) { $pluginType = Dwoo::SMARTY_BLOCK; } else { if ($pluginType===-1) { try { $this->dwoo->getLoader()->loadPlugin($name, isset($phpFunc)===false); } catch (Exception $e) { if (isset($phpFunc)) { $pluginType = Dwoo::NATIVE_PLUGIN; } elseif (is_object($this->dwoo->getPluginProxy()) && $this->dwoo->getPluginProxy()->handles($name)) { $pluginType = Dwoo::PROXY_PLUGIN; break; } else { throw $e; } } } else { throw new Dwoo_Exception('Plugin "'.$name.'" could not be found'); } $pluginType++; } } if (($pluginType & Dwoo::COMPILABLE_PLUGIN) === 0 && ($pluginType & Dwoo::NATIVE_PLUGIN) === 0 && ($pluginType & Dwoo::PROXY_PLUGIN) === 0) { $this->addUsedPlugin($name, $pluginType); } return $pluginType; }
[ "protected", "function", "getPluginType", "(", "$", "name", ")", "{", "$", "pluginType", "=", "-", "1", ";", "if", "(", "(", "$", "this", "->", "securityPolicy", "===", "null", "&&", "(", "function_exists", "(", "$", "name", ")", "||", "strtolower", "(", "$", "name", ")", "===", "'isset'", "||", "strtolower", "(", "$", "name", ")", "===", "'empty'", ")", ")", "||", "(", "$", "this", "->", "securityPolicy", "!==", "null", "&&", "in_array", "(", "strtolower", "(", "$", "name", ")", ",", "$", "this", "->", "securityPolicy", "->", "getAllowedPhpFunctions", "(", ")", ")", "!==", "false", ")", ")", "{", "$", "phpFunc", "=", "true", ";", "}", "while", "(", "$", "pluginType", "<=", "0", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "templatePlugins", "[", "$", "name", "]", ")", ")", "{", "$", "pluginType", "=", "Dwoo", "::", "TEMPLATE_PLUGIN", "|", "Dwoo", "::", "COMPILABLE_PLUGIN", ";", "}", "elseif", "(", "isset", "(", "$", "this", "->", "customPlugins", "[", "$", "name", "]", ")", ")", "{", "$", "pluginType", "=", "$", "this", "->", "customPlugins", "[", "$", "name", "]", "[", "'type'", "]", "|", "Dwoo", "::", "CUSTOM_PLUGIN", ";", "}", "elseif", "(", "class_exists", "(", "'Dwoo_Plugin_'", ".", "$", "name", ",", "false", ")", "!==", "false", ")", "{", "if", "(", "is_subclass_of", "(", "'Dwoo_Plugin_'", ".", "$", "name", ",", "'Dwoo_Block_Plugin'", ")", ")", "{", "$", "pluginType", "=", "Dwoo", "::", "BLOCK_PLUGIN", ";", "}", "else", "{", "$", "pluginType", "=", "Dwoo", "::", "CLASS_PLUGIN", ";", "}", "$", "interfaces", "=", "class_implements", "(", "'Dwoo_Plugin_'", ".", "$", "name", ",", "false", ")", ";", "if", "(", "in_array", "(", "'Dwoo_ICompilable'", ",", "$", "interfaces", ")", "!==", "false", "||", "in_array", "(", "'Dwoo_ICompilable_Block'", ",", "$", "interfaces", ")", "!==", "false", ")", "{", "$", "pluginType", "|=", "Dwoo", "::", "COMPILABLE_PLUGIN", ";", "}", "}", "elseif", "(", "function_exists", "(", "'Dwoo_Plugin_'", ".", "$", "name", ")", "!==", "false", ")", "{", "$", "pluginType", "=", "Dwoo", "::", "FUNC_PLUGIN", ";", "}", "elseif", "(", "function_exists", "(", "'Dwoo_Plugin_'", ".", "$", "name", ".", "'_compile'", ")", ")", "{", "$", "pluginType", "=", "Dwoo", "::", "FUNC_PLUGIN", "|", "Dwoo", "::", "COMPILABLE_PLUGIN", ";", "}", "elseif", "(", "function_exists", "(", "'smarty_modifier_'", ".", "$", "name", ")", "!==", "false", ")", "{", "$", "pluginType", "=", "Dwoo", "::", "SMARTY_MODIFIER", ";", "}", "elseif", "(", "function_exists", "(", "'smarty_function_'", ".", "$", "name", ")", "!==", "false", ")", "{", "$", "pluginType", "=", "Dwoo", "::", "SMARTY_FUNCTION", ";", "}", "elseif", "(", "function_exists", "(", "'smarty_block_'", ".", "$", "name", ")", "!==", "false", ")", "{", "$", "pluginType", "=", "Dwoo", "::", "SMARTY_BLOCK", ";", "}", "else", "{", "if", "(", "$", "pluginType", "===", "-", "1", ")", "{", "try", "{", "$", "this", "->", "dwoo", "->", "getLoader", "(", ")", "->", "loadPlugin", "(", "$", "name", ",", "isset", "(", "$", "phpFunc", ")", "===", "false", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "if", "(", "isset", "(", "$", "phpFunc", ")", ")", "{", "$", "pluginType", "=", "Dwoo", "::", "NATIVE_PLUGIN", ";", "}", "elseif", "(", "is_object", "(", "$", "this", "->", "dwoo", "->", "getPluginProxy", "(", ")", ")", "&&", "$", "this", "->", "dwoo", "->", "getPluginProxy", "(", ")", "->", "handles", "(", "$", "name", ")", ")", "{", "$", "pluginType", "=", "Dwoo", "::", "PROXY_PLUGIN", ";", "break", ";", "}", "else", "{", "throw", "$", "e", ";", "}", "}", "}", "else", "{", "throw", "new", "Dwoo_Exception", "(", "'Plugin \"'", ".", "$", "name", ".", "'\" could not be found'", ")", ";", "}", "$", "pluginType", "++", ";", "}", "}", "if", "(", "(", "$", "pluginType", "&", "Dwoo", "::", "COMPILABLE_PLUGIN", ")", "===", "0", "&&", "(", "$", "pluginType", "&", "Dwoo", "::", "NATIVE_PLUGIN", ")", "===", "0", "&&", "(", "$", "pluginType", "&", "Dwoo", "::", "PROXY_PLUGIN", ")", "===", "0", ")", "{", "$", "this", "->", "addUsedPlugin", "(", "$", "name", ",", "$", "pluginType", ")", ";", "}", "return", "$", "pluginType", ";", "}" ]
returns the plugin type of a plugin and adds it to the used plugins array if required @param string $name plugin name, as found in the template @return int type as a multi bit flag composed of the Dwoo plugin types constants
[ "returns", "the", "plugin", "type", "of", "a", "plugin", "and", "adds", "it", "to", "the", "used", "plugins", "array", "if", "required" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php#L2866-L2926
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php
Dwoo_Compiler.mapParams
protected function mapParams(array $params, $callback, $callType=2, $map = null) { if (!$map) { $map = $this->getParamMap($callback); } $paramlist = array(); // transforms the parameter array from (x=>array('paramname'=>array(values))) to (paramname=>array(values)) $ps = array(); foreach ($params as $p) { if (is_array($p[1])) { $ps[$p[0]] = $p[1]; } else { $ps[] = $p; } } // loops over the param map and assigns values from the template or default value for unset optional params while (list($k,$v) = each($map)) { if ($v[0] === '*') { // "rest" array parameter, fill every remaining params in it and then break if (count($ps) === 0) { if ($v[1]===false) { throw new Dwoo_Compilation_Exception($this, 'Rest argument missing for '.str_replace(array('Dwoo_Plugin_', '_compile'), '', (is_array($callback) ? $callback[0] : $callback))); } else { break; } } $tmp = array(); $tmp2 = array(); foreach ($ps as $i=>$p) { $tmp[$i] = $p[0]; $tmp2[$i] = $p[1]; unset($ps[$i]); } $paramlist[$v[0]] = array($tmp, $tmp2); unset($tmp, $tmp2, $i, $p); break; } elseif (isset($ps[$v[0]])) { // parameter is defined as named param $paramlist[$v[0]] = $ps[$v[0]]; unset($ps[$v[0]]); } elseif (isset($ps[$k])) { // parameter is defined as ordered param $paramlist[$v[0]] = $ps[$k]; unset($ps[$k]); } elseif ($v[1]===false) { // parameter is not defined and not optional, throw error if (is_array($callback)) { if (is_object($callback[0])) { $name = get_class($callback[0]) . '::' . $callback[1]; } else { $name = $callback[0]; } } else { $name = $callback; } throw new Dwoo_Compilation_Exception($this, 'Argument '.$k.'/'.$v[0].' missing for '.str_replace(array('Dwoo_Plugin_', '_compile'), '', $name)); } elseif ($v[2]===null) { // enforce lowercased null if default value is null (php outputs NULL with var export) $paramlist[$v[0]] = array('null', null); } else { // outputs default value with var_export $paramlist[$v[0]] = array(var_export($v[2], true), $v[2]); } } if (count($ps)) { foreach ($ps as $i=>$p) { array_push($paramlist, $p); } } return $paramlist; }
php
protected function mapParams(array $params, $callback, $callType=2, $map = null) { if (!$map) { $map = $this->getParamMap($callback); } $paramlist = array(); // transforms the parameter array from (x=>array('paramname'=>array(values))) to (paramname=>array(values)) $ps = array(); foreach ($params as $p) { if (is_array($p[1])) { $ps[$p[0]] = $p[1]; } else { $ps[] = $p; } } // loops over the param map and assigns values from the template or default value for unset optional params while (list($k,$v) = each($map)) { if ($v[0] === '*') { // "rest" array parameter, fill every remaining params in it and then break if (count($ps) === 0) { if ($v[1]===false) { throw new Dwoo_Compilation_Exception($this, 'Rest argument missing for '.str_replace(array('Dwoo_Plugin_', '_compile'), '', (is_array($callback) ? $callback[0] : $callback))); } else { break; } } $tmp = array(); $tmp2 = array(); foreach ($ps as $i=>$p) { $tmp[$i] = $p[0]; $tmp2[$i] = $p[1]; unset($ps[$i]); } $paramlist[$v[0]] = array($tmp, $tmp2); unset($tmp, $tmp2, $i, $p); break; } elseif (isset($ps[$v[0]])) { // parameter is defined as named param $paramlist[$v[0]] = $ps[$v[0]]; unset($ps[$v[0]]); } elseif (isset($ps[$k])) { // parameter is defined as ordered param $paramlist[$v[0]] = $ps[$k]; unset($ps[$k]); } elseif ($v[1]===false) { // parameter is not defined and not optional, throw error if (is_array($callback)) { if (is_object($callback[0])) { $name = get_class($callback[0]) . '::' . $callback[1]; } else { $name = $callback[0]; } } else { $name = $callback; } throw new Dwoo_Compilation_Exception($this, 'Argument '.$k.'/'.$v[0].' missing for '.str_replace(array('Dwoo_Plugin_', '_compile'), '', $name)); } elseif ($v[2]===null) { // enforce lowercased null if default value is null (php outputs NULL with var export) $paramlist[$v[0]] = array('null', null); } else { // outputs default value with var_export $paramlist[$v[0]] = array(var_export($v[2], true), $v[2]); } } if (count($ps)) { foreach ($ps as $i=>$p) { array_push($paramlist, $p); } } return $paramlist; }
[ "protected", "function", "mapParams", "(", "array", "$", "params", ",", "$", "callback", ",", "$", "callType", "=", "2", ",", "$", "map", "=", "null", ")", "{", "if", "(", "!", "$", "map", ")", "{", "$", "map", "=", "$", "this", "->", "getParamMap", "(", "$", "callback", ")", ";", "}", "$", "paramlist", "=", "array", "(", ")", ";", "// transforms the parameter array from (x=>array('paramname'=>array(values))) to (paramname=>array(values))", "$", "ps", "=", "array", "(", ")", ";", "foreach", "(", "$", "params", "as", "$", "p", ")", "{", "if", "(", "is_array", "(", "$", "p", "[", "1", "]", ")", ")", "{", "$", "ps", "[", "$", "p", "[", "0", "]", "]", "=", "$", "p", "[", "1", "]", ";", "}", "else", "{", "$", "ps", "[", "]", "=", "$", "p", ";", "}", "}", "// loops over the param map and assigns values from the template or default value for unset optional params", "while", "(", "list", "(", "$", "k", ",", "$", "v", ")", "=", "each", "(", "$", "map", ")", ")", "{", "if", "(", "$", "v", "[", "0", "]", "===", "'*'", ")", "{", "// \"rest\" array parameter, fill every remaining params in it and then break", "if", "(", "count", "(", "$", "ps", ")", "===", "0", ")", "{", "if", "(", "$", "v", "[", "1", "]", "===", "false", ")", "{", "throw", "new", "Dwoo_Compilation_Exception", "(", "$", "this", ",", "'Rest argument missing for '", ".", "str_replace", "(", "array", "(", "'Dwoo_Plugin_'", ",", "'_compile'", ")", ",", "''", ",", "(", "is_array", "(", "$", "callback", ")", "?", "$", "callback", "[", "0", "]", ":", "$", "callback", ")", ")", ")", ";", "}", "else", "{", "break", ";", "}", "}", "$", "tmp", "=", "array", "(", ")", ";", "$", "tmp2", "=", "array", "(", ")", ";", "foreach", "(", "$", "ps", "as", "$", "i", "=>", "$", "p", ")", "{", "$", "tmp", "[", "$", "i", "]", "=", "$", "p", "[", "0", "]", ";", "$", "tmp2", "[", "$", "i", "]", "=", "$", "p", "[", "1", "]", ";", "unset", "(", "$", "ps", "[", "$", "i", "]", ")", ";", "}", "$", "paramlist", "[", "$", "v", "[", "0", "]", "]", "=", "array", "(", "$", "tmp", ",", "$", "tmp2", ")", ";", "unset", "(", "$", "tmp", ",", "$", "tmp2", ",", "$", "i", ",", "$", "p", ")", ";", "break", ";", "}", "elseif", "(", "isset", "(", "$", "ps", "[", "$", "v", "[", "0", "]", "]", ")", ")", "{", "// parameter is defined as named param", "$", "paramlist", "[", "$", "v", "[", "0", "]", "]", "=", "$", "ps", "[", "$", "v", "[", "0", "]", "]", ";", "unset", "(", "$", "ps", "[", "$", "v", "[", "0", "]", "]", ")", ";", "}", "elseif", "(", "isset", "(", "$", "ps", "[", "$", "k", "]", ")", ")", "{", "// parameter is defined as ordered param", "$", "paramlist", "[", "$", "v", "[", "0", "]", "]", "=", "$", "ps", "[", "$", "k", "]", ";", "unset", "(", "$", "ps", "[", "$", "k", "]", ")", ";", "}", "elseif", "(", "$", "v", "[", "1", "]", "===", "false", ")", "{", "// parameter is not defined and not optional, throw error", "if", "(", "is_array", "(", "$", "callback", ")", ")", "{", "if", "(", "is_object", "(", "$", "callback", "[", "0", "]", ")", ")", "{", "$", "name", "=", "get_class", "(", "$", "callback", "[", "0", "]", ")", ".", "'::'", ".", "$", "callback", "[", "1", "]", ";", "}", "else", "{", "$", "name", "=", "$", "callback", "[", "0", "]", ";", "}", "}", "else", "{", "$", "name", "=", "$", "callback", ";", "}", "throw", "new", "Dwoo_Compilation_Exception", "(", "$", "this", ",", "'Argument '", ".", "$", "k", ".", "'/'", ".", "$", "v", "[", "0", "]", ".", "' missing for '", ".", "str_replace", "(", "array", "(", "'Dwoo_Plugin_'", ",", "'_compile'", ")", ",", "''", ",", "$", "name", ")", ")", ";", "}", "elseif", "(", "$", "v", "[", "2", "]", "===", "null", ")", "{", "// enforce lowercased null if default value is null (php outputs NULL with var export)", "$", "paramlist", "[", "$", "v", "[", "0", "]", "]", "=", "array", "(", "'null'", ",", "null", ")", ";", "}", "else", "{", "// outputs default value with var_export", "$", "paramlist", "[", "$", "v", "[", "0", "]", "]", "=", "array", "(", "var_export", "(", "$", "v", "[", "2", "]", ",", "true", ")", ",", "$", "v", "[", "2", "]", ")", ";", "}", "}", "if", "(", "count", "(", "$", "ps", ")", ")", "{", "foreach", "(", "$", "ps", "as", "$", "i", "=>", "$", "p", ")", "{", "array_push", "(", "$", "paramlist", ",", "$", "p", ")", ";", "}", "}", "return", "$", "paramlist", ";", "}" ]
maps the parameters received from the template onto the parameters required by the given callback @param array $params the array of parameters @param callback $callback the function or method to reflect on to find out the required parameters @param int $callType the type of call in the template, 0 = no params, 1 = php-style call, 2 = named parameters call @param array $map the parameter map to use, if not provided it will be built from the callback @return array parameters sorted in the correct order with missing optional parameters filled
[ "maps", "the", "parameters", "received", "from", "the", "template", "onto", "the", "parameters", "required", "by", "the", "given", "callback" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Compiler.php#L2960-L3036
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Mail/src/mail.php
ezcMail.__isset
public function __isset( $name ) { switch ( $name ) { case 'to': case 'cc': case 'bcc': case 'from': case 'subject': case 'subjectCharset': case 'body': case 'messageId': case 'returnPath': return isset( $this->properties[$name] ); case 'messageID': // deprecated version return isset( $this->properties['messageId'] ); case 'timestamp': return $this->getHeader( "Date" ) != null; default: return parent::__isset( $name ); } }
php
public function __isset( $name ) { switch ( $name ) { case 'to': case 'cc': case 'bcc': case 'from': case 'subject': case 'subjectCharset': case 'body': case 'messageId': case 'returnPath': return isset( $this->properties[$name] ); case 'messageID': // deprecated version return isset( $this->properties['messageId'] ); case 'timestamp': return $this->getHeader( "Date" ) != null; default: return parent::__isset( $name ); } }
[ "public", "function", "__isset", "(", "$", "name", ")", "{", "switch", "(", "$", "name", ")", "{", "case", "'to'", ":", "case", "'cc'", ":", "case", "'bcc'", ":", "case", "'from'", ":", "case", "'subject'", ":", "case", "'subjectCharset'", ":", "case", "'body'", ":", "case", "'messageId'", ":", "case", "'returnPath'", ":", "return", "isset", "(", "$", "this", "->", "properties", "[", "$", "name", "]", ")", ";", "case", "'messageID'", ":", "// deprecated version", "return", "isset", "(", "$", "this", "->", "properties", "[", "'messageId'", "]", ")", ";", "case", "'timestamp'", ":", "return", "$", "this", "->", "getHeader", "(", "\"Date\"", ")", "!=", "null", ";", "default", ":", "return", "parent", "::", "__isset", "(", "$", "name", ")", ";", "}", "}" ]
Returns true if the property $name is set, otherwise false. @param string $name @return bool @ignore
[ "Returns", "true", "if", "the", "property", "$name", "is", "set", "otherwise", "false", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/mail.php#L261-L285
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Mail/src/mail.php
ezcMail.generateHeaders
public function generateHeaders() { // set our headers first. if ( $this->from !== null ) { $this->setHeader( "From", ezcMailTools::composeEmailAddress( $this->from ) ); } if ( $this->to !== null ) { $this->setHeader( "To", ezcMailTools::composeEmailAddresses( $this->to ) ); } if ( count( $this->cc ) ) { $this->setHeader( "Cc", ezcMailTools::composeEmailAddresses( $this->cc ) ); } if ( count( $this->bcc ) && $this->options->stripBccHeader === false ) { $this->setHeader( "Bcc", ezcMailTools::composeEmailAddresses( $this->bcc ) ); } $this->setHeader( 'Subject', $this->subject, $this->subjectCharset ); $this->setHeader( 'MIME-Version', '1.0' ); $this->setHeader( 'User-Agent', 'eZ Components' ); $this->setHeader( 'Date', date( 'r' ) ); $idhost = $this->from != null && $this->from->email != '' ? $this->from->email : 'localhost'; if ( is_null( $this->messageId ) ) { $this->setHeader( 'Message-Id', '<' . ezcMailTools::generateMessageId( $idhost ) . '>' ); } else { $this->setHeader( 'Message-Id', $this->messageID ); } // if we have a body part, include the headers of the body if ( is_subclass_of( $this->body, "ezcMailPart" ) ) { return parent::generateHeaders() . $this->body->generateHeaders(); } return parent::generateHeaders(); }
php
public function generateHeaders() { // set our headers first. if ( $this->from !== null ) { $this->setHeader( "From", ezcMailTools::composeEmailAddress( $this->from ) ); } if ( $this->to !== null ) { $this->setHeader( "To", ezcMailTools::composeEmailAddresses( $this->to ) ); } if ( count( $this->cc ) ) { $this->setHeader( "Cc", ezcMailTools::composeEmailAddresses( $this->cc ) ); } if ( count( $this->bcc ) && $this->options->stripBccHeader === false ) { $this->setHeader( "Bcc", ezcMailTools::composeEmailAddresses( $this->bcc ) ); } $this->setHeader( 'Subject', $this->subject, $this->subjectCharset ); $this->setHeader( 'MIME-Version', '1.0' ); $this->setHeader( 'User-Agent', 'eZ Components' ); $this->setHeader( 'Date', date( 'r' ) ); $idhost = $this->from != null && $this->from->email != '' ? $this->from->email : 'localhost'; if ( is_null( $this->messageId ) ) { $this->setHeader( 'Message-Id', '<' . ezcMailTools::generateMessageId( $idhost ) . '>' ); } else { $this->setHeader( 'Message-Id', $this->messageID ); } // if we have a body part, include the headers of the body if ( is_subclass_of( $this->body, "ezcMailPart" ) ) { return parent::generateHeaders() . $this->body->generateHeaders(); } return parent::generateHeaders(); }
[ "public", "function", "generateHeaders", "(", ")", "{", "// set our headers first.", "if", "(", "$", "this", "->", "from", "!==", "null", ")", "{", "$", "this", "->", "setHeader", "(", "\"From\"", ",", "ezcMailTools", "::", "composeEmailAddress", "(", "$", "this", "->", "from", ")", ")", ";", "}", "if", "(", "$", "this", "->", "to", "!==", "null", ")", "{", "$", "this", "->", "setHeader", "(", "\"To\"", ",", "ezcMailTools", "::", "composeEmailAddresses", "(", "$", "this", "->", "to", ")", ")", ";", "}", "if", "(", "count", "(", "$", "this", "->", "cc", ")", ")", "{", "$", "this", "->", "setHeader", "(", "\"Cc\"", ",", "ezcMailTools", "::", "composeEmailAddresses", "(", "$", "this", "->", "cc", ")", ")", ";", "}", "if", "(", "count", "(", "$", "this", "->", "bcc", ")", "&&", "$", "this", "->", "options", "->", "stripBccHeader", "===", "false", ")", "{", "$", "this", "->", "setHeader", "(", "\"Bcc\"", ",", "ezcMailTools", "::", "composeEmailAddresses", "(", "$", "this", "->", "bcc", ")", ")", ";", "}", "$", "this", "->", "setHeader", "(", "'Subject'", ",", "$", "this", "->", "subject", ",", "$", "this", "->", "subjectCharset", ")", ";", "$", "this", "->", "setHeader", "(", "'MIME-Version'", ",", "'1.0'", ")", ";", "$", "this", "->", "setHeader", "(", "'User-Agent'", ",", "'eZ Components'", ")", ";", "$", "this", "->", "setHeader", "(", "'Date'", ",", "date", "(", "'r'", ")", ")", ";", "$", "idhost", "=", "$", "this", "->", "from", "!=", "null", "&&", "$", "this", "->", "from", "->", "email", "!=", "''", "?", "$", "this", "->", "from", "->", "email", ":", "'localhost'", ";", "if", "(", "is_null", "(", "$", "this", "->", "messageId", ")", ")", "{", "$", "this", "->", "setHeader", "(", "'Message-Id'", ",", "'<'", ".", "ezcMailTools", "::", "generateMessageId", "(", "$", "idhost", ")", ".", "'>'", ")", ";", "}", "else", "{", "$", "this", "->", "setHeader", "(", "'Message-Id'", ",", "$", "this", "->", "messageID", ")", ";", "}", "// if we have a body part, include the headers of the body", "if", "(", "is_subclass_of", "(", "$", "this", "->", "body", ",", "\"ezcMailPart\"", ")", ")", "{", "return", "parent", "::", "generateHeaders", "(", ")", ".", "$", "this", "->", "body", "->", "generateHeaders", "(", ")", ";", "}", "return", "parent", "::", "generateHeaders", "(", ")", ";", "}" ]
Returns the generated headers for the mail. This method is called automatically when the mail message is built. You can re-implement this method in subclasses if you wish to set different mail headers than ezcMail. @return string
[ "Returns", "the", "generated", "headers", "for", "the", "mail", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/mail.php#L342-L384
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Mail/src/mail.php
ezcMail.fetchParts
public function fetchParts( $filter = null, $includeDigests = false ) { $context = new ezcMailPartWalkContext( array( __CLASS__, 'collectPart' ) ); $context->includeDigests = $includeDigests; $context->filter = $filter; $context->level = 0; $this->walkParts( $context, $this ); return $context->getParts(); }
php
public function fetchParts( $filter = null, $includeDigests = false ) { $context = new ezcMailPartWalkContext( array( __CLASS__, 'collectPart' ) ); $context->includeDigests = $includeDigests; $context->filter = $filter; $context->level = 0; $this->walkParts( $context, $this ); return $context->getParts(); }
[ "public", "function", "fetchParts", "(", "$", "filter", "=", "null", ",", "$", "includeDigests", "=", "false", ")", "{", "$", "context", "=", "new", "ezcMailPartWalkContext", "(", "array", "(", "__CLASS__", ",", "'collectPart'", ")", ")", ";", "$", "context", "->", "includeDigests", "=", "$", "includeDigests", ";", "$", "context", "->", "filter", "=", "$", "filter", ";", "$", "context", "->", "level", "=", "0", ";", "$", "this", "->", "walkParts", "(", "$", "context", ",", "$", "this", ")", ";", "return", "$", "context", "->", "getParts", "(", ")", ";", "}" ]
Returns an array of mail parts from the current mail. The array returned contains objects of classes: - ezcMailText - ezcMailFile - ezcMailRfc822Digest If the method is called with $includeDigests as true, then the returned array will not contain ezcMailRfc822Digest objects, but instead the mail parts inside the digests. The parameter $filter can be used to restrict the returned mail parts, eg. $filter = array( 'ezcMailFile' ) to return only file mail parts. A typical use for this function is to get a list of attachments from a mail. Example: <code> // $mail is an ezcMail object $parts = $mail->fetchParts(); // after the above line is executed, $parts will contain an array of mail parts objects, // for example one ezcMailText object ($parts[0]) and two ezcMailRfc822Digest objects ($parts[1] and $parts[2]). // the ezcMailText object will be used to render the mail text, and the // other two objects will be displayed as links ("view attachment") // when user clicks on one of the two attachments, the parts of that attachment // must be retrieved in order to render the attached digest: $subparts = $parts[1]->mail->fetchParts(); // after the above line is executed, $subparts will contain an array of mail parts objects, // for example one ezcMailText object and one ezcMailFile object </code> @param array(string) $filter @param bool $includeDigests @return array(ezcMailPart)
[ "Returns", "an", "array", "of", "mail", "parts", "from", "the", "current", "mail", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/mail.php#L420-L428
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Mail/src/mail.php
ezcMail.walkParts
public function walkParts( ezcMailPartWalkContext $context, ezcMailPart $mail ) { $className = get_class( $mail ); $context->level++; switch ( $className ) { case 'ezcMail': case 'ezcMailComposer': if ( $mail->body !== null ) { $this->walkParts( $context, $mail->body ); } break; case 'ezcMailMultipartMixed': case 'ezcMailMultipartAlternative': case 'ezcMailMultipartDigest': case 'ezcMailMultipartReport': foreach ( $mail->getParts() as $part ) { $this->walkParts( $context, $part ); } break; case 'ezcMailMultipartRelated': $this->walkParts( $context, $mail->getMainPart() ); foreach ( $mail->getRelatedParts() as $part ) { $this->walkParts( $context, $part ); } break; case 'ezcMailRfc822Digest': if ( $context->includeDigests ) { $this->walkParts( $context, $mail->mail ); } elseif ( empty( $context->filter ) || in_array( $className, $context->filter ) ) { call_user_func( $context->callbackFunction, $context, $mail ); } break; case 'ezcMailText': case 'ezcMailFile': case 'ezcMailDeliveryStatus': if ( empty( $context->filter ) || in_array( $className, $context->filter ) ) { call_user_func( $context->callbackFunction, $context, $mail ); } break; default: // for cases where a custom mail class has been specified with $parser->options->mailClass if ( in_array( 'ezcMail', class_parents( $className ) ) ) { if ( $mail->body !== null ) { $this->walkParts( $context, $mail->body ); } } // for cases where a custom file class has been specified with $parser->options->fileClass if ( in_array( 'ezcMailFile', class_parents( $className ) ) ) { if ( empty( $context->filter ) || in_array( $className, $context->filter ) ) { call_user_func( $context->callbackFunction, $context, $mail ); } } } $context->level--; }
php
public function walkParts( ezcMailPartWalkContext $context, ezcMailPart $mail ) { $className = get_class( $mail ); $context->level++; switch ( $className ) { case 'ezcMail': case 'ezcMailComposer': if ( $mail->body !== null ) { $this->walkParts( $context, $mail->body ); } break; case 'ezcMailMultipartMixed': case 'ezcMailMultipartAlternative': case 'ezcMailMultipartDigest': case 'ezcMailMultipartReport': foreach ( $mail->getParts() as $part ) { $this->walkParts( $context, $part ); } break; case 'ezcMailMultipartRelated': $this->walkParts( $context, $mail->getMainPart() ); foreach ( $mail->getRelatedParts() as $part ) { $this->walkParts( $context, $part ); } break; case 'ezcMailRfc822Digest': if ( $context->includeDigests ) { $this->walkParts( $context, $mail->mail ); } elseif ( empty( $context->filter ) || in_array( $className, $context->filter ) ) { call_user_func( $context->callbackFunction, $context, $mail ); } break; case 'ezcMailText': case 'ezcMailFile': case 'ezcMailDeliveryStatus': if ( empty( $context->filter ) || in_array( $className, $context->filter ) ) { call_user_func( $context->callbackFunction, $context, $mail ); } break; default: // for cases where a custom mail class has been specified with $parser->options->mailClass if ( in_array( 'ezcMail', class_parents( $className ) ) ) { if ( $mail->body !== null ) { $this->walkParts( $context, $mail->body ); } } // for cases where a custom file class has been specified with $parser->options->fileClass if ( in_array( 'ezcMailFile', class_parents( $className ) ) ) { if ( empty( $context->filter ) || in_array( $className, $context->filter ) ) { call_user_func( $context->callbackFunction, $context, $mail ); } } } $context->level--; }
[ "public", "function", "walkParts", "(", "ezcMailPartWalkContext", "$", "context", ",", "ezcMailPart", "$", "mail", ")", "{", "$", "className", "=", "get_class", "(", "$", "mail", ")", ";", "$", "context", "->", "level", "++", ";", "switch", "(", "$", "className", ")", "{", "case", "'ezcMail'", ":", "case", "'ezcMailComposer'", ":", "if", "(", "$", "mail", "->", "body", "!==", "null", ")", "{", "$", "this", "->", "walkParts", "(", "$", "context", ",", "$", "mail", "->", "body", ")", ";", "}", "break", ";", "case", "'ezcMailMultipartMixed'", ":", "case", "'ezcMailMultipartAlternative'", ":", "case", "'ezcMailMultipartDigest'", ":", "case", "'ezcMailMultipartReport'", ":", "foreach", "(", "$", "mail", "->", "getParts", "(", ")", "as", "$", "part", ")", "{", "$", "this", "->", "walkParts", "(", "$", "context", ",", "$", "part", ")", ";", "}", "break", ";", "case", "'ezcMailMultipartRelated'", ":", "$", "this", "->", "walkParts", "(", "$", "context", ",", "$", "mail", "->", "getMainPart", "(", ")", ")", ";", "foreach", "(", "$", "mail", "->", "getRelatedParts", "(", ")", "as", "$", "part", ")", "{", "$", "this", "->", "walkParts", "(", "$", "context", ",", "$", "part", ")", ";", "}", "break", ";", "case", "'ezcMailRfc822Digest'", ":", "if", "(", "$", "context", "->", "includeDigests", ")", "{", "$", "this", "->", "walkParts", "(", "$", "context", ",", "$", "mail", "->", "mail", ")", ";", "}", "elseif", "(", "empty", "(", "$", "context", "->", "filter", ")", "||", "in_array", "(", "$", "className", ",", "$", "context", "->", "filter", ")", ")", "{", "call_user_func", "(", "$", "context", "->", "callbackFunction", ",", "$", "context", ",", "$", "mail", ")", ";", "}", "break", ";", "case", "'ezcMailText'", ":", "case", "'ezcMailFile'", ":", "case", "'ezcMailDeliveryStatus'", ":", "if", "(", "empty", "(", "$", "context", "->", "filter", ")", "||", "in_array", "(", "$", "className", ",", "$", "context", "->", "filter", ")", ")", "{", "call_user_func", "(", "$", "context", "->", "callbackFunction", ",", "$", "context", ",", "$", "mail", ")", ";", "}", "break", ";", "default", ":", "// for cases where a custom mail class has been specified with $parser->options->mailClass", "if", "(", "in_array", "(", "'ezcMail'", ",", "class_parents", "(", "$", "className", ")", ")", ")", "{", "if", "(", "$", "mail", "->", "body", "!==", "null", ")", "{", "$", "this", "->", "walkParts", "(", "$", "context", ",", "$", "mail", "->", "body", ")", ";", "}", "}", "// for cases where a custom file class has been specified with $parser->options->fileClass", "if", "(", "in_array", "(", "'ezcMailFile'", ",", "class_parents", "(", "$", "className", ")", ")", ")", "{", "if", "(", "empty", "(", "$", "context", "->", "filter", ")", "||", "in_array", "(", "$", "className", ",", "$", "context", "->", "filter", ")", ")", "{", "call_user_func", "(", "$", "context", "->", "callbackFunction", ",", "$", "context", ",", "$", "mail", ")", ";", "}", "}", "}", "$", "context", "->", "level", "--", ";", "}" ]
Walks recursively through the mail parts in the specified mail object. $context is an object of class ezcMailPartWalkContext, which must contain a valid callback function name to be applied to all mail parts. You can use the collectPart() method, or create your own callback function which can for example save the mail parts to disk or to a database. For the properties you can set to the walk context see: {@link ezcMailPartWalkContext} Example: <code> class App { public static function saveMailPart( $context, $mailPart ) { // code to save the $mailPart object to disk } } // use the saveMailPart() function as a callback in walkParts() // where $mail is an ezcMail object. $context = new ezcMailPartWalkContext( array( 'App', 'saveMailPart' ) ); $context->includeDigests = true; // if you want to go through the digests in the mail $mail->walkParts( $context, $mail ); </code> @param ezcMailPartWalkContext $context @param ezcMailPart $mail
[ "Walks", "recursively", "through", "the", "mail", "parts", "in", "the", "specified", "mail", "object", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/mail.php#L460-L532
Eresus/EresusCMS
src/core/Plugin/Templates.php
Eresus_Plugin_Templates.client
public function client($filename) { $path = $this->clientPath($filename, false); return Eresus_Template::loadFromFile($path); }
php
public function client($filename) { $path = $this->clientPath($filename, false); return Eresus_Template::loadFromFile($path); }
[ "public", "function", "client", "(", "$", "filename", ")", "{", "$", "path", "=", "$", "this", "->", "clientPath", "(", "$", "filename", ",", "false", ")", ";", "return", "Eresus_Template", "::", "loadFromFile", "(", "$", "path", ")", ";", "}" ]
Возвращает шаблон для клиентского интерфейса @param string $filename имя файла шаблона относительно папки клиентских шаблонов @return Eresus_Template @since 3.01
[ "Возвращает", "шаблон", "для", "клиентского", "интерфейса" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/Plugin/Templates.php#L76-L80
Eresus/EresusCMS
src/core/Plugin/Templates.php
Eresus_Plugin_Templates.clientWrite
public function clientWrite($filename, $source) { $path = $this->clientPath($filename); file_put_contents($path, $source); }
php
public function clientWrite($filename, $source) { $path = $this->clientPath($filename); file_put_contents($path, $source); }
[ "public", "function", "clientWrite", "(", "$", "filename", ",", "$", "source", ")", "{", "$", "path", "=", "$", "this", "->", "clientPath", "(", "$", "filename", ")", ";", "file_put_contents", "(", "$", "path", ",", "$", "source", ")", ";", "}" ]
Записывает новый исходный код в шаблон для клиентского интерфейса @param string $filename имя файла шаблона относительно папки клиентских шаблонов @param string $source новый исходный код шаблона @return void @since 3.01
[ "Записывает", "новый", "исходный", "код", "в", "шаблон", "для", "клиентского", "интерфейса" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/Plugin/Templates.php#L107-L111
Eresus/EresusCMS
src/core/Plugin/Templates.php
Eresus_Plugin_Templates.clientPath
public function clientPath($filename, $absolute = true) { $path = "templates/{$this->plugin->getName()}/$filename"; if ($absolute) { $path = $this->getFullPath($path); } return $path; }
php
public function clientPath($filename, $absolute = true) { $path = "templates/{$this->plugin->getName()}/$filename"; if ($absolute) { $path = $this->getFullPath($path); } return $path; }
[ "public", "function", "clientPath", "(", "$", "filename", ",", "$", "absolute", "=", "true", ")", "{", "$", "path", "=", "\"templates/{$this->plugin->getName()}/$filename\"", ";", "if", "(", "$", "absolute", ")", "{", "$", "path", "=", "$", "this", "->", "getFullPath", "(", "$", "path", ")", ";", "}", "return", "$", "path", ";", "}" ]
Возвращает путь к шаблону КИ @param string $filename имя файла относительно папки шаблонов @param bool $absolute если false, то вернёт путь относительно корня сайта @return string путь к файлу шаблона
[ "Возвращает", "путь", "к", "шаблону", "КИ" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/Plugin/Templates.php#L121-L129
Eresus/EresusCMS
src/core/Plugin/Templates.php
Eresus_Plugin_Templates.adminPath
public function adminPath($filename, $absolute = true) { $path = "ext/{$this->plugin->getName()}/admin/templates/$filename"; if ($absolute) { $path = $this->getFullPath($path); } return $path; }
php
public function adminPath($filename, $absolute = true) { $path = "ext/{$this->plugin->getName()}/admin/templates/$filename"; if ($absolute) { $path = $this->getFullPath($path); } return $path; }
[ "public", "function", "adminPath", "(", "$", "filename", ",", "$", "absolute", "=", "true", ")", "{", "$", "path", "=", "\"ext/{$this->plugin->getName()}/admin/templates/$filename\"", ";", "if", "(", "$", "absolute", ")", "{", "$", "path", "=", "$", "this", "->", "getFullPath", "(", "$", "path", ")", ";", "}", "return", "$", "path", ";", "}" ]
Возвращает путь к шаблону АИ @param string $filename имя файла относительно папки шаблонов @param bool $absolute если false, то вернёт путь относительно корня сайта @return string путь к файлу шаблона
[ "Возвращает", "путь", "к", "шаблону", "АИ" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/Plugin/Templates.php#L139-L147
heidelpay/PhpDoc
src/phpDocumentor/Descriptor/Builder/Reflector/ConstantAssembler.php
ConstantAssembler.create
public function create($data) { $constantDescriptor = new ConstantDescriptor(); $constantDescriptor->setName($data->getShortName()); $constantDescriptor->setValue($data->getValue()); // Reflection library formulates namespace as global but this is not wanted for phpDocumentor itself $constantDescriptor->setNamespace( '\\' . (strtolower($data->getNamespace()) == 'global' ? '' :$data->getNamespace()) ); $constantDescriptor->setFullyQualifiedStructuralElementName( (trim($constantDescriptor->getNamespace(), '\\') ? $constantDescriptor->getNamespace() : '') . '\\' . $data->getShortName() ); $this->assembleDocBlock($data->getDocBlock(), $constantDescriptor); $constantDescriptor->setLine($data->getLinenumber()); return $constantDescriptor; }
php
public function create($data) { $constantDescriptor = new ConstantDescriptor(); $constantDescriptor->setName($data->getShortName()); $constantDescriptor->setValue($data->getValue()); // Reflection library formulates namespace as global but this is not wanted for phpDocumentor itself $constantDescriptor->setNamespace( '\\' . (strtolower($data->getNamespace()) == 'global' ? '' :$data->getNamespace()) ); $constantDescriptor->setFullyQualifiedStructuralElementName( (trim($constantDescriptor->getNamespace(), '\\') ? $constantDescriptor->getNamespace() : '') . '\\' . $data->getShortName() ); $this->assembleDocBlock($data->getDocBlock(), $constantDescriptor); $constantDescriptor->setLine($data->getLinenumber()); return $constantDescriptor; }
[ "public", "function", "create", "(", "$", "data", ")", "{", "$", "constantDescriptor", "=", "new", "ConstantDescriptor", "(", ")", ";", "$", "constantDescriptor", "->", "setName", "(", "$", "data", "->", "getShortName", "(", ")", ")", ";", "$", "constantDescriptor", "->", "setValue", "(", "$", "data", "->", "getValue", "(", ")", ")", ";", "// Reflection library formulates namespace as global but this is not wanted for phpDocumentor itself", "$", "constantDescriptor", "->", "setNamespace", "(", "'\\\\'", ".", "(", "strtolower", "(", "$", "data", "->", "getNamespace", "(", ")", ")", "==", "'global'", "?", "''", ":", "$", "data", "->", "getNamespace", "(", ")", ")", ")", ";", "$", "constantDescriptor", "->", "setFullyQualifiedStructuralElementName", "(", "(", "trim", "(", "$", "constantDescriptor", "->", "getNamespace", "(", ")", ",", "'\\\\'", ")", "?", "$", "constantDescriptor", "->", "getNamespace", "(", ")", ":", "''", ")", ".", "'\\\\'", ".", "$", "data", "->", "getShortName", "(", ")", ")", ";", "$", "this", "->", "assembleDocBlock", "(", "$", "data", "->", "getDocBlock", "(", ")", ",", "$", "constantDescriptor", ")", ";", "$", "constantDescriptor", "->", "setLine", "(", "$", "data", "->", "getLinenumber", "(", ")", ")", ";", "return", "$", "constantDescriptor", ";", "}" ]
Creates a Descriptor from the provided data. @param ConstantReflector $data @return ConstantDescriptor
[ "Creates", "a", "Descriptor", "from", "the", "provided", "data", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Descriptor/Builder/Reflector/ConstantAssembler.php#L29-L48
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Mail/src/parser/parts/multipart_parser.php
ezcMailMultipartParser.parseBody
public function parseBody( $origLine ) { if ( $this->parserState == self::PARSE_STATE_POST_LAST ) { return; } $line = rtrim( $origLine, "\r\n" ); // check if we hit any of the boundaries $newPart = false; $endOfMultipart = false; if ( strlen( $line ) > 0 && $line[0] == "-" ) { if ( strcmp( trim( $line ), '--' . $this->boundary ) === 0 ) { $newPart = true; } else if ( strcmp( trim( $line ), '--' . $this->boundary . '--' ) === 0 ) { $endOfMultipart = true; } } // actions to do when starting or finishing a part if ( $newPart || $endOfMultipart ) { if ( $this->parserState != self::PARSE_STATE_BODY ) { // something is b0rked, we got a new separator before getting a body // we'll skip this part and continue to the next $this->currentPartParser = null; $this->currentPartHeaders = new ezcMailHeadersHolder(); $this->parserState = $newPart ? self::PARSE_STATE_HEADERS : self::PARSE_STATE_POST_LAST; } else { // complete the work on the current part if there was any if ( $this->currentPartParser !== null ) { $part = $this->currentPartParser->finish(); if ( $part !== null ) // parsing failed { $this->partDone( $part ); } } // prepare for a new part if any $this->currentPartParser = null; $this->parserState =self::PARSE_STATE_POST_LAST; if ( $newPart ) { $this->parserState = self::PARSE_STATE_HEADERS; $this->currentPartHeaders = new ezcMailHeadersHolder(); } } } // normal data, pass to headers or current body else { if ( $this->parserState == self::PARSE_STATE_HEADERS && $line == '' ) { $this->currentPartParser = self::createPartParserForHeaders( $this->currentPartHeaders ); $this->parserState = self::PARSE_STATE_BODY; } else if ( $this->parserState == self::PARSE_STATE_HEADERS ) { $this->parseHeader( $line, $this->currentPartHeaders ); } else if ( $this->parserState == self::PARSE_STATE_BODY ) { if ( $this->currentPartParser ) // we may have none if the part type was unknown { // send body data to the part $this->currentPartParser->parseBody( $origLine ); } } // we are done parsing the multipart, ignore anything else pushed to us. } }
php
public function parseBody( $origLine ) { if ( $this->parserState == self::PARSE_STATE_POST_LAST ) { return; } $line = rtrim( $origLine, "\r\n" ); // check if we hit any of the boundaries $newPart = false; $endOfMultipart = false; if ( strlen( $line ) > 0 && $line[0] == "-" ) { if ( strcmp( trim( $line ), '--' . $this->boundary ) === 0 ) { $newPart = true; } else if ( strcmp( trim( $line ), '--' . $this->boundary . '--' ) === 0 ) { $endOfMultipart = true; } } // actions to do when starting or finishing a part if ( $newPart || $endOfMultipart ) { if ( $this->parserState != self::PARSE_STATE_BODY ) { // something is b0rked, we got a new separator before getting a body // we'll skip this part and continue to the next $this->currentPartParser = null; $this->currentPartHeaders = new ezcMailHeadersHolder(); $this->parserState = $newPart ? self::PARSE_STATE_HEADERS : self::PARSE_STATE_POST_LAST; } else { // complete the work on the current part if there was any if ( $this->currentPartParser !== null ) { $part = $this->currentPartParser->finish(); if ( $part !== null ) // parsing failed { $this->partDone( $part ); } } // prepare for a new part if any $this->currentPartParser = null; $this->parserState =self::PARSE_STATE_POST_LAST; if ( $newPart ) { $this->parserState = self::PARSE_STATE_HEADERS; $this->currentPartHeaders = new ezcMailHeadersHolder(); } } } // normal data, pass to headers or current body else { if ( $this->parserState == self::PARSE_STATE_HEADERS && $line == '' ) { $this->currentPartParser = self::createPartParserForHeaders( $this->currentPartHeaders ); $this->parserState = self::PARSE_STATE_BODY; } else if ( $this->parserState == self::PARSE_STATE_HEADERS ) { $this->parseHeader( $line, $this->currentPartHeaders ); } else if ( $this->parserState == self::PARSE_STATE_BODY ) { if ( $this->currentPartParser ) // we may have none if the part type was unknown { // send body data to the part $this->currentPartParser->parseBody( $origLine ); } } // we are done parsing the multipart, ignore anything else pushed to us. } }
[ "public", "function", "parseBody", "(", "$", "origLine", ")", "{", "if", "(", "$", "this", "->", "parserState", "==", "self", "::", "PARSE_STATE_POST_LAST", ")", "{", "return", ";", "}", "$", "line", "=", "rtrim", "(", "$", "origLine", ",", "\"\\r\\n\"", ")", ";", "// check if we hit any of the boundaries", "$", "newPart", "=", "false", ";", "$", "endOfMultipart", "=", "false", ";", "if", "(", "strlen", "(", "$", "line", ")", ">", "0", "&&", "$", "line", "[", "0", "]", "==", "\"-\"", ")", "{", "if", "(", "strcmp", "(", "trim", "(", "$", "line", ")", ",", "'--'", ".", "$", "this", "->", "boundary", ")", "===", "0", ")", "{", "$", "newPart", "=", "true", ";", "}", "else", "if", "(", "strcmp", "(", "trim", "(", "$", "line", ")", ",", "'--'", ".", "$", "this", "->", "boundary", ".", "'--'", ")", "===", "0", ")", "{", "$", "endOfMultipart", "=", "true", ";", "}", "}", "// actions to do when starting or finishing a part", "if", "(", "$", "newPart", "||", "$", "endOfMultipart", ")", "{", "if", "(", "$", "this", "->", "parserState", "!=", "self", "::", "PARSE_STATE_BODY", ")", "{", "// something is b0rked, we got a new separator before getting a body", "// we'll skip this part and continue to the next", "$", "this", "->", "currentPartParser", "=", "null", ";", "$", "this", "->", "currentPartHeaders", "=", "new", "ezcMailHeadersHolder", "(", ")", ";", "$", "this", "->", "parserState", "=", "$", "newPart", "?", "self", "::", "PARSE_STATE_HEADERS", ":", "self", "::", "PARSE_STATE_POST_LAST", ";", "}", "else", "{", "// complete the work on the current part if there was any", "if", "(", "$", "this", "->", "currentPartParser", "!==", "null", ")", "{", "$", "part", "=", "$", "this", "->", "currentPartParser", "->", "finish", "(", ")", ";", "if", "(", "$", "part", "!==", "null", ")", "// parsing failed", "{", "$", "this", "->", "partDone", "(", "$", "part", ")", ";", "}", "}", "// prepare for a new part if any", "$", "this", "->", "currentPartParser", "=", "null", ";", "$", "this", "->", "parserState", "=", "self", "::", "PARSE_STATE_POST_LAST", ";", "if", "(", "$", "newPart", ")", "{", "$", "this", "->", "parserState", "=", "self", "::", "PARSE_STATE_HEADERS", ";", "$", "this", "->", "currentPartHeaders", "=", "new", "ezcMailHeadersHolder", "(", ")", ";", "}", "}", "}", "// normal data, pass to headers or current body", "else", "{", "if", "(", "$", "this", "->", "parserState", "==", "self", "::", "PARSE_STATE_HEADERS", "&&", "$", "line", "==", "''", ")", "{", "$", "this", "->", "currentPartParser", "=", "self", "::", "createPartParserForHeaders", "(", "$", "this", "->", "currentPartHeaders", ")", ";", "$", "this", "->", "parserState", "=", "self", "::", "PARSE_STATE_BODY", ";", "}", "else", "if", "(", "$", "this", "->", "parserState", "==", "self", "::", "PARSE_STATE_HEADERS", ")", "{", "$", "this", "->", "parseHeader", "(", "$", "line", ",", "$", "this", "->", "currentPartHeaders", ")", ";", "}", "else", "if", "(", "$", "this", "->", "parserState", "==", "self", "::", "PARSE_STATE_BODY", ")", "{", "if", "(", "$", "this", "->", "currentPartParser", ")", "// we may have none if the part type was unknown", "{", "// send body data to the part", "$", "this", "->", "currentPartParser", "->", "parseBody", "(", "$", "origLine", ")", ";", "}", "}", "// we are done parsing the multipart, ignore anything else pushed to us.", "}", "}" ]
Parses a multipart body. @throws ezcBaseFileNotFoundException if a neccessary temporary file could not be opened. @param string $origLine
[ "Parses", "a", "multipart", "body", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/parser/parts/multipart_parser.php#L106-L185
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Mail/src/parser/parts/multipart_parser.php
ezcMailMultipartParser.finish
public function finish() { if ( $this->parserState != self::PARSE_STATE_POST_LAST ) { // this should never happen // let's give the last parser a chance to clean up after himself if ( $this->currentPartParser !== null ) { $part = $this->currentPartParser->finish(); $this->partDone( $part ); $this->currentPartParser = null; } } $multipart = $this->finishMultipart(); ezcMailPartParser::parsePartHeaders( $this->headers, $multipart ); $multipart->boundary = $this->boundary; return $multipart; }
php
public function finish() { if ( $this->parserState != self::PARSE_STATE_POST_LAST ) { // this should never happen // let's give the last parser a chance to clean up after himself if ( $this->currentPartParser !== null ) { $part = $this->currentPartParser->finish(); $this->partDone( $part ); $this->currentPartParser = null; } } $multipart = $this->finishMultipart(); ezcMailPartParser::parsePartHeaders( $this->headers, $multipart ); $multipart->boundary = $this->boundary; return $multipart; }
[ "public", "function", "finish", "(", ")", "{", "if", "(", "$", "this", "->", "parserState", "!=", "self", "::", "PARSE_STATE_POST_LAST", ")", "{", "// this should never happen", "// let's give the last parser a chance to clean up after himself", "if", "(", "$", "this", "->", "currentPartParser", "!==", "null", ")", "{", "$", "part", "=", "$", "this", "->", "currentPartParser", "->", "finish", "(", ")", ";", "$", "this", "->", "partDone", "(", "$", "part", ")", ";", "$", "this", "->", "currentPartParser", "=", "null", ";", "}", "}", "$", "multipart", "=", "$", "this", "->", "finishMultipart", "(", ")", ";", "ezcMailPartParser", "::", "parsePartHeaders", "(", "$", "this", "->", "headers", ",", "$", "multipart", ")", ";", "$", "multipart", "->", "boundary", "=", "$", "this", "->", "boundary", ";", "return", "$", "multipart", ";", "}" ]
Completes the parsing of the multipart and returns the corresponding part. This method should not be overriden. Use finishMultipart() instead. @return ezcMailMultipart
[ "Completes", "the", "parsing", "of", "the", "multipart", "and", "returns", "the", "corresponding", "part", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/parser/parts/multipart_parser.php#L194-L211
j-d/draggy
src/Draggy/Autocode/PHPAttribute.php
PHPAttribute.getPhpType
public function getPhpType() { if ($this->type === 'object') { if (is_null($this->getSubtype())) { throw new \InvalidArgumentException('Attribute ' . $this->getName() . ' on the entity ' . $this->getEntity()->getName() . ' is marked as an object but doesn\'t have a subtype'); } if ($this->isEntitySubtype()) { return $this->getEntitySubtype()->getName(); } else { return $this->getSubtype(); } } elseif ($this->type === 'array' && null !== $this->getSubtype()) { if ($this->isEntitySubtype()) { return $this->getEntitySubtype()->getName() . '[]'; } else { return $this->getSubtype() . '[]'; } } else { if (is_null($this->getForeign())) { return self::$PHP_VARS[$this->getType()]; } else { if ($this->getForeign() === 'OneToOne' || $this->getForeign() === 'ManyToOne' && !$this->getInverse()) { return $this->getForeignEntity()->getName(); } else { return $this->getForeignEntity()->getName() . '[]|Collection'; } } } }
php
public function getPhpType() { if ($this->type === 'object') { if (is_null($this->getSubtype())) { throw new \InvalidArgumentException('Attribute ' . $this->getName() . ' on the entity ' . $this->getEntity()->getName() . ' is marked as an object but doesn\'t have a subtype'); } if ($this->isEntitySubtype()) { return $this->getEntitySubtype()->getName(); } else { return $this->getSubtype(); } } elseif ($this->type === 'array' && null !== $this->getSubtype()) { if ($this->isEntitySubtype()) { return $this->getEntitySubtype()->getName() . '[]'; } else { return $this->getSubtype() . '[]'; } } else { if (is_null($this->getForeign())) { return self::$PHP_VARS[$this->getType()]; } else { if ($this->getForeign() === 'OneToOne' || $this->getForeign() === 'ManyToOne' && !$this->getInverse()) { return $this->getForeignEntity()->getName(); } else { return $this->getForeignEntity()->getName() . '[]|Collection'; } } } }
[ "public", "function", "getPhpType", "(", ")", "{", "if", "(", "$", "this", "->", "type", "===", "'object'", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "getSubtype", "(", ")", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Attribute '", ".", "$", "this", "->", "getName", "(", ")", ".", "' on the entity '", ".", "$", "this", "->", "getEntity", "(", ")", "->", "getName", "(", ")", ".", "' is marked as an object but doesn\\'t have a subtype'", ")", ";", "}", "if", "(", "$", "this", "->", "isEntitySubtype", "(", ")", ")", "{", "return", "$", "this", "->", "getEntitySubtype", "(", ")", "->", "getName", "(", ")", ";", "}", "else", "{", "return", "$", "this", "->", "getSubtype", "(", ")", ";", "}", "}", "elseif", "(", "$", "this", "->", "type", "===", "'array'", "&&", "null", "!==", "$", "this", "->", "getSubtype", "(", ")", ")", "{", "if", "(", "$", "this", "->", "isEntitySubtype", "(", ")", ")", "{", "return", "$", "this", "->", "getEntitySubtype", "(", ")", "->", "getName", "(", ")", ".", "'[]'", ";", "}", "else", "{", "return", "$", "this", "->", "getSubtype", "(", ")", ".", "'[]'", ";", "}", "}", "else", "{", "if", "(", "is_null", "(", "$", "this", "->", "getForeign", "(", ")", ")", ")", "{", "return", "self", "::", "$", "PHP_VARS", "[", "$", "this", "->", "getType", "(", ")", "]", ";", "}", "else", "{", "if", "(", "$", "this", "->", "getForeign", "(", ")", "===", "'OneToOne'", "||", "$", "this", "->", "getForeign", "(", ")", "===", "'ManyToOne'", "&&", "!", "$", "this", "->", "getInverse", "(", ")", ")", "{", "return", "$", "this", "->", "getForeignEntity", "(", ")", "->", "getName", "(", ")", ";", "}", "else", "{", "return", "$", "this", "->", "getForeignEntity", "(", ")", "->", "getName", "(", ")", ".", "'[]|Collection'", ";", "}", "}", "}", "}" ]
<user-additions part="settersAndGetters">
[ "<user", "-", "additions", "part", "=", "settersAndGetters", ">" ]
train
https://github.com/j-d/draggy/blob/97ffc66e1aacb5f685d7aac5251c4abb8888d4bb/src/Draggy/Autocode/PHPAttribute.php#L53-L82
j-d/draggy
src/Draggy/Autocode/PHPAttribute.php
PHPAttribute.describe
public function describe() { $ret = ''; $ret .= 'PHPType = ' . $this->getPhpType() . "\n"; $ret .= 'PHPParameterType = ' . $this->getPhpParameterType() . "\n"; return parent::describe() . $ret; }
php
public function describe() { $ret = ''; $ret .= 'PHPType = ' . $this->getPhpType() . "\n"; $ret .= 'PHPParameterType = ' . $this->getPhpParameterType() . "\n"; return parent::describe() . $ret; }
[ "public", "function", "describe", "(", ")", "{", "$", "ret", "=", "''", ";", "$", "ret", ".=", "'PHPType = '", ".", "$", "this", "->", "getPhpType", "(", ")", ".", "\"\\n\"", ";", "$", "ret", ".=", "'PHPParameterType = '", ".", "$", "this", "->", "getPhpParameterType", "(", ")", ".", "\"\\n\"", ";", "return", "parent", "::", "describe", "(", ")", ".", "$", "ret", ";", "}" ]
<user-additions part="otherMethods">
[ "<user", "-", "additions", "part", "=", "otherMethods", ">" ]
train
https://github.com/j-d/draggy/blob/97ffc66e1aacb5f685d7aac5251c4abb8888d4bb/src/Draggy/Autocode/PHPAttribute.php#L341-L349
inhere/php-librarys
src/Traits/ConfigTrait.php
ConfigTrait.getValue
public function getValue(string $name, $default = null) { $value = Arr::getByPath($this->config, $name, $default); if ($value && $value instanceof \Closure) { $value = $value(); } return $value; }
php
public function getValue(string $name, $default = null) { $value = Arr::getByPath($this->config, $name, $default); if ($value && $value instanceof \Closure) { $value = $value(); } return $value; }
[ "public", "function", "getValue", "(", "string", "$", "name", ",", "$", "default", "=", "null", ")", "{", "$", "value", "=", "Arr", "::", "getByPath", "(", "$", "this", "->", "config", ",", "$", "name", ",", "$", "default", ")", ";", "if", "(", "$", "value", "&&", "$", "value", "instanceof", "\\", "Closure", ")", "{", "$", "value", "=", "$", "value", "(", ")", ";", "}", "return", "$", "value", ";", "}" ]
Method to get property Options @param string $name @param mixed $default @return mixed
[ "Method", "to", "get", "property", "Options" ]
train
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Traits/ConfigTrait.php#L37-L46
inhere/php-librarys
src/Traits/ConfigTrait.php
ConfigTrait.delValue
public function delValue($name) { $value = null; if ($this->hasConfig($name)) { $value = $this->getValue($name); unset($this->config[$name]); } return $value; }
php
public function delValue($name) { $value = null; if ($this->hasConfig($name)) { $value = $this->getValue($name); unset($this->config[$name]); } return $value; }
[ "public", "function", "delValue", "(", "$", "name", ")", "{", "$", "value", "=", "null", ";", "if", "(", "$", "this", "->", "hasConfig", "(", "$", "name", ")", ")", "{", "$", "value", "=", "$", "this", "->", "getValue", "(", "$", "name", ")", ";", "unset", "(", "$", "this", "->", "config", "[", "$", "name", "]", ")", ";", "}", "return", "$", "value", ";", "}" ]
delete a option @param $name @return mixed|null
[ "delete", "a", "option" ]
train
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Traits/ConfigTrait.php#L66-L77
inhere/php-librarys
src/Traits/ConfigTrait.php
ConfigTrait.getConfig
public function getConfig(string $key = null) { if ($key) { return $this->getValue($key); } return $this->config; }
php
public function getConfig(string $key = null) { if ($key) { return $this->getValue($key); } return $this->config; }
[ "public", "function", "getConfig", "(", "string", "$", "key", "=", "null", ")", "{", "if", "(", "$", "key", ")", "{", "return", "$", "this", "->", "getValue", "(", "$", "key", ")", ";", "}", "return", "$", "this", "->", "config", ";", "}" ]
Method to get property Options @param string|null $key @return array
[ "Method", "to", "get", "property", "Options" ]
train
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Traits/ConfigTrait.php#L84-L91
inhere/php-librarys
src/Traits/ConfigTrait.php
ConfigTrait.setConfig
public function setConfig(array $config, $loopMerge = true) { $this->config = $loopMerge ? Arr::merge($this->config, $config) : $config; return $this; }
php
public function setConfig(array $config, $loopMerge = true) { $this->config = $loopMerge ? Arr::merge($this->config, $config) : $config; return $this; }
[ "public", "function", "setConfig", "(", "array", "$", "config", ",", "$", "loopMerge", "=", "true", ")", "{", "$", "this", "->", "config", "=", "$", "loopMerge", "?", "Arr", "::", "merge", "(", "$", "this", "->", "config", ",", "$", "config", ")", ":", "$", "config", ";", "return", "$", "this", ";", "}" ]
Method to set property config @param array $config @param bool $loopMerge @return static Return self to support chaining.
[ "Method", "to", "set", "property", "config" ]
train
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Traits/ConfigTrait.php#L99-L104
antaresproject/notifications
src/Contents.php
Contents.find
public function find(string $operation, string $locale) { $model = $this->notifications->first(function ($value) use($operation, $locale) { return $value->code === $locale && ($value->title === $operation || $value->name === $operation); }); return $model ? $model->content : false; }
php
public function find(string $operation, string $locale) { $model = $this->notifications->first(function ($value) use($operation, $locale) { return $value->code === $locale && ($value->title === $operation || $value->name === $operation); }); return $model ? $model->content : false; }
[ "public", "function", "find", "(", "string", "$", "operation", ",", "string", "$", "locale", ")", "{", "$", "model", "=", "$", "this", "->", "notifications", "->", "first", "(", "function", "(", "$", "value", ")", "use", "(", "$", "operation", ",", "$", "locale", ")", "{", "return", "$", "value", "->", "code", "===", "$", "locale", "&&", "(", "$", "value", "->", "title", "===", "$", "operation", "||", "$", "value", "->", "name", "===", "$", "operation", ")", ";", "}", ")", ";", "return", "$", "model", "?", "$", "model", "->", "content", ":", "false", ";", "}" ]
Finds notification content by title and locale. @param string $operation @param string $locale @return bool
[ "Finds", "notification", "content", "by", "title", "and", "locale", "." ]
train
https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Contents.php#L64-L71
sciactive/nymph-server
src/Drivers/PostgreSQLDriver.php
PostgreSQLDriver.connect
public function connect() { // Check that the PostgreSQL extension is installed. if (!is_callable('pg_connect')) { throw new Exceptions\UnableToConnectException( 'PostgreSQL PHP extension is not available. It probably has not '. 'been installed. Please install and configure it in order to use '. 'PostgreSQL.' ); } $connectionType = $this->config['PostgreSQL']['connection_type']; $host = $this->config['PostgreSQL']['host']; $port = $this->config['PostgreSQL']['port']; $user = $this->config['PostgreSQL']['user']; $password = $this->config['PostgreSQL']['password']; $database = $this->config['PostgreSQL']['database']; // Connecting, selecting database if (!$this->connected) { if ($connectionType === 'host') { $connectString = 'host=\''.addslashes($host). '\' port=\''.addslashes($port). '\' dbname=\''.addslashes($database). '\' user=\''.addslashes($user). '\' password=\''.addslashes($password). '\' connect_timeout=5'; } else { $connectString = 'dbname=\''.addslashes($database). '\' user=\''.addslashes($user). '\' password=\''.addslashes($password). '\' connect_timeout=5'; } if ($this->config['PostgreSQL']['allow_persistent']) { $this->link = pg_connect( $connectString. ' options=\'-c enable_hashjoin=off -c enable_mergejoin=off\'' ); } else { $this->link = pg_connect( $connectString. ' options=\'-c enable_hashjoin=off -c enable_mergejoin=off\'', PGSQL_CONNECT_FORCE_NEW ); // Don't think this is necessary, but if put in options, will guarantee // connection is new. " -c timezone='.round(rand(10001000, 10009999)).'" } if ($this->link) { $this->connected = true; } else { $this->connected = false; if ($host === 'localhost' && $user === 'nymph' && $password === 'password' && $database === 'nymph' && $connectionType === 'host') { throw new Exceptions\NotConfiguredException(); } else { throw new Exceptions\UnableToConnectException( 'Could not connect: '. pg_last_error() ); } } } return $this->connected; }
php
public function connect() { // Check that the PostgreSQL extension is installed. if (!is_callable('pg_connect')) { throw new Exceptions\UnableToConnectException( 'PostgreSQL PHP extension is not available. It probably has not '. 'been installed. Please install and configure it in order to use '. 'PostgreSQL.' ); } $connectionType = $this->config['PostgreSQL']['connection_type']; $host = $this->config['PostgreSQL']['host']; $port = $this->config['PostgreSQL']['port']; $user = $this->config['PostgreSQL']['user']; $password = $this->config['PostgreSQL']['password']; $database = $this->config['PostgreSQL']['database']; // Connecting, selecting database if (!$this->connected) { if ($connectionType === 'host') { $connectString = 'host=\''.addslashes($host). '\' port=\''.addslashes($port). '\' dbname=\''.addslashes($database). '\' user=\''.addslashes($user). '\' password=\''.addslashes($password). '\' connect_timeout=5'; } else { $connectString = 'dbname=\''.addslashes($database). '\' user=\''.addslashes($user). '\' password=\''.addslashes($password). '\' connect_timeout=5'; } if ($this->config['PostgreSQL']['allow_persistent']) { $this->link = pg_connect( $connectString. ' options=\'-c enable_hashjoin=off -c enable_mergejoin=off\'' ); } else { $this->link = pg_connect( $connectString. ' options=\'-c enable_hashjoin=off -c enable_mergejoin=off\'', PGSQL_CONNECT_FORCE_NEW ); // Don't think this is necessary, but if put in options, will guarantee // connection is new. " -c timezone='.round(rand(10001000, 10009999)).'" } if ($this->link) { $this->connected = true; } else { $this->connected = false; if ($host === 'localhost' && $user === 'nymph' && $password === 'password' && $database === 'nymph' && $connectionType === 'host') { throw new Exceptions\NotConfiguredException(); } else { throw new Exceptions\UnableToConnectException( 'Could not connect: '. pg_last_error() ); } } } return $this->connected; }
[ "public", "function", "connect", "(", ")", "{", "// Check that the PostgreSQL extension is installed.", "if", "(", "!", "is_callable", "(", "'pg_connect'", ")", ")", "{", "throw", "new", "Exceptions", "\\", "UnableToConnectException", "(", "'PostgreSQL PHP extension is not available. It probably has not '", ".", "'been installed. Please install and configure it in order to use '", ".", "'PostgreSQL.'", ")", ";", "}", "$", "connectionType", "=", "$", "this", "->", "config", "[", "'PostgreSQL'", "]", "[", "'connection_type'", "]", ";", "$", "host", "=", "$", "this", "->", "config", "[", "'PostgreSQL'", "]", "[", "'host'", "]", ";", "$", "port", "=", "$", "this", "->", "config", "[", "'PostgreSQL'", "]", "[", "'port'", "]", ";", "$", "user", "=", "$", "this", "->", "config", "[", "'PostgreSQL'", "]", "[", "'user'", "]", ";", "$", "password", "=", "$", "this", "->", "config", "[", "'PostgreSQL'", "]", "[", "'password'", "]", ";", "$", "database", "=", "$", "this", "->", "config", "[", "'PostgreSQL'", "]", "[", "'database'", "]", ";", "// Connecting, selecting database", "if", "(", "!", "$", "this", "->", "connected", ")", "{", "if", "(", "$", "connectionType", "===", "'host'", ")", "{", "$", "connectString", "=", "'host=\\''", ".", "addslashes", "(", "$", "host", ")", ".", "'\\' port=\\''", ".", "addslashes", "(", "$", "port", ")", ".", "'\\' dbname=\\''", ".", "addslashes", "(", "$", "database", ")", ".", "'\\' user=\\''", ".", "addslashes", "(", "$", "user", ")", ".", "'\\' password=\\''", ".", "addslashes", "(", "$", "password", ")", ".", "'\\' connect_timeout=5'", ";", "}", "else", "{", "$", "connectString", "=", "'dbname=\\''", ".", "addslashes", "(", "$", "database", ")", ".", "'\\' user=\\''", ".", "addslashes", "(", "$", "user", ")", ".", "'\\' password=\\''", ".", "addslashes", "(", "$", "password", ")", ".", "'\\' connect_timeout=5'", ";", "}", "if", "(", "$", "this", "->", "config", "[", "'PostgreSQL'", "]", "[", "'allow_persistent'", "]", ")", "{", "$", "this", "->", "link", "=", "pg_connect", "(", "$", "connectString", ".", "' options=\\'-c enable_hashjoin=off -c enable_mergejoin=off\\''", ")", ";", "}", "else", "{", "$", "this", "->", "link", "=", "pg_connect", "(", "$", "connectString", ".", "' options=\\'-c enable_hashjoin=off -c enable_mergejoin=off\\''", ",", "PGSQL_CONNECT_FORCE_NEW", ")", ";", "// Don't think this is necessary, but if put in options, will guarantee", "// connection is new. \" -c timezone='.round(rand(10001000, 10009999)).'\"", "}", "if", "(", "$", "this", "->", "link", ")", "{", "$", "this", "->", "connected", "=", "true", ";", "}", "else", "{", "$", "this", "->", "connected", "=", "false", ";", "if", "(", "$", "host", "===", "'localhost'", "&&", "$", "user", "===", "'nymph'", "&&", "$", "password", "===", "'password'", "&&", "$", "database", "===", "'nymph'", "&&", "$", "connectionType", "===", "'host'", ")", "{", "throw", "new", "Exceptions", "\\", "NotConfiguredException", "(", ")", ";", "}", "else", "{", "throw", "new", "Exceptions", "\\", "UnableToConnectException", "(", "'Could not connect: '", ".", "pg_last_error", "(", ")", ")", ";", "}", "}", "}", "return", "$", "this", "->", "connected", ";", "}" ]
Connect to the PostgreSQL database. @return bool Whether this instance is connected to a PostgreSQL database after the method has run.
[ "Connect", "to", "the", "PostgreSQL", "database", "." ]
train
https://github.com/sciactive/nymph-server/blob/3c18dbf45c2750d07c798e14534dba87387beeba/src/Drivers/PostgreSQLDriver.php#L54-L117
sciactive/nymph-server
src/Drivers/PostgreSQLDriver.php
PostgreSQLDriver.disconnect
public function disconnect() { if ($this->connected) { if (is_resource($this->link)) { pg_close($this->link); } $this->connected = false; } return $this->connected; }
php
public function disconnect() { if ($this->connected) { if (is_resource($this->link)) { pg_close($this->link); } $this->connected = false; } return $this->connected; }
[ "public", "function", "disconnect", "(", ")", "{", "if", "(", "$", "this", "->", "connected", ")", "{", "if", "(", "is_resource", "(", "$", "this", "->", "link", ")", ")", "{", "pg_close", "(", "$", "this", "->", "link", ")", ";", "}", "$", "this", "->", "connected", "=", "false", ";", "}", "return", "$", "this", "->", "connected", ";", "}" ]
Disconnect from the PostgreSQL database. @return bool Whether this instance is connected to a PostgreSQL database after the method has run.
[ "Disconnect", "from", "the", "PostgreSQL", "database", "." ]
train
https://github.com/sciactive/nymph-server/blob/3c18dbf45c2750d07c798e14534dba87387beeba/src/Drivers/PostgreSQLDriver.php#L125-L133
sciactive/nymph-server
src/Drivers/PostgreSQLDriver.php
PostgreSQLDriver.createTables
private function createTables($etype = null) { $this->query('ROLLBACK; BEGIN;'); if (isset($etype)) { $etype = '_'.pg_escape_string($this->link, $etype); // Create the entity table. $this->query("CREATE TABLE IF NOT EXISTS \"{$this->prefix}entities{$etype}\" ( \"guid\" BIGINT NOT NULL, \"tags\" TEXT[], \"cdate\" NUMERIC(18,6) NOT NULL, \"mdate\" NUMERIC(18,6) NOT NULL, PRIMARY KEY (\"guid\") ) WITH ( OIDS=FALSE ); ". "ALTER TABLE \"{$this->prefix}entities{$etype}\" OWNER TO \"".pg_escape_string($this->link, $this->config['PostgreSQL']['user'])."\"; ". "DROP INDEX IF EXISTS \"{$this->prefix}entities{$etype}_id_cdate\"; ". "CREATE INDEX \"{$this->prefix}entities{$etype}_id_cdate\" ON \"{$this->prefix}entities{$etype}\" USING btree (\"cdate\"); ". "DROP INDEX IF EXISTS \"{$this->prefix}entities{$etype}_id_mdate\"; ". "CREATE INDEX \"{$this->prefix}entities{$etype}_id_mdate\" ON \"{$this->prefix}entities{$etype}\" USING btree (\"mdate\"); ". "DROP INDEX IF EXISTS \"{$this->prefix}entities{$etype}_id_tags\"; ". "CREATE INDEX \"{$this->prefix}entities{$etype}_id_tags\" ON \"{$this->prefix}entities{$etype}\" USING gin (\"tags\");"); // Create the data table. $this->query("CREATE TABLE IF NOT EXISTS \"{$this->prefix}data{$etype}\" ( \"guid\" BIGINT NOT NULL, \"name\" TEXT NOT NULL, \"value\" TEXT NOT NULL, PRIMARY KEY (\"guid\", \"name\"), FOREIGN KEY (\"guid\") REFERENCES \"{$this->prefix}entities{$etype}\" (\"guid\") MATCH SIMPLE ON UPDATE NO ACTION ON DELETE CASCADE ) WITH ( OIDS=FALSE ); ". "ALTER TABLE \"{$this->prefix}data{$etype}\" OWNER TO \"".pg_escape_string($this->link, $this->config['PostgreSQL']['user'])."\"; ". "DROP INDEX IF EXISTS \"{$this->prefix}data{$etype}_id_guid\"; ". "CREATE INDEX \"{$this->prefix}data{$etype}_id_guid\" ON \"{$this->prefix}data{$etype}\" USING btree (\"guid\"); ". "DROP INDEX IF EXISTS \"{$this->prefix}data{$etype}_id_name\"; ". "CREATE INDEX \"{$this->prefix}data{$etype}_id_name\" ON \"{$this->prefix}data{$etype}\" USING btree (\"name\"); ". "DROP INDEX IF EXISTS \"{$this->prefix}data{$etype}_id_guid_name__user\"; ". "CREATE INDEX \"{$this->prefix}data{$etype}_id_guid_name__user\" ON \"{$this->prefix}data{$etype}\" USING btree (\"guid\") WHERE \"name\" = 'user'::text; ". "DROP INDEX IF EXISTS \"{$this->prefix}data{$etype}_id_guid_name__group\"; ". "CREATE INDEX \"{$this->prefix}data{$etype}_id_guid_name__group\" ON \"{$this->prefix}data{$etype}\" USING btree (\"guid\") WHERE \"name\" = 'group'::text;"); $this->query("CREATE TABLE IF NOT EXISTS \"{$this->prefix}comparisons{$etype}\" ( \"guid\" BIGINT NOT NULL, \"name\" TEXT NOT NULL, \"eq_true\" BOOLEAN, \"eq_one\" BOOLEAN, \"eq_zero\" BOOLEAN, \"eq_negone\" BOOLEAN, \"eq_emptyarray\" BOOLEAN, \"string\" TEXT, \"int\" BIGINT, \"float\" DOUBLE PRECISION, \"is_int\" BOOLEAN NOT NULL, PRIMARY KEY (\"guid\", \"name\"), FOREIGN KEY (\"guid\") REFERENCES \"{$this->prefix}entities{$etype}\" (\"guid\") MATCH SIMPLE ON UPDATE NO ACTION ON DELETE CASCADE ) WITH ( OIDS=FALSE ); ". "ALTER TABLE \"{$this->prefix}comparisons{$etype}\" OWNER TO \"".pg_escape_string($this->link, $this->config['PostgreSQL']['user'])."\"; ". "DROP INDEX IF EXISTS \"{$this->prefix}comparisons{$etype}_id_guid\"; ". "CREATE INDEX \"{$this->prefix}comparisons{$etype}_id_guid\" ON \"{$this->prefix}comparisons{$etype}\" USING btree (\"guid\"); ". "DROP INDEX IF EXISTS \"{$this->prefix}comparisons{$etype}_id_name\"; ". "CREATE INDEX \"{$this->prefix}comparisons{$etype}_id_name\" ON \"{$this->prefix}comparisons{$etype}\" USING btree (\"name\"); ". "DROP INDEX IF EXISTS \"{$this->prefix}comparisons{$etype}_id_guid_name_eq_true\"; ". "CREATE INDEX \"{$this->prefix}comparisons{$etype}_id_guid_name_eq_true\" ON \"{$this->prefix}comparisons{$etype}\" USING btree (\"guid\", \"name\") WHERE \"eq_true\" = TRUE; ". "DROP INDEX IF EXISTS \"{$this->prefix}comparisons{$etype}_id_guid_name_not_eq_true\"; ". "CREATE INDEX \"{$this->prefix}comparisons{$etype}_id_guid_name_not_eq_true\" ON \"{$this->prefix}comparisons{$etype}\" USING btree (\"guid\", \"name\") WHERE \"eq_true\" <> TRUE; "); $this->query("CREATE TABLE IF NOT EXISTS \"{$this->prefix}references{$etype}\" ( \"guid\" BIGINT NOT NULL, \"name\" TEXT NOT NULL, \"reference\" BIGINT NOT NULL, PRIMARY KEY (\"guid\", \"name\", \"reference\"), FOREIGN KEY (\"guid\") REFERENCES \"{$this->prefix}entities{$etype}\" (\"guid\") MATCH SIMPLE ON UPDATE NO ACTION ON DELETE CASCADE ) WITH ( OIDS=FALSE ); ". "ALTER TABLE \"{$this->prefix}references{$etype}\" OWNER TO \"".pg_escape_string($this->link, $this->config['PostgreSQL']['user'])."\"; ". "DROP INDEX IF EXISTS \"{$this->prefix}references{$etype}_id_guid\"; ". "CREATE INDEX \"{$this->prefix}references{$etype}_id_guid\" ON \"{$this->prefix}references{$etype}\" USING btree (\"guid\"); ". "DROP INDEX IF EXISTS \"{$this->prefix}references{$etype}_id_name\"; ". "CREATE INDEX \"{$this->prefix}references{$etype}_id_name\" ON \"{$this->prefix}references{$etype}\" USING btree (\"name\"); ". "DROP INDEX IF EXISTS \"{$this->prefix}references{$etype}_id_references\"; ". "CREATE INDEX \"{$this->prefix}references{$etype}_id_reference\" ON \"{$this->prefix}references{$etype}\" USING btree (\"reference\"); "); } else { // Create the GUID table. $this->query("CREATE TABLE IF NOT EXISTS \"{$this->prefix}guids\" ( \"guid\" BIGINT NOT NULL, PRIMARY KEY (\"guid\")); ". "ALTER TABLE \"{$this->prefix}guids\" OWNER TO \"".pg_escape_string($this->link, $this->config['PostgreSQL']['user'])."\";"); // Create the UID table. $this->query("CREATE TABLE IF NOT EXISTS \"{$this->prefix}uids\" ( \"name\" TEXT NOT NULL, \"cur_uid\" BIGINT NOT NULL, PRIMARY KEY (\"name\") ) WITH ( OIDS = FALSE ); ". "ALTER TABLE \"{$this->prefix}uids\" OWNER TO \"".pg_escape_string($this->link, $this->config['PostgreSQL']['user'])."\";"); if ($this->usePLPerl) { // Create the perl_match function. It's separated into two calls so // Postgres will ignore the error if plperl already exists. $this->query("CREATE OR REPLACE PROCEDURAL LANGUAGE plperl;"); $this->query("CREATE OR REPLACE FUNCTION {$this->prefix}match_perl( TEXT, TEXT, TEXT ) RETURNS BOOL AS \$code$ ". "my (\$str, \$pattern, \$mods) = @_; ". "if (\$pattern eq \'\') { ". "return true; ". "} ". "if (\$mods eq \'\') { ". "if (\$str =~ /(\$pattern)/) { ". "return true; ". "} else { ". "return false; ". "} ". "} else { ". "if (\$str =~ /(?\$mods)(\$pattern)/) { ". "return true; ". "} else { ". "return false; ". "} ". "} \$code$ LANGUAGE plperl IMMUTABLE STRICT COST 10000;"); } } $this->query('COMMIT;'); return true; }
php
private function createTables($etype = null) { $this->query('ROLLBACK; BEGIN;'); if (isset($etype)) { $etype = '_'.pg_escape_string($this->link, $etype); // Create the entity table. $this->query("CREATE TABLE IF NOT EXISTS \"{$this->prefix}entities{$etype}\" ( \"guid\" BIGINT NOT NULL, \"tags\" TEXT[], \"cdate\" NUMERIC(18,6) NOT NULL, \"mdate\" NUMERIC(18,6) NOT NULL, PRIMARY KEY (\"guid\") ) WITH ( OIDS=FALSE ); ". "ALTER TABLE \"{$this->prefix}entities{$etype}\" OWNER TO \"".pg_escape_string($this->link, $this->config['PostgreSQL']['user'])."\"; ". "DROP INDEX IF EXISTS \"{$this->prefix}entities{$etype}_id_cdate\"; ". "CREATE INDEX \"{$this->prefix}entities{$etype}_id_cdate\" ON \"{$this->prefix}entities{$etype}\" USING btree (\"cdate\"); ". "DROP INDEX IF EXISTS \"{$this->prefix}entities{$etype}_id_mdate\"; ". "CREATE INDEX \"{$this->prefix}entities{$etype}_id_mdate\" ON \"{$this->prefix}entities{$etype}\" USING btree (\"mdate\"); ". "DROP INDEX IF EXISTS \"{$this->prefix}entities{$etype}_id_tags\"; ". "CREATE INDEX \"{$this->prefix}entities{$etype}_id_tags\" ON \"{$this->prefix}entities{$etype}\" USING gin (\"tags\");"); // Create the data table. $this->query("CREATE TABLE IF NOT EXISTS \"{$this->prefix}data{$etype}\" ( \"guid\" BIGINT NOT NULL, \"name\" TEXT NOT NULL, \"value\" TEXT NOT NULL, PRIMARY KEY (\"guid\", \"name\"), FOREIGN KEY (\"guid\") REFERENCES \"{$this->prefix}entities{$etype}\" (\"guid\") MATCH SIMPLE ON UPDATE NO ACTION ON DELETE CASCADE ) WITH ( OIDS=FALSE ); ". "ALTER TABLE \"{$this->prefix}data{$etype}\" OWNER TO \"".pg_escape_string($this->link, $this->config['PostgreSQL']['user'])."\"; ". "DROP INDEX IF EXISTS \"{$this->prefix}data{$etype}_id_guid\"; ". "CREATE INDEX \"{$this->prefix}data{$etype}_id_guid\" ON \"{$this->prefix}data{$etype}\" USING btree (\"guid\"); ". "DROP INDEX IF EXISTS \"{$this->prefix}data{$etype}_id_name\"; ". "CREATE INDEX \"{$this->prefix}data{$etype}_id_name\" ON \"{$this->prefix}data{$etype}\" USING btree (\"name\"); ". "DROP INDEX IF EXISTS \"{$this->prefix}data{$etype}_id_guid_name__user\"; ". "CREATE INDEX \"{$this->prefix}data{$etype}_id_guid_name__user\" ON \"{$this->prefix}data{$etype}\" USING btree (\"guid\") WHERE \"name\" = 'user'::text; ". "DROP INDEX IF EXISTS \"{$this->prefix}data{$etype}_id_guid_name__group\"; ". "CREATE INDEX \"{$this->prefix}data{$etype}_id_guid_name__group\" ON \"{$this->prefix}data{$etype}\" USING btree (\"guid\") WHERE \"name\" = 'group'::text;"); $this->query("CREATE TABLE IF NOT EXISTS \"{$this->prefix}comparisons{$etype}\" ( \"guid\" BIGINT NOT NULL, \"name\" TEXT NOT NULL, \"eq_true\" BOOLEAN, \"eq_one\" BOOLEAN, \"eq_zero\" BOOLEAN, \"eq_negone\" BOOLEAN, \"eq_emptyarray\" BOOLEAN, \"string\" TEXT, \"int\" BIGINT, \"float\" DOUBLE PRECISION, \"is_int\" BOOLEAN NOT NULL, PRIMARY KEY (\"guid\", \"name\"), FOREIGN KEY (\"guid\") REFERENCES \"{$this->prefix}entities{$etype}\" (\"guid\") MATCH SIMPLE ON UPDATE NO ACTION ON DELETE CASCADE ) WITH ( OIDS=FALSE ); ". "ALTER TABLE \"{$this->prefix}comparisons{$etype}\" OWNER TO \"".pg_escape_string($this->link, $this->config['PostgreSQL']['user'])."\"; ". "DROP INDEX IF EXISTS \"{$this->prefix}comparisons{$etype}_id_guid\"; ". "CREATE INDEX \"{$this->prefix}comparisons{$etype}_id_guid\" ON \"{$this->prefix}comparisons{$etype}\" USING btree (\"guid\"); ". "DROP INDEX IF EXISTS \"{$this->prefix}comparisons{$etype}_id_name\"; ". "CREATE INDEX \"{$this->prefix}comparisons{$etype}_id_name\" ON \"{$this->prefix}comparisons{$etype}\" USING btree (\"name\"); ". "DROP INDEX IF EXISTS \"{$this->prefix}comparisons{$etype}_id_guid_name_eq_true\"; ". "CREATE INDEX \"{$this->prefix}comparisons{$etype}_id_guid_name_eq_true\" ON \"{$this->prefix}comparisons{$etype}\" USING btree (\"guid\", \"name\") WHERE \"eq_true\" = TRUE; ". "DROP INDEX IF EXISTS \"{$this->prefix}comparisons{$etype}_id_guid_name_not_eq_true\"; ". "CREATE INDEX \"{$this->prefix}comparisons{$etype}_id_guid_name_not_eq_true\" ON \"{$this->prefix}comparisons{$etype}\" USING btree (\"guid\", \"name\") WHERE \"eq_true\" <> TRUE; "); $this->query("CREATE TABLE IF NOT EXISTS \"{$this->prefix}references{$etype}\" ( \"guid\" BIGINT NOT NULL, \"name\" TEXT NOT NULL, \"reference\" BIGINT NOT NULL, PRIMARY KEY (\"guid\", \"name\", \"reference\"), FOREIGN KEY (\"guid\") REFERENCES \"{$this->prefix}entities{$etype}\" (\"guid\") MATCH SIMPLE ON UPDATE NO ACTION ON DELETE CASCADE ) WITH ( OIDS=FALSE ); ". "ALTER TABLE \"{$this->prefix}references{$etype}\" OWNER TO \"".pg_escape_string($this->link, $this->config['PostgreSQL']['user'])."\"; ". "DROP INDEX IF EXISTS \"{$this->prefix}references{$etype}_id_guid\"; ". "CREATE INDEX \"{$this->prefix}references{$etype}_id_guid\" ON \"{$this->prefix}references{$etype}\" USING btree (\"guid\"); ". "DROP INDEX IF EXISTS \"{$this->prefix}references{$etype}_id_name\"; ". "CREATE INDEX \"{$this->prefix}references{$etype}_id_name\" ON \"{$this->prefix}references{$etype}\" USING btree (\"name\"); ". "DROP INDEX IF EXISTS \"{$this->prefix}references{$etype}_id_references\"; ". "CREATE INDEX \"{$this->prefix}references{$etype}_id_reference\" ON \"{$this->prefix}references{$etype}\" USING btree (\"reference\"); "); } else { // Create the GUID table. $this->query("CREATE TABLE IF NOT EXISTS \"{$this->prefix}guids\" ( \"guid\" BIGINT NOT NULL, PRIMARY KEY (\"guid\")); ". "ALTER TABLE \"{$this->prefix}guids\" OWNER TO \"".pg_escape_string($this->link, $this->config['PostgreSQL']['user'])."\";"); // Create the UID table. $this->query("CREATE TABLE IF NOT EXISTS \"{$this->prefix}uids\" ( \"name\" TEXT NOT NULL, \"cur_uid\" BIGINT NOT NULL, PRIMARY KEY (\"name\") ) WITH ( OIDS = FALSE ); ". "ALTER TABLE \"{$this->prefix}uids\" OWNER TO \"".pg_escape_string($this->link, $this->config['PostgreSQL']['user'])."\";"); if ($this->usePLPerl) { // Create the perl_match function. It's separated into two calls so // Postgres will ignore the error if plperl already exists. $this->query("CREATE OR REPLACE PROCEDURAL LANGUAGE plperl;"); $this->query("CREATE OR REPLACE FUNCTION {$this->prefix}match_perl( TEXT, TEXT, TEXT ) RETURNS BOOL AS \$code$ ". "my (\$str, \$pattern, \$mods) = @_; ". "if (\$pattern eq \'\') { ". "return true; ". "} ". "if (\$mods eq \'\') { ". "if (\$str =~ /(\$pattern)/) { ". "return true; ". "} else { ". "return false; ". "} ". "} else { ". "if (\$str =~ /(?\$mods)(\$pattern)/) { ". "return true; ". "} else { ". "return false; ". "} ". "} \$code$ LANGUAGE plperl IMMUTABLE STRICT COST 10000;"); } } $this->query('COMMIT;'); return true; }
[ "private", "function", "createTables", "(", "$", "etype", "=", "null", ")", "{", "$", "this", "->", "query", "(", "'ROLLBACK; BEGIN;'", ")", ";", "if", "(", "isset", "(", "$", "etype", ")", ")", "{", "$", "etype", "=", "'_'", ".", "pg_escape_string", "(", "$", "this", "->", "link", ",", "$", "etype", ")", ";", "// Create the entity table.", "$", "this", "->", "query", "(", "\"CREATE TABLE IF NOT EXISTS \\\"{$this->prefix}entities{$etype}\\\" ( \\\"guid\\\" BIGINT NOT NULL, \\\"tags\\\" TEXT[], \\\"cdate\\\" NUMERIC(18,6) NOT NULL, \\\"mdate\\\" NUMERIC(18,6) NOT NULL, PRIMARY KEY (\\\"guid\\\") ) WITH ( OIDS=FALSE ); \"", ".", "\"ALTER TABLE \\\"{$this->prefix}entities{$etype}\\\" OWNER TO \\\"\"", ".", "pg_escape_string", "(", "$", "this", "->", "link", ",", "$", "this", "->", "config", "[", "'PostgreSQL'", "]", "[", "'user'", "]", ")", ".", "\"\\\"; \"", ".", "\"DROP INDEX IF EXISTS \\\"{$this->prefix}entities{$etype}_id_cdate\\\"; \"", ".", "\"CREATE INDEX \\\"{$this->prefix}entities{$etype}_id_cdate\\\" ON \\\"{$this->prefix}entities{$etype}\\\" USING btree (\\\"cdate\\\"); \"", ".", "\"DROP INDEX IF EXISTS \\\"{$this->prefix}entities{$etype}_id_mdate\\\"; \"", ".", "\"CREATE INDEX \\\"{$this->prefix}entities{$etype}_id_mdate\\\" ON \\\"{$this->prefix}entities{$etype}\\\" USING btree (\\\"mdate\\\"); \"", ".", "\"DROP INDEX IF EXISTS \\\"{$this->prefix}entities{$etype}_id_tags\\\"; \"", ".", "\"CREATE INDEX \\\"{$this->prefix}entities{$etype}_id_tags\\\" ON \\\"{$this->prefix}entities{$etype}\\\" USING gin (\\\"tags\\\");\"", ")", ";", "// Create the data table.", "$", "this", "->", "query", "(", "\"CREATE TABLE IF NOT EXISTS \\\"{$this->prefix}data{$etype}\\\" ( \\\"guid\\\" BIGINT NOT NULL, \\\"name\\\" TEXT NOT NULL, \\\"value\\\" TEXT NOT NULL, PRIMARY KEY (\\\"guid\\\", \\\"name\\\"), FOREIGN KEY (\\\"guid\\\") REFERENCES \\\"{$this->prefix}entities{$etype}\\\" (\\\"guid\\\") MATCH SIMPLE ON UPDATE NO ACTION ON DELETE CASCADE ) WITH ( OIDS=FALSE ); \"", ".", "\"ALTER TABLE \\\"{$this->prefix}data{$etype}\\\" OWNER TO \\\"\"", ".", "pg_escape_string", "(", "$", "this", "->", "link", ",", "$", "this", "->", "config", "[", "'PostgreSQL'", "]", "[", "'user'", "]", ")", ".", "\"\\\"; \"", ".", "\"DROP INDEX IF EXISTS \\\"{$this->prefix}data{$etype}_id_guid\\\"; \"", ".", "\"CREATE INDEX \\\"{$this->prefix}data{$etype}_id_guid\\\" ON \\\"{$this->prefix}data{$etype}\\\" USING btree (\\\"guid\\\"); \"", ".", "\"DROP INDEX IF EXISTS \\\"{$this->prefix}data{$etype}_id_name\\\"; \"", ".", "\"CREATE INDEX \\\"{$this->prefix}data{$etype}_id_name\\\" ON \\\"{$this->prefix}data{$etype}\\\" USING btree (\\\"name\\\"); \"", ".", "\"DROP INDEX IF EXISTS \\\"{$this->prefix}data{$etype}_id_guid_name__user\\\"; \"", ".", "\"CREATE INDEX \\\"{$this->prefix}data{$etype}_id_guid_name__user\\\" ON \\\"{$this->prefix}data{$etype}\\\" USING btree (\\\"guid\\\") WHERE \\\"name\\\" = 'user'::text; \"", ".", "\"DROP INDEX IF EXISTS \\\"{$this->prefix}data{$etype}_id_guid_name__group\\\"; \"", ".", "\"CREATE INDEX \\\"{$this->prefix}data{$etype}_id_guid_name__group\\\" ON \\\"{$this->prefix}data{$etype}\\\" USING btree (\\\"guid\\\") WHERE \\\"name\\\" = 'group'::text;\"", ")", ";", "$", "this", "->", "query", "(", "\"CREATE TABLE IF NOT EXISTS \\\"{$this->prefix}comparisons{$etype}\\\" ( \\\"guid\\\" BIGINT NOT NULL, \\\"name\\\" TEXT NOT NULL, \\\"eq_true\\\" BOOLEAN, \\\"eq_one\\\" BOOLEAN, \\\"eq_zero\\\" BOOLEAN, \\\"eq_negone\\\" BOOLEAN, \\\"eq_emptyarray\\\" BOOLEAN, \\\"string\\\" TEXT, \\\"int\\\" BIGINT, \\\"float\\\" DOUBLE PRECISION, \\\"is_int\\\" BOOLEAN NOT NULL, PRIMARY KEY (\\\"guid\\\", \\\"name\\\"), FOREIGN KEY (\\\"guid\\\") REFERENCES \\\"{$this->prefix}entities{$etype}\\\" (\\\"guid\\\") MATCH SIMPLE ON UPDATE NO ACTION ON DELETE CASCADE ) WITH ( OIDS=FALSE ); \"", ".", "\"ALTER TABLE \\\"{$this->prefix}comparisons{$etype}\\\" OWNER TO \\\"\"", ".", "pg_escape_string", "(", "$", "this", "->", "link", ",", "$", "this", "->", "config", "[", "'PostgreSQL'", "]", "[", "'user'", "]", ")", ".", "\"\\\"; \"", ".", "\"DROP INDEX IF EXISTS \\\"{$this->prefix}comparisons{$etype}_id_guid\\\"; \"", ".", "\"CREATE INDEX \\\"{$this->prefix}comparisons{$etype}_id_guid\\\" ON \\\"{$this->prefix}comparisons{$etype}\\\" USING btree (\\\"guid\\\"); \"", ".", "\"DROP INDEX IF EXISTS \\\"{$this->prefix}comparisons{$etype}_id_name\\\"; \"", ".", "\"CREATE INDEX \\\"{$this->prefix}comparisons{$etype}_id_name\\\" ON \\\"{$this->prefix}comparisons{$etype}\\\" USING btree (\\\"name\\\"); \"", ".", "\"DROP INDEX IF EXISTS \\\"{$this->prefix}comparisons{$etype}_id_guid_name_eq_true\\\"; \"", ".", "\"CREATE INDEX \\\"{$this->prefix}comparisons{$etype}_id_guid_name_eq_true\\\" ON \\\"{$this->prefix}comparisons{$etype}\\\" USING btree (\\\"guid\\\", \\\"name\\\") WHERE \\\"eq_true\\\" = TRUE; \"", ".", "\"DROP INDEX IF EXISTS \\\"{$this->prefix}comparisons{$etype}_id_guid_name_not_eq_true\\\"; \"", ".", "\"CREATE INDEX \\\"{$this->prefix}comparisons{$etype}_id_guid_name_not_eq_true\\\" ON \\\"{$this->prefix}comparisons{$etype}\\\" USING btree (\\\"guid\\\", \\\"name\\\") WHERE \\\"eq_true\\\" <> TRUE; \"", ")", ";", "$", "this", "->", "query", "(", "\"CREATE TABLE IF NOT EXISTS \\\"{$this->prefix}references{$etype}\\\" ( \\\"guid\\\" BIGINT NOT NULL, \\\"name\\\" TEXT NOT NULL, \\\"reference\\\" BIGINT NOT NULL, PRIMARY KEY (\\\"guid\\\", \\\"name\\\", \\\"reference\\\"), FOREIGN KEY (\\\"guid\\\") REFERENCES \\\"{$this->prefix}entities{$etype}\\\" (\\\"guid\\\") MATCH SIMPLE ON UPDATE NO ACTION ON DELETE CASCADE ) WITH ( OIDS=FALSE ); \"", ".", "\"ALTER TABLE \\\"{$this->prefix}references{$etype}\\\" OWNER TO \\\"\"", ".", "pg_escape_string", "(", "$", "this", "->", "link", ",", "$", "this", "->", "config", "[", "'PostgreSQL'", "]", "[", "'user'", "]", ")", ".", "\"\\\"; \"", ".", "\"DROP INDEX IF EXISTS \\\"{$this->prefix}references{$etype}_id_guid\\\"; \"", ".", "\"CREATE INDEX \\\"{$this->prefix}references{$etype}_id_guid\\\" ON \\\"{$this->prefix}references{$etype}\\\" USING btree (\\\"guid\\\"); \"", ".", "\"DROP INDEX IF EXISTS \\\"{$this->prefix}references{$etype}_id_name\\\"; \"", ".", "\"CREATE INDEX \\\"{$this->prefix}references{$etype}_id_name\\\" ON \\\"{$this->prefix}references{$etype}\\\" USING btree (\\\"name\\\"); \"", ".", "\"DROP INDEX IF EXISTS \\\"{$this->prefix}references{$etype}_id_references\\\"; \"", ".", "\"CREATE INDEX \\\"{$this->prefix}references{$etype}_id_reference\\\" ON \\\"{$this->prefix}references{$etype}\\\" USING btree (\\\"reference\\\"); \"", ")", ";", "}", "else", "{", "// Create the GUID table.", "$", "this", "->", "query", "(", "\"CREATE TABLE IF NOT EXISTS \\\"{$this->prefix}guids\\\" ( \\\"guid\\\" BIGINT NOT NULL, PRIMARY KEY (\\\"guid\\\")); \"", ".", "\"ALTER TABLE \\\"{$this->prefix}guids\\\" OWNER TO \\\"\"", ".", "pg_escape_string", "(", "$", "this", "->", "link", ",", "$", "this", "->", "config", "[", "'PostgreSQL'", "]", "[", "'user'", "]", ")", ".", "\"\\\";\"", ")", ";", "// Create the UID table.", "$", "this", "->", "query", "(", "\"CREATE TABLE IF NOT EXISTS \\\"{$this->prefix}uids\\\" ( \\\"name\\\" TEXT NOT NULL, \\\"cur_uid\\\" BIGINT NOT NULL, PRIMARY KEY (\\\"name\\\") ) WITH ( OIDS = FALSE ); \"", ".", "\"ALTER TABLE \\\"{$this->prefix}uids\\\" OWNER TO \\\"\"", ".", "pg_escape_string", "(", "$", "this", "->", "link", ",", "$", "this", "->", "config", "[", "'PostgreSQL'", "]", "[", "'user'", "]", ")", ".", "\"\\\";\"", ")", ";", "if", "(", "$", "this", "->", "usePLPerl", ")", "{", "// Create the perl_match function. It's separated into two calls so", "// Postgres will ignore the error if plperl already exists.", "$", "this", "->", "query", "(", "\"CREATE OR REPLACE PROCEDURAL LANGUAGE plperl;\"", ")", ";", "$", "this", "->", "query", "(", "\"CREATE OR REPLACE FUNCTION {$this->prefix}match_perl( TEXT, TEXT, TEXT ) RETURNS BOOL AS \\$code$ \"", ".", "\"my (\\$str, \\$pattern, \\$mods) = @_; \"", ".", "\"if (\\$pattern eq \\'\\') { \"", ".", "\"return true; \"", ".", "\"} \"", ".", "\"if (\\$mods eq \\'\\') { \"", ".", "\"if (\\$str =~ /(\\$pattern)/) { \"", ".", "\"return true; \"", ".", "\"} else { \"", ".", "\"return false; \"", ".", "\"} \"", ".", "\"} else { \"", ".", "\"if (\\$str =~ /(?\\$mods)(\\$pattern)/) { \"", ".", "\"return true; \"", ".", "\"} else { \"", ".", "\"return false; \"", ".", "\"} \"", ".", "\"} \\$code$ LANGUAGE plperl IMMUTABLE STRICT COST 10000;\"", ")", ";", "}", "}", "$", "this", "->", "query", "(", "'COMMIT;'", ")", ";", "return", "true", ";", "}" ]
Create entity tables in the database. @param string $etype The entity type to create a table for. If this is blank, the default tables are created.
[ "Create", "entity", "tables", "in", "the", "database", "." ]
train
https://github.com/sciactive/nymph-server/blob/3c18dbf45c2750d07c798e14534dba87387beeba/src/Drivers/PostgreSQLDriver.php#L141-L216
mikebarlow/html-helper
src/Services/CometPHP/Assets.php
Assets.getAsset
protected function getAsset($assetData) { try { $Comet = \CometPHP\Comet::getInstance(); } catch (\CometPHP\Exceptions\CometNotBooted $e) { return null; } if (! is_array($assetData)) { $assetData = [$assetData]; } $asset = $Comet['template']->getFunction('asset')->call( $this->template, $assetData ); return $asset; }
php
protected function getAsset($assetData) { try { $Comet = \CometPHP\Comet::getInstance(); } catch (\CometPHP\Exceptions\CometNotBooted $e) { return null; } if (! is_array($assetData)) { $assetData = [$assetData]; } $asset = $Comet['template']->getFunction('asset')->call( $this->template, $assetData ); return $asset; }
[ "protected", "function", "getAsset", "(", "$", "assetData", ")", "{", "try", "{", "$", "Comet", "=", "\\", "CometPHP", "\\", "Comet", "::", "getInstance", "(", ")", ";", "}", "catch", "(", "\\", "CometPHP", "\\", "Exceptions", "\\", "CometNotBooted", "$", "e", ")", "{", "return", "null", ";", "}", "if", "(", "!", "is_array", "(", "$", "assetData", ")", ")", "{", "$", "assetData", "=", "[", "$", "assetData", "]", ";", "}", "$", "asset", "=", "$", "Comet", "[", "'template'", "]", "->", "getFunction", "(", "'asset'", ")", "->", "call", "(", "$", "this", "->", "template", ",", "$", "assetData", ")", ";", "return", "$", "asset", ";", "}" ]
base function to return assets @param mixed asset path data received from the image method @return string url to pass to img or css
[ "base", "function", "to", "return", "assets" ]
train
https://github.com/mikebarlow/html-helper/blob/d9d9dc3e92ba3ecd75f3a2e5a5bc2d23f38b5f65/src/Services/CometPHP/Assets.php#L13-L31
GrupaZero/api
src/Gzero/Api/Controller/Admin/LangController.php
LangController.show
public function show($code) { $lang = $this->langRepo->getByCode($code); if (empty($lang)) { return $this->respondNotFound(); } return $this->respondWithSuccess($lang, new LangTransformer); }
php
public function show($code) { $lang = $this->langRepo->getByCode($code); if (empty($lang)) { return $this->respondNotFound(); } return $this->respondWithSuccess($lang, new LangTransformer); }
[ "public", "function", "show", "(", "$", "code", ")", "{", "$", "lang", "=", "$", "this", "->", "langRepo", "->", "getByCode", "(", "$", "code", ")", ";", "if", "(", "empty", "(", "$", "lang", ")", ")", "{", "return", "$", "this", "->", "respondNotFound", "(", ")", ";", "}", "return", "$", "this", "->", "respondWithSuccess", "(", "$", "lang", ",", "new", "LangTransformer", ")", ";", "}" ]
Display the specified resource. @param int $code Lang code @return Response
[ "Display", "the", "specified", "resource", "." ]
train
https://github.com/GrupaZero/api/blob/fc544bb6057274e9d5e7b617346c3f854ea5effd/src/Gzero/Api/Controller/Admin/LangController.php#L53-L60
rem42/scraper
Cache/FileSystemCache.php
FileSystemCache.setCacheFolder
public function setCacheFolder(?string $cacheFolder) { if (substr($cacheFolder, -1) !== '/') { $cacheFolder .= "/"; } $this->cacheFolder = $cacheFolder; $this->initCache(); return $this; }
php
public function setCacheFolder(?string $cacheFolder) { if (substr($cacheFolder, -1) !== '/') { $cacheFolder .= "/"; } $this->cacheFolder = $cacheFolder; $this->initCache(); return $this; }
[ "public", "function", "setCacheFolder", "(", "?", "string", "$", "cacheFolder", ")", "{", "if", "(", "substr", "(", "$", "cacheFolder", ",", "-", "1", ")", "!==", "'/'", ")", "{", "$", "cacheFolder", ".=", "\"/\"", ";", "}", "$", "this", "->", "cacheFolder", "=", "$", "cacheFolder", ";", "$", "this", "->", "initCache", "(", ")", ";", "return", "$", "this", ";", "}" ]
@param string $cacheFolder @return $this
[ "@param", "string", "$cacheFolder" ]
train
https://github.com/rem42/scraper/blob/7c4ec23ce61b8187f2d8cfebdd233525359adb83/Cache/FileSystemCache.php#L43-L51
rem42/scraper
Cache/FileSystemCache.php
FileSystemCache.write
public function write($data) { $this->createFolderIfNotExist($this->folderPath()); $this->createFile($this->getFilePath(), $data); }
php
public function write($data) { $this->createFolderIfNotExist($this->folderPath()); $this->createFile($this->getFilePath(), $data); }
[ "public", "function", "write", "(", "$", "data", ")", "{", "$", "this", "->", "createFolderIfNotExist", "(", "$", "this", "->", "folderPath", "(", ")", ")", ";", "$", "this", "->", "createFile", "(", "$", "this", "->", "getFilePath", "(", ")", ",", "$", "data", ")", ";", "}" ]
@param $data @return bool|void
[ "@param", "$data" ]
train
https://github.com/rem42/scraper/blob/7c4ec23ce61b8187f2d8cfebdd233525359adb83/Cache/FileSystemCache.php#L58-L62
xiewulong/yii2-fileupload
oss/libs/guzzle/plugin/Guzzle/Plugin/Cookie/Cookie.php
Cookie.matchesDomain
public function matchesDomain($domain) { $cookieDomain = $this->getDomain(); // Domain not set or exact match. if (!$cookieDomain || !strcasecmp($domain, $cookieDomain)) { return true; } // . prefix match. if (strpos($cookieDomain, '.') === 0) { $realDomain = substr($cookieDomain, 1); // Root domains don't match except for .local. if (!substr_count($realDomain, '.') && strcasecmp($realDomain, 'local')) { return false; } if (filter_var($domain, FILTER_VALIDATE_IP)) { return false; } if (substr($domain, -strlen($realDomain)) === $realDomain) { // Match exact or 1 deep subdomain. return !strcasecmp($domain, $realDomain) || substr_count(substr($domain, 0, -strlen($realDomain)), '.') === 1; } } return false; }
php
public function matchesDomain($domain) { $cookieDomain = $this->getDomain(); // Domain not set or exact match. if (!$cookieDomain || !strcasecmp($domain, $cookieDomain)) { return true; } // . prefix match. if (strpos($cookieDomain, '.') === 0) { $realDomain = substr($cookieDomain, 1); // Root domains don't match except for .local. if (!substr_count($realDomain, '.') && strcasecmp($realDomain, 'local')) { return false; } if (filter_var($domain, FILTER_VALIDATE_IP)) { return false; } if (substr($domain, -strlen($realDomain)) === $realDomain) { // Match exact or 1 deep subdomain. return !strcasecmp($domain, $realDomain) || substr_count(substr($domain, 0, -strlen($realDomain)), '.') === 1; } } return false; }
[ "public", "function", "matchesDomain", "(", "$", "domain", ")", "{", "$", "cookieDomain", "=", "$", "this", "->", "getDomain", "(", ")", ";", "// Domain not set or exact match.", "if", "(", "!", "$", "cookieDomain", "||", "!", "strcasecmp", "(", "$", "domain", ",", "$", "cookieDomain", ")", ")", "{", "return", "true", ";", "}", "// . prefix match.", "if", "(", "strpos", "(", "$", "cookieDomain", ",", "'.'", ")", "===", "0", ")", "{", "$", "realDomain", "=", "substr", "(", "$", "cookieDomain", ",", "1", ")", ";", "// Root domains don't match except for .local.", "if", "(", "!", "substr_count", "(", "$", "realDomain", ",", "'.'", ")", "&&", "strcasecmp", "(", "$", "realDomain", ",", "'local'", ")", ")", "{", "return", "false", ";", "}", "if", "(", "filter_var", "(", "$", "domain", ",", "FILTER_VALIDATE_IP", ")", ")", "{", "return", "false", ";", "}", "if", "(", "substr", "(", "$", "domain", ",", "-", "strlen", "(", "$", "realDomain", ")", ")", "===", "$", "realDomain", ")", "{", "// Match exact or 1 deep subdomain.", "return", "!", "strcasecmp", "(", "$", "domain", ",", "$", "realDomain", ")", "||", "substr_count", "(", "substr", "(", "$", "domain", ",", "0", ",", "-", "strlen", "(", "$", "realDomain", ")", ")", ",", "'.'", ")", "===", "1", ";", "}", "}", "return", "false", ";", "}" ]
Check if the cookie matches a domain value @param string $domain Domain to check against @return bool
[ "Check", "if", "the", "cookie", "matches", "a", "domain", "value" ]
train
https://github.com/xiewulong/yii2-fileupload/blob/3e75b17a4a18dd8466e3f57c63136de03470ca82/oss/libs/guzzle/plugin/Guzzle/Plugin/Cookie/Cookie.php#L425-L455
inhere/php-librarys
src/Utils/DbRecordSort.php
DbRecordSort.setValue
public function setValue($name, $value = '') { if (\is_array($name)) { foreach ($name as $key => $val) { if (isset($this->$key)) { $this->$key = $val; } } } else { if (isset($this->$name)) { $this->$name = $value; } } }
php
public function setValue($name, $value = '') { if (\is_array($name)) { foreach ($name as $key => $val) { if (isset($this->$key)) { $this->$key = $val; } } } else { if (isset($this->$name)) { $this->$name = $value; } } }
[ "public", "function", "setValue", "(", "$", "name", ",", "$", "value", "=", "''", ")", "{", "if", "(", "\\", "is_array", "(", "$", "name", ")", ")", "{", "foreach", "(", "$", "name", "as", "$", "key", "=>", "$", "val", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "$", "key", ")", ")", "{", "$", "this", "->", "$", "key", "=", "$", "val", ";", "}", "}", "}", "else", "{", "if", "(", "isset", "(", "$", "this", "->", "$", "name", ")", ")", "{", "$", "this", "->", "$", "name", "=", "$", "value", ";", "}", "}", "}" ]
/* 1.array( 'firstRank' => rankValue, 'lastRank' => rankValue ) 2. ('firstRank','rankValue')
[ "/", "*", "1", ".", "array", "(", "firstRank", "=", ">", "rankValue", "lastRank", "=", ">", "rankValue", ")", "2", ".", "(", "firstRank", "rankValue", ")" ]
train
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Utils/DbRecordSort.php#L78-L91
inhere/php-librarys
src/Utils/DbRecordSort.php
DbRecordSort.execute
public function execute($id, $oldSortVal, $sortType = self::MOVE_UP) { if (empty($this->tableName)) { $this->error = '必须传入或设置要操作的表名称(无需前缀)!'; return false; } if ($this->firstRank === '' || $this->lastRank === '') { $this->error = '必须传入首尾记录的排序值!'; return false; } $first_rank = $this->firstRank; $last_rank = $this->lastRank; $table = $this->tableName; $PK = $this->tablePK; $field = $this->sortField; $whereCondition = $this->addCondition; switch ((string)$sortType) { case self::MOVE_TOP: # 置顶 # 阻止第一条记录升序 if ($first_rank === $oldSortVal) { $this->error = '记录已在最顶部!'; return false; } $sql = "UPDATE $table SET {$field}=" . ((int)$this->firstRank + 1) . " WHERE {$PK}=" . $id; break; case self::MOVE_UP: # 上移一位 // 阻止第一条记录升序 if ($first_rank === $oldSortVal) { $this->error = '记录已在最顶部!'; return false; } # 获取前面一记录的信息 $str_sql = "SELECT {$PK},{$field} FROM " . $table . " WHERE {$whereCondition} {$field}>'{$oldSortVal}' ORDER BY rank ASC LIMIT 1"; $pre_record = $this->pdo->query($str_sql)->fetch(\PDO::FETCH_ASSOC); $pre_record_rank = $pre_record[$field]; $pre_record_id = $pre_record[$PK]; $sql = "UPDATE $table SET {$field}='{$pre_record_rank}' WHERE {$PK}='{$id}'; UPDATE $table SET {$field}='{$oldSortVal}' WHERE {$PK}='{$pre_record_id}'"; break; case self::MOVE_DOWN: # 下移一位 // 阻止最后一条记录降序 if ($last_rank === $oldSortVal) { $this->error = '记录已在最底部!'; return false; } # 获取后面一记录的信息 $str_sql = "SELECT {$PK},{$field} FROM " . $table . " WHERE {$whereCondition} {$field}<'{$oldSortVal}' ORDER BY rank DESC LIMIT 1"; $suf_record = $this->pdo->query($str_sql)->fetch(\PDO::FETCH_ASSOC); $suf_record_rank = $suf_record[$field]; $suf_record_id = $suf_record[$PK]; $sql = "UPDATE {$table} SET {$field}='{$suf_record_rank}' WHERE {$PK}='{$id}'; UPDATE {$table} SET {$field}='{$oldSortVal}' WHERE {$PK}='{$suf_record_id}'"; break; case self::MOVE_BOTTOM: # 置底 // 阻止最后一条记录降序 if ($last_rank === $oldSortVal) { $this->error = '记录已在最底部!'; return false; } $sql = "UPDATE $table SET {$field}=" . ((int)$this->lastRank - 1) . " WHERE {$PK}=" . $id; break; default: throw new \InvalidArgumentException('Invalid argument'); break; } $affected = $this->pdo->exec($sql); if (false === $affected) { $this->error = '操作失败!请重试...'; } return true; }
php
public function execute($id, $oldSortVal, $sortType = self::MOVE_UP) { if (empty($this->tableName)) { $this->error = '必须传入或设置要操作的表名称(无需前缀)!'; return false; } if ($this->firstRank === '' || $this->lastRank === '') { $this->error = '必须传入首尾记录的排序值!'; return false; } $first_rank = $this->firstRank; $last_rank = $this->lastRank; $table = $this->tableName; $PK = $this->tablePK; $field = $this->sortField; $whereCondition = $this->addCondition; switch ((string)$sortType) { case self::MOVE_TOP: # 置顶 # 阻止第一条记录升序 if ($first_rank === $oldSortVal) { $this->error = '记录已在最顶部!'; return false; } $sql = "UPDATE $table SET {$field}=" . ((int)$this->firstRank + 1) . " WHERE {$PK}=" . $id; break; case self::MOVE_UP: # 上移一位 // 阻止第一条记录升序 if ($first_rank === $oldSortVal) { $this->error = '记录已在最顶部!'; return false; } # 获取前面一记录的信息 $str_sql = "SELECT {$PK},{$field} FROM " . $table . " WHERE {$whereCondition} {$field}>'{$oldSortVal}' ORDER BY rank ASC LIMIT 1"; $pre_record = $this->pdo->query($str_sql)->fetch(\PDO::FETCH_ASSOC); $pre_record_rank = $pre_record[$field]; $pre_record_id = $pre_record[$PK]; $sql = "UPDATE $table SET {$field}='{$pre_record_rank}' WHERE {$PK}='{$id}'; UPDATE $table SET {$field}='{$oldSortVal}' WHERE {$PK}='{$pre_record_id}'"; break; case self::MOVE_DOWN: # 下移一位 // 阻止最后一条记录降序 if ($last_rank === $oldSortVal) { $this->error = '记录已在最底部!'; return false; } # 获取后面一记录的信息 $str_sql = "SELECT {$PK},{$field} FROM " . $table . " WHERE {$whereCondition} {$field}<'{$oldSortVal}' ORDER BY rank DESC LIMIT 1"; $suf_record = $this->pdo->query($str_sql)->fetch(\PDO::FETCH_ASSOC); $suf_record_rank = $suf_record[$field]; $suf_record_id = $suf_record[$PK]; $sql = "UPDATE {$table} SET {$field}='{$suf_record_rank}' WHERE {$PK}='{$id}'; UPDATE {$table} SET {$field}='{$oldSortVal}' WHERE {$PK}='{$suf_record_id}'"; break; case self::MOVE_BOTTOM: # 置底 // 阻止最后一条记录降序 if ($last_rank === $oldSortVal) { $this->error = '记录已在最底部!'; return false; } $sql = "UPDATE $table SET {$field}=" . ((int)$this->lastRank - 1) . " WHERE {$PK}=" . $id; break; default: throw new \InvalidArgumentException('Invalid argument'); break; } $affected = $this->pdo->exec($sql); if (false === $affected) { $this->error = '操作失败!请重试...'; } return true; }
[ "public", "function", "execute", "(", "$", "id", ",", "$", "oldSortVal", ",", "$", "sortType", "=", "self", "::", "MOVE_UP", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "tableName", ")", ")", "{", "$", "this", "->", "error", "=", "'必须传入或设置要操作的表名称(无需前缀)!';", "", "return", "false", ";", "}", "if", "(", "$", "this", "->", "firstRank", "===", "''", "||", "$", "this", "->", "lastRank", "===", "''", ")", "{", "$", "this", "->", "error", "=", "'必须传入首尾记录的排序值!';", "", "return", "false", ";", "}", "$", "first_rank", "=", "$", "this", "->", "firstRank", ";", "$", "last_rank", "=", "$", "this", "->", "lastRank", ";", "$", "table", "=", "$", "this", "->", "tableName", ";", "$", "PK", "=", "$", "this", "->", "tablePK", ";", "$", "field", "=", "$", "this", "->", "sortField", ";", "$", "whereCondition", "=", "$", "this", "->", "addCondition", ";", "switch", "(", "(", "string", ")", "$", "sortType", ")", "{", "case", "self", "::", "MOVE_TOP", ":", "# 置顶", "# 阻止第一条记录升序", "if", "(", "$", "first_rank", "===", "$", "oldSortVal", ")", "{", "$", "this", "->", "error", "=", "'记录已在最顶部!';", "", "return", "false", ";", "}", "$", "sql", "=", "\"UPDATE $table SET {$field}=\"", ".", "(", "(", "int", ")", "$", "this", "->", "firstRank", "+", "1", ")", ".", "\" WHERE {$PK}=\"", ".", "$", "id", ";", "break", ";", "case", "self", "::", "MOVE_UP", ":", "# 上移一位", "// 阻止第一条记录升序", "if", "(", "$", "first_rank", "===", "$", "oldSortVal", ")", "{", "$", "this", "->", "error", "=", "'记录已在最顶部!';", "", "return", "false", ";", "}", "# 获取前面一记录的信息", "$", "str_sql", "=", "\"SELECT {$PK},{$field} FROM \"", ".", "$", "table", ".", "\" WHERE {$whereCondition} {$field}>'{$oldSortVal}' ORDER BY rank ASC LIMIT 1\"", ";", "$", "pre_record", "=", "$", "this", "->", "pdo", "->", "query", "(", "$", "str_sql", ")", "->", "fetch", "(", "\\", "PDO", "::", "FETCH_ASSOC", ")", ";", "$", "pre_record_rank", "=", "$", "pre_record", "[", "$", "field", "]", ";", "$", "pre_record_id", "=", "$", "pre_record", "[", "$", "PK", "]", ";", "$", "sql", "=", "\"UPDATE $table SET {$field}='{$pre_record_rank}' WHERE {$PK}='{$id}';\n UPDATE $table SET {$field}='{$oldSortVal}' WHERE {$PK}='{$pre_record_id}'\"", ";", "break", ";", "case", "self", "::", "MOVE_DOWN", ":", "# 下移一位", "// 阻止最后一条记录降序", "if", "(", "$", "last_rank", "===", "$", "oldSortVal", ")", "{", "$", "this", "->", "error", "=", "'记录已在最底部!';", "", "return", "false", ";", "}", "# 获取后面一记录的信息", "$", "str_sql", "=", "\"SELECT {$PK},{$field} FROM \"", ".", "$", "table", ".", "\" WHERE {$whereCondition} {$field}<'{$oldSortVal}' ORDER BY rank DESC LIMIT 1\"", ";", "$", "suf_record", "=", "$", "this", "->", "pdo", "->", "query", "(", "$", "str_sql", ")", "->", "fetch", "(", "\\", "PDO", "::", "FETCH_ASSOC", ")", ";", "$", "suf_record_rank", "=", "$", "suf_record", "[", "$", "field", "]", ";", "$", "suf_record_id", "=", "$", "suf_record", "[", "$", "PK", "]", ";", "$", "sql", "=", "\"UPDATE {$table} SET {$field}='{$suf_record_rank}' WHERE {$PK}='{$id}';\n UPDATE {$table} SET {$field}='{$oldSortVal}' WHERE {$PK}='{$suf_record_id}'\"", ";", "break", ";", "case", "self", "::", "MOVE_BOTTOM", ":", "# 置底", "// 阻止最后一条记录降序", "if", "(", "$", "last_rank", "===", "$", "oldSortVal", ")", "{", "$", "this", "->", "error", "=", "'记录已在最底部!';", "", "return", "false", ";", "}", "$", "sql", "=", "\"UPDATE $table SET {$field}=\"", ".", "(", "(", "int", ")", "$", "this", "->", "lastRank", "-", "1", ")", ".", "\" WHERE {$PK}=\"", ".", "$", "id", ";", "break", ";", "default", ":", "throw", "new", "\\", "InvalidArgumentException", "(", "'Invalid argument'", ")", ";", "break", ";", "}", "$", "affected", "=", "$", "this", "->", "pdo", "->", "exec", "(", "$", "sql", ")", ";", "if", "(", "false", "===", "$", "affected", ")", "{", "$", "this", "->", "error", "=", "'操作失败!请重试...';", "", "}", "return", "true", ";", "}" ]
execute 执行排序, @param int $id 当前记录 Id @param int $oldSortVal 当前记录的排序值 @param int $sortType 排序请求 @return bool @throws \InvalidArgumentException
[ "execute", "执行排序," ]
train
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Utils/DbRecordSort.php#L101-L184
ProjetPP/WikidataQueryApi
src/Services/SimpleQueryService.php
SimpleQueryService.doQuery
public function doQuery( AbstractQuery $query ) { $result = $this->api->doQuery( [ 'q' => $this->querySerializer->serialize( $query ) ] ); return $this->parseItemList( $result['items'] ); }
php
public function doQuery( AbstractQuery $query ) { $result = $this->api->doQuery( [ 'q' => $this->querySerializer->serialize( $query ) ] ); return $this->parseItemList( $result['items'] ); }
[ "public", "function", "doQuery", "(", "AbstractQuery", "$", "query", ")", "{", "$", "result", "=", "$", "this", "->", "api", "->", "doQuery", "(", "[", "'q'", "=>", "$", "this", "->", "querySerializer", "->", "serialize", "(", "$", "query", ")", "]", ")", ";", "return", "$", "this", "->", "parseItemList", "(", "$", "result", "[", "'items'", "]", ")", ";", "}" ]
@param AbstractQuery $query @return ItemId[] @throws WikibaseQueryApiException
[ "@param", "AbstractQuery", "$query", "@return", "ItemId", "[]" ]
train
https://github.com/ProjetPP/WikidataQueryApi/blob/d6c448a4ca8e9472b0a223f88cc7c28baffac861/src/Services/SimpleQueryService.php#L44-L50
alevilar/ristorantino-vendor
Product/Model/Categoria.php
Categoria.array_listado
function array_listado($categoria_id = 1){ $array_categoria = array(); $array_final = array(); $this->recursive = 1; $this->id = $categoria_id; // $this->contain(array( // 'Producto', // 'Sabor', // )); $array_categoria = $this->read(); if (empty($array_categoria)) { return array(); } $array_final = $array_categoria['Categoria']; $array_final['Producto'] = $array_categoria['Producto']; $array_final['Sabor'] = $array_categoria['Sabor']; //agarro los herederos del ROOT $resultado = $this->children($categoria_id,1); foreach ($resultado as $r): $hijos = $this->array_listado($r['Categoria']['id']); if (count($hijos) > 0) { $array_final['Hijos'][] = $hijos; } endforeach; if ($array_final == false) { $array_final = array(); } return $array_final; }
php
function array_listado($categoria_id = 1){ $array_categoria = array(); $array_final = array(); $this->recursive = 1; $this->id = $categoria_id; // $this->contain(array( // 'Producto', // 'Sabor', // )); $array_categoria = $this->read(); if (empty($array_categoria)) { return array(); } $array_final = $array_categoria['Categoria']; $array_final['Producto'] = $array_categoria['Producto']; $array_final['Sabor'] = $array_categoria['Sabor']; //agarro los herederos del ROOT $resultado = $this->children($categoria_id,1); foreach ($resultado as $r): $hijos = $this->array_listado($r['Categoria']['id']); if (count($hijos) > 0) { $array_final['Hijos'][] = $hijos; } endforeach; if ($array_final == false) { $array_final = array(); } return $array_final; }
[ "function", "array_listado", "(", "$", "categoria_id", "=", "1", ")", "{", "$", "array_categoria", "=", "array", "(", ")", ";", "$", "array_final", "=", "array", "(", ")", ";", "$", "this", "->", "recursive", "=", "1", ";", "$", "this", "->", "id", "=", "$", "categoria_id", ";", "// $this->contain(array(", "// 'Producto', ", "// 'Sabor',", "// ));", "$", "array_categoria", "=", "$", "this", "->", "read", "(", ")", ";", "if", "(", "empty", "(", "$", "array_categoria", ")", ")", "{", "return", "array", "(", ")", ";", "}", "$", "array_final", "=", "$", "array_categoria", "[", "'Categoria'", "]", ";", "$", "array_final", "[", "'Producto'", "]", "=", "$", "array_categoria", "[", "'Producto'", "]", ";", "$", "array_final", "[", "'Sabor'", "]", "=", "$", "array_categoria", "[", "'Sabor'", "]", ";", "//agarro los herederos del ROOT", "$", "resultado", "=", "$", "this", "->", "children", "(", "$", "categoria_id", ",", "1", ")", ";", "foreach", "(", "$", "resultado", "as", "$", "r", ")", ":", "$", "hijos", "=", "$", "this", "->", "array_listado", "(", "$", "r", "[", "'Categoria'", "]", "[", "'id'", "]", ")", ";", "if", "(", "count", "(", "$", "hijos", ")", ">", "0", ")", "{", "$", "array_final", "[", "'Hijos'", "]", "[", "]", "=", "$", "hijos", ";", "}", "endforeach", ";", "if", "(", "$", "array_final", "==", "false", ")", "{", "$", "array_final", "=", "array", "(", ")", ";", "}", "return", "$", "array_final", ";", "}" ]
Me devuelve un array lindo con sub arrays para cada subarbol @param $categoria_id de donde yovoy a leer los hijos @return unknown_type
[ "Me", "devuelve", "un", "array", "lindo", "con", "sub", "arrays", "para", "cada", "subarbol" ]
train
https://github.com/alevilar/ristorantino-vendor/blob/6b91a1e20cc0ba09a1968d77e3de6512cfa2d966/Product/Model/Categoria.php#L59-L90
rhosocial/yii2-user
web/admin/controllers/UserController.php
UserController.initMessages
protected function initMessages() { if (!is_string($this->registerSuccessMessage)) { $this->registerSuccessMessage = Yii::t('user' ,'User Registered.'); } if (!is_string($this->registerFailedMessage)) { $this->registerFailedMessage = Yii::t('user', 'Register Failed.'); } if (!is_string($this->deregisterSuccessMessage)) { $this->deregisterSuccessMessage = Yii::t('user', 'User Deregistered.'); } if (!is_string($this->deregisterFailedMessage)) { $this->deregisterFailedMessage = Yii::t('user', 'Failed to Deregister User.'); } if (!is_string($this->updateSuccessMessage)) { $this->updateSuccessMessage = Yii::t('user', 'Updated.'); } if (!is_string($this->updateFailedMessage)) { $this->updateFailedMessage = Yii::t('user', 'Failed to Update.'); } }
php
protected function initMessages() { if (!is_string($this->registerSuccessMessage)) { $this->registerSuccessMessage = Yii::t('user' ,'User Registered.'); } if (!is_string($this->registerFailedMessage)) { $this->registerFailedMessage = Yii::t('user', 'Register Failed.'); } if (!is_string($this->deregisterSuccessMessage)) { $this->deregisterSuccessMessage = Yii::t('user', 'User Deregistered.'); } if (!is_string($this->deregisterFailedMessage)) { $this->deregisterFailedMessage = Yii::t('user', 'Failed to Deregister User.'); } if (!is_string($this->updateSuccessMessage)) { $this->updateSuccessMessage = Yii::t('user', 'Updated.'); } if (!is_string($this->updateFailedMessage)) { $this->updateFailedMessage = Yii::t('user', 'Failed to Update.'); } }
[ "protected", "function", "initMessages", "(", ")", "{", "if", "(", "!", "is_string", "(", "$", "this", "->", "registerSuccessMessage", ")", ")", "{", "$", "this", "->", "registerSuccessMessage", "=", "Yii", "::", "t", "(", "'user'", ",", "'User Registered.'", ")", ";", "}", "if", "(", "!", "is_string", "(", "$", "this", "->", "registerFailedMessage", ")", ")", "{", "$", "this", "->", "registerFailedMessage", "=", "Yii", "::", "t", "(", "'user'", ",", "'Register Failed.'", ")", ";", "}", "if", "(", "!", "is_string", "(", "$", "this", "->", "deregisterSuccessMessage", ")", ")", "{", "$", "this", "->", "deregisterSuccessMessage", "=", "Yii", "::", "t", "(", "'user'", ",", "'User Deregistered.'", ")", ";", "}", "if", "(", "!", "is_string", "(", "$", "this", "->", "deregisterFailedMessage", ")", ")", "{", "$", "this", "->", "deregisterFailedMessage", "=", "Yii", "::", "t", "(", "'user'", ",", "'Failed to Deregister User.'", ")", ";", "}", "if", "(", "!", "is_string", "(", "$", "this", "->", "updateSuccessMessage", ")", ")", "{", "$", "this", "->", "updateSuccessMessage", "=", "Yii", "::", "t", "(", "'user'", ",", "'Updated.'", ")", ";", "}", "if", "(", "!", "is_string", "(", "$", "this", "->", "updateFailedMessage", ")", ")", "{", "$", "this", "->", "updateFailedMessage", "=", "Yii", "::", "t", "(", "'user'", ",", "'Failed to Update.'", ")", ";", "}", "}" ]
Initialize messages.
[ "Initialize", "messages", "." ]
train
https://github.com/rhosocial/yii2-user/blob/96737a9d8ca7e9c42cd2b7736d6c0a90ede6e5bc/web/admin/controllers/UserController.php#L58-L78
rhosocial/yii2-user
web/admin/controllers/UserController.php
UserController.actionRegisterNewUser
public function actionRegisterNewUser() { $model = new RegisterForm(); if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) { Yii::$app->response = Response::FORMAT_JSON; return ActiveForm::validate($model); } if ($model->load(Yii::$app->request->post())) { try { if (($result = $model->register()) === true) { Yii::$app->session->setFlash(Module::SESSION_KEY_RESULT, Module::RESULT_SUCCESS); Yii::$app->session->setFlash(Module::SESSION_KEY_MESSAGE, '(' . $model->model->getID() . ') ' . $this->registerSuccessMessage); return $this->redirect($model->continue ? '' : ['index']); } if ($result instanceof \Exception) { throw $result; } } catch (\Exception $ex) { Yii::error($ex->getMessage(), __METHOD__); Yii::$app->session->setFlash(Module::SESSION_KEY_RESULT, Module::RESULT_FAILED); Yii::$app->session->setFlash(Module::SESSION_KEY_MESSAGE, $ex->getMessage()); } } return $this->render('register-new-user', ['model' => $model]); }
php
public function actionRegisterNewUser() { $model = new RegisterForm(); if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) { Yii::$app->response = Response::FORMAT_JSON; return ActiveForm::validate($model); } if ($model->load(Yii::$app->request->post())) { try { if (($result = $model->register()) === true) { Yii::$app->session->setFlash(Module::SESSION_KEY_RESULT, Module::RESULT_SUCCESS); Yii::$app->session->setFlash(Module::SESSION_KEY_MESSAGE, '(' . $model->model->getID() . ') ' . $this->registerSuccessMessage); return $this->redirect($model->continue ? '' : ['index']); } if ($result instanceof \Exception) { throw $result; } } catch (\Exception $ex) { Yii::error($ex->getMessage(), __METHOD__); Yii::$app->session->setFlash(Module::SESSION_KEY_RESULT, Module::RESULT_FAILED); Yii::$app->session->setFlash(Module::SESSION_KEY_MESSAGE, $ex->getMessage()); } } return $this->render('register-new-user', ['model' => $model]); }
[ "public", "function", "actionRegisterNewUser", "(", ")", "{", "$", "model", "=", "new", "RegisterForm", "(", ")", ";", "if", "(", "Yii", "::", "$", "app", "->", "request", "->", "isAjax", "&&", "$", "model", "->", "load", "(", "Yii", "::", "$", "app", "->", "request", "->", "post", "(", ")", ")", ")", "{", "Yii", "::", "$", "app", "->", "response", "=", "Response", "::", "FORMAT_JSON", ";", "return", "ActiveForm", "::", "validate", "(", "$", "model", ")", ";", "}", "if", "(", "$", "model", "->", "load", "(", "Yii", "::", "$", "app", "->", "request", "->", "post", "(", ")", ")", ")", "{", "try", "{", "if", "(", "(", "$", "result", "=", "$", "model", "->", "register", "(", ")", ")", "===", "true", ")", "{", "Yii", "::", "$", "app", "->", "session", "->", "setFlash", "(", "Module", "::", "SESSION_KEY_RESULT", ",", "Module", "::", "RESULT_SUCCESS", ")", ";", "Yii", "::", "$", "app", "->", "session", "->", "setFlash", "(", "Module", "::", "SESSION_KEY_MESSAGE", ",", "'('", ".", "$", "model", "->", "model", "->", "getID", "(", ")", ".", "') '", ".", "$", "this", "->", "registerSuccessMessage", ")", ";", "return", "$", "this", "->", "redirect", "(", "$", "model", "->", "continue", "?", "''", ":", "[", "'index'", "]", ")", ";", "}", "if", "(", "$", "result", "instanceof", "\\", "Exception", ")", "{", "throw", "$", "result", ";", "}", "}", "catch", "(", "\\", "Exception", "$", "ex", ")", "{", "Yii", "::", "error", "(", "$", "ex", "->", "getMessage", "(", ")", ",", "__METHOD__", ")", ";", "Yii", "::", "$", "app", "->", "session", "->", "setFlash", "(", "Module", "::", "SESSION_KEY_RESULT", ",", "Module", "::", "RESULT_FAILED", ")", ";", "Yii", "::", "$", "app", "->", "session", "->", "setFlash", "(", "Module", "::", "SESSION_KEY_MESSAGE", ",", "$", "ex", "->", "getMessage", "(", ")", ")", ";", "}", "}", "return", "$", "this", "->", "render", "(", "'register-new-user'", ",", "[", "'model'", "=>", "$", "model", "]", ")", ";", "}" ]
Register new user. @return string|\yii\web\Response
[ "Register", "new", "user", "." ]
train
https://github.com/rhosocial/yii2-user/blob/96737a9d8ca7e9c42cd2b7736d6c0a90ede6e5bc/web/admin/controllers/UserController.php#L164-L188
rhosocial/yii2-user
web/admin/controllers/UserController.php
UserController.getUser
protected function getUser($id) { $class = Yii::$app->user->identityClass; if (!class_exists($class)) { return null; } $user = $class::find()->id($id)->one(); if (empty($user) || !($user instanceof User)) { throw new BadRequestHttpException(Yii::t('user', 'User Not Found.')); } return $user; }
php
protected function getUser($id) { $class = Yii::$app->user->identityClass; if (!class_exists($class)) { return null; } $user = $class::find()->id($id)->one(); if (empty($user) || !($user instanceof User)) { throw new BadRequestHttpException(Yii::t('user', 'User Not Found.')); } return $user; }
[ "protected", "function", "getUser", "(", "$", "id", ")", "{", "$", "class", "=", "Yii", "::", "$", "app", "->", "user", "->", "identityClass", ";", "if", "(", "!", "class_exists", "(", "$", "class", ")", ")", "{", "return", "null", ";", "}", "$", "user", "=", "$", "class", "::", "find", "(", ")", "->", "id", "(", "$", "id", ")", "->", "one", "(", ")", ";", "if", "(", "empty", "(", "$", "user", ")", "||", "!", "(", "$", "user", "instanceof", "User", ")", ")", "{", "throw", "new", "BadRequestHttpException", "(", "Yii", "::", "t", "(", "'user'", ",", "'User Not Found.'", ")", ")", ";", "}", "return", "$", "user", ";", "}" ]
Get user by ID. @param string $id User ID. @return User @throws BadRequestHttpException throw if user not found.
[ "Get", "user", "by", "ID", "." ]
train
https://github.com/rhosocial/yii2-user/blob/96737a9d8ca7e9c42cd2b7736d6c0a90ede6e5bc/web/admin/controllers/UserController.php#L196-L207
rhosocial/yii2-user
web/admin/controllers/UserController.php
UserController.actionDeregister
public function actionDeregister($id) { $id = (int)$id; if (Yii::$app->user->identity->getID() == $id) { throw new ForbiddenHttpException(Yii::t('user', 'You cannot deregister yourself.')); } $user = $this->getUser($id); try { $result = $user->deregister(); if ($result instanceof \Exception) { throw $result; } } catch (\Exception $ex) { throw new ServerErrorHttpException($ex->getMessage()); } if ($result !== true) { throw new ServerErrorHttpException(Yii::t('user', 'Failed to deregister user.')); } Yii::$app->session->setFlash(Module::SESSION_KEY_RESULT, Module::RESULT_SUCCESS); Yii::$app->session->setFlash(Module::SESSION_KEY_MESSAGE, '(' . $user->getID() . ') ' . $this->deregisterSuccessMessage); return $this->redirect(['index']); }
php
public function actionDeregister($id) { $id = (int)$id; if (Yii::$app->user->identity->getID() == $id) { throw new ForbiddenHttpException(Yii::t('user', 'You cannot deregister yourself.')); } $user = $this->getUser($id); try { $result = $user->deregister(); if ($result instanceof \Exception) { throw $result; } } catch (\Exception $ex) { throw new ServerErrorHttpException($ex->getMessage()); } if ($result !== true) { throw new ServerErrorHttpException(Yii::t('user', 'Failed to deregister user.')); } Yii::$app->session->setFlash(Module::SESSION_KEY_RESULT, Module::RESULT_SUCCESS); Yii::$app->session->setFlash(Module::SESSION_KEY_MESSAGE, '(' . $user->getID() . ') ' . $this->deregisterSuccessMessage); return $this->redirect(['index']); }
[ "public", "function", "actionDeregister", "(", "$", "id", ")", "{", "$", "id", "=", "(", "int", ")", "$", "id", ";", "if", "(", "Yii", "::", "$", "app", "->", "user", "->", "identity", "->", "getID", "(", ")", "==", "$", "id", ")", "{", "throw", "new", "ForbiddenHttpException", "(", "Yii", "::", "t", "(", "'user'", ",", "'You cannot deregister yourself.'", ")", ")", ";", "}", "$", "user", "=", "$", "this", "->", "getUser", "(", "$", "id", ")", ";", "try", "{", "$", "result", "=", "$", "user", "->", "deregister", "(", ")", ";", "if", "(", "$", "result", "instanceof", "\\", "Exception", ")", "{", "throw", "$", "result", ";", "}", "}", "catch", "(", "\\", "Exception", "$", "ex", ")", "{", "throw", "new", "ServerErrorHttpException", "(", "$", "ex", "->", "getMessage", "(", ")", ")", ";", "}", "if", "(", "$", "result", "!==", "true", ")", "{", "throw", "new", "ServerErrorHttpException", "(", "Yii", "::", "t", "(", "'user'", ",", "'Failed to deregister user.'", ")", ")", ";", "}", "Yii", "::", "$", "app", "->", "session", "->", "setFlash", "(", "Module", "::", "SESSION_KEY_RESULT", ",", "Module", "::", "RESULT_SUCCESS", ")", ";", "Yii", "::", "$", "app", "->", "session", "->", "setFlash", "(", "Module", "::", "SESSION_KEY_MESSAGE", ",", "'('", ".", "$", "user", "->", "getID", "(", ")", ".", "') '", ".", "$", "this", "->", "deregisterSuccessMessage", ")", ";", "return", "$", "this", "->", "redirect", "(", "[", "'index'", "]", ")", ";", "}" ]
Deregister User. @param string $id User ID. @return string @throws ServerErrorHttpException @throws ForbiddenHttpException
[ "Deregister", "User", "." ]
train
https://github.com/rhosocial/yii2-user/blob/96737a9d8ca7e9c42cd2b7736d6c0a90ede6e5bc/web/admin/controllers/UserController.php#L216-L237
gregoryv/php-logger
src/ConsoleWriter.php
ConsoleWriter.swrite
public function swrite($severity, $message='') { if($severity <= LOG_ERR) { fwrite(STDERR, $message . "\n"); } else { fwrite(STDOUT, $message . "\n"); } }
php
public function swrite($severity, $message='') { if($severity <= LOG_ERR) { fwrite(STDERR, $message . "\n"); } else { fwrite(STDOUT, $message . "\n"); } }
[ "public", "function", "swrite", "(", "$", "severity", ",", "$", "message", "=", "''", ")", "{", "if", "(", "$", "severity", "<=", "LOG_ERR", ")", "{", "fwrite", "(", "STDERR", ",", "$", "message", ".", "\"\\n\"", ")", ";", "}", "else", "{", "fwrite", "(", "STDOUT", ",", "$", "message", ".", "\"\\n\"", ")", ";", "}", "}" ]
If severity is equal or lower than LOG_ERR then the message is written to STDERR, otherwise STDOUT is used.
[ "If", "severity", "is", "equal", "or", "lower", "than", "LOG_ERR", "then", "the", "message", "is", "written", "to", "STDERR", "otherwise", "STDOUT", "is", "used", "." ]
train
https://github.com/gregoryv/php-logger/blob/0f8ffc360a0233531a9775359929af8876997862/src/ConsoleWriter.php#L17-L24
ZayconFoods/whatcounts
src/ZayconWhatCounts/Folder.php
Folder.setFolderId
public function setFolderId( $folder_id ) { $this->folder_id = (is_numeric($folder_id)) ? abs(round($folder_id)) : NULL; return $this; }
php
public function setFolderId( $folder_id ) { $this->folder_id = (is_numeric($folder_id)) ? abs(round($folder_id)) : NULL; return $this; }
[ "public", "function", "setFolderId", "(", "$", "folder_id", ")", "{", "$", "this", "->", "folder_id", "=", "(", "is_numeric", "(", "$", "folder_id", ")", ")", "?", "abs", "(", "round", "(", "$", "folder_id", ")", ")", ":", "NULL", ";", "return", "$", "this", ";", "}" ]
@param mixed $folder_id @return Folder
[ "@param", "mixed", "$folder_id" ]
train
https://github.com/ZayconFoods/whatcounts/blob/ff18491fc152571a72e4b558f8102f4fbb9bb7fd/src/ZayconWhatCounts/Folder.php#L36-L41
ZayconFoods/whatcounts
src/ZayconWhatCounts/Folder.php
Folder.setFolderType
public function setFolderType( $folder_type ) { $this->folder_type = (in_array($folder_type, $this->folder_types)) ? $folder_type : NULL; return $this; }
php
public function setFolderType( $folder_type ) { $this->folder_type = (in_array($folder_type, $this->folder_types)) ? $folder_type : NULL; return $this; }
[ "public", "function", "setFolderType", "(", "$", "folder_type", ")", "{", "$", "this", "->", "folder_type", "=", "(", "in_array", "(", "$", "folder_type", ",", "$", "this", "->", "folder_types", ")", ")", "?", "$", "folder_type", ":", "NULL", ";", "return", "$", "this", ";", "}" ]
@param mixed $folder_type @return Folder
[ "@param", "mixed", "$folder_type" ]
train
https://github.com/ZayconFoods/whatcounts/blob/ff18491fc152571a72e4b558f8102f4fbb9bb7fd/src/ZayconWhatCounts/Folder.php#L76-L81