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
mossphp/moss-storage
Moss/Storage/Schema/Schema.php
Schema.quoteIdentifier
protected function quoteIdentifier($identifier) { if (!is_array($identifier)) { return $this->connection->quoteIdentifier($identifier); } foreach ($identifier as &$value) { $value = $this->connection->quoteIdentifier($value); unset($value); } return $identifier; }
php
protected function quoteIdentifier($identifier) { if (!is_array($identifier)) { return $this->connection->quoteIdentifier($identifier); } foreach ($identifier as &$value) { $value = $this->connection->quoteIdentifier($value); unset($value); } return $identifier; }
[ "protected", "function", "quoteIdentifier", "(", "$", "identifier", ")", "{", "if", "(", "!", "is_array", "(", "$", "identifier", ")", ")", "{", "return", "$", "this", "->", "connection", "->", "quoteIdentifier", "(", "$", "identifier", ")", ";", "}", "foreach", "(", "$", "identifier", "as", "&", "$", "value", ")", "{", "$", "value", "=", "$", "this", "->", "connection", "->", "quoteIdentifier", "(", "$", "value", ")", ";", "unset", "(", "$", "value", ")", ";", "}", "return", "$", "identifier", ";", "}" ]
Quotes SQL identifier or array of identifiers @param string|array $identifier @return string|array
[ "Quotes", "SQL", "identifier", "or", "array", "of", "identifiers" ]
train
https://github.com/mossphp/moss-storage/blob/0d123e7ae6bbfce1e2a18e73bf70997277b430c1/Moss/Storage/Schema/Schema.php#L249-L261
mossphp/moss-storage
Moss/Storage/Schema/Schema.php
Schema.buildDrop
protected function buildDrop(array $models) { $fromSchema = $this->connection->getSchemaManager()->createSchema(); $toSchema = clone $fromSchema; foreach ($models as $model) { if (!$toSchema->hasTable($model->table())) { continue; } $toSchema->dropTable($model->table()); } $sql = $fromSchema->getMigrateToSql($toSchema, $this->connection->getDatabasePlatform()); $this->queries = array_merge($this->queries, $sql); }
php
protected function buildDrop(array $models) { $fromSchema = $this->connection->getSchemaManager()->createSchema(); $toSchema = clone $fromSchema; foreach ($models as $model) { if (!$toSchema->hasTable($model->table())) { continue; } $toSchema->dropTable($model->table()); } $sql = $fromSchema->getMigrateToSql($toSchema, $this->connection->getDatabasePlatform()); $this->queries = array_merge($this->queries, $sql); }
[ "protected", "function", "buildDrop", "(", "array", "$", "models", ")", "{", "$", "fromSchema", "=", "$", "this", "->", "connection", "->", "getSchemaManager", "(", ")", "->", "createSchema", "(", ")", ";", "$", "toSchema", "=", "clone", "$", "fromSchema", ";", "foreach", "(", "$", "models", "as", "$", "model", ")", "{", "if", "(", "!", "$", "toSchema", "->", "hasTable", "(", "$", "model", "->", "table", "(", ")", ")", ")", "{", "continue", ";", "}", "$", "toSchema", "->", "dropTable", "(", "$", "model", "->", "table", "(", ")", ")", ";", "}", "$", "sql", "=", "$", "fromSchema", "->", "getMigrateToSql", "(", "$", "toSchema", ",", "$", "this", "->", "connection", "->", "getDatabasePlatform", "(", ")", ")", ";", "$", "this", "->", "queries", "=", "array_merge", "(", "$", "this", "->", "queries", ",", "$", "sql", ")", ";", "}" ]
Builds drop table query @param ModelInterface[] $models
[ "Builds", "drop", "table", "query" ]
train
https://github.com/mossphp/moss-storage/blob/0d123e7ae6bbfce1e2a18e73bf70997277b430c1/Moss/Storage/Schema/Schema.php#L268-L284
mossphp/moss-storage
Moss/Storage/Schema/Schema.php
Schema.execute
public function execute() { $result = []; foreach ($this->queryString() as $query) { $stmt = $this->connection->prepare($query); $stmt->execute(); $result[] = $query; } $this->reset(); return $result; }
php
public function execute() { $result = []; foreach ($this->queryString() as $query) { $stmt = $this->connection->prepare($query); $stmt->execute(); $result[] = $query; } $this->reset(); return $result; }
[ "public", "function", "execute", "(", ")", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "queryString", "(", ")", "as", "$", "query", ")", "{", "$", "stmt", "=", "$", "this", "->", "connection", "->", "prepare", "(", "$", "query", ")", ";", "$", "stmt", "->", "execute", "(", ")", ";", "$", "result", "[", "]", "=", "$", "query", ";", "}", "$", "this", "->", "reset", "(", ")", ";", "return", "$", "result", ";", "}" ]
Executes query After execution query is reset @return mixed|null|void
[ "Executes", "query", "After", "execution", "query", "is", "reset" ]
train
https://github.com/mossphp/moss-storage/blob/0d123e7ae6bbfce1e2a18e73bf70997277b430c1/Moss/Storage/Schema/Schema.php#L292-L305
jabernardo/lollipop-php
Library/Cache/MemcachedAdapter.php
MemcachedAdapter.exists
public function exists($key) { $key = $this->_encrypt($key); $data = $this->_memcached->get($key); return $data ? true : false; }
php
public function exists($key) { $key = $this->_encrypt($key); $data = $this->_memcached->get($key); return $data ? true : false; }
[ "public", "function", "exists", "(", "$", "key", ")", "{", "$", "key", "=", "$", "this", "->", "_encrypt", "(", "$", "key", ")", ";", "$", "data", "=", "$", "this", "->", "_memcached", "->", "get", "(", "$", "key", ")", ";", "return", "$", "data", "?", "true", ":", "false", ";", "}" ]
Check if cache exists @access public @param string $key Cache key @return bool
[ "Check", "if", "cache", "exists" ]
train
https://github.com/jabernardo/lollipop-php/blob/004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5/Library/Cache/MemcachedAdapter.php#L72-L77
jabernardo/lollipop-php
Library/Cache/MemcachedAdapter.php
MemcachedAdapter.save
public function save($key, $data, $force = false, $ttl = 1440) { $ttl = $ttl * 60; // Minutes to Seconds // Store result from last query for checking if cache is existing // This will avoid locked database error for sqlite3 $cache_exists = $this->exists($key); if (!$cache_exists || $force) { $key = $this->_encrypt($key); $this->_memcached->set($key, $data, $ttl); return true; } return false; }
php
public function save($key, $data, $force = false, $ttl = 1440) { $ttl = $ttl * 60; // Minutes to Seconds // Store result from last query for checking if cache is existing // This will avoid locked database error for sqlite3 $cache_exists = $this->exists($key); if (!$cache_exists || $force) { $key = $this->_encrypt($key); $this->_memcached->set($key, $data, $ttl); return true; } return false; }
[ "public", "function", "save", "(", "$", "key", ",", "$", "data", ",", "$", "force", "=", "false", ",", "$", "ttl", "=", "1440", ")", "{", "$", "ttl", "=", "$", "ttl", "*", "60", ";", "// Minutes to Seconds", "// Store result from last query for checking if cache is existing", "// This will avoid locked database error for sqlite3", "$", "cache_exists", "=", "$", "this", "->", "exists", "(", "$", "key", ")", ";", "if", "(", "!", "$", "cache_exists", "||", "$", "force", ")", "{", "$", "key", "=", "$", "this", "->", "_encrypt", "(", "$", "key", ")", ";", "$", "this", "->", "_memcached", "->", "set", "(", "$", "key", ",", "$", "data", ",", "$", "ttl", ")", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Save cache @access public @param string $key Cache key @param mixed $data Data to be saved @param bool $force Force to override old data @param int $ttl Time-to-leave (default to 24 Hrs) @return bool
[ "Save", "cache" ]
train
https://github.com/jabernardo/lollipop-php/blob/004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5/Library/Cache/MemcachedAdapter.php#L90-L104
jabernardo/lollipop-php
Library/Cache/MemcachedAdapter.php
MemcachedAdapter.remove
public function remove($key) { if ($this->exists($key)) { $key = $this->_encrypt($key); $this->_memcached->delete($key); return true; } return false; }
php
public function remove($key) { if ($this->exists($key)) { $key = $this->_encrypt($key); $this->_memcached->delete($key); return true; } return false; }
[ "public", "function", "remove", "(", "$", "key", ")", "{", "if", "(", "$", "this", "->", "exists", "(", "$", "key", ")", ")", "{", "$", "key", "=", "$", "this", "->", "_encrypt", "(", "$", "key", ")", ";", "$", "this", "->", "_memcached", "->", "delete", "(", "$", "key", ")", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Remove cache @access public @param string $key @return bool
[ "Remove", "cache" ]
train
https://github.com/jabernardo/lollipop-php/blob/004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5/Library/Cache/MemcachedAdapter.php#L126-L135
ZendExperts/phpids
lib/IDS/Caching/Apc.php
IDS_Caching_Apc.getInstance
public static function getInstance($type, $init) { if (!self::$cachingInstance) { self::$cachingInstance = new IDS_Caching_Apc($type, $init); } return self::$cachingInstance; }
php
public static function getInstance($type, $init) { if (!self::$cachingInstance) { self::$cachingInstance = new IDS_Caching_Apc($type, $init); } return self::$cachingInstance; }
[ "public", "static", "function", "getInstance", "(", "$", "type", ",", "$", "init", ")", "{", "if", "(", "!", "self", "::", "$", "cachingInstance", ")", "{", "self", "::", "$", "cachingInstance", "=", "new", "IDS_Caching_Apc", "(", "$", "type", ",", "$", "init", ")", ";", "}", "return", "self", "::", "$", "cachingInstance", ";", "}" ]
Returns an instance of this class @param string $type caching type @param object $init the IDS_Init object @return object $this
[ "Returns", "an", "instance", "of", "this", "class" ]
train
https://github.com/ZendExperts/phpids/blob/f30df04eea47b94d056e2ae9ec8fea1c626f1c03/lib/IDS/Caching/Apc.php#L104-L112
PowerSync/tnw-soap-client
src/Tnw/SoapClient/Result/DescribeSObjectResult.php
DescribeSObjectResult.getChildRelationship
public function getChildRelationship($name) { $result = array_filter($this->getChildRelationships(), function($input) use ($name) { return $name === $input->getRelationshipName(); }); return reset($result); }
php
public function getChildRelationship($name) { $result = array_filter($this->getChildRelationships(), function($input) use ($name) { return $name === $input->getRelationshipName(); }); return reset($result); }
[ "public", "function", "getChildRelationship", "(", "$", "name", ")", "{", "$", "result", "=", "array_filter", "(", "$", "this", "->", "getChildRelationships", "(", ")", ",", "function", "(", "$", "input", ")", "use", "(", "$", "name", ")", "{", "return", "$", "name", "===", "$", "input", "->", "getRelationshipName", "(", ")", ";", "}", ")", ";", "return", "reset", "(", "$", "result", ")", ";", "}" ]
Get child relationship by name @param string $name Relationship name @return ChildRelationship
[ "Get", "child", "relationship", "by", "name" ]
train
https://github.com/PowerSync/tnw-soap-client/blob/cd936da20bdfbd6da99fe44ffa1a4761e0b56c23/src/Tnw/SoapClient/Result/DescribeSObjectResult.php#L54-L61
PowerSync/tnw-soap-client
src/Tnw/SoapClient/Result/DescribeSObjectResult.php
DescribeSObjectResult.getField
public function getField($field) { $result = array_filter($this->getFields(), function($input) use ($field) { return $field === $input->getName(); }); return reset($result); }
php
public function getField($field) { $result = array_filter($this->getFields(), function($input) use ($field) { return $field === $input->getName(); }); return reset($result); }
[ "public", "function", "getField", "(", "$", "field", ")", "{", "$", "result", "=", "array_filter", "(", "$", "this", "->", "getFields", "(", ")", ",", "function", "(", "$", "input", ")", "use", "(", "$", "field", ")", "{", "return", "$", "field", "===", "$", "input", "->", "getName", "(", ")", ";", "}", ")", ";", "return", "reset", "(", "$", "result", ")", ";", "}" ]
Get field description by field name @param string $field Field name @return Field
[ "Get", "field", "description", "by", "field", "name" ]
train
https://github.com/PowerSync/tnw-soap-client/blob/cd936da20bdfbd6da99fe44ffa1a4761e0b56c23/src/Tnw/SoapClient/Result/DescribeSObjectResult.php#L126-L133
PowerSync/tnw-soap-client
src/Tnw/SoapClient/Result/DescribeSObjectResult.php
DescribeSObjectResult.getRelationshipField
public function getRelationshipField($name) { $result = array_filter($this->getRelationshipFields(), function($field) use ($name) { return $name === $field->getName(); }); return reset($result); }
php
public function getRelationshipField($name) { $result = array_filter($this->getRelationshipFields(), function($field) use ($name) { return $name === $field->getName(); }); return reset($result); }
[ "public", "function", "getRelationshipField", "(", "$", "name", ")", "{", "$", "result", "=", "array_filter", "(", "$", "this", "->", "getRelationshipFields", "(", ")", ",", "function", "(", "$", "field", ")", "use", "(", "$", "name", ")", "{", "return", "$", "name", "===", "$", "field", "->", "getName", "(", ")", ";", "}", ")", ";", "return", "reset", "(", "$", "result", ")", ";", "}" ]
Get a relationship field @param string $name @return Field
[ "Get", "a", "relationship", "field" ]
train
https://github.com/PowerSync/tnw-soap-client/blob/cd936da20bdfbd6da99fe44ffa1a4761e0b56c23/src/Tnw/SoapClient/Result/DescribeSObjectResult.php#L257-L264
JurJean/SpraySerializer
src/Object/BoundClosureSerializer.php
BoundClosureSerializer.construct
public function construct($subject, &$data = array()) { if (null === $this->constructed) { $this->constructed = unserialize( sprintf( 'O:%d:"%s":0:{}', strlen($subject), $subject ) ); } return clone $this->constructed; }
php
public function construct($subject, &$data = array()) { if (null === $this->constructed) { $this->constructed = unserialize( sprintf( 'O:%d:"%s":0:{}', strlen($subject), $subject ) ); } return clone $this->constructed; }
[ "public", "function", "construct", "(", "$", "subject", ",", "&", "$", "data", "=", "array", "(", ")", ")", "{", "if", "(", "null", "===", "$", "this", "->", "constructed", ")", "{", "$", "this", "->", "constructed", "=", "unserialize", "(", "sprintf", "(", "'O:%d:\"%s\":0:{}'", ",", "strlen", "(", "$", "subject", ")", ",", "$", "subject", ")", ")", ";", "}", "return", "clone", "$", "this", "->", "constructed", ";", "}" ]
Construct a new object. By default a new empty object is deserialized and from then on cloned. @param string $subject The class name of the object to create @param array $data The data to deserialize @return object
[ "Construct", "a", "new", "object", "." ]
train
https://github.com/JurJean/SpraySerializer/blob/4d2883efe489cc8716aea3334f622a576f650397/src/Object/BoundClosureSerializer.php#L65-L77
JurJean/SpraySerializer
src/Object/BoundClosureSerializer.php
BoundClosureSerializer.serializer
protected function serializer() { if (null === $this->serializer) { $self = $this; $this->serializer = Closure::bind($this->bindSerializer(), null, $this->class); } return $this->serializer; }
php
protected function serializer() { if (null === $this->serializer) { $self = $this; $this->serializer = Closure::bind($this->bindSerializer(), null, $this->class); } return $this->serializer; }
[ "protected", "function", "serializer", "(", ")", "{", "if", "(", "null", "===", "$", "this", "->", "serializer", ")", "{", "$", "self", "=", "$", "this", ";", "$", "this", "->", "serializer", "=", "Closure", "::", "bind", "(", "$", "this", "->", "bindSerializer", "(", ")", ",", "null", ",", "$", "this", "->", "class", ")", ";", "}", "return", "$", "this", "->", "serializer", ";", "}" ]
Get a reference to the bound serialization closure. @return Closure
[ "Get", "a", "reference", "to", "the", "bound", "serialization", "closure", "." ]
train
https://github.com/JurJean/SpraySerializer/blob/4d2883efe489cc8716aea3334f622a576f650397/src/Object/BoundClosureSerializer.php#L84-L91
JurJean/SpraySerializer
src/Object/BoundClosureSerializer.php
BoundClosureSerializer.serialize
public function serialize($subject, &$data = array(), SerializerInterface $serializer = null) { $context = $this->serializer(); $context($subject, $data, $serializer); return $data; }
php
public function serialize($subject, &$data = array(), SerializerInterface $serializer = null) { $context = $this->serializer(); $context($subject, $data, $serializer); return $data; }
[ "public", "function", "serialize", "(", "$", "subject", ",", "&", "$", "data", "=", "array", "(", ")", ",", "SerializerInterface", "$", "serializer", "=", "null", ")", "{", "$", "context", "=", "$", "this", "->", "serializer", "(", ")", ";", "$", "context", "(", "$", "subject", ",", "$", "data", ",", "$", "serializer", ")", ";", "return", "$", "data", ";", "}" ]
Turn $subject (object) into $data (array). @param object $subject @param array $data @param SerializerInterface $serializer @return object
[ "Turn", "$subject", "(", "object", ")", "into", "$data", "(", "array", ")", "." ]
train
https://github.com/JurJean/SpraySerializer/blob/4d2883efe489cc8716aea3334f622a576f650397/src/Object/BoundClosureSerializer.php#L117-L122
JurJean/SpraySerializer
src/Object/BoundClosureSerializer.php
BoundClosureSerializer.deserializer
protected function deserializer() { if (null === $this->deserializer) { $self = $this; $this->deserializer = Closure::bind($this->bindDeserializer(), null, $this->class); } return $this->deserializer; }
php
protected function deserializer() { if (null === $this->deserializer) { $self = $this; $this->deserializer = Closure::bind($this->bindDeserializer(), null, $this->class); } return $this->deserializer; }
[ "protected", "function", "deserializer", "(", ")", "{", "if", "(", "null", "===", "$", "this", "->", "deserializer", ")", "{", "$", "self", "=", "$", "this", ";", "$", "this", "->", "deserializer", "=", "Closure", "::", "bind", "(", "$", "this", "->", "bindDeserializer", "(", ")", ",", "null", ",", "$", "this", "->", "class", ")", ";", "}", "return", "$", "this", "->", "deserializer", ";", "}" ]
Get a reference to the bound deserialization closure. @return Closure
[ "Get", "a", "reference", "to", "the", "bound", "deserialization", "closure", "." ]
train
https://github.com/JurJean/SpraySerializer/blob/4d2883efe489cc8716aea3334f622a576f650397/src/Object/BoundClosureSerializer.php#L129-L136
JurJean/SpraySerializer
src/Object/BoundClosureSerializer.php
BoundClosureSerializer.deserialize
public function deserialize($subject, &$data = array(), SerializerInterface $serializer = null) { $context = $this->deserializer(); $context($subject, $data, $serializer); return $subject; }
php
public function deserialize($subject, &$data = array(), SerializerInterface $serializer = null) { $context = $this->deserializer(); $context($subject, $data, $serializer); return $subject; }
[ "public", "function", "deserialize", "(", "$", "subject", ",", "&", "$", "data", "=", "array", "(", ")", ",", "SerializerInterface", "$", "serializer", "=", "null", ")", "{", "$", "context", "=", "$", "this", "->", "deserializer", "(", ")", ";", "$", "context", "(", "$", "subject", ",", "$", "data", ",", "$", "serializer", ")", ";", "return", "$", "subject", ";", "}" ]
Turn $data (array) into $subject (object). @param object $subject @param array $data @param SerializerInterface $serializer @return object
[ "Turn", "$data", "(", "array", ")", "into", "$subject", "(", "object", ")", "." ]
train
https://github.com/JurJean/SpraySerializer/blob/4d2883efe489cc8716aea3334f622a576f650397/src/Object/BoundClosureSerializer.php#L162-L167
JurJean/SpraySerializer
src/Object/BoundClosureSerializer.php
BoundClosureSerializer.valueDeserializer
protected function valueDeserializer() { return function($subject, array $data, $property, $defaultValue) { if (array_key_exists($property, $data)) { return $data[$property]; } if (null === $defaultValue) { throw new MissingDataException(sprintf( 'Data is missing for %s::$%s, received keys: %s', get_class($subject), $property, implode(', ', array_keys($data)) )); } return $defaultValue; }; }
php
protected function valueDeserializer() { return function($subject, array $data, $property, $defaultValue) { if (array_key_exists($property, $data)) { return $data[$property]; } if (null === $defaultValue) { throw new MissingDataException(sprintf( 'Data is missing for %s::$%s, received keys: %s', get_class($subject), $property, implode(', ', array_keys($data)) )); } return $defaultValue; }; }
[ "protected", "function", "valueDeserializer", "(", ")", "{", "return", "function", "(", "$", "subject", ",", "array", "$", "data", ",", "$", "property", ",", "$", "defaultValue", ")", "{", "if", "(", "array_key_exists", "(", "$", "property", ",", "$", "data", ")", ")", "{", "return", "$", "data", "[", "$", "property", "]", ";", "}", "if", "(", "null", "===", "$", "defaultValue", ")", "{", "throw", "new", "MissingDataException", "(", "sprintf", "(", "'Data is missing for %s::$%s, received keys: %s'", ",", "get_class", "(", "$", "subject", ")", ",", "$", "property", ",", "implode", "(", "', '", ",", "array_keys", "(", "$", "data", ")", ")", ")", ")", ";", "}", "return", "$", "defaultValue", ";", "}", ";", "}" ]
@param mixed $value @return closure @throws MissingDataException
[ "@param", "mixed", "$value" ]
train
https://github.com/JurJean/SpraySerializer/blob/4d2883efe489cc8716aea3334f622a576f650397/src/Object/BoundClosureSerializer.php#L176-L192
KDF5000/EasyThink
src/ThinkPHP/Library/Think/Model.php
Model._checkTableInfo
protected function _checkTableInfo() { // 如果不是Model类 自动记录数据表信息 // 只在第一次执行记录 if(empty($this->fields)) { // 如果数据表字段没有定义则自动获取 if(C('DB_FIELDS_CACHE')) { $db = $this->dbName?:C('DB_NAME'); $fields = F('_fields/'.strtolower($db.'.'.$this->tablePrefix.$this->name)); if($fields) { $this->fields = $fields; if(!empty($fields['_pk'])){ $this->pk = $fields['_pk']; } return ; } } // 每次都会读取数据表信息 $this->flush(); } }
php
protected function _checkTableInfo() { // 如果不是Model类 自动记录数据表信息 // 只在第一次执行记录 if(empty($this->fields)) { // 如果数据表字段没有定义则自动获取 if(C('DB_FIELDS_CACHE')) { $db = $this->dbName?:C('DB_NAME'); $fields = F('_fields/'.strtolower($db.'.'.$this->tablePrefix.$this->name)); if($fields) { $this->fields = $fields; if(!empty($fields['_pk'])){ $this->pk = $fields['_pk']; } return ; } } // 每次都会读取数据表信息 $this->flush(); } }
[ "protected", "function", "_checkTableInfo", "(", ")", "{", "// 如果不是Model类 自动记录数据表信息", "// 只在第一次执行记录", "if", "(", "empty", "(", "$", "this", "->", "fields", ")", ")", "{", "// 如果数据表字段没有定义则自动获取", "if", "(", "C", "(", "'DB_FIELDS_CACHE'", ")", ")", "{", "$", "db", "=", "$", "this", "->", "dbName", "?", ":", "C", "(", "'DB_NAME'", ")", ";", "$", "fields", "=", "F", "(", "'_fields/'", ".", "strtolower", "(", "$", "db", ".", "'.'", ".", "$", "this", "->", "tablePrefix", ".", "$", "this", "->", "name", ")", ")", ";", "if", "(", "$", "fields", ")", "{", "$", "this", "->", "fields", "=", "$", "fields", ";", "if", "(", "!", "empty", "(", "$", "fields", "[", "'_pk'", "]", ")", ")", "{", "$", "this", "->", "pk", "=", "$", "fields", "[", "'_pk'", "]", ";", "}", "return", ";", "}", "}", "// 每次都会读取数据表信息", "$", "this", "->", "flush", "(", ")", ";", "}", "}" ]
自动检测数据表信息 @access protected @return void
[ "自动检测数据表信息" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Model.php#L105-L124
KDF5000/EasyThink
src/ThinkPHP/Library/Think/Model.php
Model.flush
public function flush() { // 缓存不存在则查询数据表信息 $this->db->setModel($this->name); $fields = $this->db->getFields($this->getTableName()); if(!$fields) { // 无法获取字段信息 return false; } $this->fields = array_keys($fields); unset($this->fields['_pk']); foreach ($fields as $key=>$val){ // 记录字段类型 $type[$key] = $val['type']; if($val['primary']) { // 增加复合主键支持 if (isset($this->fields['_pk']) && $this->fields['_pk'] != null) { if (is_string($this->fields['_pk'])) { $this->pk = array($this->fields['_pk']); $this->fields['_pk'] = $this->pk; } $this->pk[] = $key; $this->fields['_pk'][] = $key; } else { $this->pk = $key; $this->fields['_pk'] = $key; } if($val['autoinc']) $this->autoinc = true; } } // 记录字段类型信息 $this->fields['_type'] = $type; // 2008-3-7 增加缓存开关控制 if(C('DB_FIELDS_CACHE')){ // 永久缓存数据表信息 $db = $this->dbName?:C('DB_NAME'); F('_fields/'.strtolower($db.'.'.$this->tablePrefix.$this->name),$this->fields); } }
php
public function flush() { // 缓存不存在则查询数据表信息 $this->db->setModel($this->name); $fields = $this->db->getFields($this->getTableName()); if(!$fields) { // 无法获取字段信息 return false; } $this->fields = array_keys($fields); unset($this->fields['_pk']); foreach ($fields as $key=>$val){ // 记录字段类型 $type[$key] = $val['type']; if($val['primary']) { // 增加复合主键支持 if (isset($this->fields['_pk']) && $this->fields['_pk'] != null) { if (is_string($this->fields['_pk'])) { $this->pk = array($this->fields['_pk']); $this->fields['_pk'] = $this->pk; } $this->pk[] = $key; $this->fields['_pk'][] = $key; } else { $this->pk = $key; $this->fields['_pk'] = $key; } if($val['autoinc']) $this->autoinc = true; } } // 记录字段类型信息 $this->fields['_type'] = $type; // 2008-3-7 增加缓存开关控制 if(C('DB_FIELDS_CACHE')){ // 永久缓存数据表信息 $db = $this->dbName?:C('DB_NAME'); F('_fields/'.strtolower($db.'.'.$this->tablePrefix.$this->name),$this->fields); } }
[ "public", "function", "flush", "(", ")", "{", "// 缓存不存在则查询数据表信息", "$", "this", "->", "db", "->", "setModel", "(", "$", "this", "->", "name", ")", ";", "$", "fields", "=", "$", "this", "->", "db", "->", "getFields", "(", "$", "this", "->", "getTableName", "(", ")", ")", ";", "if", "(", "!", "$", "fields", ")", "{", "// 无法获取字段信息", "return", "false", ";", "}", "$", "this", "->", "fields", "=", "array_keys", "(", "$", "fields", ")", ";", "unset", "(", "$", "this", "->", "fields", "[", "'_pk'", "]", ")", ";", "foreach", "(", "$", "fields", "as", "$", "key", "=>", "$", "val", ")", "{", "// 记录字段类型", "$", "type", "[", "$", "key", "]", "=", "$", "val", "[", "'type'", "]", ";", "if", "(", "$", "val", "[", "'primary'", "]", ")", "{", "// 增加复合主键支持", "if", "(", "isset", "(", "$", "this", "->", "fields", "[", "'_pk'", "]", ")", "&&", "$", "this", "->", "fields", "[", "'_pk'", "]", "!=", "null", ")", "{", "if", "(", "is_string", "(", "$", "this", "->", "fields", "[", "'_pk'", "]", ")", ")", "{", "$", "this", "->", "pk", "=", "array", "(", "$", "this", "->", "fields", "[", "'_pk'", "]", ")", ";", "$", "this", "->", "fields", "[", "'_pk'", "]", "=", "$", "this", "->", "pk", ";", "}", "$", "this", "->", "pk", "[", "]", "=", "$", "key", ";", "$", "this", "->", "fields", "[", "'_pk'", "]", "[", "]", "=", "$", "key", ";", "}", "else", "{", "$", "this", "->", "pk", "=", "$", "key", ";", "$", "this", "->", "fields", "[", "'_pk'", "]", "=", "$", "key", ";", "}", "if", "(", "$", "val", "[", "'autoinc'", "]", ")", "$", "this", "->", "autoinc", "=", "true", ";", "}", "}", "// 记录字段类型信息", "$", "this", "->", "fields", "[", "'_type'", "]", "=", "$", "type", ";", "// 2008-3-7 增加缓存开关控制", "if", "(", "C", "(", "'DB_FIELDS_CACHE'", ")", ")", "{", "// 永久缓存数据表信息", "$", "db", "=", "$", "this", "->", "dbName", "?", ":", "C", "(", "'DB_NAME'", ")", ";", "F", "(", "'_fields/'", ".", "strtolower", "(", "$", "db", ".", "'.'", ".", "$", "this", "->", "tablePrefix", ".", "$", "this", "->", "name", ")", ",", "$", "this", "->", "fields", ")", ";", "}", "}" ]
获取字段信息并缓存 @access public @return void
[ "获取字段信息并缓存" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Model.php#L131-L168
KDF5000/EasyThink
src/ThinkPHP/Library/Think/Model.php
Model._facade
protected function _facade($data) { // 检查数据字段合法性 if(!empty($this->fields)) { if(!empty($this->options['field'])) { $fields = $this->options['field']; unset($this->options['field']); if(is_string($fields)) { $fields = explode(',',$fields); } }else{ $fields = $this->fields; } foreach ($data as $key=>$val){ if(!in_array($key,$fields,true)){ if(!empty($this->options['strict'])){ E(L('_DATA_TYPE_INVALID_').':['.$key.'=>'.$val.']'); } unset($data[$key]); }elseif(is_scalar($val)) { // 字段类型检查 和 强制转换 $this->_parseType($data,$key); } } } // 安全过滤 if(!empty($this->options['filter'])) { $data = array_map($this->options['filter'],$data); unset($this->options['filter']); } $this->_before_write($data); return $data; }
php
protected function _facade($data) { // 检查数据字段合法性 if(!empty($this->fields)) { if(!empty($this->options['field'])) { $fields = $this->options['field']; unset($this->options['field']); if(is_string($fields)) { $fields = explode(',',$fields); } }else{ $fields = $this->fields; } foreach ($data as $key=>$val){ if(!in_array($key,$fields,true)){ if(!empty($this->options['strict'])){ E(L('_DATA_TYPE_INVALID_').':['.$key.'=>'.$val.']'); } unset($data[$key]); }elseif(is_scalar($val)) { // 字段类型检查 和 强制转换 $this->_parseType($data,$key); } } } // 安全过滤 if(!empty($this->options['filter'])) { $data = array_map($this->options['filter'],$data); unset($this->options['filter']); } $this->_before_write($data); return $data; }
[ "protected", "function", "_facade", "(", "$", "data", ")", "{", "// 检查数据字段合法性", "if", "(", "!", "empty", "(", "$", "this", "->", "fields", ")", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "options", "[", "'field'", "]", ")", ")", "{", "$", "fields", "=", "$", "this", "->", "options", "[", "'field'", "]", ";", "unset", "(", "$", "this", "->", "options", "[", "'field'", "]", ")", ";", "if", "(", "is_string", "(", "$", "fields", ")", ")", "{", "$", "fields", "=", "explode", "(", "','", ",", "$", "fields", ")", ";", "}", "}", "else", "{", "$", "fields", "=", "$", "this", "->", "fields", ";", "}", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "val", ")", "{", "if", "(", "!", "in_array", "(", "$", "key", ",", "$", "fields", ",", "true", ")", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "options", "[", "'strict'", "]", ")", ")", "{", "E", "(", "L", "(", "'_DATA_TYPE_INVALID_'", ")", ".", "':['", ".", "$", "key", ".", "'=>'", ".", "$", "val", ".", "']'", ")", ";", "}", "unset", "(", "$", "data", "[", "$", "key", "]", ")", ";", "}", "elseif", "(", "is_scalar", "(", "$", "val", ")", ")", "{", "// 字段类型检查 和 强制转换", "$", "this", "->", "_parseType", "(", "$", "data", ",", "$", "key", ")", ";", "}", "}", "}", "// 安全过滤", "if", "(", "!", "empty", "(", "$", "this", "->", "options", "[", "'filter'", "]", ")", ")", "{", "$", "data", "=", "array_map", "(", "$", "this", "->", "options", "[", "'filter'", "]", ",", "$", "data", ")", ";", "unset", "(", "$", "this", "->", "options", "[", "'filter'", "]", ")", ";", "}", "$", "this", "->", "_before_write", "(", "$", "data", ")", ";", "return", "$", "data", ";", "}" ]
对保存到数据库的数据进行处理 @access protected @param mixed $data 要操作的数据 @return boolean
[ "对保存到数据库的数据进行处理" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Model.php#L254-L287
KDF5000/EasyThink
src/ThinkPHP/Library/Think/Model.php
Model.save
public function save($data='',$options=array()) { if(empty($data)) { // 没有传递数据,获取当前数据对象的值 if(!empty($this->data)) { $data = $this->data; // 重置数据 $this->data = array(); }else{ $this->error = L('_DATA_TYPE_INVALID_'); return false; } } // 数据处理 $data = $this->_facade($data); if(empty($data)){ // 没有数据则不执行 $this->error = L('_DATA_TYPE_INVALID_'); return false; } // 分析表达式 $options = $this->_parseOptions($options); $pk = $this->getPk(); if(!isset($options['where']) ) { // 如果存在主键数据 则自动作为更新条件 if (is_string($pk) && isset($data[$pk])) { $where[$pk] = $data[$pk]; unset($data[$pk]); } elseif (is_array($pk)) { // 增加复合主键支持 foreach ($pk as $field) { if(isset($data[$field])) { $where[$field] = $data[$field]; } else { // 如果缺少复合主键数据则不执行 $this->error = L('_OPERATION_WRONG_'); return false; } unset($data[$field]); } } if(!isset($where)){ // 如果没有任何更新条件则不执行 $this->error = L('_OPERATION_WRONG_'); return false; }else{ $options['where'] = $where; } } if(is_array($options['where']) && isset($options['where'][$pk])){ $pkValue = $options['where'][$pk]; } if(false === $this->_before_update($data,$options)) { return false; } $result = $this->db->update($data,$options); if(false !== $result && is_numeric($result)) { if(isset($pkValue)) $data[$pk] = $pkValue; $this->_after_update($data,$options); } return $result; }
php
public function save($data='',$options=array()) { if(empty($data)) { // 没有传递数据,获取当前数据对象的值 if(!empty($this->data)) { $data = $this->data; // 重置数据 $this->data = array(); }else{ $this->error = L('_DATA_TYPE_INVALID_'); return false; } } // 数据处理 $data = $this->_facade($data); if(empty($data)){ // 没有数据则不执行 $this->error = L('_DATA_TYPE_INVALID_'); return false; } // 分析表达式 $options = $this->_parseOptions($options); $pk = $this->getPk(); if(!isset($options['where']) ) { // 如果存在主键数据 则自动作为更新条件 if (is_string($pk) && isset($data[$pk])) { $where[$pk] = $data[$pk]; unset($data[$pk]); } elseif (is_array($pk)) { // 增加复合主键支持 foreach ($pk as $field) { if(isset($data[$field])) { $where[$field] = $data[$field]; } else { // 如果缺少复合主键数据则不执行 $this->error = L('_OPERATION_WRONG_'); return false; } unset($data[$field]); } } if(!isset($where)){ // 如果没有任何更新条件则不执行 $this->error = L('_OPERATION_WRONG_'); return false; }else{ $options['where'] = $where; } } if(is_array($options['where']) && isset($options['where'][$pk])){ $pkValue = $options['where'][$pk]; } if(false === $this->_before_update($data,$options)) { return false; } $result = $this->db->update($data,$options); if(false !== $result && is_numeric($result)) { if(isset($pkValue)) $data[$pk] = $pkValue; $this->_after_update($data,$options); } return $result; }
[ "public", "function", "save", "(", "$", "data", "=", "''", ",", "$", "options", "=", "array", "(", ")", ")", "{", "if", "(", "empty", "(", "$", "data", ")", ")", "{", "// 没有传递数据,获取当前数据对象的值", "if", "(", "!", "empty", "(", "$", "this", "->", "data", ")", ")", "{", "$", "data", "=", "$", "this", "->", "data", ";", "// 重置数据", "$", "this", "->", "data", "=", "array", "(", ")", ";", "}", "else", "{", "$", "this", "->", "error", "=", "L", "(", "'_DATA_TYPE_INVALID_'", ")", ";", "return", "false", ";", "}", "}", "// 数据处理", "$", "data", "=", "$", "this", "->", "_facade", "(", "$", "data", ")", ";", "if", "(", "empty", "(", "$", "data", ")", ")", "{", "// 没有数据则不执行", "$", "this", "->", "error", "=", "L", "(", "'_DATA_TYPE_INVALID_'", ")", ";", "return", "false", ";", "}", "// 分析表达式", "$", "options", "=", "$", "this", "->", "_parseOptions", "(", "$", "options", ")", ";", "$", "pk", "=", "$", "this", "->", "getPk", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "options", "[", "'where'", "]", ")", ")", "{", "// 如果存在主键数据 则自动作为更新条件", "if", "(", "is_string", "(", "$", "pk", ")", "&&", "isset", "(", "$", "data", "[", "$", "pk", "]", ")", ")", "{", "$", "where", "[", "$", "pk", "]", "=", "$", "data", "[", "$", "pk", "]", ";", "unset", "(", "$", "data", "[", "$", "pk", "]", ")", ";", "}", "elseif", "(", "is_array", "(", "$", "pk", ")", ")", "{", "// 增加复合主键支持", "foreach", "(", "$", "pk", "as", "$", "field", ")", "{", "if", "(", "isset", "(", "$", "data", "[", "$", "field", "]", ")", ")", "{", "$", "where", "[", "$", "field", "]", "=", "$", "data", "[", "$", "field", "]", ";", "}", "else", "{", "// 如果缺少复合主键数据则不执行", "$", "this", "->", "error", "=", "L", "(", "'_OPERATION_WRONG_'", ")", ";", "return", "false", ";", "}", "unset", "(", "$", "data", "[", "$", "field", "]", ")", ";", "}", "}", "if", "(", "!", "isset", "(", "$", "where", ")", ")", "{", "// 如果没有任何更新条件则不执行", "$", "this", "->", "error", "=", "L", "(", "'_OPERATION_WRONG_'", ")", ";", "return", "false", ";", "}", "else", "{", "$", "options", "[", "'where'", "]", "=", "$", "where", ";", "}", "}", "if", "(", "is_array", "(", "$", "options", "[", "'where'", "]", ")", "&&", "isset", "(", "$", "options", "[", "'where'", "]", "[", "$", "pk", "]", ")", ")", "{", "$", "pkValue", "=", "$", "options", "[", "'where'", "]", "[", "$", "pk", "]", ";", "}", "if", "(", "false", "===", "$", "this", "->", "_before_update", "(", "$", "data", ",", "$", "options", ")", ")", "{", "return", "false", ";", "}", "$", "result", "=", "$", "this", "->", "db", "->", "update", "(", "$", "data", ",", "$", "options", ")", ";", "if", "(", "false", "!==", "$", "result", "&&", "is_numeric", "(", "$", "result", ")", ")", "{", "if", "(", "isset", "(", "$", "pkValue", ")", ")", "$", "data", "[", "$", "pk", "]", "=", "$", "pkValue", ";", "$", "this", "->", "_after_update", "(", "$", "data", ",", "$", "options", ")", ";", "}", "return", "$", "result", ";", "}" ]
保存数据 @access public @param mixed $data 数据 @param array $options 表达式 @return boolean
[ "保存数据" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Model.php#L396-L457
KDF5000/EasyThink
src/ThinkPHP/Library/Think/Model.php
Model._parseType
protected function _parseType(&$data,$key) { if(!isset($this->options['bind'][':'.$key]) && isset($this->fields['_type'][$key])){ $fieldType = strtolower($this->fields['_type'][$key]); if(false !== strpos($fieldType,'enum')){ // 支持ENUM类型优先检测 }elseif(false === strpos($fieldType,'bigint') && false !== strpos($fieldType,'int')) { $data[$key] = intval($data[$key]); }elseif(false !== strpos($fieldType,'float') || false !== strpos($fieldType,'double')){ $data[$key] = floatval($data[$key]); }elseif(false !== strpos($fieldType,'bool')){ $data[$key] = (bool)$data[$key]; } } }
php
protected function _parseType(&$data,$key) { if(!isset($this->options['bind'][':'.$key]) && isset($this->fields['_type'][$key])){ $fieldType = strtolower($this->fields['_type'][$key]); if(false !== strpos($fieldType,'enum')){ // 支持ENUM类型优先检测 }elseif(false === strpos($fieldType,'bigint') && false !== strpos($fieldType,'int')) { $data[$key] = intval($data[$key]); }elseif(false !== strpos($fieldType,'float') || false !== strpos($fieldType,'double')){ $data[$key] = floatval($data[$key]); }elseif(false !== strpos($fieldType,'bool')){ $data[$key] = (bool)$data[$key]; } } }
[ "protected", "function", "_parseType", "(", "&", "$", "data", ",", "$", "key", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "options", "[", "'bind'", "]", "[", "':'", ".", "$", "key", "]", ")", "&&", "isset", "(", "$", "this", "->", "fields", "[", "'_type'", "]", "[", "$", "key", "]", ")", ")", "{", "$", "fieldType", "=", "strtolower", "(", "$", "this", "->", "fields", "[", "'_type'", "]", "[", "$", "key", "]", ")", ";", "if", "(", "false", "!==", "strpos", "(", "$", "fieldType", ",", "'enum'", ")", ")", "{", "// 支持ENUM类型优先检测", "}", "elseif", "(", "false", "===", "strpos", "(", "$", "fieldType", ",", "'bigint'", ")", "&&", "false", "!==", "strpos", "(", "$", "fieldType", ",", "'int'", ")", ")", "{", "$", "data", "[", "$", "key", "]", "=", "intval", "(", "$", "data", "[", "$", "key", "]", ")", ";", "}", "elseif", "(", "false", "!==", "strpos", "(", "$", "fieldType", ",", "'float'", ")", "||", "false", "!==", "strpos", "(", "$", "fieldType", ",", "'double'", ")", ")", "{", "$", "data", "[", "$", "key", "]", "=", "floatval", "(", "$", "data", "[", "$", "key", "]", ")", ";", "}", "elseif", "(", "false", "!==", "strpos", "(", "$", "fieldType", ",", "'bool'", ")", ")", "{", "$", "data", "[", "$", "key", "]", "=", "(", "bool", ")", "$", "data", "[", "$", "key", "]", ";", "}", "}", "}" ]
数据类型检测 @access protected @param mixed $data 数据 @param string $key 字段名 @return void
[ "数据类型检测" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Model.php#L680-L693
KDF5000/EasyThink
src/ThinkPHP/Library/Think/Model.php
Model._read_data
protected function _read_data($data) { // 检查字段映射 if(!empty($this->_map) && C('READ_DATA_MAP')) { foreach ($this->_map as $key=>$val){ if(isset($data[$val])) { $data[$key] = $data[$val]; unset($data[$val]); } } } return $data; }
php
protected function _read_data($data) { // 检查字段映射 if(!empty($this->_map) && C('READ_DATA_MAP')) { foreach ($this->_map as $key=>$val){ if(isset($data[$val])) { $data[$key] = $data[$val]; unset($data[$val]); } } } return $data; }
[ "protected", "function", "_read_data", "(", "$", "data", ")", "{", "// 检查字段映射", "if", "(", "!", "empty", "(", "$", "this", "->", "_map", ")", "&&", "C", "(", "'READ_DATA_MAP'", ")", ")", "{", "foreach", "(", "$", "this", "->", "_map", "as", "$", "key", "=>", "$", "val", ")", "{", "if", "(", "isset", "(", "$", "data", "[", "$", "val", "]", ")", ")", "{", "$", "data", "[", "$", "key", "]", "=", "$", "data", "[", "$", "val", "]", ";", "unset", "(", "$", "data", "[", "$", "val", "]", ")", ";", "}", "}", "}", "return", "$", "data", ";", "}" ]
数据读取后的处理 @access protected @param array $data 当前数据 @return array
[ "数据读取后的处理" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Model.php#L701-L712
KDF5000/EasyThink
src/ThinkPHP/Library/Think/Model.php
Model.find
public function find($options=array()) { if(is_numeric($options) || is_string($options)) { $where[$this->getPk()] = $options; $options = array(); $options['where'] = $where; } // 根据复合主键查找记录 $pk = $this->getPk(); if (is_array($options) && (count($options) > 0) && is_array($pk)) { // 根据复合主键查询 $count = 0; foreach (array_keys($options) as $key) { if (is_int($key)) $count++; } if ($count == count($pk)) { $i = 0; foreach ($pk as $field) { $where[$field] = $options[$i]; unset($options[$i++]); } $options['where'] = $where; } else { return false; } } // 总是查找一条记录 $options['limit'] = 1; // 分析表达式 $options = $this->_parseOptions($options); // 判断查询缓存 if(isset($options['cache'])){ $cache = $options['cache']; $key = is_string($cache['key'])?$cache['key']:md5(serialize($options)); $data = S($key,'',$cache); if(false !== $data){ $this->data = $data; return $data; } } $resultSet = $this->db->select($options); if(false === $resultSet) { return false; } if(empty($resultSet)) {// 查询结果为空 return null; } if(is_string($resultSet)){ return $resultSet; } // 读取数据后的处理 $data = $this->_read_data($resultSet[0]); $this->_after_find($data,$options); if(!empty($this->options['result'])) { return $this->returnResult($data,$this->options['result']); } $this->data = $data; if(isset($cache)){ S($key,$data,$cache); } return $this->data; }
php
public function find($options=array()) { if(is_numeric($options) || is_string($options)) { $where[$this->getPk()] = $options; $options = array(); $options['where'] = $where; } // 根据复合主键查找记录 $pk = $this->getPk(); if (is_array($options) && (count($options) > 0) && is_array($pk)) { // 根据复合主键查询 $count = 0; foreach (array_keys($options) as $key) { if (is_int($key)) $count++; } if ($count == count($pk)) { $i = 0; foreach ($pk as $field) { $where[$field] = $options[$i]; unset($options[$i++]); } $options['where'] = $where; } else { return false; } } // 总是查找一条记录 $options['limit'] = 1; // 分析表达式 $options = $this->_parseOptions($options); // 判断查询缓存 if(isset($options['cache'])){ $cache = $options['cache']; $key = is_string($cache['key'])?$cache['key']:md5(serialize($options)); $data = S($key,'',$cache); if(false !== $data){ $this->data = $data; return $data; } } $resultSet = $this->db->select($options); if(false === $resultSet) { return false; } if(empty($resultSet)) {// 查询结果为空 return null; } if(is_string($resultSet)){ return $resultSet; } // 读取数据后的处理 $data = $this->_read_data($resultSet[0]); $this->_after_find($data,$options); if(!empty($this->options['result'])) { return $this->returnResult($data,$this->options['result']); } $this->data = $data; if(isset($cache)){ S($key,$data,$cache); } return $this->data; }
[ "public", "function", "find", "(", "$", "options", "=", "array", "(", ")", ")", "{", "if", "(", "is_numeric", "(", "$", "options", ")", "||", "is_string", "(", "$", "options", ")", ")", "{", "$", "where", "[", "$", "this", "->", "getPk", "(", ")", "]", "=", "$", "options", ";", "$", "options", "=", "array", "(", ")", ";", "$", "options", "[", "'where'", "]", "=", "$", "where", ";", "}", "// 根据复合主键查找记录", "$", "pk", "=", "$", "this", "->", "getPk", "(", ")", ";", "if", "(", "is_array", "(", "$", "options", ")", "&&", "(", "count", "(", "$", "options", ")", ">", "0", ")", "&&", "is_array", "(", "$", "pk", ")", ")", "{", "// 根据复合主键查询", "$", "count", "=", "0", ";", "foreach", "(", "array_keys", "(", "$", "options", ")", "as", "$", "key", ")", "{", "if", "(", "is_int", "(", "$", "key", ")", ")", "$", "count", "++", ";", "}", "if", "(", "$", "count", "==", "count", "(", "$", "pk", ")", ")", "{", "$", "i", "=", "0", ";", "foreach", "(", "$", "pk", "as", "$", "field", ")", "{", "$", "where", "[", "$", "field", "]", "=", "$", "options", "[", "$", "i", "]", ";", "unset", "(", "$", "options", "[", "$", "i", "++", "]", ")", ";", "}", "$", "options", "[", "'where'", "]", "=", "$", "where", ";", "}", "else", "{", "return", "false", ";", "}", "}", "// 总是查找一条记录", "$", "options", "[", "'limit'", "]", "=", "1", ";", "// 分析表达式", "$", "options", "=", "$", "this", "->", "_parseOptions", "(", "$", "options", ")", ";", "// 判断查询缓存", "if", "(", "isset", "(", "$", "options", "[", "'cache'", "]", ")", ")", "{", "$", "cache", "=", "$", "options", "[", "'cache'", "]", ";", "$", "key", "=", "is_string", "(", "$", "cache", "[", "'key'", "]", ")", "?", "$", "cache", "[", "'key'", "]", ":", "md5", "(", "serialize", "(", "$", "options", ")", ")", ";", "$", "data", "=", "S", "(", "$", "key", ",", "''", ",", "$", "cache", ")", ";", "if", "(", "false", "!==", "$", "data", ")", "{", "$", "this", "->", "data", "=", "$", "data", ";", "return", "$", "data", ";", "}", "}", "$", "resultSet", "=", "$", "this", "->", "db", "->", "select", "(", "$", "options", ")", ";", "if", "(", "false", "===", "$", "resultSet", ")", "{", "return", "false", ";", "}", "if", "(", "empty", "(", "$", "resultSet", ")", ")", "{", "// 查询结果为空", "return", "null", ";", "}", "if", "(", "is_string", "(", "$", "resultSet", ")", ")", "{", "return", "$", "resultSet", ";", "}", "// 读取数据后的处理", "$", "data", "=", "$", "this", "->", "_read_data", "(", "$", "resultSet", "[", "0", "]", ")", ";", "$", "this", "->", "_after_find", "(", "$", "data", ",", "$", "options", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "options", "[", "'result'", "]", ")", ")", "{", "return", "$", "this", "->", "returnResult", "(", "$", "data", ",", "$", "this", "->", "options", "[", "'result'", "]", ")", ";", "}", "$", "this", "->", "data", "=", "$", "data", ";", "if", "(", "isset", "(", "$", "cache", ")", ")", "{", "S", "(", "$", "key", ",", "$", "data", ",", "$", "cache", ")", ";", "}", "return", "$", "this", "->", "data", ";", "}" ]
查询数据 @access public @param mixed $options 表达式参数 @return mixed
[ "查询数据" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Model.php#L720-L781
KDF5000/EasyThink
src/ThinkPHP/Library/Think/Model.php
Model.setField
public function setField($field,$value='') { if(is_array($field)) { $data = $field; }else{ $data[$field] = $value; } return $this->save($data); }
php
public function setField($field,$value='') { if(is_array($field)) { $data = $field; }else{ $data[$field] = $value; } return $this->save($data); }
[ "public", "function", "setField", "(", "$", "field", ",", "$", "value", "=", "''", ")", "{", "if", "(", "is_array", "(", "$", "field", ")", ")", "{", "$", "data", "=", "$", "field", ";", "}", "else", "{", "$", "data", "[", "$", "field", "]", "=", "$", "value", ";", "}", "return", "$", "this", "->", "save", "(", "$", "data", ")", ";", "}" ]
设置记录的某个字段值 支持使用数据库字段和方法 @access public @param string|array $field 字段名 @param string $value 字段值 @return boolean
[ "设置记录的某个字段值", "支持使用数据库字段和方法" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Model.php#L835-L842
KDF5000/EasyThink
src/ThinkPHP/Library/Think/Model.php
Model.lazyWrite
protected function lazyWrite($guid,$step,$lazyTime) { if(false !== ($value = S($guid))) { // 存在缓存写入数据 if(NOW_TIME > S($guid.'_time')+$lazyTime) { // 延时更新时间到了,删除缓存数据 并实际写入数据库 S($guid,NULL); S($guid.'_time',NULL); return $value+$step; }else{ // 追加数据到缓存 S($guid,$value+$step); return false; } }else{ // 没有缓存数据 S($guid,$step); // 计时开始 S($guid.'_time',NOW_TIME); return false; } }
php
protected function lazyWrite($guid,$step,$lazyTime) { if(false !== ($value = S($guid))) { // 存在缓存写入数据 if(NOW_TIME > S($guid.'_time')+$lazyTime) { // 延时更新时间到了,删除缓存数据 并实际写入数据库 S($guid,NULL); S($guid.'_time',NULL); return $value+$step; }else{ // 追加数据到缓存 S($guid,$value+$step); return false; } }else{ // 没有缓存数据 S($guid,$step); // 计时开始 S($guid.'_time',NOW_TIME); return false; } }
[ "protected", "function", "lazyWrite", "(", "$", "guid", ",", "$", "step", ",", "$", "lazyTime", ")", "{", "if", "(", "false", "!==", "(", "$", "value", "=", "S", "(", "$", "guid", ")", ")", ")", "{", "// 存在缓存写入数据", "if", "(", "NOW_TIME", ">", "S", "(", "$", "guid", ".", "'_time'", ")", "+", "$", "lazyTime", ")", "{", "// 延时更新时间到了,删除缓存数据 并实际写入数据库", "S", "(", "$", "guid", ",", "NULL", ")", ";", "S", "(", "$", "guid", ".", "'_time'", ",", "NULL", ")", ";", "return", "$", "value", "+", "$", "step", ";", "}", "else", "{", "// 追加数据到缓存", "S", "(", "$", "guid", ",", "$", "value", "+", "$", "step", ")", ";", "return", "false", ";", "}", "}", "else", "{", "// 没有缓存数据", "S", "(", "$", "guid", ",", "$", "step", ")", ";", "// 计时开始", "S", "(", "$", "guid", ".", "'_time'", ",", "NOW_TIME", ")", ";", "return", "false", ";", "}", "}" ]
延时更新检查 返回false表示需要延时 否则返回实际写入的数值 @access public @param string $guid 写入标识 @param integer $step 写入步进值 @param integer $lazyTime 延时时间(s) @return false|integer
[ "延时更新检查", "返回false表示需要延时", "否则返回实际写入的数值" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Model.php#L897-L915
KDF5000/EasyThink
src/ThinkPHP/Library/Think/Model.php
Model.create
public function create($data='',$type='') { // 如果没有传值默认取POST数据 if(empty($data)) { $data = I('post.'); }elseif(is_object($data)){ $data = get_object_vars($data); } // 验证数据 if(empty($data) || !is_array($data)) { $this->error = L('_DATA_TYPE_INVALID_'); return false; } // 状态 $type = $type?:(!empty($data[$this->getPk()])?self::MODEL_UPDATE:self::MODEL_INSERT); // 检查字段映射 $data = $this->parseFieldsMap($data,0); // 检测提交字段的合法性 if(isset($this->options['field'])) { // $this->field('field1,field2...')->create() $fields = $this->options['field']; unset($this->options['field']); }elseif($type == self::MODEL_INSERT && isset($this->insertFields)) { $fields = $this->insertFields; }elseif($type == self::MODEL_UPDATE && isset($this->updateFields)) { $fields = $this->updateFields; } if(isset($fields)) { if(is_string($fields)) { $fields = explode(',',$fields); } // 判断令牌验证字段 if(C('TOKEN_ON')) $fields[] = C('TOKEN_NAME', null, '__hash__'); foreach ($data as $key=>$val){ if(!in_array($key,$fields)) { unset($data[$key]); } } } // 数据自动验证 if(!$this->autoValidation($data,$type)) return false; // 表单令牌验证 if(!$this->autoCheckToken($data)) { $this->error = L('_TOKEN_ERROR_'); return false; } // 验证完成生成数据对象 if($this->autoCheckFields) { // 开启字段检测 则过滤非法字段数据 $fields = $this->getDbFields(); foreach ($data as $key=>$val){ if(!in_array($key,$fields)) { unset($data[$key]); }elseif(MAGIC_QUOTES_GPC && is_string($val)){ $data[$key] = stripslashes($val); } } } // 创建完成对数据进行自动处理 $this->autoOperation($data,$type); // 赋值当前数据对象 $this->data = $data; // 返回创建的数据以供其他调用 return $data; }
php
public function create($data='',$type='') { // 如果没有传值默认取POST数据 if(empty($data)) { $data = I('post.'); }elseif(is_object($data)){ $data = get_object_vars($data); } // 验证数据 if(empty($data) || !is_array($data)) { $this->error = L('_DATA_TYPE_INVALID_'); return false; } // 状态 $type = $type?:(!empty($data[$this->getPk()])?self::MODEL_UPDATE:self::MODEL_INSERT); // 检查字段映射 $data = $this->parseFieldsMap($data,0); // 检测提交字段的合法性 if(isset($this->options['field'])) { // $this->field('field1,field2...')->create() $fields = $this->options['field']; unset($this->options['field']); }elseif($type == self::MODEL_INSERT && isset($this->insertFields)) { $fields = $this->insertFields; }elseif($type == self::MODEL_UPDATE && isset($this->updateFields)) { $fields = $this->updateFields; } if(isset($fields)) { if(is_string($fields)) { $fields = explode(',',$fields); } // 判断令牌验证字段 if(C('TOKEN_ON')) $fields[] = C('TOKEN_NAME', null, '__hash__'); foreach ($data as $key=>$val){ if(!in_array($key,$fields)) { unset($data[$key]); } } } // 数据自动验证 if(!$this->autoValidation($data,$type)) return false; // 表单令牌验证 if(!$this->autoCheckToken($data)) { $this->error = L('_TOKEN_ERROR_'); return false; } // 验证完成生成数据对象 if($this->autoCheckFields) { // 开启字段检测 则过滤非法字段数据 $fields = $this->getDbFields(); foreach ($data as $key=>$val){ if(!in_array($key,$fields)) { unset($data[$key]); }elseif(MAGIC_QUOTES_GPC && is_string($val)){ $data[$key] = stripslashes($val); } } } // 创建完成对数据进行自动处理 $this->autoOperation($data,$type); // 赋值当前数据对象 $this->data = $data; // 返回创建的数据以供其他调用 return $data; }
[ "public", "function", "create", "(", "$", "data", "=", "''", ",", "$", "type", "=", "''", ")", "{", "// 如果没有传值默认取POST数据", "if", "(", "empty", "(", "$", "data", ")", ")", "{", "$", "data", "=", "I", "(", "'post.'", ")", ";", "}", "elseif", "(", "is_object", "(", "$", "data", ")", ")", "{", "$", "data", "=", "get_object_vars", "(", "$", "data", ")", ";", "}", "// 验证数据", "if", "(", "empty", "(", "$", "data", ")", "||", "!", "is_array", "(", "$", "data", ")", ")", "{", "$", "this", "->", "error", "=", "L", "(", "'_DATA_TYPE_INVALID_'", ")", ";", "return", "false", ";", "}", "// 状态", "$", "type", "=", "$", "type", "?", ":", "(", "!", "empty", "(", "$", "data", "[", "$", "this", "->", "getPk", "(", ")", "]", ")", "?", "self", "::", "MODEL_UPDATE", ":", "self", "::", "MODEL_INSERT", ")", ";", "// 检查字段映射", "$", "data", "=", "$", "this", "->", "parseFieldsMap", "(", "$", "data", ",", "0", ")", ";", "// 检测提交字段的合法性", "if", "(", "isset", "(", "$", "this", "->", "options", "[", "'field'", "]", ")", ")", "{", "// $this->field('field1,field2...')->create()", "$", "fields", "=", "$", "this", "->", "options", "[", "'field'", "]", ";", "unset", "(", "$", "this", "->", "options", "[", "'field'", "]", ")", ";", "}", "elseif", "(", "$", "type", "==", "self", "::", "MODEL_INSERT", "&&", "isset", "(", "$", "this", "->", "insertFields", ")", ")", "{", "$", "fields", "=", "$", "this", "->", "insertFields", ";", "}", "elseif", "(", "$", "type", "==", "self", "::", "MODEL_UPDATE", "&&", "isset", "(", "$", "this", "->", "updateFields", ")", ")", "{", "$", "fields", "=", "$", "this", "->", "updateFields", ";", "}", "if", "(", "isset", "(", "$", "fields", ")", ")", "{", "if", "(", "is_string", "(", "$", "fields", ")", ")", "{", "$", "fields", "=", "explode", "(", "','", ",", "$", "fields", ")", ";", "}", "// 判断令牌验证字段", "if", "(", "C", "(", "'TOKEN_ON'", ")", ")", "$", "fields", "[", "]", "=", "C", "(", "'TOKEN_NAME'", ",", "null", ",", "'__hash__'", ")", ";", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "val", ")", "{", "if", "(", "!", "in_array", "(", "$", "key", ",", "$", "fields", ")", ")", "{", "unset", "(", "$", "data", "[", "$", "key", "]", ")", ";", "}", "}", "}", "// 数据自动验证", "if", "(", "!", "$", "this", "->", "autoValidation", "(", "$", "data", ",", "$", "type", ")", ")", "return", "false", ";", "// 表单令牌验证", "if", "(", "!", "$", "this", "->", "autoCheckToken", "(", "$", "data", ")", ")", "{", "$", "this", "->", "error", "=", "L", "(", "'_TOKEN_ERROR_'", ")", ";", "return", "false", ";", "}", "// 验证完成生成数据对象", "if", "(", "$", "this", "->", "autoCheckFields", ")", "{", "// 开启字段检测 则过滤非法字段数据", "$", "fields", "=", "$", "this", "->", "getDbFields", "(", ")", ";", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "val", ")", "{", "if", "(", "!", "in_array", "(", "$", "key", ",", "$", "fields", ")", ")", "{", "unset", "(", "$", "data", "[", "$", "key", "]", ")", ";", "}", "elseif", "(", "MAGIC_QUOTES_GPC", "&&", "is_string", "(", "$", "val", ")", ")", "{", "$", "data", "[", "$", "key", "]", "=", "stripslashes", "(", "$", "val", ")", ";", "}", "}", "}", "// 创建完成对数据进行自动处理", "$", "this", "->", "autoOperation", "(", "$", "data", ",", "$", "type", ")", ";", "// 赋值当前数据对象", "$", "this", "->", "data", "=", "$", "data", ";", "// 返回创建的数据以供其他调用", "return", "$", "data", ";", "}" ]
创建数据对象 但不保存到数据库 @access public @param mixed $data 创建数据 @param string $type 状态 @return mixed
[ "创建数据对象", "但不保存到数据库" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Model.php#L1001-L1069
KDF5000/EasyThink
src/ThinkPHP/Library/Think/Model.php
Model.autoCheckToken
public function autoCheckToken($data) { // 支持使用token(false) 关闭令牌验证 if(isset($this->options['token']) && !$this->options['token']) return true; if(C('TOKEN_ON')){ $name = C('TOKEN_NAME', null, '__hash__'); if(!isset($data[$name]) || !isset($_SESSION[$name])) { // 令牌数据无效 return false; } // 令牌验证 list($key,$value) = explode('_',$data[$name]); if(isset($_SESSION[$name][$key]) && $value && $_SESSION[$name][$key] === $value) { // 防止重复提交 unset($_SESSION[$name][$key]); // 验证完成销毁session return true; } // 开启TOKEN重置 if(C('TOKEN_RESET')) unset($_SESSION[$name][$key]); return false; } return true; }
php
public function autoCheckToken($data) { // 支持使用token(false) 关闭令牌验证 if(isset($this->options['token']) && !$this->options['token']) return true; if(C('TOKEN_ON')){ $name = C('TOKEN_NAME', null, '__hash__'); if(!isset($data[$name]) || !isset($_SESSION[$name])) { // 令牌数据无效 return false; } // 令牌验证 list($key,$value) = explode('_',$data[$name]); if(isset($_SESSION[$name][$key]) && $value && $_SESSION[$name][$key] === $value) { // 防止重复提交 unset($_SESSION[$name][$key]); // 验证完成销毁session return true; } // 开启TOKEN重置 if(C('TOKEN_RESET')) unset($_SESSION[$name][$key]); return false; } return true; }
[ "public", "function", "autoCheckToken", "(", "$", "data", ")", "{", "// 支持使用token(false) 关闭令牌验证", "if", "(", "isset", "(", "$", "this", "->", "options", "[", "'token'", "]", ")", "&&", "!", "$", "this", "->", "options", "[", "'token'", "]", ")", "return", "true", ";", "if", "(", "C", "(", "'TOKEN_ON'", ")", ")", "{", "$", "name", "=", "C", "(", "'TOKEN_NAME'", ",", "null", ",", "'__hash__'", ")", ";", "if", "(", "!", "isset", "(", "$", "data", "[", "$", "name", "]", ")", "||", "!", "isset", "(", "$", "_SESSION", "[", "$", "name", "]", ")", ")", "{", "// 令牌数据无效", "return", "false", ";", "}", "// 令牌验证", "list", "(", "$", "key", ",", "$", "value", ")", "=", "explode", "(", "'_'", ",", "$", "data", "[", "$", "name", "]", ")", ";", "if", "(", "isset", "(", "$", "_SESSION", "[", "$", "name", "]", "[", "$", "key", "]", ")", "&&", "$", "value", "&&", "$", "_SESSION", "[", "$", "name", "]", "[", "$", "key", "]", "===", "$", "value", ")", "{", "// 防止重复提交", "unset", "(", "$", "_SESSION", "[", "$", "name", "]", "[", "$", "key", "]", ")", ";", "// 验证完成销毁session", "return", "true", ";", "}", "// 开启TOKEN重置", "if", "(", "C", "(", "'TOKEN_RESET'", ")", ")", "unset", "(", "$", "_SESSION", "[", "$", "name", "]", "[", "$", "key", "]", ")", ";", "return", "false", ";", "}", "return", "true", ";", "}" ]
TODO ajax无刷新多次提交暂不能满足
[ "TODO", "ajax无刷新多次提交暂不能满足" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Model.php#L1073-L1093
KDF5000/EasyThink
src/ThinkPHP/Library/Think/Model.php
Model.regex
public function regex($value,$rule) { $validate = array( 'require' => '/\S+/', 'email' => '/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/', 'url' => '/^http(s?):\/\/(?:[A-za-z0-9-]+\.)+[A-za-z]{2,4}(:\d+)?(?:[\/\?#][\/=\?%\-&~`@[\]\':+!\.#\w]*)?$/', 'currency' => '/^\d+(\.\d+)?$/', 'number' => '/^\d+$/', 'zip' => '/^\d{6}$/', 'integer' => '/^[-\+]?\d+$/', 'double' => '/^[-\+]?\d+(\.\d+)?$/', 'english' => '/^[A-Za-z]+$/', ); // 检查是否有内置的正则表达式 if(isset($validate[strtolower($rule)])) $rule = $validate[strtolower($rule)]; return preg_match($rule,$value)===1; }
php
public function regex($value,$rule) { $validate = array( 'require' => '/\S+/', 'email' => '/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/', 'url' => '/^http(s?):\/\/(?:[A-za-z0-9-]+\.)+[A-za-z]{2,4}(:\d+)?(?:[\/\?#][\/=\?%\-&~`@[\]\':+!\.#\w]*)?$/', 'currency' => '/^\d+(\.\d+)?$/', 'number' => '/^\d+$/', 'zip' => '/^\d{6}$/', 'integer' => '/^[-\+]?\d+$/', 'double' => '/^[-\+]?\d+(\.\d+)?$/', 'english' => '/^[A-Za-z]+$/', ); // 检查是否有内置的正则表达式 if(isset($validate[strtolower($rule)])) $rule = $validate[strtolower($rule)]; return preg_match($rule,$value)===1; }
[ "public", "function", "regex", "(", "$", "value", ",", "$", "rule", ")", "{", "$", "validate", "=", "array", "(", "'require'", "=>", "'/\\S+/'", ",", "'email'", "=>", "'/^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$/'", ",", "'url'", "=>", "'/^http(s?):\\/\\/(?:[A-za-z0-9-]+\\.)+[A-za-z]{2,4}(:\\d+)?(?:[\\/\\?#][\\/=\\?%\\-&~`@[\\]\\':+!\\.#\\w]*)?$/'", ",", "'currency'", "=>", "'/^\\d+(\\.\\d+)?$/'", ",", "'number'", "=>", "'/^\\d+$/'", ",", "'zip'", "=>", "'/^\\d{6}$/'", ",", "'integer'", "=>", "'/^[-\\+]?\\d+$/'", ",", "'double'", "=>", "'/^[-\\+]?\\d+(\\.\\d+)?$/'", ",", "'english'", "=>", "'/^[A-Za-z]+$/'", ",", ")", ";", "// 检查是否有内置的正则表达式", "if", "(", "isset", "(", "$", "validate", "[", "strtolower", "(", "$", "rule", ")", "]", ")", ")", "$", "rule", "=", "$", "validate", "[", "strtolower", "(", "$", "rule", ")", "]", ";", "return", "preg_match", "(", "$", "rule", ",", "$", "value", ")", "===", "1", ";", "}" ]
使用正则验证数据 @access public @param string $value 要验证的数据 @param string $rule 验证规则 @return boolean
[ "使用正则验证数据" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Model.php#L1102-L1118
KDF5000/EasyThink
src/ThinkPHP/Library/Think/Model.php
Model.autoOperation
private function autoOperation(&$data,$type) { if(false === $this->options['auto']){ // 关闭自动完成 return $data; } if(!empty($this->options['auto'])) { $_auto = $this->options['auto']; unset($this->options['auto']); }elseif(!empty($this->_auto)){ $_auto = $this->_auto; } // 自动填充 if(isset($_auto)) { foreach ($_auto as $auto){ // 填充因子定义格式 // array('field','填充内容','填充条件','附加规则',[额外参数]) if(empty($auto[2])) $auto[2] = self::MODEL_INSERT; // 默认为新增的时候自动填充 if( $type == $auto[2] || $auto[2] == self::MODEL_BOTH) { if(empty($auto[3])) $auto[3] = 'string'; switch(trim($auto[3])) { case 'function': // 使用函数进行填充 字段的值作为参数 case 'callback': // 使用回调方法 $args = isset($auto[4])?(array)$auto[4]:array(); if(isset($data[$auto[0]])) { array_unshift($args,$data[$auto[0]]); } if('function'==$auto[3]) { $data[$auto[0]] = call_user_func_array($auto[1], $args); }else{ $data[$auto[0]] = call_user_func_array(array(&$this,$auto[1]), $args); } break; case 'field': // 用其它字段的值进行填充 $data[$auto[0]] = $data[$auto[1]]; break; case 'ignore': // 为空忽略 if($auto[1]===$data[$auto[0]]) unset($data[$auto[0]]); break; case 'string': default: // 默认作为字符串填充 $data[$auto[0]] = $auto[1]; } if(isset($data[$auto[0]]) && false === $data[$auto[0]] ) unset($data[$auto[0]]); } } } return $data; }
php
private function autoOperation(&$data,$type) { if(false === $this->options['auto']){ // 关闭自动完成 return $data; } if(!empty($this->options['auto'])) { $_auto = $this->options['auto']; unset($this->options['auto']); }elseif(!empty($this->_auto)){ $_auto = $this->_auto; } // 自动填充 if(isset($_auto)) { foreach ($_auto as $auto){ // 填充因子定义格式 // array('field','填充内容','填充条件','附加规则',[额外参数]) if(empty($auto[2])) $auto[2] = self::MODEL_INSERT; // 默认为新增的时候自动填充 if( $type == $auto[2] || $auto[2] == self::MODEL_BOTH) { if(empty($auto[3])) $auto[3] = 'string'; switch(trim($auto[3])) { case 'function': // 使用函数进行填充 字段的值作为参数 case 'callback': // 使用回调方法 $args = isset($auto[4])?(array)$auto[4]:array(); if(isset($data[$auto[0]])) { array_unshift($args,$data[$auto[0]]); } if('function'==$auto[3]) { $data[$auto[0]] = call_user_func_array($auto[1], $args); }else{ $data[$auto[0]] = call_user_func_array(array(&$this,$auto[1]), $args); } break; case 'field': // 用其它字段的值进行填充 $data[$auto[0]] = $data[$auto[1]]; break; case 'ignore': // 为空忽略 if($auto[1]===$data[$auto[0]]) unset($data[$auto[0]]); break; case 'string': default: // 默认作为字符串填充 $data[$auto[0]] = $auto[1]; } if(isset($data[$auto[0]]) && false === $data[$auto[0]] ) unset($data[$auto[0]]); } } } return $data; }
[ "private", "function", "autoOperation", "(", "&", "$", "data", ",", "$", "type", ")", "{", "if", "(", "false", "===", "$", "this", "->", "options", "[", "'auto'", "]", ")", "{", "// 关闭自动完成", "return", "$", "data", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "options", "[", "'auto'", "]", ")", ")", "{", "$", "_auto", "=", "$", "this", "->", "options", "[", "'auto'", "]", ";", "unset", "(", "$", "this", "->", "options", "[", "'auto'", "]", ")", ";", "}", "elseif", "(", "!", "empty", "(", "$", "this", "->", "_auto", ")", ")", "{", "$", "_auto", "=", "$", "this", "->", "_auto", ";", "}", "// 自动填充", "if", "(", "isset", "(", "$", "_auto", ")", ")", "{", "foreach", "(", "$", "_auto", "as", "$", "auto", ")", "{", "// 填充因子定义格式", "// array('field','填充内容','填充条件','附加规则',[额外参数])", "if", "(", "empty", "(", "$", "auto", "[", "2", "]", ")", ")", "$", "auto", "[", "2", "]", "=", "self", "::", "MODEL_INSERT", ";", "// 默认为新增的时候自动填充", "if", "(", "$", "type", "==", "$", "auto", "[", "2", "]", "||", "$", "auto", "[", "2", "]", "==", "self", "::", "MODEL_BOTH", ")", "{", "if", "(", "empty", "(", "$", "auto", "[", "3", "]", ")", ")", "$", "auto", "[", "3", "]", "=", "'string'", ";", "switch", "(", "trim", "(", "$", "auto", "[", "3", "]", ")", ")", "{", "case", "'function'", ":", "// 使用函数进行填充 字段的值作为参数", "case", "'callback'", ":", "// 使用回调方法", "$", "args", "=", "isset", "(", "$", "auto", "[", "4", "]", ")", "?", "(", "array", ")", "$", "auto", "[", "4", "]", ":", "array", "(", ")", ";", "if", "(", "isset", "(", "$", "data", "[", "$", "auto", "[", "0", "]", "]", ")", ")", "{", "array_unshift", "(", "$", "args", ",", "$", "data", "[", "$", "auto", "[", "0", "]", "]", ")", ";", "}", "if", "(", "'function'", "==", "$", "auto", "[", "3", "]", ")", "{", "$", "data", "[", "$", "auto", "[", "0", "]", "]", "=", "call_user_func_array", "(", "$", "auto", "[", "1", "]", ",", "$", "args", ")", ";", "}", "else", "{", "$", "data", "[", "$", "auto", "[", "0", "]", "]", "=", "call_user_func_array", "(", "array", "(", "&", "$", "this", ",", "$", "auto", "[", "1", "]", ")", ",", "$", "args", ")", ";", "}", "break", ";", "case", "'field'", ":", "// 用其它字段的值进行填充", "$", "data", "[", "$", "auto", "[", "0", "]", "]", "=", "$", "data", "[", "$", "auto", "[", "1", "]", "]", ";", "break", ";", "case", "'ignore'", ":", "// 为空忽略", "if", "(", "$", "auto", "[", "1", "]", "===", "$", "data", "[", "$", "auto", "[", "0", "]", "]", ")", "unset", "(", "$", "data", "[", "$", "auto", "[", "0", "]", "]", ")", ";", "break", ";", "case", "'string'", ":", "default", ":", "// 默认作为字符串填充", "$", "data", "[", "$", "auto", "[", "0", "]", "]", "=", "$", "auto", "[", "1", "]", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "$", "auto", "[", "0", "]", "]", ")", "&&", "false", "===", "$", "data", "[", "$", "auto", "[", "0", "]", "]", ")", "unset", "(", "$", "data", "[", "$", "auto", "[", "0", "]", "]", ")", ";", "}", "}", "}", "return", "$", "data", ";", "}" ]
自动表单处理 @access public @param array $data 创建数据 @param string $type 创建类型 @return mixed
[ "自动表单处理" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Model.php#L1127-L1175
KDF5000/EasyThink
src/ThinkPHP/Library/Think/Model.php
Model._validationFieldItem
protected function _validationFieldItem($data,$val) { switch(strtolower(trim($val[4]))) { case 'function':// 使用函数进行验证 case 'callback':// 调用方法进行验证 $args = isset($val[6])?(array)$val[6]:array(); if(is_string($val[0]) && strpos($val[0], ',')) $val[0] = explode(',', $val[0]); if(is_array($val[0])){ // 支持多个字段验证 foreach($val[0] as $field) $_data[$field] = $data[$field]; array_unshift($args, $_data); }else{ array_unshift($args, $data[$val[0]]); } if('function'==$val[4]) { return call_user_func_array($val[1], $args); }else{ return call_user_func_array(array(&$this, $val[1]), $args); } case 'confirm': // 验证两个字段是否相同 return $data[$val[0]] == $data[$val[1]]; case 'unique': // 验证某个值是否唯一 if(is_string($val[0]) && strpos($val[0],',')) $val[0] = explode(',',$val[0]); $map = array(); if(is_array($val[0])) { // 支持多个字段验证 foreach ($val[0] as $field) $map[$field] = $data[$field]; }else{ $map[$val[0]] = $data[$val[0]]; } $pk = $this->getPk(); if(!empty($data[$pk]) && is_string($pk)) { // 完善编辑的时候验证唯一 $map[$pk] = array('neq',$data[$pk]); } if($this->where($map)->find()) return false; return true; default: // 检查附加规则 return $this->check($data[$val[0]],$val[1],$val[4]); } }
php
protected function _validationFieldItem($data,$val) { switch(strtolower(trim($val[4]))) { case 'function':// 使用函数进行验证 case 'callback':// 调用方法进行验证 $args = isset($val[6])?(array)$val[6]:array(); if(is_string($val[0]) && strpos($val[0], ',')) $val[0] = explode(',', $val[0]); if(is_array($val[0])){ // 支持多个字段验证 foreach($val[0] as $field) $_data[$field] = $data[$field]; array_unshift($args, $_data); }else{ array_unshift($args, $data[$val[0]]); } if('function'==$val[4]) { return call_user_func_array($val[1], $args); }else{ return call_user_func_array(array(&$this, $val[1]), $args); } case 'confirm': // 验证两个字段是否相同 return $data[$val[0]] == $data[$val[1]]; case 'unique': // 验证某个值是否唯一 if(is_string($val[0]) && strpos($val[0],',')) $val[0] = explode(',',$val[0]); $map = array(); if(is_array($val[0])) { // 支持多个字段验证 foreach ($val[0] as $field) $map[$field] = $data[$field]; }else{ $map[$val[0]] = $data[$val[0]]; } $pk = $this->getPk(); if(!empty($data[$pk]) && is_string($pk)) { // 完善编辑的时候验证唯一 $map[$pk] = array('neq',$data[$pk]); } if($this->where($map)->find()) return false; return true; default: // 检查附加规则 return $this->check($data[$val[0]],$val[1],$val[4]); } }
[ "protected", "function", "_validationFieldItem", "(", "$", "data", ",", "$", "val", ")", "{", "switch", "(", "strtolower", "(", "trim", "(", "$", "val", "[", "4", "]", ")", ")", ")", "{", "case", "'function'", ":", "// 使用函数进行验证", "case", "'callback'", ":", "// 调用方法进行验证", "$", "args", "=", "isset", "(", "$", "val", "[", "6", "]", ")", "?", "(", "array", ")", "$", "val", "[", "6", "]", ":", "array", "(", ")", ";", "if", "(", "is_string", "(", "$", "val", "[", "0", "]", ")", "&&", "strpos", "(", "$", "val", "[", "0", "]", ",", "','", ")", ")", "$", "val", "[", "0", "]", "=", "explode", "(", "','", ",", "$", "val", "[", "0", "]", ")", ";", "if", "(", "is_array", "(", "$", "val", "[", "0", "]", ")", ")", "{", "// 支持多个字段验证", "foreach", "(", "$", "val", "[", "0", "]", "as", "$", "field", ")", "$", "_data", "[", "$", "field", "]", "=", "$", "data", "[", "$", "field", "]", ";", "array_unshift", "(", "$", "args", ",", "$", "_data", ")", ";", "}", "else", "{", "array_unshift", "(", "$", "args", ",", "$", "data", "[", "$", "val", "[", "0", "]", "]", ")", ";", "}", "if", "(", "'function'", "==", "$", "val", "[", "4", "]", ")", "{", "return", "call_user_func_array", "(", "$", "val", "[", "1", "]", ",", "$", "args", ")", ";", "}", "else", "{", "return", "call_user_func_array", "(", "array", "(", "&", "$", "this", ",", "$", "val", "[", "1", "]", ")", ",", "$", "args", ")", ";", "}", "case", "'confirm'", ":", "// 验证两个字段是否相同", "return", "$", "data", "[", "$", "val", "[", "0", "]", "]", "==", "$", "data", "[", "$", "val", "[", "1", "]", "]", ";", "case", "'unique'", ":", "// 验证某个值是否唯一", "if", "(", "is_string", "(", "$", "val", "[", "0", "]", ")", "&&", "strpos", "(", "$", "val", "[", "0", "]", ",", "','", ")", ")", "$", "val", "[", "0", "]", "=", "explode", "(", "','", ",", "$", "val", "[", "0", "]", ")", ";", "$", "map", "=", "array", "(", ")", ";", "if", "(", "is_array", "(", "$", "val", "[", "0", "]", ")", ")", "{", "// 支持多个字段验证", "foreach", "(", "$", "val", "[", "0", "]", "as", "$", "field", ")", "$", "map", "[", "$", "field", "]", "=", "$", "data", "[", "$", "field", "]", ";", "}", "else", "{", "$", "map", "[", "$", "val", "[", "0", "]", "]", "=", "$", "data", "[", "$", "val", "[", "0", "]", "]", ";", "}", "$", "pk", "=", "$", "this", "->", "getPk", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "data", "[", "$", "pk", "]", ")", "&&", "is_string", "(", "$", "pk", ")", ")", "{", "// 完善编辑的时候验证唯一", "$", "map", "[", "$", "pk", "]", "=", "array", "(", "'neq'", ",", "$", "data", "[", "$", "pk", "]", ")", ";", "}", "if", "(", "$", "this", "->", "where", "(", "$", "map", ")", "->", "find", "(", ")", ")", "return", "false", ";", "return", "true", ";", "default", ":", "// 检查附加规则", "return", "$", "this", "->", "check", "(", "$", "data", "[", "$", "val", "[", "0", "]", "]", ",", "$", "val", "[", "1", "]", ",", "$", "val", "[", "4", "]", ")", ";", "}", "}" ]
根据验证因子验证字段 @access protected @param array $data 创建数据 @param array $val 验证因子 @return boolean
[ "根据验证因子验证字段" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Model.php#L1263-L1305
KDF5000/EasyThink
src/ThinkPHP/Library/Think/Model.php
Model.check
public function check($value,$rule,$type='regex'){ $type = strtolower(trim($type)); switch($type) { case 'in': // 验证是否在某个指定范围之内 逗号分隔字符串或者数组 case 'notin': $range = is_array($rule)? $rule : explode(',',$rule); return $type == 'in' ? in_array($value ,$range) : !in_array($value ,$range); case 'between': // 验证是否在某个范围 case 'notbetween': // 验证是否不在某个范围 if (is_array($rule)){ $min = $rule[0]; $max = $rule[1]; }else{ list($min,$max) = explode(',',$rule); } return $type == 'between' ? $value>=$min && $value<=$max : $value<$min || $value>$max; case 'equal': // 验证是否等于某个值 case 'notequal': // 验证是否等于某个值 return $type == 'equal' ? $value == $rule : $value != $rule; case 'length': // 验证长度 $length = mb_strlen($value,'utf-8'); // 当前数据长度 if(strpos($rule,',')) { // 长度区间 list($min,$max) = explode(',',$rule); return $length >= $min && $length <= $max; }else{// 指定长度 return $length == $rule; } case 'expire': list($start,$end) = explode(',',$rule); if(!is_numeric($start)) $start = strtotime($start); if(!is_numeric($end)) $end = strtotime($end); return NOW_TIME >= $start && NOW_TIME <= $end; case 'ip_allow': // IP 操作许可验证 return in_array(get_client_ip(),explode(',',$rule)); case 'ip_deny': // IP 操作禁止验证 return !in_array(get_client_ip(),explode(',',$rule)); case 'regex': default: // 默认使用正则验证 可以使用验证类中定义的验证名称 // 检查附加规则 return $this->regex($value,$rule); } }
php
public function check($value,$rule,$type='regex'){ $type = strtolower(trim($type)); switch($type) { case 'in': // 验证是否在某个指定范围之内 逗号分隔字符串或者数组 case 'notin': $range = is_array($rule)? $rule : explode(',',$rule); return $type == 'in' ? in_array($value ,$range) : !in_array($value ,$range); case 'between': // 验证是否在某个范围 case 'notbetween': // 验证是否不在某个范围 if (is_array($rule)){ $min = $rule[0]; $max = $rule[1]; }else{ list($min,$max) = explode(',',$rule); } return $type == 'between' ? $value>=$min && $value<=$max : $value<$min || $value>$max; case 'equal': // 验证是否等于某个值 case 'notequal': // 验证是否等于某个值 return $type == 'equal' ? $value == $rule : $value != $rule; case 'length': // 验证长度 $length = mb_strlen($value,'utf-8'); // 当前数据长度 if(strpos($rule,',')) { // 长度区间 list($min,$max) = explode(',',$rule); return $length >= $min && $length <= $max; }else{// 指定长度 return $length == $rule; } case 'expire': list($start,$end) = explode(',',$rule); if(!is_numeric($start)) $start = strtotime($start); if(!is_numeric($end)) $end = strtotime($end); return NOW_TIME >= $start && NOW_TIME <= $end; case 'ip_allow': // IP 操作许可验证 return in_array(get_client_ip(),explode(',',$rule)); case 'ip_deny': // IP 操作禁止验证 return !in_array(get_client_ip(),explode(',',$rule)); case 'regex': default: // 默认使用正则验证 可以使用验证类中定义的验证名称 // 检查附加规则 return $this->regex($value,$rule); } }
[ "public", "function", "check", "(", "$", "value", ",", "$", "rule", ",", "$", "type", "=", "'regex'", ")", "{", "$", "type", "=", "strtolower", "(", "trim", "(", "$", "type", ")", ")", ";", "switch", "(", "$", "type", ")", "{", "case", "'in'", ":", "// 验证是否在某个指定范围之内 逗号分隔字符串或者数组", "case", "'notin'", ":", "$", "range", "=", "is_array", "(", "$", "rule", ")", "?", "$", "rule", ":", "explode", "(", "','", ",", "$", "rule", ")", ";", "return", "$", "type", "==", "'in'", "?", "in_array", "(", "$", "value", ",", "$", "range", ")", ":", "!", "in_array", "(", "$", "value", ",", "$", "range", ")", ";", "case", "'between'", ":", "// 验证是否在某个范围", "case", "'notbetween'", ":", "// 验证是否不在某个范围 ", "if", "(", "is_array", "(", "$", "rule", ")", ")", "{", "$", "min", "=", "$", "rule", "[", "0", "]", ";", "$", "max", "=", "$", "rule", "[", "1", "]", ";", "}", "else", "{", "list", "(", "$", "min", ",", "$", "max", ")", "=", "explode", "(", "','", ",", "$", "rule", ")", ";", "}", "return", "$", "type", "==", "'between'", "?", "$", "value", ">=", "$", "min", "&&", "$", "value", "<=", "$", "max", ":", "$", "value", "<", "$", "min", "||", "$", "value", ">", "$", "max", ";", "case", "'equal'", ":", "// 验证是否等于某个值", "case", "'notequal'", ":", "// 验证是否等于某个值 ", "return", "$", "type", "==", "'equal'", "?", "$", "value", "==", "$", "rule", ":", "$", "value", "!=", "$", "rule", ";", "case", "'length'", ":", "// 验证长度", "$", "length", "=", "mb_strlen", "(", "$", "value", ",", "'utf-8'", ")", ";", "// 当前数据长度", "if", "(", "strpos", "(", "$", "rule", ",", "','", ")", ")", "{", "// 长度区间", "list", "(", "$", "min", ",", "$", "max", ")", "=", "explode", "(", "','", ",", "$", "rule", ")", ";", "return", "$", "length", ">=", "$", "min", "&&", "$", "length", "<=", "$", "max", ";", "}", "else", "{", "// 指定长度", "return", "$", "length", "==", "$", "rule", ";", "}", "case", "'expire'", ":", "list", "(", "$", "start", ",", "$", "end", ")", "=", "explode", "(", "','", ",", "$", "rule", ")", ";", "if", "(", "!", "is_numeric", "(", "$", "start", ")", ")", "$", "start", "=", "strtotime", "(", "$", "start", ")", ";", "if", "(", "!", "is_numeric", "(", "$", "end", ")", ")", "$", "end", "=", "strtotime", "(", "$", "end", ")", ";", "return", "NOW_TIME", ">=", "$", "start", "&&", "NOW_TIME", "<=", "$", "end", ";", "case", "'ip_allow'", ":", "// IP 操作许可验证", "return", "in_array", "(", "get_client_ip", "(", ")", ",", "explode", "(", "','", ",", "$", "rule", ")", ")", ";", "case", "'ip_deny'", ":", "// IP 操作禁止验证", "return", "!", "in_array", "(", "get_client_ip", "(", ")", ",", "explode", "(", "','", ",", "$", "rule", ")", ")", ";", "case", "'regex'", ":", "default", ":", "// 默认使用正则验证 可以使用验证类中定义的验证名称", "// 检查附加规则", "return", "$", "this", "->", "regex", "(", "$", "value", ",", "$", "rule", ")", ";", "}", "}" ]
验证数据 支持 in between equal length regex expire ip_allow ip_deny @access public @param string $value 验证数据 @param mixed $rule 验证表达式 @param string $type 验证方式 默认为正则验证 @return boolean
[ "验证数据", "支持", "in", "between", "equal", "length", "regex", "expire", "ip_allow", "ip_deny" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Model.php#L1315-L1356
KDF5000/EasyThink
src/ThinkPHP/Library/Think/Model.php
Model.query
public function query($sql,$parse=false) { if(!is_bool($parse) && !is_array($parse)) { $parse = func_get_args(); array_shift($parse); } $sql = $this->parseSql($sql,$parse); return $this->db->query($sql); }
php
public function query($sql,$parse=false) { if(!is_bool($parse) && !is_array($parse)) { $parse = func_get_args(); array_shift($parse); } $sql = $this->parseSql($sql,$parse); return $this->db->query($sql); }
[ "public", "function", "query", "(", "$", "sql", ",", "$", "parse", "=", "false", ")", "{", "if", "(", "!", "is_bool", "(", "$", "parse", ")", "&&", "!", "is_array", "(", "$", "parse", ")", ")", "{", "$", "parse", "=", "func_get_args", "(", ")", ";", "array_shift", "(", "$", "parse", ")", ";", "}", "$", "sql", "=", "$", "this", "->", "parseSql", "(", "$", "sql", ",", "$", "parse", ")", ";", "return", "$", "this", "->", "db", "->", "query", "(", "$", "sql", ")", ";", "}" ]
SQL查询 @access public @param string $sql SQL指令 @param mixed $parse 是否需要解析SQL @return mixed
[ "SQL查询" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Model.php#L1376-L1383
KDF5000/EasyThink
src/ThinkPHP/Library/Think/Model.php
Model.parseSql
protected function parseSql($sql,$parse) { // 分析表达式 if(true === $parse) { $options = $this->_parseOptions(); $sql = $this->db->parseSql($sql,$options); }elseif(is_array($parse)){ // SQL预处理 $parse = array_map(array($this->db,'escapeString'),$parse); $sql = vsprintf($sql,$parse); }else{ $sql = strtr($sql,array('__TABLE__'=>$this->getTableName(),'__PREFIX__'=>$this->tablePrefix)); $prefix = $this->tablePrefix; $sql = preg_replace_callback("/__([A-Z0-9_-]+)__/sU", function($match) use($prefix){ return $prefix.strtolower($match[1]);}, $sql); } $this->db->setModel($this->name); return $sql; }
php
protected function parseSql($sql,$parse) { // 分析表达式 if(true === $parse) { $options = $this->_parseOptions(); $sql = $this->db->parseSql($sql,$options); }elseif(is_array($parse)){ // SQL预处理 $parse = array_map(array($this->db,'escapeString'),$parse); $sql = vsprintf($sql,$parse); }else{ $sql = strtr($sql,array('__TABLE__'=>$this->getTableName(),'__PREFIX__'=>$this->tablePrefix)); $prefix = $this->tablePrefix; $sql = preg_replace_callback("/__([A-Z0-9_-]+)__/sU", function($match) use($prefix){ return $prefix.strtolower($match[1]);}, $sql); } $this->db->setModel($this->name); return $sql; }
[ "protected", "function", "parseSql", "(", "$", "sql", ",", "$", "parse", ")", "{", "// 分析表达式", "if", "(", "true", "===", "$", "parse", ")", "{", "$", "options", "=", "$", "this", "->", "_parseOptions", "(", ")", ";", "$", "sql", "=", "$", "this", "->", "db", "->", "parseSql", "(", "$", "sql", ",", "$", "options", ")", ";", "}", "elseif", "(", "is_array", "(", "$", "parse", ")", ")", "{", "// SQL预处理", "$", "parse", "=", "array_map", "(", "array", "(", "$", "this", "->", "db", ",", "'escapeString'", ")", ",", "$", "parse", ")", ";", "$", "sql", "=", "vsprintf", "(", "$", "sql", ",", "$", "parse", ")", ";", "}", "else", "{", "$", "sql", "=", "strtr", "(", "$", "sql", ",", "array", "(", "'__TABLE__'", "=>", "$", "this", "->", "getTableName", "(", ")", ",", "'__PREFIX__'", "=>", "$", "this", "->", "tablePrefix", ")", ")", ";", "$", "prefix", "=", "$", "this", "->", "tablePrefix", ";", "$", "sql", "=", "preg_replace_callback", "(", "\"/__([A-Z0-9_-]+)__/sU\"", ",", "function", "(", "$", "match", ")", "use", "(", "$", "prefix", ")", "{", "return", "$", "prefix", ".", "strtolower", "(", "$", "match", "[", "1", "]", ")", ";", "}", ",", "$", "sql", ")", ";", "}", "$", "this", "->", "db", "->", "setModel", "(", "$", "this", "->", "name", ")", ";", "return", "$", "sql", ";", "}" ]
解析SQL语句 @access public @param string $sql SQL指令 @param boolean $parse 是否需要解析SQL @return string
[ "解析SQL语句" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Model.php#L1408-L1423
KDF5000/EasyThink
src/ThinkPHP/Library/Think/Model.php
Model.db
public function db($linkNum='',$config='',$force=false) { if('' === $linkNum && $this->db) { return $this->db; } if(!isset($this->_db[$linkNum]) || $force ) { // 创建一个新的实例 if(!empty($config) && is_string($config) && false === strpos($config,'/')) { // 支持读取配置参数 $config = C($config); } $this->_db[$linkNum] = Db::getInstance($config); }elseif(NULL === $config){ $this->_db[$linkNum]->close(); // 关闭数据库连接 unset($this->_db[$linkNum]); return ; } // 切换数据库连接 $this->db = $this->_db[$linkNum]; $this->_after_db(); // 字段检测 if(!empty($this->name) && $this->autoCheckFields) $this->_checkTableInfo(); return $this; }
php
public function db($linkNum='',$config='',$force=false) { if('' === $linkNum && $this->db) { return $this->db; } if(!isset($this->_db[$linkNum]) || $force ) { // 创建一个新的实例 if(!empty($config) && is_string($config) && false === strpos($config,'/')) { // 支持读取配置参数 $config = C($config); } $this->_db[$linkNum] = Db::getInstance($config); }elseif(NULL === $config){ $this->_db[$linkNum]->close(); // 关闭数据库连接 unset($this->_db[$linkNum]); return ; } // 切换数据库连接 $this->db = $this->_db[$linkNum]; $this->_after_db(); // 字段检测 if(!empty($this->name) && $this->autoCheckFields) $this->_checkTableInfo(); return $this; }
[ "public", "function", "db", "(", "$", "linkNum", "=", "''", ",", "$", "config", "=", "''", ",", "$", "force", "=", "false", ")", "{", "if", "(", "''", "===", "$", "linkNum", "&&", "$", "this", "->", "db", ")", "{", "return", "$", "this", "->", "db", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "_db", "[", "$", "linkNum", "]", ")", "||", "$", "force", ")", "{", "// 创建一个新的实例", "if", "(", "!", "empty", "(", "$", "config", ")", "&&", "is_string", "(", "$", "config", ")", "&&", "false", "===", "strpos", "(", "$", "config", ",", "'/'", ")", ")", "{", "// 支持读取配置参数", "$", "config", "=", "C", "(", "$", "config", ")", ";", "}", "$", "this", "->", "_db", "[", "$", "linkNum", "]", "=", "Db", "::", "getInstance", "(", "$", "config", ")", ";", "}", "elseif", "(", "NULL", "===", "$", "config", ")", "{", "$", "this", "->", "_db", "[", "$", "linkNum", "]", "->", "close", "(", ")", ";", "// 关闭数据库连接", "unset", "(", "$", "this", "->", "_db", "[", "$", "linkNum", "]", ")", ";", "return", ";", "}", "// 切换数据库连接", "$", "this", "->", "db", "=", "$", "this", "->", "_db", "[", "$", "linkNum", "]", ";", "$", "this", "->", "_after_db", "(", ")", ";", "// 字段检测", "if", "(", "!", "empty", "(", "$", "this", "->", "name", ")", "&&", "$", "this", "->", "autoCheckFields", ")", "$", "this", "->", "_checkTableInfo", "(", ")", ";", "return", "$", "this", ";", "}" ]
切换当前的数据库连接 @access public @param integer $linkNum 连接序号 @param mixed $config 数据库连接信息 @param boolean $force 强制重新连接 @return Model
[ "切换当前的数据库连接" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Model.php#L1433-L1456
KDF5000/EasyThink
src/ThinkPHP/Library/Think/Model.php
Model.getModelName
public function getModelName() { if(empty($this->name)){ $name = substr(get_class($this),0,-strlen(C('DEFAULT_M_LAYER'))); if ( $pos = strrpos($name,'\\') ) {//有命名空间 $this->name = substr($name,$pos+1); }else{ $this->name = $name; } } return $this->name; }
php
public function getModelName() { if(empty($this->name)){ $name = substr(get_class($this),0,-strlen(C('DEFAULT_M_LAYER'))); if ( $pos = strrpos($name,'\\') ) {//有命名空间 $this->name = substr($name,$pos+1); }else{ $this->name = $name; } } return $this->name; }
[ "public", "function", "getModelName", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "name", ")", ")", "{", "$", "name", "=", "substr", "(", "get_class", "(", "$", "this", ")", ",", "0", ",", "-", "strlen", "(", "C", "(", "'DEFAULT_M_LAYER'", ")", ")", ")", ";", "if", "(", "$", "pos", "=", "strrpos", "(", "$", "name", ",", "'\\\\'", ")", ")", "{", "//有命名空间", "$", "this", "->", "name", "=", "substr", "(", "$", "name", ",", "$", "pos", "+", "1", ")", ";", "}", "else", "{", "$", "this", "->", "name", "=", "$", "name", ";", "}", "}", "return", "$", "this", "->", "name", ";", "}" ]
得到当前的数据对象名称 @access public @return string
[ "得到当前的数据对象名称" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Model.php#L1465-L1475
KDF5000/EasyThink
src/ThinkPHP/Library/Think/Model.php
Model.getTableName
public function getTableName() { if(empty($this->trueTableName)) { $tableName = !empty($this->tablePrefix) ? $this->tablePrefix : ''; if(!empty($this->tableName)) { $tableName .= $this->tableName; }else{ $tableName .= parse_name($this->name); } $this->trueTableName = strtolower($tableName); } return (!empty($this->dbName)?$this->dbName.'.':'').$this->trueTableName; }
php
public function getTableName() { if(empty($this->trueTableName)) { $tableName = !empty($this->tablePrefix) ? $this->tablePrefix : ''; if(!empty($this->tableName)) { $tableName .= $this->tableName; }else{ $tableName .= parse_name($this->name); } $this->trueTableName = strtolower($tableName); } return (!empty($this->dbName)?$this->dbName.'.':'').$this->trueTableName; }
[ "public", "function", "getTableName", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "trueTableName", ")", ")", "{", "$", "tableName", "=", "!", "empty", "(", "$", "this", "->", "tablePrefix", ")", "?", "$", "this", "->", "tablePrefix", ":", "''", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "tableName", ")", ")", "{", "$", "tableName", ".=", "$", "this", "->", "tableName", ";", "}", "else", "{", "$", "tableName", ".=", "parse_name", "(", "$", "this", "->", "name", ")", ";", "}", "$", "this", "->", "trueTableName", "=", "strtolower", "(", "$", "tableName", ")", ";", "}", "return", "(", "!", "empty", "(", "$", "this", "->", "dbName", ")", "?", "$", "this", "->", "dbName", ".", "'.'", ":", "''", ")", ".", "$", "this", "->", "trueTableName", ";", "}" ]
得到完整的数据表名 @access public @return string
[ "得到完整的数据表名" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Model.php#L1482-L1493
KDF5000/EasyThink
src/ThinkPHP/Library/Think/Model.php
Model.getDbFields
public function getDbFields(){ if(isset($this->options['table'])) {// 动态指定表名 if(is_array($this->options['table'])){ $table = key($this->options['table']); }else{ $table = $this->options['table']; if(strpos($table,')')){ // 子查询 return false; } } $fields = $this->db->getFields($table); return $fields ? array_keys($fields) : false; } if($this->fields) { $fields = $this->fields; unset($fields['_type'],$fields['_pk']); return $fields; } return false; }
php
public function getDbFields(){ if(isset($this->options['table'])) {// 动态指定表名 if(is_array($this->options['table'])){ $table = key($this->options['table']); }else{ $table = $this->options['table']; if(strpos($table,')')){ // 子查询 return false; } } $fields = $this->db->getFields($table); return $fields ? array_keys($fields) : false; } if($this->fields) { $fields = $this->fields; unset($fields['_type'],$fields['_pk']); return $fields; } return false; }
[ "public", "function", "getDbFields", "(", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "options", "[", "'table'", "]", ")", ")", "{", "// 动态指定表名", "if", "(", "is_array", "(", "$", "this", "->", "options", "[", "'table'", "]", ")", ")", "{", "$", "table", "=", "key", "(", "$", "this", "->", "options", "[", "'table'", "]", ")", ";", "}", "else", "{", "$", "table", "=", "$", "this", "->", "options", "[", "'table'", "]", ";", "if", "(", "strpos", "(", "$", "table", ",", "')'", ")", ")", "{", "// 子查询", "return", "false", ";", "}", "}", "$", "fields", "=", "$", "this", "->", "db", "->", "getFields", "(", "$", "table", ")", ";", "return", "$", "fields", "?", "array_keys", "(", "$", "fields", ")", ":", "false", ";", "}", "if", "(", "$", "this", "->", "fields", ")", "{", "$", "fields", "=", "$", "this", "->", "fields", ";", "unset", "(", "$", "fields", "[", "'_type'", "]", ",", "$", "fields", "[", "'_pk'", "]", ")", ";", "return", "$", "fields", ";", "}", "return", "false", ";", "}" ]
获取数据表字段信息 @access public @return array
[ "获取数据表字段信息" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Model.php#L1578-L1598
KDF5000/EasyThink
src/ThinkPHP/Library/Think/Model.php
Model.data
public function data($data=''){ if('' === $data && !empty($this->data)) { return $this->data; } if(is_object($data)){ $data = get_object_vars($data); }elseif(is_string($data)){ parse_str($data,$data); }elseif(!is_array($data)){ E(L('_DATA_TYPE_INVALID_')); } $this->data = $data; return $this; }
php
public function data($data=''){ if('' === $data && !empty($this->data)) { return $this->data; } if(is_object($data)){ $data = get_object_vars($data); }elseif(is_string($data)){ parse_str($data,$data); }elseif(!is_array($data)){ E(L('_DATA_TYPE_INVALID_')); } $this->data = $data; return $this; }
[ "public", "function", "data", "(", "$", "data", "=", "''", ")", "{", "if", "(", "''", "===", "$", "data", "&&", "!", "empty", "(", "$", "this", "->", "data", ")", ")", "{", "return", "$", "this", "->", "data", ";", "}", "if", "(", "is_object", "(", "$", "data", ")", ")", "{", "$", "data", "=", "get_object_vars", "(", "$", "data", ")", ";", "}", "elseif", "(", "is_string", "(", "$", "data", ")", ")", "{", "parse_str", "(", "$", "data", ",", "$", "data", ")", ";", "}", "elseif", "(", "!", "is_array", "(", "$", "data", ")", ")", "{", "E", "(", "L", "(", "'_DATA_TYPE_INVALID_'", ")", ")", ";", "}", "$", "this", "->", "data", "=", "$", "data", ";", "return", "$", "this", ";", "}" ]
设置数据对象值 @access public @param mixed $data 数据 @return Model
[ "设置数据对象值" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Model.php#L1606-L1619
KDF5000/EasyThink
src/ThinkPHP/Library/Think/Model.php
Model.table
public function table($table) { $prefix = $this->tablePrefix; if(is_array($table)) { $this->options['table'] = $table; }elseif(!empty($table)) { //将__TABLE_NAME__替换成带前缀的表名 $table = preg_replace_callback("/__([A-Z0-9_-]+)__/sU", function($match) use($prefix){ return $prefix.strtolower($match[1]);}, $table); $this->options['table'] = $table; } return $this; }
php
public function table($table) { $prefix = $this->tablePrefix; if(is_array($table)) { $this->options['table'] = $table; }elseif(!empty($table)) { //将__TABLE_NAME__替换成带前缀的表名 $table = preg_replace_callback("/__([A-Z0-9_-]+)__/sU", function($match) use($prefix){ return $prefix.strtolower($match[1]);}, $table); $this->options['table'] = $table; } return $this; }
[ "public", "function", "table", "(", "$", "table", ")", "{", "$", "prefix", "=", "$", "this", "->", "tablePrefix", ";", "if", "(", "is_array", "(", "$", "table", ")", ")", "{", "$", "this", "->", "options", "[", "'table'", "]", "=", "$", "table", ";", "}", "elseif", "(", "!", "empty", "(", "$", "table", ")", ")", "{", "//将__TABLE_NAME__替换成带前缀的表名", "$", "table", "=", "preg_replace_callback", "(", "\"/__([A-Z0-9_-]+)__/sU\"", ",", "function", "(", "$", "match", ")", "use", "(", "$", "prefix", ")", "{", "return", "$", "prefix", ".", "strtolower", "(", "$", "match", "[", "1", "]", ")", ";", "}", ",", "$", "table", ")", ";", "$", "this", "->", "options", "[", "'table'", "]", "=", "$", "table", ";", "}", "return", "$", "this", ";", "}" ]
指定当前的数据表 @access public @param mixed $table @return Model
[ "指定当前的数据表" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Model.php#L1627-L1637
KDF5000/EasyThink
src/ThinkPHP/Library/Think/Model.php
Model.using
public function using($using){ $prefix = $this->tablePrefix; if(is_array($using)) { $this->options['using'] = $using; }elseif(!empty($using)) { //将__TABLE_NAME__替换成带前缀的表名 $using = preg_replace_callback("/__([A-Z0-9_-]+)__/sU", function($match) use($prefix){ return $prefix.strtolower($match[1]);}, $using); $this->options['using'] = $using; } return $this; }
php
public function using($using){ $prefix = $this->tablePrefix; if(is_array($using)) { $this->options['using'] = $using; }elseif(!empty($using)) { //将__TABLE_NAME__替换成带前缀的表名 $using = preg_replace_callback("/__([A-Z0-9_-]+)__/sU", function($match) use($prefix){ return $prefix.strtolower($match[1]);}, $using); $this->options['using'] = $using; } return $this; }
[ "public", "function", "using", "(", "$", "using", ")", "{", "$", "prefix", "=", "$", "this", "->", "tablePrefix", ";", "if", "(", "is_array", "(", "$", "using", ")", ")", "{", "$", "this", "->", "options", "[", "'using'", "]", "=", "$", "using", ";", "}", "elseif", "(", "!", "empty", "(", "$", "using", ")", ")", "{", "//将__TABLE_NAME__替换成带前缀的表名", "$", "using", "=", "preg_replace_callback", "(", "\"/__([A-Z0-9_-]+)__/sU\"", ",", "function", "(", "$", "match", ")", "use", "(", "$", "prefix", ")", "{", "return", "$", "prefix", ".", "strtolower", "(", "$", "match", "[", "1", "]", ")", ";", "}", ",", "$", "using", ")", ";", "$", "this", "->", "options", "[", "'using'", "]", "=", "$", "using", ";", "}", "return", "$", "this", ";", "}" ]
USING支持 用于多表删除 @access public @param mixed $using @return Model
[ "USING支持", "用于多表删除" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Model.php#L1645-L1655
KDF5000/EasyThink
src/ThinkPHP/Library/Think/Model.php
Model.join
public function join($join,$type='INNER') { $prefix = $this->tablePrefix; if(is_array($join)) { foreach ($join as $key=>&$_join){ $_join = preg_replace_callback("/__([A-Z0-9_-]+)__/sU", function($match) use($prefix){ return $prefix.strtolower($match[1]);}, $_join); $_join = false !== stripos($_join,'JOIN')? $_join : $type.' JOIN ' .$_join; } $this->options['join'] = $join; }elseif(!empty($join)) { //将__TABLE_NAME__字符串替换成带前缀的表名 $join = preg_replace_callback("/__([A-Z0-9_-]+)__/sU", function($match) use($prefix){ return $prefix.strtolower($match[1]);}, $join); $this->options['join'][] = false !== stripos($join,'JOIN')? $join : $type.' JOIN '.$join; } return $this; }
php
public function join($join,$type='INNER') { $prefix = $this->tablePrefix; if(is_array($join)) { foreach ($join as $key=>&$_join){ $_join = preg_replace_callback("/__([A-Z0-9_-]+)__/sU", function($match) use($prefix){ return $prefix.strtolower($match[1]);}, $_join); $_join = false !== stripos($_join,'JOIN')? $_join : $type.' JOIN ' .$_join; } $this->options['join'] = $join; }elseif(!empty($join)) { //将__TABLE_NAME__字符串替换成带前缀的表名 $join = preg_replace_callback("/__([A-Z0-9_-]+)__/sU", function($match) use($prefix){ return $prefix.strtolower($match[1]);}, $join); $this->options['join'][] = false !== stripos($join,'JOIN')? $join : $type.' JOIN '.$join; } return $this; }
[ "public", "function", "join", "(", "$", "join", ",", "$", "type", "=", "'INNER'", ")", "{", "$", "prefix", "=", "$", "this", "->", "tablePrefix", ";", "if", "(", "is_array", "(", "$", "join", ")", ")", "{", "foreach", "(", "$", "join", "as", "$", "key", "=>", "&", "$", "_join", ")", "{", "$", "_join", "=", "preg_replace_callback", "(", "\"/__([A-Z0-9_-]+)__/sU\"", ",", "function", "(", "$", "match", ")", "use", "(", "$", "prefix", ")", "{", "return", "$", "prefix", ".", "strtolower", "(", "$", "match", "[", "1", "]", ")", ";", "}", ",", "$", "_join", ")", ";", "$", "_join", "=", "false", "!==", "stripos", "(", "$", "_join", ",", "'JOIN'", ")", "?", "$", "_join", ":", "$", "type", ".", "' JOIN '", ".", "$", "_join", ";", "}", "$", "this", "->", "options", "[", "'join'", "]", "=", "$", "join", ";", "}", "elseif", "(", "!", "empty", "(", "$", "join", ")", ")", "{", "//将__TABLE_NAME__字符串替换成带前缀的表名", "$", "join", "=", "preg_replace_callback", "(", "\"/__([A-Z0-9_-]+)__/sU\"", ",", "function", "(", "$", "match", ")", "use", "(", "$", "prefix", ")", "{", "return", "$", "prefix", ".", "strtolower", "(", "$", "match", "[", "1", "]", ")", ";", "}", ",", "$", "join", ")", ";", "$", "this", "->", "options", "[", "'join'", "]", "[", "]", "=", "false", "!==", "stripos", "(", "$", "join", ",", "'JOIN'", ")", "?", "$", "join", ":", "$", "type", ".", "' JOIN '", ".", "$", "join", ";", "}", "return", "$", "this", ";", "}" ]
查询SQL组装 join @access public @param mixed $join @param string $type JOIN类型 @return Model
[ "查询SQL组装", "join" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Model.php#L1664-L1678
KDF5000/EasyThink
src/ThinkPHP/Library/Think/Model.php
Model.union
public function union($union,$all=false) { if(empty($union)) return $this; if($all) { $this->options['union']['_all'] = true; } if(is_object($union)) { $union = get_object_vars($union); } // 转换union表达式 if(is_string($union) ) { $prefix = $this->tablePrefix; //将__TABLE_NAME__字符串替换成带前缀的表名 $options = preg_replace_callback("/__([A-Z0-9_-]+)__/sU", function($match) use($prefix){ return $prefix.strtolower($match[1]);}, $union); }elseif(is_array($union)){ if(isset($union[0])) { $this->options['union'] = array_merge($this->options['union'],$union); return $this; }else{ $options = $union; } }else{ E(L('_DATA_TYPE_INVALID_')); } $this->options['union'][] = $options; return $this; }
php
public function union($union,$all=false) { if(empty($union)) return $this; if($all) { $this->options['union']['_all'] = true; } if(is_object($union)) { $union = get_object_vars($union); } // 转换union表达式 if(is_string($union) ) { $prefix = $this->tablePrefix; //将__TABLE_NAME__字符串替换成带前缀的表名 $options = preg_replace_callback("/__([A-Z0-9_-]+)__/sU", function($match) use($prefix){ return $prefix.strtolower($match[1]);}, $union); }elseif(is_array($union)){ if(isset($union[0])) { $this->options['union'] = array_merge($this->options['union'],$union); return $this; }else{ $options = $union; } }else{ E(L('_DATA_TYPE_INVALID_')); } $this->options['union'][] = $options; return $this; }
[ "public", "function", "union", "(", "$", "union", ",", "$", "all", "=", "false", ")", "{", "if", "(", "empty", "(", "$", "union", ")", ")", "return", "$", "this", ";", "if", "(", "$", "all", ")", "{", "$", "this", "->", "options", "[", "'union'", "]", "[", "'_all'", "]", "=", "true", ";", "}", "if", "(", "is_object", "(", "$", "union", ")", ")", "{", "$", "union", "=", "get_object_vars", "(", "$", "union", ")", ";", "}", "// 转换union表达式", "if", "(", "is_string", "(", "$", "union", ")", ")", "{", "$", "prefix", "=", "$", "this", "->", "tablePrefix", ";", "//将__TABLE_NAME__字符串替换成带前缀的表名", "$", "options", "=", "preg_replace_callback", "(", "\"/__([A-Z0-9_-]+)__/sU\"", ",", "function", "(", "$", "match", ")", "use", "(", "$", "prefix", ")", "{", "return", "$", "prefix", ".", "strtolower", "(", "$", "match", "[", "1", "]", ")", ";", "}", ",", "$", "union", ")", ";", "}", "elseif", "(", "is_array", "(", "$", "union", ")", ")", "{", "if", "(", "isset", "(", "$", "union", "[", "0", "]", ")", ")", "{", "$", "this", "->", "options", "[", "'union'", "]", "=", "array_merge", "(", "$", "this", "->", "options", "[", "'union'", "]", ",", "$", "union", ")", ";", "return", "$", "this", ";", "}", "else", "{", "$", "options", "=", "$", "union", ";", "}", "}", "else", "{", "E", "(", "L", "(", "'_DATA_TYPE_INVALID_'", ")", ")", ";", "}", "$", "this", "->", "options", "[", "'union'", "]", "[", "]", "=", "$", "options", ";", "return", "$", "this", ";", "}" ]
查询SQL组装 union @access public @param mixed $union @param boolean $all @return Model
[ "查询SQL组装", "union" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Model.php#L1687-L1712
KDF5000/EasyThink
src/ThinkPHP/Library/Think/Model.php
Model.cache
public function cache($key=true,$expire=null,$type=''){ // 增加快捷调用方式 cache(10) 等同于 cache(true, 10) if(is_numeric($key) && is_null($expire)){ $expire = $key; $key = true; } if(false !== $key) $this->options['cache'] = array('key'=>$key,'expire'=>$expire,'type'=>$type); return $this; }
php
public function cache($key=true,$expire=null,$type=''){ // 增加快捷调用方式 cache(10) 等同于 cache(true, 10) if(is_numeric($key) && is_null($expire)){ $expire = $key; $key = true; } if(false !== $key) $this->options['cache'] = array('key'=>$key,'expire'=>$expire,'type'=>$type); return $this; }
[ "public", "function", "cache", "(", "$", "key", "=", "true", ",", "$", "expire", "=", "null", ",", "$", "type", "=", "''", ")", "{", "// 增加快捷调用方式 cache(10) 等同于 cache(true, 10)", "if", "(", "is_numeric", "(", "$", "key", ")", "&&", "is_null", "(", "$", "expire", ")", ")", "{", "$", "expire", "=", "$", "key", ";", "$", "key", "=", "true", ";", "}", "if", "(", "false", "!==", "$", "key", ")", "$", "this", "->", "options", "[", "'cache'", "]", "=", "array", "(", "'key'", "=>", "$", "key", ",", "'expire'", "=>", "$", "expire", ",", "'type'", "=>", "$", "type", ")", ";", "return", "$", "this", ";", "}" ]
查询缓存 @access public @param mixed $key @param integer $expire @param string $type @return Model
[ "查询缓存" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Model.php#L1722-L1731
KDF5000/EasyThink
src/ThinkPHP/Library/Think/Model.php
Model.field
public function field($field,$except=false){ if(true === $field) {// 获取全部字段 $fields = $this->getDbFields(); $field = $fields?:'*'; }elseif($except) {// 字段排除 if(is_string($field)) { $field = explode(',',$field); } $fields = $this->getDbFields(); $field = $fields?array_diff($fields,$field):$field; } $this->options['field'] = $field; return $this; }
php
public function field($field,$except=false){ if(true === $field) {// 获取全部字段 $fields = $this->getDbFields(); $field = $fields?:'*'; }elseif($except) {// 字段排除 if(is_string($field)) { $field = explode(',',$field); } $fields = $this->getDbFields(); $field = $fields?array_diff($fields,$field):$field; } $this->options['field'] = $field; return $this; }
[ "public", "function", "field", "(", "$", "field", ",", "$", "except", "=", "false", ")", "{", "if", "(", "true", "===", "$", "field", ")", "{", "// 获取全部字段", "$", "fields", "=", "$", "this", "->", "getDbFields", "(", ")", ";", "$", "field", "=", "$", "fields", "?", ":", "'*'", ";", "}", "elseif", "(", "$", "except", ")", "{", "// 字段排除", "if", "(", "is_string", "(", "$", "field", ")", ")", "{", "$", "field", "=", "explode", "(", "','", ",", "$", "field", ")", ";", "}", "$", "fields", "=", "$", "this", "->", "getDbFields", "(", ")", ";", "$", "field", "=", "$", "fields", "?", "array_diff", "(", "$", "fields", ",", "$", "field", ")", ":", "$", "field", ";", "}", "$", "this", "->", "options", "[", "'field'", "]", "=", "$", "field", ";", "return", "$", "this", ";", "}" ]
指定查询字段 支持字段排除 @access public @param mixed $field @param boolean $except 是否排除 @return Model
[ "指定查询字段", "支持字段排除" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Model.php#L1740-L1753
KDF5000/EasyThink
src/ThinkPHP/Library/Think/Model.php
Model.where
public function where($where,$parse=null){ if(!is_null($parse) && is_string($where)) { if(!is_array($parse)) { $parse = func_get_args(); array_shift($parse); } $parse = array_map(array($this->db,'escapeString'),$parse); $where = vsprintf($where,$parse); }elseif(is_object($where)){ $where = get_object_vars($where); } if(is_string($where) && '' != $where){ $map = array(); $map['_string'] = $where; $where = $map; } if(isset($this->options['where'])){ $this->options['where'] = array_merge($this->options['where'],$where); }else{ $this->options['where'] = $where; } return $this; }
php
public function where($where,$parse=null){ if(!is_null($parse) && is_string($where)) { if(!is_array($parse)) { $parse = func_get_args(); array_shift($parse); } $parse = array_map(array($this->db,'escapeString'),$parse); $where = vsprintf($where,$parse); }elseif(is_object($where)){ $where = get_object_vars($where); } if(is_string($where) && '' != $where){ $map = array(); $map['_string'] = $where; $where = $map; } if(isset($this->options['where'])){ $this->options['where'] = array_merge($this->options['where'],$where); }else{ $this->options['where'] = $where; } return $this; }
[ "public", "function", "where", "(", "$", "where", ",", "$", "parse", "=", "null", ")", "{", "if", "(", "!", "is_null", "(", "$", "parse", ")", "&&", "is_string", "(", "$", "where", ")", ")", "{", "if", "(", "!", "is_array", "(", "$", "parse", ")", ")", "{", "$", "parse", "=", "func_get_args", "(", ")", ";", "array_shift", "(", "$", "parse", ")", ";", "}", "$", "parse", "=", "array_map", "(", "array", "(", "$", "this", "->", "db", ",", "'escapeString'", ")", ",", "$", "parse", ")", ";", "$", "where", "=", "vsprintf", "(", "$", "where", ",", "$", "parse", ")", ";", "}", "elseif", "(", "is_object", "(", "$", "where", ")", ")", "{", "$", "where", "=", "get_object_vars", "(", "$", "where", ")", ";", "}", "if", "(", "is_string", "(", "$", "where", ")", "&&", "''", "!=", "$", "where", ")", "{", "$", "map", "=", "array", "(", ")", ";", "$", "map", "[", "'_string'", "]", "=", "$", "where", ";", "$", "where", "=", "$", "map", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "options", "[", "'where'", "]", ")", ")", "{", "$", "this", "->", "options", "[", "'where'", "]", "=", "array_merge", "(", "$", "this", "->", "options", "[", "'where'", "]", ",", "$", "where", ")", ";", "}", "else", "{", "$", "this", "->", "options", "[", "'where'", "]", "=", "$", "where", ";", "}", "return", "$", "this", ";", "}" ]
指定查询条件 支持安全过滤 @access public @param mixed $where 条件表达式 @param mixed $parse 预处理参数 @return Model
[ "指定查询条件", "支持安全过滤" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Model.php#L1797-L1820
KDF5000/EasyThink
src/ThinkPHP/Library/Think/Model.php
Model.page
public function page($page,$listRows=null){ if(is_null($listRows) && strpos($page,',')){ list($page,$listRows) = explode(',',$page); } $this->options['page'] = array(intval($page),intval($listRows)); return $this; }
php
public function page($page,$listRows=null){ if(is_null($listRows) && strpos($page,',')){ list($page,$listRows) = explode(',',$page); } $this->options['page'] = array(intval($page),intval($listRows)); return $this; }
[ "public", "function", "page", "(", "$", "page", ",", "$", "listRows", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "listRows", ")", "&&", "strpos", "(", "$", "page", ",", "','", ")", ")", "{", "list", "(", "$", "page", ",", "$", "listRows", ")", "=", "explode", "(", "','", ",", "$", "page", ")", ";", "}", "$", "this", "->", "options", "[", "'page'", "]", "=", "array", "(", "intval", "(", "$", "page", ")", ",", "intval", "(", "$", "listRows", ")", ")", ";", "return", "$", "this", ";", "}" ]
指定分页 @access public @param mixed $page 页数 @param mixed $listRows 每页数量 @return Model
[ "指定分页" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Model.php#L1844-L1850
KDF5000/EasyThink
src/ThinkPHP/Library/Think/Model.php
Model.bind
public function bind($key,$value=false) { if(is_array($key)){ $this->options['bind'] = $key; }else{ $num = func_num_args(); if($num>2){ $params = func_get_args(); array_shift($params); $this->options['bind'][$key] = $params; }else{ $this->options['bind'][$key] = $value; } } return $this; }
php
public function bind($key,$value=false) { if(is_array($key)){ $this->options['bind'] = $key; }else{ $num = func_num_args(); if($num>2){ $params = func_get_args(); array_shift($params); $this->options['bind'][$key] = $params; }else{ $this->options['bind'][$key] = $value; } } return $this; }
[ "public", "function", "bind", "(", "$", "key", ",", "$", "value", "=", "false", ")", "{", "if", "(", "is_array", "(", "$", "key", ")", ")", "{", "$", "this", "->", "options", "[", "'bind'", "]", "=", "$", "key", ";", "}", "else", "{", "$", "num", "=", "func_num_args", "(", ")", ";", "if", "(", "$", "num", ">", "2", ")", "{", "$", "params", "=", "func_get_args", "(", ")", ";", "array_shift", "(", "$", "params", ")", ";", "$", "this", "->", "options", "[", "'bind'", "]", "[", "$", "key", "]", "=", "$", "params", ";", "}", "else", "{", "$", "this", "->", "options", "[", "'bind'", "]", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "return", "$", "this", ";", "}" ]
参数绑定 @access public @param string $key 参数名 @param mixed $value 绑定的变量及绑定参数 @return Model
[ "参数绑定" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Model.php#L1881-L1895
KDF5000/EasyThink
src/ThinkPHP/Library/Think/Model.php
Model.setProperty
public function setProperty($name,$value) { if(property_exists($this,$name)) $this->$name = $value; return $this; }
php
public function setProperty($name,$value) { if(property_exists($this,$name)) $this->$name = $value; return $this; }
[ "public", "function", "setProperty", "(", "$", "name", ",", "$", "value", ")", "{", "if", "(", "property_exists", "(", "$", "this", ",", "$", "name", ")", ")", "$", "this", "->", "$", "name", "=", "$", "value", ";", "return", "$", "this", ";", "}" ]
设置模型的属性值 @access public @param string $name 名称 @param mixed $value 值 @return Model
[ "设置模型的属性值" ]
train
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Model.php#L1904-L1908
gplcart/backup
Main.php
Main.hookModuleInstallBefore
public function hookModuleInstallBefore(&$result) { if (!class_exists('ZipArchive')) { $result = $this->getTranslationModel()->text('Class ZipArchive does not exist'); } else { try { $this->db->importScheme('backup', $this->getDbScheme()); } catch (Exception $ex) { $result = $ex->getMessage(); } } }
php
public function hookModuleInstallBefore(&$result) { if (!class_exists('ZipArchive')) { $result = $this->getTranslationModel()->text('Class ZipArchive does not exist'); } else { try { $this->db->importScheme('backup', $this->getDbScheme()); } catch (Exception $ex) { $result = $ex->getMessage(); } } }
[ "public", "function", "hookModuleInstallBefore", "(", "&", "$", "result", ")", "{", "if", "(", "!", "class_exists", "(", "'ZipArchive'", ")", ")", "{", "$", "result", "=", "$", "this", "->", "getTranslationModel", "(", ")", "->", "text", "(", "'Class ZipArchive does not exist'", ")", ";", "}", "else", "{", "try", "{", "$", "this", "->", "db", "->", "importScheme", "(", "'backup'", ",", "$", "this", "->", "getDbScheme", "(", ")", ")", ";", "}", "catch", "(", "Exception", "$", "ex", ")", "{", "$", "result", "=", "$", "ex", "->", "getMessage", "(", ")", ";", "}", "}", "}" ]
Implements hook "module.install.before" @param null|string $result
[ "Implements", "hook", "module", ".", "install", ".", "before" ]
train
https://github.com/gplcart/backup/blob/5838e2f47f0bb8c2e18b6697e20bec5682b71393/Main.php#L41-L53
gplcart/backup
Main.php
Main.getDbScheme
protected function getDbScheme() { return array( 'backup' => array( 'fields' => array( 'backup_id' => array('type' => 'int', 'length' => 10, 'auto_increment' => true, 'primary' => true), 'created' => array('type' => 'int', 'length' => 10, 'not_null' => true), 'name' => array('type' => 'varchar', 'length' => 255, 'not_null' => true), 'path' => array('type' => 'varchar', 'length' => 255, 'not_null' => true), 'user_id' => array('type' => 'int', 'length' => 10, 'not_null' => true, 'default' => 0), 'type' => array('type' => 'varchar', 'length' => 50, 'not_null' => true, 'default' => ''), 'version' => array('type' => 'varchar', 'length' => 50, 'not_null' => true, 'default' => ''), 'id' => array('type' => 'varchar', 'length' => 50, 'not_null' => true, 'default' => '') ) ) ); }
php
protected function getDbScheme() { return array( 'backup' => array( 'fields' => array( 'backup_id' => array('type' => 'int', 'length' => 10, 'auto_increment' => true, 'primary' => true), 'created' => array('type' => 'int', 'length' => 10, 'not_null' => true), 'name' => array('type' => 'varchar', 'length' => 255, 'not_null' => true), 'path' => array('type' => 'varchar', 'length' => 255, 'not_null' => true), 'user_id' => array('type' => 'int', 'length' => 10, 'not_null' => true, 'default' => 0), 'type' => array('type' => 'varchar', 'length' => 50, 'not_null' => true, 'default' => ''), 'version' => array('type' => 'varchar', 'length' => 50, 'not_null' => true, 'default' => ''), 'id' => array('type' => 'varchar', 'length' => 50, 'not_null' => true, 'default' => '') ) ) ); }
[ "protected", "function", "getDbScheme", "(", ")", "{", "return", "array", "(", "'backup'", "=>", "array", "(", "'fields'", "=>", "array", "(", "'backup_id'", "=>", "array", "(", "'type'", "=>", "'int'", ",", "'length'", "=>", "10", ",", "'auto_increment'", "=>", "true", ",", "'primary'", "=>", "true", ")", ",", "'created'", "=>", "array", "(", "'type'", "=>", "'int'", ",", "'length'", "=>", "10", ",", "'not_null'", "=>", "true", ")", ",", "'name'", "=>", "array", "(", "'type'", "=>", "'varchar'", ",", "'length'", "=>", "255", ",", "'not_null'", "=>", "true", ")", ",", "'path'", "=>", "array", "(", "'type'", "=>", "'varchar'", ",", "'length'", "=>", "255", ",", "'not_null'", "=>", "true", ")", ",", "'user_id'", "=>", "array", "(", "'type'", "=>", "'int'", ",", "'length'", "=>", "10", ",", "'not_null'", "=>", "true", ",", "'default'", "=>", "0", ")", ",", "'type'", "=>", "array", "(", "'type'", "=>", "'varchar'", ",", "'length'", "=>", "50", ",", "'not_null'", "=>", "true", ",", "'default'", "=>", "''", ")", ",", "'version'", "=>", "array", "(", "'type'", "=>", "'varchar'", ",", "'length'", "=>", "50", ",", "'not_null'", "=>", "true", ",", "'default'", "=>", "''", ")", ",", "'id'", "=>", "array", "(", "'type'", "=>", "'varchar'", ",", "'length'", "=>", "50", ",", "'not_null'", "=>", "true", ",", "'default'", "=>", "''", ")", ")", ")", ")", ";", "}" ]
Returns an array of database scheme @return array
[ "Returns", "an", "array", "of", "database", "scheme" ]
train
https://github.com/gplcart/backup/blob/5838e2f47f0bb8c2e18b6697e20bec5682b71393/Main.php#L159-L175
GetOlympus/olympus-html-field
src/Html/Html.php
Html.setVars
protected function setVars() { $this->getModel()->setFaIcon('fa-html5'); $this->getModel()->setHasId(false); $this->getModel()->setTemplate('html.html.twig'); }
php
protected function setVars() { $this->getModel()->setFaIcon('fa-html5'); $this->getModel()->setHasId(false); $this->getModel()->setTemplate('html.html.twig'); }
[ "protected", "function", "setVars", "(", ")", "{", "$", "this", "->", "getModel", "(", ")", "->", "setFaIcon", "(", "'fa-html5'", ")", ";", "$", "this", "->", "getModel", "(", ")", "->", "setHasId", "(", "false", ")", ";", "$", "this", "->", "getModel", "(", ")", "->", "setTemplate", "(", "'html.html.twig'", ")", ";", "}" ]
Prepare variables.
[ "Prepare", "variables", "." ]
train
https://github.com/GetOlympus/olympus-html-field/blob/cfc8d51a3e1e76385949e0c6dba348fcc1354fb9/src/Html/Html.php#L24-L29
GetOlympus/olympus-html-field
src/Html/Html.php
Html.getVars
protected function getVars($content, $details = []) { // Build defaults $defaults = [ 'data' => '', ]; // Build defaults data $vars = array_merge($defaults, $content); // Update vars $this->getModel()->setVars($vars); }
php
protected function getVars($content, $details = []) { // Build defaults $defaults = [ 'data' => '', ]; // Build defaults data $vars = array_merge($defaults, $content); // Update vars $this->getModel()->setVars($vars); }
[ "protected", "function", "getVars", "(", "$", "content", ",", "$", "details", "=", "[", "]", ")", "{", "// Build defaults", "$", "defaults", "=", "[", "'data'", "=>", "''", ",", "]", ";", "// Build defaults data", "$", "vars", "=", "array_merge", "(", "$", "defaults", ",", "$", "content", ")", ";", "// Update vars", "$", "this", "->", "getModel", "(", ")", "->", "setVars", "(", "$", "vars", ")", ";", "}" ]
Prepare HTML component. @param array $content @param array $details @since 0.0.1
[ "Prepare", "HTML", "component", "." ]
train
https://github.com/GetOlympus/olympus-html-field/blob/cfc8d51a3e1e76385949e0c6dba348fcc1354fb9/src/Html/Html.php#L39-L51
spryker/company-business-unit-data-import
src/Spryker/Zed/CompanyBusinessUnitDataImport/Business/Model/CompanyBusinessUnitWriterStep.php
CompanyBusinessUnitWriterStep.execute
public function execute(DataSetInterface $dataSet): void { $companyBusinessUnitEntity = SpyCompanyBusinessUnitQuery::create() ->filterByKey($dataSet[CompanyBusinessUnitDataSet::BUSINESS_UNIT_KEY]) ->filterByFkCompany($dataSet[CompanyBusinessUnitDataSet::ID_COMPANY]) ->findOneOrCreate(); $companyBusinessUnitEntity->fromArray($dataSet->getArrayCopy()); $companyBusinessUnitEntity->save(); }
php
public function execute(DataSetInterface $dataSet): void { $companyBusinessUnitEntity = SpyCompanyBusinessUnitQuery::create() ->filterByKey($dataSet[CompanyBusinessUnitDataSet::BUSINESS_UNIT_KEY]) ->filterByFkCompany($dataSet[CompanyBusinessUnitDataSet::ID_COMPANY]) ->findOneOrCreate(); $companyBusinessUnitEntity->fromArray($dataSet->getArrayCopy()); $companyBusinessUnitEntity->save(); }
[ "public", "function", "execute", "(", "DataSetInterface", "$", "dataSet", ")", ":", "void", "{", "$", "companyBusinessUnitEntity", "=", "SpyCompanyBusinessUnitQuery", "::", "create", "(", ")", "->", "filterByKey", "(", "$", "dataSet", "[", "CompanyBusinessUnitDataSet", "::", "BUSINESS_UNIT_KEY", "]", ")", "->", "filterByFkCompany", "(", "$", "dataSet", "[", "CompanyBusinessUnitDataSet", "::", "ID_COMPANY", "]", ")", "->", "findOneOrCreate", "(", ")", ";", "$", "companyBusinessUnitEntity", "->", "fromArray", "(", "$", "dataSet", "->", "getArrayCopy", "(", ")", ")", ";", "$", "companyBusinessUnitEntity", "->", "save", "(", ")", ";", "}" ]
@param \Spryker\Zed\DataImport\Business\Model\DataSet\DataSetInterface $dataSet @return void
[ "@param", "\\", "Spryker", "\\", "Zed", "\\", "DataImport", "\\", "Business", "\\", "Model", "\\", "DataSet", "\\", "DataSetInterface", "$dataSet" ]
train
https://github.com/spryker/company-business-unit-data-import/blob/8cf3af02dd354b9f0a3a37d048b8bda6a87d3f65/src/Spryker/Zed/CompanyBusinessUnitDataImport/Business/Model/CompanyBusinessUnitWriterStep.php#L22-L32
honey-comb/resources
src/database/migrations/2018_09_16_125204_add_width_height_fields_to_hc_resource_grab_property_table.php
AddWidthHeightFieldsToHcResourceGrabPropertyTable.up
public function up() { Schema::table('hc_resource_grab_property', function (Blueprint $table) { $table->string('width')->default('0'); $table->string('height')->default('0'); $table->string('x')->change(); $table->string('y')->change(); }); }
php
public function up() { Schema::table('hc_resource_grab_property', function (Blueprint $table) { $table->string('width')->default('0'); $table->string('height')->default('0'); $table->string('x')->change(); $table->string('y')->change(); }); }
[ "public", "function", "up", "(", ")", "{", "Schema", "::", "table", "(", "'hc_resource_grab_property'", ",", "function", "(", "Blueprint", "$", "table", ")", "{", "$", "table", "->", "string", "(", "'width'", ")", "->", "default", "(", "'0'", ")", ";", "$", "table", "->", "string", "(", "'height'", ")", "->", "default", "(", "'0'", ")", ";", "$", "table", "->", "string", "(", "'x'", ")", "->", "change", "(", ")", ";", "$", "table", "->", "string", "(", "'y'", ")", "->", "change", "(", ")", ";", "}", ")", ";", "}" ]
Run the migrations. @return void
[ "Run", "the", "migrations", "." ]
train
https://github.com/honey-comb/resources/blob/9b82eb2fd99be99edfdc4e76803d95caf981e14b/src/database/migrations/2018_09_16_125204_add_width_height_fields_to_hc_resource_grab_property_table.php#L14-L22
honey-comb/resources
src/database/migrations/2018_09_16_125204_add_width_height_fields_to_hc_resource_grab_property_table.php
AddWidthHeightFieldsToHcResourceGrabPropertyTable.down
public function down() { Schema::table('hc_resource_grab_property', function (Blueprint $table) { $table->dropColumn(['width', 'height']); $table->integer('x')->change(); $table->integer('y')->change(); }); }
php
public function down() { Schema::table('hc_resource_grab_property', function (Blueprint $table) { $table->dropColumn(['width', 'height']); $table->integer('x')->change(); $table->integer('y')->change(); }); }
[ "public", "function", "down", "(", ")", "{", "Schema", "::", "table", "(", "'hc_resource_grab_property'", ",", "function", "(", "Blueprint", "$", "table", ")", "{", "$", "table", "->", "dropColumn", "(", "[", "'width'", ",", "'height'", "]", ")", ";", "$", "table", "->", "integer", "(", "'x'", ")", "->", "change", "(", ")", ";", "$", "table", "->", "integer", "(", "'y'", ")", "->", "change", "(", ")", ";", "}", ")", ";", "}" ]
Reverse the migrations. @return void
[ "Reverse", "the", "migrations", "." ]
train
https://github.com/honey-comb/resources/blob/9b82eb2fd99be99edfdc4e76803d95caf981e14b/src/database/migrations/2018_09_16_125204_add_width_height_fields_to_hc_resource_grab_property_table.php#L29-L36
RocketPropelledTortoise/Core
src/Entities/FieldCollection.php
FieldCollection.initField
public static function initField($configuration = []) { if (!array_key_exists('type', $configuration) || !class_exists($configuration['type'])) { throw new InvalidFieldTypeException('You did not specify a type on this class.'); } $collection = new static(); $collection->configuration = $configuration; $collection->type = $configuration['type']; if (array_key_exists('max_items', $configuration)) { $collection->maxItems = $configuration['max_items']; } return $collection; }
php
public static function initField($configuration = []) { if (!array_key_exists('type', $configuration) || !class_exists($configuration['type'])) { throw new InvalidFieldTypeException('You did not specify a type on this class.'); } $collection = new static(); $collection->configuration = $configuration; $collection->type = $configuration['type']; if (array_key_exists('max_items', $configuration)) { $collection->maxItems = $configuration['max_items']; } return $collection; }
[ "public", "static", "function", "initField", "(", "$", "configuration", "=", "[", "]", ")", "{", "if", "(", "!", "array_key_exists", "(", "'type'", ",", "$", "configuration", ")", "||", "!", "class_exists", "(", "$", "configuration", "[", "'type'", "]", ")", ")", "{", "throw", "new", "InvalidFieldTypeException", "(", "'You did not specify a type on this class.'", ")", ";", "}", "$", "collection", "=", "new", "static", "(", ")", ";", "$", "collection", "->", "configuration", "=", "$", "configuration", ";", "$", "collection", "->", "type", "=", "$", "configuration", "[", "'type'", "]", ";", "if", "(", "array_key_exists", "(", "'max_items'", ",", "$", "configuration", ")", ")", "{", "$", "collection", "->", "maxItems", "=", "$", "configuration", "[", "'max_items'", "]", ";", "}", "return", "$", "collection", ";", "}" ]
Initialize a collection with the configuration @param array $configuration @throws InvalidFieldTypeException @return static
[ "Initialize", "a", "collection", "with", "the", "configuration" ]
train
https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Entities/FieldCollection.php#L46-L61
RocketPropelledTortoise/Core
src/Entities/FieldCollection.php
FieldCollection.validateSet
protected function validateSet($key, $value) { $maxItems = $this->getMaxItems(); if ((is_null($key) || !array_key_exists($key, $this->items)) && $maxItems != 0 && $this->count() >= $maxItems) { throw new ItemCountException('The maximum number of items has been reached on this field.'); } if (is_null($key) && is_null($value)) { throw new NullValueException('You cannot add a null value'); } }
php
protected function validateSet($key, $value) { $maxItems = $this->getMaxItems(); if ((is_null($key) || !array_key_exists($key, $this->items)) && $maxItems != 0 && $this->count() >= $maxItems) { throw new ItemCountException('The maximum number of items has been reached on this field.'); } if (is_null($key) && is_null($value)) { throw new NullValueException('You cannot add a null value'); } }
[ "protected", "function", "validateSet", "(", "$", "key", ",", "$", "value", ")", "{", "$", "maxItems", "=", "$", "this", "->", "getMaxItems", "(", ")", ";", "if", "(", "(", "is_null", "(", "$", "key", ")", "||", "!", "array_key_exists", "(", "$", "key", ",", "$", "this", "->", "items", ")", ")", "&&", "$", "maxItems", "!=", "0", "&&", "$", "this", "->", "count", "(", ")", ">=", "$", "maxItems", ")", "{", "throw", "new", "ItemCountException", "(", "'The maximum number of items has been reached on this field.'", ")", ";", "}", "if", "(", "is_null", "(", "$", "key", ")", "&&", "is_null", "(", "$", "value", ")", ")", "{", "throw", "new", "NullValueException", "(", "'You cannot add a null value'", ")", ";", "}", "}" ]
Validate input of OffsetSet @param $key @param $value @throws ItemCountException @throws NullValueException
[ "Validate", "input", "of", "OffsetSet" ]
train
https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Entities/FieldCollection.php#L71-L81
RocketPropelledTortoise/Core
src/Entities/FieldCollection.php
FieldCollection.getFieldInstance
protected function getFieldInstance($value) { if ($value instanceof Field) { return $value; } $container = new $this->type(); $container->value = $value; return $container; }
php
protected function getFieldInstance($value) { if ($value instanceof Field) { return $value; } $container = new $this->type(); $container->value = $value; return $container; }
[ "protected", "function", "getFieldInstance", "(", "$", "value", ")", "{", "if", "(", "$", "value", "instanceof", "Field", ")", "{", "return", "$", "value", ";", "}", "$", "container", "=", "new", "$", "this", "->", "type", "(", ")", ";", "$", "container", "->", "value", "=", "$", "value", ";", "return", "$", "container", ";", "}" ]
Get a field from a value @param Field|mixed $value @return Field
[ "Get", "a", "field", "from", "a", "value" ]
train
https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Entities/FieldCollection.php#L89-L99
RocketPropelledTortoise/Core
src/Entities/FieldCollection.php
FieldCollection.offsetSet
public function offsetSet($key, $value) { $this->validateSet($key, $value); if (is_null($value)) { $this->offsetUnset($key); return; } if (is_null($key)) { $this->items[] = $this->getFieldInstance($value); return; } if ($value instanceof Field && $this->has($key)) { $this->deleted[] = $this->items[$key]; } $this->items[$key] = $this->getFieldInstance($value); }
php
public function offsetSet($key, $value) { $this->validateSet($key, $value); if (is_null($value)) { $this->offsetUnset($key); return; } if (is_null($key)) { $this->items[] = $this->getFieldInstance($value); return; } if ($value instanceof Field && $this->has($key)) { $this->deleted[] = $this->items[$key]; } $this->items[$key] = $this->getFieldInstance($value); }
[ "public", "function", "offsetSet", "(", "$", "key", ",", "$", "value", ")", "{", "$", "this", "->", "validateSet", "(", "$", "key", ",", "$", "value", ")", ";", "if", "(", "is_null", "(", "$", "value", ")", ")", "{", "$", "this", "->", "offsetUnset", "(", "$", "key", ")", ";", "return", ";", "}", "if", "(", "is_null", "(", "$", "key", ")", ")", "{", "$", "this", "->", "items", "[", "]", "=", "$", "this", "->", "getFieldInstance", "(", "$", "value", ")", ";", "return", ";", "}", "if", "(", "$", "value", "instanceof", "Field", "&&", "$", "this", "->", "has", "(", "$", "key", ")", ")", "{", "$", "this", "->", "deleted", "[", "]", "=", "$", "this", "->", "items", "[", "$", "key", "]", ";", "}", "$", "this", "->", "items", "[", "$", "key", "]", "=", "$", "this", "->", "getFieldInstance", "(", "$", "value", ")", ";", "}" ]
Set the item at a given offset. @param mixed $key @param mixed $value @return void
[ "Set", "the", "item", "at", "a", "given", "offset", "." ]
train
https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Entities/FieldCollection.php#L108-L129
RocketPropelledTortoise/Core
src/Entities/FieldCollection.php
FieldCollection.offsetUnset
public function offsetUnset($key) { if ($this->offsetExists($key)) { $this->deleted[] = $this->items[$key]; } parent::offsetUnset($key); }
php
public function offsetUnset($key) { if ($this->offsetExists($key)) { $this->deleted[] = $this->items[$key]; } parent::offsetUnset($key); }
[ "public", "function", "offsetUnset", "(", "$", "key", ")", "{", "if", "(", "$", "this", "->", "offsetExists", "(", "$", "key", ")", ")", "{", "$", "this", "->", "deleted", "[", "]", "=", "$", "this", "->", "items", "[", "$", "key", "]", ";", "}", "parent", "::", "offsetUnset", "(", "$", "key", ")", ";", "}" ]
Unset the item at a given offset. @param string $key @return void
[ "Unset", "the", "item", "at", "a", "given", "offset", "." ]
train
https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Entities/FieldCollection.php#L148-L154
RocketPropelledTortoise/Core
src/Entities/FieldCollection.php
FieldCollection.clear
public function clear() { foreach ($this->items as $item) { $this->deleted[] = $item; } $this->items = []; }
php
public function clear() { foreach ($this->items as $item) { $this->deleted[] = $item; } $this->items = []; }
[ "public", "function", "clear", "(", ")", "{", "foreach", "(", "$", "this", "->", "items", "as", "$", "item", ")", "{", "$", "this", "->", "deleted", "[", "]", "=", "$", "item", ";", "}", "$", "this", "->", "items", "=", "[", "]", ";", "}" ]
Remove all items in this collection @return void
[ "Remove", "all", "items", "in", "this", "collection" ]
train
https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Entities/FieldCollection.php#L179-L186
RocketPropelledTortoise/Core
src/Entities/FieldCollection.php
FieldCollection.toArray
public function toArray() { if ($this->getMaxItems() != 1) { return parent::toArray(); } if (!array_key_exists(0, $this->items)) { return null; } return $this->get(0)->toArray(); }
php
public function toArray() { if ($this->getMaxItems() != 1) { return parent::toArray(); } if (!array_key_exists(0, $this->items)) { return null; } return $this->get(0)->toArray(); }
[ "public", "function", "toArray", "(", ")", "{", "if", "(", "$", "this", "->", "getMaxItems", "(", ")", "!=", "1", ")", "{", "return", "parent", "::", "toArray", "(", ")", ";", "}", "if", "(", "!", "array_key_exists", "(", "0", ",", "$", "this", "->", "items", ")", ")", "{", "return", "null", ";", "}", "return", "$", "this", "->", "get", "(", "0", ")", "->", "toArray", "(", ")", ";", "}" ]
As we use a field collection even if we have only one value, we use it that way. @return array|mixed|null
[ "As", "we", "use", "a", "field", "collection", "even", "if", "we", "have", "only", "one", "value", "we", "use", "it", "that", "way", "." ]
train
https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Entities/FieldCollection.php#L203-L214
struggle-for-php/SfpStreamView
src/SfpStreamView/View.php
View.getScriptPath
function getScriptPath() { $fileName = $this->stack->pop(); if ($this->baseDir) { return $this->baseDir . \DIRECTORY_SEPARATOR . $fileName; } else { return (string)$fileName; } }
php
function getScriptPath() { $fileName = $this->stack->pop(); if ($this->baseDir) { return $this->baseDir . \DIRECTORY_SEPARATOR . $fileName; } else { return (string)$fileName; } }
[ "function", "getScriptPath", "(", ")", "{", "$", "fileName", "=", "$", "this", "->", "stack", "->", "pop", "(", ")", ";", "if", "(", "$", "this", "->", "baseDir", ")", "{", "return", "$", "this", "->", "baseDir", ".", "\\", "DIRECTORY_SEPARATOR", ".", "$", "fileName", ";", "}", "else", "{", "return", "(", "string", ")", "$", "fileName", ";", "}", "}" ]
Get script file path @return string
[ "Get", "script", "file", "path" ]
train
https://github.com/struggle-for-php/SfpStreamView/blob/1ee960e122e4e7754a90cf81452567668ea1b32d/src/SfpStreamView/View.php#L66-L74
struggle-for-php/SfpStreamView
src/SfpStreamView/View.php
View.assign
function assign($array) { if (!is_array($array) && !($array instanceof \Traversable)) { throw new \InvalidArgumentException('$array must be array or Traversable.'); } foreach ($array as $key => $value) { $this->storage[$key] = $value; } }
php
function assign($array) { if (!is_array($array) && !($array instanceof \Traversable)) { throw new \InvalidArgumentException('$array must be array or Traversable.'); } foreach ($array as $key => $value) { $this->storage[$key] = $value; } }
[ "function", "assign", "(", "$", "array", ")", "{", "if", "(", "!", "is_array", "(", "$", "array", ")", "&&", "!", "(", "$", "array", "instanceof", "\\", "Traversable", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'$array must be array or Traversable.'", ")", ";", "}", "foreach", "(", "$", "array", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "this", "->", "storage", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}" ]
assign view vars @param array|\Traversable $array
[ "assign", "view", "vars" ]
train
https://github.com/struggle-for-php/SfpStreamView/blob/1ee960e122e4e7754a90cf81452567668ea1b32d/src/SfpStreamView/View.php#L89-L98
spryker/merchant-relationship-data-import
src/Spryker/Zed/MerchantRelationshipDataImport/Business/Model/Step/MerchantKeyToIdMerchantStep.php
MerchantKeyToIdMerchantStep.execute
public function execute(DataSetInterface $dataSet): void { $merchantKey = $dataSet[MerchantRelationshipDataSetInterface::MERCHANT_KEY]; if (!$merchantKey) { throw new InvalidDataException('"' . MerchantRelationshipDataSetInterface::MERCHANT_KEY . '" is required.'); } if (!isset($this->idMerchantCache[$merchantKey])) { $idMerchant = SpyMerchantQuery::create() ->select(SpyMerchantTableMap::COL_ID_MERCHANT) ->findOneByMerchantKey($merchantKey); if (!$idMerchant) { throw new EntityNotFoundException(sprintf('Could not find Merchant by key "%s"', $merchantKey)); } $this->idMerchantCache[$merchantKey] = $idMerchant; } $dataSet[MerchantRelationshipDataSetInterface::ID_MERCHANT] = $this->idMerchantCache[$merchantKey]; }
php
public function execute(DataSetInterface $dataSet): void { $merchantKey = $dataSet[MerchantRelationshipDataSetInterface::MERCHANT_KEY]; if (!$merchantKey) { throw new InvalidDataException('"' . MerchantRelationshipDataSetInterface::MERCHANT_KEY . '" is required.'); } if (!isset($this->idMerchantCache[$merchantKey])) { $idMerchant = SpyMerchantQuery::create() ->select(SpyMerchantTableMap::COL_ID_MERCHANT) ->findOneByMerchantKey($merchantKey); if (!$idMerchant) { throw new EntityNotFoundException(sprintf('Could not find Merchant by key "%s"', $merchantKey)); } $this->idMerchantCache[$merchantKey] = $idMerchant; } $dataSet[MerchantRelationshipDataSetInterface::ID_MERCHANT] = $this->idMerchantCache[$merchantKey]; }
[ "public", "function", "execute", "(", "DataSetInterface", "$", "dataSet", ")", ":", "void", "{", "$", "merchantKey", "=", "$", "dataSet", "[", "MerchantRelationshipDataSetInterface", "::", "MERCHANT_KEY", "]", ";", "if", "(", "!", "$", "merchantKey", ")", "{", "throw", "new", "InvalidDataException", "(", "'\"'", ".", "MerchantRelationshipDataSetInterface", "::", "MERCHANT_KEY", ".", "'\" is required.'", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "idMerchantCache", "[", "$", "merchantKey", "]", ")", ")", "{", "$", "idMerchant", "=", "SpyMerchantQuery", "::", "create", "(", ")", "->", "select", "(", "SpyMerchantTableMap", "::", "COL_ID_MERCHANT", ")", "->", "findOneByMerchantKey", "(", "$", "merchantKey", ")", ";", "if", "(", "!", "$", "idMerchant", ")", "{", "throw", "new", "EntityNotFoundException", "(", "sprintf", "(", "'Could not find Merchant by key \"%s\"'", ",", "$", "merchantKey", ")", ")", ";", "}", "$", "this", "->", "idMerchantCache", "[", "$", "merchantKey", "]", "=", "$", "idMerchant", ";", "}", "$", "dataSet", "[", "MerchantRelationshipDataSetInterface", "::", "ID_MERCHANT", "]", "=", "$", "this", "->", "idMerchantCache", "[", "$", "merchantKey", "]", ";", "}" ]
@param \Spryker\Zed\DataImport\Business\Model\DataSet\DataSetInterface $dataSet @throws \Spryker\Zed\DataImport\Business\Exception\EntityNotFoundException @throws \Spryker\Zed\DataImport\Business\Exception\InvalidDataException @return void
[ "@param", "\\", "Spryker", "\\", "Zed", "\\", "DataImport", "\\", "Business", "\\", "Model", "\\", "DataSet", "\\", "DataSetInterface", "$dataSet" ]
train
https://github.com/spryker/merchant-relationship-data-import/blob/085d48de67de3f241eaf0b704151129ddc09dc42/src/Spryker/Zed/MerchantRelationshipDataImport/Business/Model/Step/MerchantKeyToIdMerchantStep.php#L33-L53
eureka-framework/component-response
src/Response/Header/HttpCode.php
HttpCode.getText
public static function getText($code) { $code = (int) $code; if (!self::exists($code)) { throw new \DomainException('Http Code does not exist!'); } return self::$httpCodes[$code]; }
php
public static function getText($code) { $code = (int) $code; if (!self::exists($code)) { throw new \DomainException('Http Code does not exist!'); } return self::$httpCodes[$code]; }
[ "public", "static", "function", "getText", "(", "$", "code", ")", "{", "$", "code", "=", "(", "int", ")", "$", "code", ";", "if", "(", "!", "self", "::", "exists", "(", "$", "code", ")", ")", "{", "throw", "new", "\\", "DomainException", "(", "'Http Code does not exist!'", ")", ";", "}", "return", "self", "::", "$", "httpCodes", "[", "$", "code", "]", ";", "}" ]
Return text for the specified http code. @param int $code @return string @throws \DomainException
[ "Return", "text", "for", "the", "specified", "http", "code", "." ]
train
https://github.com/eureka-framework/component-response/blob/f34aea3a0aa67b88c5e7f8a3b86af29c550fa99a/src/Response/Header/HttpCode.php#L98-L107
PenoaksDev/Milky-Framework
src/Milky/Console/Scheduling/CallbackEvent.php
CallbackEvent.run
public function run() { if ( $this->description ) touch( $this->mutexPath() ); try { UniversalBuilder::call( $this->callback, $this->parameters ) } finally { $this->removeMutex(); } parent::callAfterCallbacks(); return $response; }
php
public function run() { if ( $this->description ) touch( $this->mutexPath() ); try { UniversalBuilder::call( $this->callback, $this->parameters ) } finally { $this->removeMutex(); } parent::callAfterCallbacks(); return $response; }
[ "public", "function", "run", "(", ")", "{", "if", "(", "$", "this", "->", "description", ")", "touch", "(", "$", "this", "->", "mutexPath", "(", ")", ")", ";", "try", "{", "UniversalBuilder", "::", "call", "(", "$", "this", "->", "callback", ",", "$", "this", "->", "parameters", ")", "}", "finally", "{", "$", "this", "->", "removeMutex", "(", ")", ";", "}", "parent", "::", "callAfterCallbacks", "(", ")", ";", "return", "$", "response", ";", "}" ]
Run the given event. @return mixed @throws \Exception
[ "Run", "the", "given", "event", "." ]
train
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Console/Scheduling/CallbackEvent.php#L48-L65
PenoaksDev/Milky-Framework
src/Milky/Console/Scheduling/CallbackEvent.php
CallbackEvent.withoutOverlapping
public function withoutOverlapping() { if ( !isset( $this->description ) ) throw new LogicException( "A scheduled event name is required to prevent overlapping. Use the 'name' method before 'withoutOverlapping'." ); return $this->skip( function () { return file_exists( $this->mutexPath() ); } ); }
php
public function withoutOverlapping() { if ( !isset( $this->description ) ) throw new LogicException( "A scheduled event name is required to prevent overlapping. Use the 'name' method before 'withoutOverlapping'." ); return $this->skip( function () { return file_exists( $this->mutexPath() ); } ); }
[ "public", "function", "withoutOverlapping", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "description", ")", ")", "throw", "new", "LogicException", "(", "\"A scheduled event name is required to prevent overlapping. Use the 'name' method before 'withoutOverlapping'.\"", ")", ";", "return", "$", "this", "->", "skip", "(", "function", "(", ")", "{", "return", "file_exists", "(", "$", "this", "->", "mutexPath", "(", ")", ")", ";", "}", ")", ";", "}" ]
Do not allow the event to overlap each other. @return $this @throws \LogicException
[ "Do", "not", "allow", "the", "event", "to", "overlap", "each", "other", "." ]
train
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Console/Scheduling/CallbackEvent.php#L85-L94
PenoaksDev/Milky-Framework
src/Milky/Console/Scheduling/CallbackEvent.php
CallbackEvent.getSummaryForDisplay
public function getSummaryForDisplay() { if ( is_string( $this->description ) ) return $this->description; return is_string( $this->callback ) ? $this->callback : 'Closure'; }
php
public function getSummaryForDisplay() { if ( is_string( $this->description ) ) return $this->description; return is_string( $this->callback ) ? $this->callback : 'Closure'; }
[ "public", "function", "getSummaryForDisplay", "(", ")", "{", "if", "(", "is_string", "(", "$", "this", "->", "description", ")", ")", "return", "$", "this", "->", "description", ";", "return", "is_string", "(", "$", "this", "->", "callback", ")", "?", "$", "this", "->", "callback", ":", "'Closure'", ";", "}" ]
Get the summary of the event for display. @return string
[ "Get", "the", "summary", "of", "the", "event", "for", "display", "." ]
train
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Console/Scheduling/CallbackEvent.php#L111-L117
octolabot/Common
src/Doctrine/Migration/FileBasedMigration.php
FileBasedMigration.preDown
final public function preDown(Schema $schema) { $this->prepare(array_map(function (string $migration) : string { return $this->getFullPath($migration); }, $this->getDowngradeMigrations())); }
php
final public function preDown(Schema $schema) { $this->prepare(array_map(function (string $migration) : string { return $this->getFullPath($migration); }, $this->getDowngradeMigrations())); }
[ "final", "public", "function", "preDown", "(", "Schema", "$", "schema", ")", "{", "$", "this", "->", "prepare", "(", "array_map", "(", "function", "(", "string", "$", "migration", ")", ":", "string", "{", "return", "$", "this", "->", "getFullPath", "(", "$", "migration", ")", ";", "}", ",", "$", "this", "->", "getDowngradeMigrations", "(", ")", ")", ")", ";", "}" ]
@param Schema $schema @api
[ "@param", "Schema", "$schema" ]
train
https://github.com/octolabot/Common/blob/fb41f9c6736139e651de5e3ed1a7f4bd422c8e5b/src/Doctrine/Migration/FileBasedMigration.php#L78-L83
octolabot/Common
src/Doctrine/Migration/FileBasedMigration.php
FileBasedMigration.preUp
final public function preUp(Schema $schema) { $this->prepare(array_map(function (string $value) : string { return $this->getFullPath($value); }, $this->getUpgradeMigrations())); }
php
final public function preUp(Schema $schema) { $this->prepare(array_map(function (string $value) : string { return $this->getFullPath($value); }, $this->getUpgradeMigrations())); }
[ "final", "public", "function", "preUp", "(", "Schema", "$", "schema", ")", "{", "$", "this", "->", "prepare", "(", "array_map", "(", "function", "(", "string", "$", "value", ")", ":", "string", "{", "return", "$", "this", "->", "getFullPath", "(", "$", "value", ")", ";", "}", ",", "$", "this", "->", "getUpgradeMigrations", "(", ")", ")", ")", ";", "}" ]
@param Schema $schema @api
[ "@param", "Schema", "$schema" ]
train
https://github.com/octolabot/Common/blob/fb41f9c6736139e651de5e3ed1a7f4bd422c8e5b/src/Doctrine/Migration/FileBasedMigration.php#L90-L95
octolabot/Common
src/Doctrine/Migration/FileBasedMigration.php
FileBasedMigration.getFullPath
public function getFullPath(string $migration): string { return implode('/', array_merge( [$this->getBasePath()], array_filter( [$this->getMajorVersion(), $this->getMinorVersion(), $this->getPatch()], function (string $value) : bool { return $value === '0' || (bool)$value; } ), [$migration] )); }
php
public function getFullPath(string $migration): string { return implode('/', array_merge( [$this->getBasePath()], array_filter( [$this->getMajorVersion(), $this->getMinorVersion(), $this->getPatch()], function (string $value) : bool { return $value === '0' || (bool)$value; } ), [$migration] )); }
[ "public", "function", "getFullPath", "(", "string", "$", "migration", ")", ":", "string", "{", "return", "implode", "(", "'/'", ",", "array_merge", "(", "[", "$", "this", "->", "getBasePath", "(", ")", "]", ",", "array_filter", "(", "[", "$", "this", "->", "getMajorVersion", "(", ")", ",", "$", "this", "->", "getMinorVersion", "(", ")", ",", "$", "this", "->", "getPatch", "(", ")", "]", ",", "function", "(", "string", "$", "value", ")", ":", "bool", "{", "return", "$", "value", "===", "'0'", "||", "(", "bool", ")", "$", "value", ";", "}", ")", ",", "[", "$", "migration", "]", ")", ")", ";", "}" ]
@param string $migration @return string @api
[ "@param", "string", "$migration" ]
train
https://github.com/octolabot/Common/blob/fb41f9c6736139e651de5e3ed1a7f4bd422c8e5b/src/Doctrine/Migration/FileBasedMigration.php#L114-L126
DeimosProject/Request
src/Request/RequestExtension.php
RequestExtension.json
public function json(array $data = array(), $options = JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) { if (!headers_sent()) { header('Cache-Control: no-cache, must-revalidate'); header('Expires: Tue, 19 May 1981 18:00:00 GMT'); header('Content-type: application/json; charset=utf-8'); } /** * @var \Deimos\Helper\Helpers\Json $json */ $json = clone $this->helper->json(); $json->setOption((array)$options); return $json->encode($data); }
php
public function json(array $data = array(), $options = JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) { if (!headers_sent()) { header('Cache-Control: no-cache, must-revalidate'); header('Expires: Tue, 19 May 1981 18:00:00 GMT'); header('Content-type: application/json; charset=utf-8'); } /** * @var \Deimos\Helper\Helpers\Json $json */ $json = clone $this->helper->json(); $json->setOption((array)$options); return $json->encode($data); }
[ "public", "function", "json", "(", "array", "$", "data", "=", "array", "(", ")", ",", "$", "options", "=", "JSON_PRETTY_PRINT", "|", "JSON_UNESCAPED_UNICODE", ")", "{", "if", "(", "!", "headers_sent", "(", ")", ")", "{", "header", "(", "'Cache-Control: no-cache, must-revalidate'", ")", ";", "header", "(", "'Expires: Tue, 19 May 1981 18:00:00 GMT'", ")", ";", "header", "(", "'Content-type: application/json; charset=utf-8'", ")", ";", "}", "/**\n * @var \\Deimos\\Helper\\Helpers\\Json $json\n */", "$", "json", "=", "clone", "$", "this", "->", "helper", "->", "json", "(", ")", ";", "$", "json", "->", "setOption", "(", "(", "array", ")", "$", "options", ")", ";", "return", "$", "json", "->", "encode", "(", "$", "data", ")", ";", "}" ]
@param array $data @param int|array $options @return string
[ "@param", "array", "$data", "@param", "int|array", "$options" ]
train
https://github.com/DeimosProject/Request/blob/3e45af0fdbfc3c47c27de27a98e8980ba42c3737/src/Request/RequestExtension.php#L19-L37
UWEnrollmentManagement/Connection
src/Connection.php
Connection.execGET
public function execGET($url, array $params = []) { $url = $this->baseUrl . $url; // Build the query from the parameters if ($params !== []) { $url .= '?' . http_build_query($params); } // Set request options $this->addOptions([ CURLOPT_URL => $url, CURLOPT_HTTPGET => true, ]); return $this->exec(); }
php
public function execGET($url, array $params = []) { $url = $this->baseUrl . $url; // Build the query from the parameters if ($params !== []) { $url .= '?' . http_build_query($params); } // Set request options $this->addOptions([ CURLOPT_URL => $url, CURLOPT_HTTPGET => true, ]); return $this->exec(); }
[ "public", "function", "execGET", "(", "$", "url", ",", "array", "$", "params", "=", "[", "]", ")", "{", "$", "url", "=", "$", "this", "->", "baseUrl", ".", "$", "url", ";", "// Build the query from the parameters", "if", "(", "$", "params", "!==", "[", "]", ")", "{", "$", "url", ".=", "'?'", ".", "http_build_query", "(", "$", "params", ")", ";", "}", "// Set request options", "$", "this", "->", "addOptions", "(", "[", "CURLOPT_URL", "=>", "$", "url", ",", "CURLOPT_HTTPGET", "=>", "true", ",", "]", ")", ";", "return", "$", "this", "->", "exec", "(", ")", ";", "}" ]
Execute a GET request to a given URL, with optional parameters. @param string $url @param string[] $params Array of query parameter $key=>$value pairs. @return ConnectionReturn The server's response
[ "Execute", "a", "GET", "request", "to", "a", "given", "URL", "with", "optional", "parameters", "." ]
train
https://github.com/UWEnrollmentManagement/Connection/blob/56cadfd9003a3e2d875494a26d9cce69b9b0aa57/src/Connection.php#L103-L119
UWEnrollmentManagement/Connection
src/Connection.php
Connection.execPOST
public function execPOST($url, array $params = []) { $url = $this->baseUrl . $url; $this->addOptions([ CURLOPT_URL => $url, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $params, ]); return $this->exec(); }
php
public function execPOST($url, array $params = []) { $url = $this->baseUrl . $url; $this->addOptions([ CURLOPT_URL => $url, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $params, ]); return $this->exec(); }
[ "public", "function", "execPOST", "(", "$", "url", ",", "array", "$", "params", "=", "[", "]", ")", "{", "$", "url", "=", "$", "this", "->", "baseUrl", ".", "$", "url", ";", "$", "this", "->", "addOptions", "(", "[", "CURLOPT_URL", "=>", "$", "url", ",", "CURLOPT_POST", "=>", "true", ",", "CURLOPT_POSTFIELDS", "=>", "$", "params", ",", "]", ")", ";", "return", "$", "this", "->", "exec", "(", ")", ";", "}" ]
Execute a POST request to a given URL, with optional parameters. @param string $url @param string[] $params Array of POST parameter $key=>$value pairs. @return ConnectionReturn The server's response.
[ "Execute", "a", "POST", "request", "to", "a", "given", "URL", "with", "optional", "parameters", "." ]
train
https://github.com/UWEnrollmentManagement/Connection/blob/56cadfd9003a3e2d875494a26d9cce69b9b0aa57/src/Connection.php#L128-L139
spiral/console
src/Config/ConsoleConfig.php
ConsoleConfig.configureSequence
public function configureSequence(): \Generator { $sequence = $this->config['configure'] ?? $this->config['configureSequence'] ?? []; foreach ($sequence as $item) { yield $this->parseSequence($item); } }
php
public function configureSequence(): \Generator { $sequence = $this->config['configure'] ?? $this->config['configureSequence'] ?? []; foreach ($sequence as $item) { yield $this->parseSequence($item); } }
[ "public", "function", "configureSequence", "(", ")", ":", "\\", "Generator", "{", "$", "sequence", "=", "$", "this", "->", "config", "[", "'configure'", "]", "??", "$", "this", "->", "config", "[", "'configureSequence'", "]", "??", "[", "]", ";", "foreach", "(", "$", "sequence", "as", "$", "item", ")", "{", "yield", "$", "this", "->", "parseSequence", "(", "$", "item", ")", ";", "}", "}" ]
Get list of configure sequences. @return \Generator|SequenceInterface[] @throws ConfigException
[ "Get", "list", "of", "configure", "sequences", "." ]
train
https://github.com/spiral/console/blob/c3d99450ddd32bcc6f87e2b2ed40821054a93da3/src/Config/ConsoleConfig.php#L69-L75
spiral/console
src/Config/ConsoleConfig.php
ConsoleConfig.updateSequence
public function updateSequence(): \Generator { $sequence = $this->config['update'] ?? $this->config['updateSequence'] ?? []; foreach ($sequence as $item) { yield $this->parseSequence($item); } }
php
public function updateSequence(): \Generator { $sequence = $this->config['update'] ?? $this->config['updateSequence'] ?? []; foreach ($sequence as $item) { yield $this->parseSequence($item); } }
[ "public", "function", "updateSequence", "(", ")", ":", "\\", "Generator", "{", "$", "sequence", "=", "$", "this", "->", "config", "[", "'update'", "]", "??", "$", "this", "->", "config", "[", "'updateSequence'", "]", "??", "[", "]", ";", "foreach", "(", "$", "sequence", "as", "$", "item", ")", "{", "yield", "$", "this", "->", "parseSequence", "(", "$", "item", ")", ";", "}", "}" ]
Get list of all update sequences. @return \Generator|SequenceInterface[] @throws ConfigException
[ "Get", "list", "of", "all", "update", "sequences", "." ]
train
https://github.com/spiral/console/blob/c3d99450ddd32bcc6f87e2b2ed40821054a93da3/src/Config/ConsoleConfig.php#L84-L90
spiral/console
src/Config/ConsoleConfig.php
ConsoleConfig.parseSequence
protected function parseSequence($item): SequenceInterface { if ($item instanceof SequenceInterface) { return $item; } if (is_string($item)) { return new CallableSequence($item); } if (is_array($item) && isset($item['command'])) { return new CommandSequence( $item['command'], $item['options'] ?? [], $item['header'] ?? '', $item['footer'] ?? '' ); } if (is_array($item) && isset($item['invoke'])) { return new CallableSequence( $item['invoke'], $item['parameters'] ?? [], $item['header'] ?? '', $item['footer'] ?? '' ); } throw new ConfigException(sprintf( "Unable to parse sequence `%s`.", json_encode($item) )); }
php
protected function parseSequence($item): SequenceInterface { if ($item instanceof SequenceInterface) { return $item; } if (is_string($item)) { return new CallableSequence($item); } if (is_array($item) && isset($item['command'])) { return new CommandSequence( $item['command'], $item['options'] ?? [], $item['header'] ?? '', $item['footer'] ?? '' ); } if (is_array($item) && isset($item['invoke'])) { return new CallableSequence( $item['invoke'], $item['parameters'] ?? [], $item['header'] ?? '', $item['footer'] ?? '' ); } throw new ConfigException(sprintf( "Unable to parse sequence `%s`.", json_encode($item) )); }
[ "protected", "function", "parseSequence", "(", "$", "item", ")", ":", "SequenceInterface", "{", "if", "(", "$", "item", "instanceof", "SequenceInterface", ")", "{", "return", "$", "item", ";", "}", "if", "(", "is_string", "(", "$", "item", ")", ")", "{", "return", "new", "CallableSequence", "(", "$", "item", ")", ";", "}", "if", "(", "is_array", "(", "$", "item", ")", "&&", "isset", "(", "$", "item", "[", "'command'", "]", ")", ")", "{", "return", "new", "CommandSequence", "(", "$", "item", "[", "'command'", "]", ",", "$", "item", "[", "'options'", "]", "??", "[", "]", ",", "$", "item", "[", "'header'", "]", "??", "''", ",", "$", "item", "[", "'footer'", "]", "??", "''", ")", ";", "}", "if", "(", "is_array", "(", "$", "item", ")", "&&", "isset", "(", "$", "item", "[", "'invoke'", "]", ")", ")", "{", "return", "new", "CallableSequence", "(", "$", "item", "[", "'invoke'", "]", ",", "$", "item", "[", "'parameters'", "]", "??", "[", "]", ",", "$", "item", "[", "'header'", "]", "??", "''", ",", "$", "item", "[", "'footer'", "]", "??", "''", ")", ";", "}", "throw", "new", "ConfigException", "(", "sprintf", "(", "\"Unable to parse sequence `%s`.\"", ",", "json_encode", "(", "$", "item", ")", ")", ")", ";", "}" ]
@param mixed $item @return SequenceInterface @throws ConfigException
[ "@param", "mixed", "$item", "@return", "SequenceInterface" ]
train
https://github.com/spiral/console/blob/c3d99450ddd32bcc6f87e2b2ed40821054a93da3/src/Config/ConsoleConfig.php#L98-L130
mcustiel/phiremock-server
src/Http/InputSources/InputSourceLocator.php
InputSourceLocator.locate
public function locate($inputSourceIdentifier) { if (InputSources::isValidInputSource($inputSourceIdentifier)) { return $this->factory->{self::INPUT_SOURCE_FACTORY_METHOD_MAP[$inputSourceIdentifier]}(); }
php
public function locate($inputSourceIdentifier) { if (InputSources::isValidInputSource($inputSourceIdentifier)) { return $this->factory->{self::INPUT_SOURCE_FACTORY_METHOD_MAP[$inputSourceIdentifier]}(); }
[ "public", "function", "locate", "(", "$", "inputSourceIdentifier", ")", "{", "if", "(", "InputSources", "::", "isValidInputSource", "(", "$", "inputSourceIdentifier", ")", ")", "{", "return", "$", "this", "->", "factory", "->", "{", "self", "::", "INPUT_SOURCE_FACTORY_METHOD_MAP", "", "[", "$", "inputSourceIdentifier", "]", "}", "(", "", ")", ";", "}" ]
@param string $inputSourceIdentifier @throws \InvalidArgumentException @return InputSourceInterface
[ "@param", "string", "$inputSourceIdentifier" ]
train
https://github.com/mcustiel/phiremock-server/blob/7be42ce7c5c4d441410d80e158477910924cfbd9/src/Http/InputSources/InputSourceLocator.php#L31-L35
ekyna/Table
Http/Handler/ExportHandler.php
ExportHandler.getAdapter
private function getAdapter(TableInterface $table, $format) { $adapters = $table->getConfig()->getExportAdapters(); foreach ($adapters as $adapter) { if ($adapter->supports($format)) { return $adapter; } } return null; }
php
private function getAdapter(TableInterface $table, $format) { $adapters = $table->getConfig()->getExportAdapters(); foreach ($adapters as $adapter) { if ($adapter->supports($format)) { return $adapter; } } return null; }
[ "private", "function", "getAdapter", "(", "TableInterface", "$", "table", ",", "$", "format", ")", "{", "$", "adapters", "=", "$", "table", "->", "getConfig", "(", ")", "->", "getExportAdapters", "(", ")", ";", "foreach", "(", "$", "adapters", "as", "$", "adapter", ")", "{", "if", "(", "$", "adapter", "->", "supports", "(", "$", "format", ")", ")", "{", "return", "$", "adapter", ";", "}", "}", "return", "null", ";", "}" ]
Returns the adapter supporting the given format. @param TableInterface $table @param string $format @return \Ekyna\Component\Table\Export\AdapterInterface|null
[ "Returns", "the", "adapter", "supporting", "the", "given", "format", "." ]
train
https://github.com/ekyna/Table/blob/6f06e8fd8a3248d52f3a91f10508471344db311a/Http/Handler/ExportHandler.php#L64-L75
nguyenanhung/my-debug
src/Utils.php
Utils.slugify
public static function slugify($str = '') { if (!class_exists('\Cocur\Slugify\Slugify')) { if (function_exists('log_message')) { $message = 'Không tồn tại class Slugify'; log_message('error', $message); } return self::convert_vi_to_en($str); } try { $slugify = new \Cocur\Slugify\Slugify(); return $slugify->slugify($str); } catch (\Exception $e) { if (function_exists('log_message')) { $message = 'Error Code: ' . $e->getCode() . ' - File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Message: ' . $e->getMessage(); log_message('error', $message); } return self::convert_vi_to_en($str); } }
php
public static function slugify($str = '') { if (!class_exists('\Cocur\Slugify\Slugify')) { if (function_exists('log_message')) { $message = 'Không tồn tại class Slugify'; log_message('error', $message); } return self::convert_vi_to_en($str); } try { $slugify = new \Cocur\Slugify\Slugify(); return $slugify->slugify($str); } catch (\Exception $e) { if (function_exists('log_message')) { $message = 'Error Code: ' . $e->getCode() . ' - File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Message: ' . $e->getMessage(); log_message('error', $message); } return self::convert_vi_to_en($str); } }
[ "public", "static", "function", "slugify", "(", "$", "str", "=", "''", ")", "{", "if", "(", "!", "class_exists", "(", "'\\Cocur\\Slugify\\Slugify'", ")", ")", "{", "if", "(", "function_exists", "(", "'log_message'", ")", ")", "{", "$", "message", "=", "'Không tồn tại class Slugify';", "", "log_message", "(", "'error'", ",", "$", "message", ")", ";", "}", "return", "self", "::", "convert_vi_to_en", "(", "$", "str", ")", ";", "}", "try", "{", "$", "slugify", "=", "new", "\\", "Cocur", "\\", "Slugify", "\\", "Slugify", "(", ")", ";", "return", "$", "slugify", "->", "slugify", "(", "$", "str", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "if", "(", "function_exists", "(", "'log_message'", ")", ")", "{", "$", "message", "=", "'Error Code: '", ".", "$", "e", "->", "getCode", "(", ")", ".", "' - File: '", ".", "$", "e", "->", "getFile", "(", ")", ".", "' - Line: '", ".", "$", "e", "->", "getLine", "(", ")", ".", "' - Message: '", ".", "$", "e", "->", "getMessage", "(", ")", ";", "log_message", "(", "'error'", ",", "$", "message", ")", ";", "}", "return", "self", "::", "convert_vi_to_en", "(", "$", "str", ")", ";", "}", "}" ]
Function slugify Hàm chuyển đổi ký tự từ tiếng Việt, và các ký tự đặc biệt sang ký tự không dấu @author: 713uk13m <[email protected]> @time : 10/9/18 00:31 @param string $str Chuỗi ký tự đầu vào @return mixed|null|string Đầu ra rà 1 chuỗi ký tự
[ "Function", "slugify" ]
train
https://github.com/nguyenanhung/my-debug/blob/9dde293d6c04098ee68858035bd04076874f43d6/src/Utils.php#L47-L70
nguyenanhung/my-debug
src/Utils.php
Utils.convert_vi_to_en
public static function convert_vi_to_en($str = '') { $str = trim($str); $str = function_exists('mb_strtolower') ? mb_strtolower($str) : strtolower($str); $data = DataRepository::getData('convert_vi_to_en'); if (!empty($str)) { $str = str_replace($data['vn_array'], $data['en_array'], $str); $str = str_replace($data['special_array'], $data['separator'], $str); $str = str_replace(' ', $data['separator'], $str); while (strpos($str, '--') > 0) { $str = str_replace('--', $data['separator'], $str); } while (strpos($str, '--') === 0) { $str = str_replace('--', $data['separator'], $str); } } return $str; }
php
public static function convert_vi_to_en($str = '') { $str = trim($str); $str = function_exists('mb_strtolower') ? mb_strtolower($str) : strtolower($str); $data = DataRepository::getData('convert_vi_to_en'); if (!empty($str)) { $str = str_replace($data['vn_array'], $data['en_array'], $str); $str = str_replace($data['special_array'], $data['separator'], $str); $str = str_replace(' ', $data['separator'], $str); while (strpos($str, '--') > 0) { $str = str_replace('--', $data['separator'], $str); } while (strpos($str, '--') === 0) { $str = str_replace('--', $data['separator'], $str); } } return $str; }
[ "public", "static", "function", "convert_vi_to_en", "(", "$", "str", "=", "''", ")", "{", "$", "str", "=", "trim", "(", "$", "str", ")", ";", "$", "str", "=", "function_exists", "(", "'mb_strtolower'", ")", "?", "mb_strtolower", "(", "$", "str", ")", ":", "strtolower", "(", "$", "str", ")", ";", "$", "data", "=", "DataRepository", "::", "getData", "(", "'convert_vi_to_en'", ")", ";", "if", "(", "!", "empty", "(", "$", "str", ")", ")", "{", "$", "str", "=", "str_replace", "(", "$", "data", "[", "'vn_array'", "]", ",", "$", "data", "[", "'en_array'", "]", ",", "$", "str", ")", ";", "$", "str", "=", "str_replace", "(", "$", "data", "[", "'special_array'", "]", ",", "$", "data", "[", "'separator'", "]", ",", "$", "str", ")", ";", "$", "str", "=", "str_replace", "(", "' '", ",", "$", "data", "[", "'separator'", "]", ",", "$", "str", ")", ";", "while", "(", "strpos", "(", "$", "str", ",", "'--'", ")", ">", "0", ")", "{", "$", "str", "=", "str_replace", "(", "'--'", ",", "$", "data", "[", "'separator'", "]", ",", "$", "str", ")", ";", "}", "while", "(", "strpos", "(", "$", "str", ",", "'--'", ")", "===", "0", ")", "{", "$", "str", "=", "str_replace", "(", "'--'", ",", "$", "data", "[", "'separator'", "]", ",", "$", "str", ")", ";", "}", "}", "return", "$", "str", ";", "}" ]
Function convert_vi_to_en Hàm chuyển đổi ký tự từ tiếng Việt, và các ký tự đặc biệt sang ký tự không dấu Sử dụng trong trường hợp class slugify nó không chạy @author: 713uk13m <[email protected]> @time : 10/13/18 01:17 @param string $str Chuỗi ký tự đầu vào @return mixed|string Đầu ra rà 1 chuỗi ký tự
[ "Function", "convert_vi_to_en" ]
train
https://github.com/nguyenanhung/my-debug/blob/9dde293d6c04098ee68858035bd04076874f43d6/src/Utils.php#L87-L105
jenskooij/cloudcontrol
src/util/DocumentSorter.php
DocumentSorter.sortDocumentsByField
public static function sortDocumentsByField($documents, $field, $order = 'ASC') { self::$orderByField = $field; self::$order = strtoupper($order) === 'ASC' ? 'ASC' : 'DESC'; usort($documents, '\CloudControl\Cms\util\DocumentSorter::fieldCompare'); if ($order === 'DESC') { return array_reverse($documents); } return $documents; }
php
public static function sortDocumentsByField($documents, $field, $order = 'ASC') { self::$orderByField = $field; self::$order = strtoupper($order) === 'ASC' ? 'ASC' : 'DESC'; usort($documents, '\CloudControl\Cms\util\DocumentSorter::fieldCompare'); if ($order === 'DESC') { return array_reverse($documents); } return $documents; }
[ "public", "static", "function", "sortDocumentsByField", "(", "$", "documents", ",", "$", "field", ",", "$", "order", "=", "'ASC'", ")", "{", "self", "::", "$", "orderByField", "=", "$", "field", ";", "self", "::", "$", "order", "=", "strtoupper", "(", "$", "order", ")", "===", "'ASC'", "?", "'ASC'", ":", "'DESC'", ";", "usort", "(", "$", "documents", ",", "'\\CloudControl\\Cms\\util\\DocumentSorter::fieldCompare'", ")", ";", "if", "(", "$", "order", "===", "'DESC'", ")", "{", "return", "array_reverse", "(", "$", "documents", ")", ";", "}", "return", "$", "documents", ";", "}" ]
Sorts an array of Document instances @param array $documents @param string $field @param string $order @return array
[ "Sorts", "an", "array", "of", "Document", "instances" ]
train
https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/util/DocumentSorter.php#L23-L32
jenskooij/cloudcontrol
src/util/DocumentSorter.php
DocumentSorter.fieldCompare
protected static function fieldCompare(Document $a, Document $b) { $field = self::$orderByField; if (property_exists('\CloudControl\Cms\storage\entities\Document', $field)) { return strcasecmp($a->{$field}, $b->{$field}); } if (!isset($a->fields->{$field}[0])) { return -3; } if (!isset($b->fields->{$field}[0])) { return 3; } return strcasecmp($a->fields->{$field}[0], $b->fields->{$field}[0]); }
php
protected static function fieldCompare(Document $a, Document $b) { $field = self::$orderByField; if (property_exists('\CloudControl\Cms\storage\entities\Document', $field)) { return strcasecmp($a->{$field}, $b->{$field}); } if (!isset($a->fields->{$field}[0])) { return -3; } if (!isset($b->fields->{$field}[0])) { return 3; } return strcasecmp($a->fields->{$field}[0], $b->fields->{$field}[0]); }
[ "protected", "static", "function", "fieldCompare", "(", "Document", "$", "a", ",", "Document", "$", "b", ")", "{", "$", "field", "=", "self", "::", "$", "orderByField", ";", "if", "(", "property_exists", "(", "'\\CloudControl\\Cms\\storage\\entities\\Document'", ",", "$", "field", ")", ")", "{", "return", "strcasecmp", "(", "$", "a", "->", "{", "$", "field", "}", ",", "$", "b", "->", "{", "$", "field", "}", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "a", "->", "fields", "->", "{", "$", "field", "}", "[", "0", "]", ")", ")", "{", "return", "-", "3", ";", "}", "if", "(", "!", "isset", "(", "$", "b", "->", "fields", "->", "{", "$", "field", "}", "[", "0", "]", ")", ")", "{", "return", "3", ";", "}", "return", "strcasecmp", "(", "$", "a", "->", "fields", "->", "{", "$", "field", "}", "[", "0", "]", ",", "$", "b", "->", "fields", "->", "{", "$", "field", "}", "[", "0", "]", ")", ";", "}" ]
Compares two documents @param Document $a @param Document $b @return int
[ "Compares", "two", "documents" ]
train
https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/util/DocumentSorter.php#L40-L55
RhubarbPHP/Module.ImageProcessing
src/Image.php
Image.checkCacheValid
private function checkCacheValid( $cacheFile ) { if ( file_exists( $cacheFile ) && ( filemtime( $cacheFile ) > filemtime( $this->filePath ) ) ) { return true; } return false; }
php
private function checkCacheValid( $cacheFile ) { if ( file_exists( $cacheFile ) && ( filemtime( $cacheFile ) > filemtime( $this->filePath ) ) ) { return true; } return false; }
[ "private", "function", "checkCacheValid", "(", "$", "cacheFile", ")", "{", "if", "(", "file_exists", "(", "$", "cacheFile", ")", "&&", "(", "filemtime", "(", "$", "cacheFile", ")", ">", "filemtime", "(", "$", "this", "->", "filePath", ")", ")", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Returns true if the cache file exists and is current. @param mixed $cacheFile @return bool
[ "Returns", "true", "if", "the", "cache", "file", "exists", "and", "is", "current", "." ]
train
https://github.com/RhubarbPHP/Module.ImageProcessing/blob/e980ae6b524ce60f550064257eb7318dce331c1a/src/Image.php#L163-L171
RhubarbPHP/Module.ImageProcessing
src/Image.php
Image.ApplyMetricsToCanvas
public function ApplyMetricsToCanvas() { $destinationCanvas = @imageCreateTrueColor( $this->_metrics->frameWidth, $this->_metrics->frameHeight ); $backColor = imagecolorallocate( $destinationCanvas, 255, 255, 255 ); if( $this->_metrics->sourceFormat == 3 ) { $backColor = imagecolorallocatealpha( $destinationCanvas, 255, 255, 255, 127 ); imagealphablending( $destinationCanvas, true ); imagesavealpha( $destinationCanvas, true ); } imagefill( $destinationCanvas, 1, 1, $backColor ); @imageCopyResampled( $destinationCanvas, $this->GetCanvas(), $this->_metrics->offsetX, $this->_metrics->offsetY, 0, 0, $this->_metrics->scaleWidth, $this->_metrics->scaleHeight, $this->_metrics->sourceWidth, $this->_metrics->sourceHeight ); $this->SetCanvas( $destinationCanvas ); $this->_metrics->Commit(); }
php
public function ApplyMetricsToCanvas() { $destinationCanvas = @imageCreateTrueColor( $this->_metrics->frameWidth, $this->_metrics->frameHeight ); $backColor = imagecolorallocate( $destinationCanvas, 255, 255, 255 ); if( $this->_metrics->sourceFormat == 3 ) { $backColor = imagecolorallocatealpha( $destinationCanvas, 255, 255, 255, 127 ); imagealphablending( $destinationCanvas, true ); imagesavealpha( $destinationCanvas, true ); } imagefill( $destinationCanvas, 1, 1, $backColor ); @imageCopyResampled( $destinationCanvas, $this->GetCanvas(), $this->_metrics->offsetX, $this->_metrics->offsetY, 0, 0, $this->_metrics->scaleWidth, $this->_metrics->scaleHeight, $this->_metrics->sourceWidth, $this->_metrics->sourceHeight ); $this->SetCanvas( $destinationCanvas ); $this->_metrics->Commit(); }
[ "public", "function", "ApplyMetricsToCanvas", "(", ")", "{", "$", "destinationCanvas", "=", "@", "imageCreateTrueColor", "(", "$", "this", "->", "_metrics", "->", "frameWidth", ",", "$", "this", "->", "_metrics", "->", "frameHeight", ")", ";", "$", "backColor", "=", "imagecolorallocate", "(", "$", "destinationCanvas", ",", "255", ",", "255", ",", "255", ")", ";", "if", "(", "$", "this", "->", "_metrics", "->", "sourceFormat", "==", "3", ")", "{", "$", "backColor", "=", "imagecolorallocatealpha", "(", "$", "destinationCanvas", ",", "255", ",", "255", ",", "255", ",", "127", ")", ";", "imagealphablending", "(", "$", "destinationCanvas", ",", "true", ")", ";", "imagesavealpha", "(", "$", "destinationCanvas", ",", "true", ")", ";", "}", "imagefill", "(", "$", "destinationCanvas", ",", "1", ",", "1", ",", "$", "backColor", ")", ";", "@", "imageCopyResampled", "(", "$", "destinationCanvas", ",", "$", "this", "->", "GetCanvas", "(", ")", ",", "$", "this", "->", "_metrics", "->", "offsetX", ",", "$", "this", "->", "_metrics", "->", "offsetY", ",", "0", ",", "0", ",", "$", "this", "->", "_metrics", "->", "scaleWidth", ",", "$", "this", "->", "_metrics", "->", "scaleHeight", ",", "$", "this", "->", "_metrics", "->", "sourceWidth", ",", "$", "this", "->", "_metrics", "->", "sourceHeight", ")", ";", "$", "this", "->", "SetCanvas", "(", "$", "destinationCanvas", ")", ";", "$", "this", "->", "_metrics", "->", "Commit", "(", ")", ";", "}" ]
Makes sure that the current image metrics are applied to the canvas, essentially committing the changes.
[ "Makes", "sure", "that", "the", "current", "image", "metrics", "are", "applied", "to", "the", "canvas", "essentially", "committing", "the", "changes", "." ]
train
https://github.com/RhubarbPHP/Module.ImageProcessing/blob/e980ae6b524ce60f550064257eb7318dce331c1a/src/Image.php#L188-L213
agentmedia/phine-core
src/Core/Logic/Access/Backend/UserGuard.php
UserGuard.HasAnyPageRight
private function HasAnyPageRight(BackendPageRights $pageRights) { return $pageRights->GetRemove() || $pageRights->GetCreateIn() || $pageRights->GetEdit() || $pageRights->GetMove(); }
php
private function HasAnyPageRight(BackendPageRights $pageRights) { return $pageRights->GetRemove() || $pageRights->GetCreateIn() || $pageRights->GetEdit() || $pageRights->GetMove(); }
[ "private", "function", "HasAnyPageRight", "(", "BackendPageRights", "$", "pageRights", ")", "{", "return", "$", "pageRights", "->", "GetRemove", "(", ")", "||", "$", "pageRights", "->", "GetCreateIn", "(", ")", "||", "$", "pageRights", "->", "GetEdit", "(", ")", "||", "$", "pageRights", "->", "GetMove", "(", ")", ";", "}" ]
True if any of the page rights is true @param BackendPageRights $pageRights The page right @return boolean Returns true if any access action is allowed
[ "True", "if", "any", "of", "the", "page", "rights", "is", "true" ]
train
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Access/Backend/UserGuard.php#L222-L228
agentmedia/phine-core
src/Core/Logic/Access/Backend/UserGuard.php
UserGuard.HasAnyContentRight
private function HasAnyContentRight(BackendContentRights $contentRights) { return $contentRights->GetEdit() || $contentRights->GetRemove() || $contentRights->GetCreateIn() || $contentRights->GetMove(); }
php
private function HasAnyContentRight(BackendContentRights $contentRights) { return $contentRights->GetEdit() || $contentRights->GetRemove() || $contentRights->GetCreateIn() || $contentRights->GetMove(); }
[ "private", "function", "HasAnyContentRight", "(", "BackendContentRights", "$", "contentRights", ")", "{", "return", "$", "contentRights", "->", "GetEdit", "(", ")", "||", "$", "contentRights", "->", "GetRemove", "(", ")", "||", "$", "contentRights", "->", "GetCreateIn", "(", ")", "||", "$", "contentRights", "->", "GetMove", "(", ")", ";", "}" ]
True if any of the content rights is true @param BackendContentRights $contentRights @return boolean Returns true if any access action is allowed
[ "True", "if", "any", "of", "the", "content", "rights", "is", "true" ]
train
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Access/Backend/UserGuard.php#L247-L253
agentmedia/phine-core
src/Core/Logic/Access/Backend/UserGuard.php
UserGuard.GrantGroupOnContent
private function GrantGroupOnContent(Usergroup $group, Usergroup $contentGroup, BackendContentRights $contentRights, BackendAction $action) { if (!$group->Equals($contentGroup)) { return GrantResult::NoAccess(); } $allowed = false; switch ($action) { case BackendAction::Create(): $allowed = $contentRights->GetCreateIn(); break; case BackendAction::Edit(): $allowed = $contentRights->GetEdit(); break; case BackendAction::Move(): $allowed = $contentRights->GetMove(); break; case BackendAction::Delete(): $allowed = $contentRights->GetRemove(); break; case BackendAction::Read(): $allowed = $this->HasAnyContentRight($contentRights); break; } return $allowed ? GrantResult::Allowed() : GrantResult::NoAccess(); }
php
private function GrantGroupOnContent(Usergroup $group, Usergroup $contentGroup, BackendContentRights $contentRights, BackendAction $action) { if (!$group->Equals($contentGroup)) { return GrantResult::NoAccess(); } $allowed = false; switch ($action) { case BackendAction::Create(): $allowed = $contentRights->GetCreateIn(); break; case BackendAction::Edit(): $allowed = $contentRights->GetEdit(); break; case BackendAction::Move(): $allowed = $contentRights->GetMove(); break; case BackendAction::Delete(): $allowed = $contentRights->GetRemove(); break; case BackendAction::Read(): $allowed = $this->HasAnyContentRight($contentRights); break; } return $allowed ? GrantResult::Allowed() : GrantResult::NoAccess(); }
[ "private", "function", "GrantGroupOnContent", "(", "Usergroup", "$", "group", ",", "Usergroup", "$", "contentGroup", ",", "BackendContentRights", "$", "contentRights", ",", "BackendAction", "$", "action", ")", "{", "if", "(", "!", "$", "group", "->", "Equals", "(", "$", "contentGroup", ")", ")", "{", "return", "GrantResult", "::", "NoAccess", "(", ")", ";", "}", "$", "allowed", "=", "false", ";", "switch", "(", "$", "action", ")", "{", "case", "BackendAction", "::", "Create", "(", ")", ":", "$", "allowed", "=", "$", "contentRights", "->", "GetCreateIn", "(", ")", ";", "break", ";", "case", "BackendAction", "::", "Edit", "(", ")", ":", "$", "allowed", "=", "$", "contentRights", "->", "GetEdit", "(", ")", ";", "break", ";", "case", "BackendAction", "::", "Move", "(", ")", ":", "$", "allowed", "=", "$", "contentRights", "->", "GetMove", "(", ")", ";", "break", ";", "case", "BackendAction", "::", "Delete", "(", ")", ":", "$", "allowed", "=", "$", "contentRights", "->", "GetRemove", "(", ")", ";", "break", ";", "case", "BackendAction", "::", "Read", "(", ")", ":", "$", "allowed", "=", "$", "this", "->", "HasAnyContentRight", "(", "$", "contentRights", ")", ";", "break", ";", "}", "return", "$", "allowed", "?", "GrantResult", "::", "Allowed", "(", ")", ":", "GrantResult", "::", "NoAccess", "(", ")", ";", "}" ]
Calculates the grant result for a group on a content @param Usergroup $group The evaluated group @param Usergroup $contentGroup The group of the content @param BackendContentRights $contentRights The rights of the content @param BackendAction $action The action that shall be taken for the content @return GrantResult Returns the calculated result
[ "Calculates", "the", "grant", "result", "for", "a", "group", "on", "a", "content" ]
train
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Access/Backend/UserGuard.php#L400-L431
agentmedia/phine-core
src/Core/Logic/Access/Backend/UserGuard.php
UserGuard.GrantCreateLayout
private function GrantCreateLayout() { $groups = $this->GetGroups(); foreach ($groups as $group) { if ($group->GetCreateLayouts()) { return GrantResult::Allowed(); } } return GrantResult::NoAccess(); }
php
private function GrantCreateLayout() { $groups = $this->GetGroups(); foreach ($groups as $group) { if ($group->GetCreateLayouts()) { return GrantResult::Allowed(); } } return GrantResult::NoAccess(); }
[ "private", "function", "GrantCreateLayout", "(", ")", "{", "$", "groups", "=", "$", "this", "->", "GetGroups", "(", ")", ";", "foreach", "(", "$", "groups", "as", "$", "group", ")", "{", "if", "(", "$", "group", "->", "GetCreateLayouts", "(", ")", ")", "{", "return", "GrantResult", "::", "Allowed", "(", ")", ";", "}", "}", "return", "GrantResult", "::", "NoAccess", "(", ")", ";", "}" ]
Grant access to create a new layout by common group settings @return GrantResult
[ "Grant", "access", "to", "create", "a", "new", "layout", "by", "common", "group", "settings" ]
train
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Access/Backend/UserGuard.php#L437-L448
agentmedia/phine-core
src/Core/Logic/Access/Backend/UserGuard.php
UserGuard.GrantCreateSite
private function GrantCreateSite() { $groups = $this->GetGroups(); foreach ($groups as $group) { if ($group->GetCreateSites()) { return GrantResult::Allowed(); } } return GrantResult::NoAccess(); }
php
private function GrantCreateSite() { $groups = $this->GetGroups(); foreach ($groups as $group) { if ($group->GetCreateSites()) { return GrantResult::Allowed(); } } return GrantResult::NoAccess(); }
[ "private", "function", "GrantCreateSite", "(", ")", "{", "$", "groups", "=", "$", "this", "->", "GetGroups", "(", ")", ";", "foreach", "(", "$", "groups", "as", "$", "group", ")", "{", "if", "(", "$", "group", "->", "GetCreateSites", "(", ")", ")", "{", "return", "GrantResult", "::", "Allowed", "(", ")", ";", "}", "}", "return", "GrantResult", "::", "NoAccess", "(", ")", ";", "}" ]
Grant access to create a new site by common group settings @return GrantResult
[ "Grant", "access", "to", "create", "a", "new", "site", "by", "common", "group", "settings" ]
train
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Access/Backend/UserGuard.php#L455-L466
agentmedia/phine-core
src/Core/Logic/Access/Backend/UserGuard.php
UserGuard.GrantCreateContainer
private function GrantCreateContainer() { $groups = $this->GetGroups(); foreach ($groups as $group) { if ($group->GetCreateContainers()) { return GrantResult::Allowed(); } } return GrantResult::NoAccess(); }
php
private function GrantCreateContainer() { $groups = $this->GetGroups(); foreach ($groups as $group) { if ($group->GetCreateContainers()) { return GrantResult::Allowed(); } } return GrantResult::NoAccess(); }
[ "private", "function", "GrantCreateContainer", "(", ")", "{", "$", "groups", "=", "$", "this", "->", "GetGroups", "(", ")", ";", "foreach", "(", "$", "groups", "as", "$", "group", ")", "{", "if", "(", "$", "group", "->", "GetCreateContainers", "(", ")", ")", "{", "return", "GrantResult", "::", "Allowed", "(", ")", ";", "}", "}", "return", "GrantResult", "::", "NoAccess", "(", ")", ";", "}" ]
Grant access to create a new site by common group settings @return GrantResult
[ "Grant", "access", "to", "create", "a", "new", "site", "by", "common", "group", "settings" ]
train
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Access/Backend/UserGuard.php#L473-L484
agentmedia/phine-core
src/Core/Logic/Access/Backend/UserGuard.php
UserGuard.GrantOnContent
private function GrantOnContent(Content $content, BackendAction $action) { if ($this->GetUser()->Equals($content->GetUser())) { return GrantResult::Allowed(); } $contentRights = RightsFinder::FindContentRights($content); $contentGroup = GroupFinder::FindContentGroup($content); if (!$contentRights || !$contentGroup) { return GrantResult::NoAccess(); } $groups = $this->GetGroups(); foreach ($groups as $group) { $result = $this->GrantGroupOnContent($group, $contentGroup, $contentRights, $action); if ($result->Equals(GrantResult::Allowed())) { return $result; } } return GrantResult::NoAccess(); }
php
private function GrantOnContent(Content $content, BackendAction $action) { if ($this->GetUser()->Equals($content->GetUser())) { return GrantResult::Allowed(); } $contentRights = RightsFinder::FindContentRights($content); $contentGroup = GroupFinder::FindContentGroup($content); if (!$contentRights || !$contentGroup) { return GrantResult::NoAccess(); } $groups = $this->GetGroups(); foreach ($groups as $group) { $result = $this->GrantGroupOnContent($group, $contentGroup, $contentRights, $action); if ($result->Equals(GrantResult::Allowed())) { return $result; } } return GrantResult::NoAccess(); }
[ "private", "function", "GrantOnContent", "(", "Content", "$", "content", ",", "BackendAction", "$", "action", ")", "{", "if", "(", "$", "this", "->", "GetUser", "(", ")", "->", "Equals", "(", "$", "content", "->", "GetUser", "(", ")", ")", ")", "{", "return", "GrantResult", "::", "Allowed", "(", ")", ";", "}", "$", "contentRights", "=", "RightsFinder", "::", "FindContentRights", "(", "$", "content", ")", ";", "$", "contentGroup", "=", "GroupFinder", "::", "FindContentGroup", "(", "$", "content", ")", ";", "if", "(", "!", "$", "contentRights", "||", "!", "$", "contentGroup", ")", "{", "return", "GrantResult", "::", "NoAccess", "(", ")", ";", "}", "$", "groups", "=", "$", "this", "->", "GetGroups", "(", ")", ";", "foreach", "(", "$", "groups", "as", "$", "group", ")", "{", "$", "result", "=", "$", "this", "->", "GrantGroupOnContent", "(", "$", "group", ",", "$", "contentGroup", ",", "$", "contentRights", ",", "$", "action", ")", ";", "if", "(", "$", "result", "->", "Equals", "(", "GrantResult", "::", "Allowed", "(", ")", ")", ")", "{", "return", "$", "result", ";", "}", "}", "return", "GrantResult", "::", "NoAccess", "(", ")", ";", "}" ]
Calculates the grant result for a content @param Content $content The content @param BackendAction $action The action that shall be taken on the content @return GrantResult Returns the calculated grant result
[ "Calculates", "the", "grant", "result", "for", "a", "content" ]
train
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Access/Backend/UserGuard.php#L491-L513
agentmedia/phine-core
src/Core/Logic/Access/Backend/UserGuard.php
UserGuard.GrantAddPageToSite
function GrantAddPageToSite(Site $site) { //Dummy page for evaluation $page = new Page(); $page->SetUserGroup($site->GetUserGroup()); $siteRights = $site->GetUserGroupRights(); if ($siteRights) { $page->SetUserGroupRights($siteRights->GetPageRights()); } return $this->Grant(BackendAction::Create(), $page); }
php
function GrantAddPageToSite(Site $site) { //Dummy page for evaluation $page = new Page(); $page->SetUserGroup($site->GetUserGroup()); $siteRights = $site->GetUserGroupRights(); if ($siteRights) { $page->SetUserGroupRights($siteRights->GetPageRights()); } return $this->Grant(BackendAction::Create(), $page); }
[ "function", "GrantAddPageToSite", "(", "Site", "$", "site", ")", "{", "//Dummy page for evaluation", "$", "page", "=", "new", "Page", "(", ")", ";", "$", "page", "->", "SetUserGroup", "(", "$", "site", "->", "GetUserGroup", "(", ")", ")", ";", "$", "siteRights", "=", "$", "site", "->", "GetUserGroupRights", "(", ")", ";", "if", "(", "$", "siteRights", ")", "{", "$", "page", "->", "SetUserGroupRights", "(", "$", "siteRights", "->", "GetPageRights", "(", ")", ")", ";", "}", "return", "$", "this", "->", "Grant", "(", "BackendAction", "::", "Create", "(", ")", ",", "$", "page", ")", ";", "}" ]
Grant evaluation for adding a page on top of the site @param Site $site The site @return GrantResult The result
[ "Grant", "evaluation", "for", "adding", "a", "page", "on", "top", "of", "the", "site" ]
train
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Access/Backend/UserGuard.php#L610-L621
agentmedia/phine-core
src/Core/Logic/Access/Backend/UserGuard.php
UserGuard.GrantAddContentToPageArea
function GrantAddContentToPageArea(Page $page, Area $area) { $result = $this->Grant(BackendAction::Create(), $area); if (!$result->ToBool()) { return $result; } return $this->GrantAddContentToPage($page); }
php
function GrantAddContentToPageArea(Page $page, Area $area) { $result = $this->Grant(BackendAction::Create(), $area); if (!$result->ToBool()) { return $result; } return $this->GrantAddContentToPage($page); }
[ "function", "GrantAddContentToPageArea", "(", "Page", "$", "page", ",", "Area", "$", "area", ")", "{", "$", "result", "=", "$", "this", "->", "Grant", "(", "BackendAction", "::", "Create", "(", ")", ",", "$", "area", ")", ";", "if", "(", "!", "$", "result", "->", "ToBool", "(", ")", ")", "{", "return", "$", "result", ";", "}", "return", "$", "this", "->", "GrantAddContentToPage", "(", "$", "page", ")", ";", "}" ]
Grant evaluation vor a page are @param Page $page @param Area $area @return GrantResult
[ "Grant", "evaluation", "vor", "a", "page", "are" ]
train
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Access/Backend/UserGuard.php#L628-L637
agentmedia/phine-core
src/Core/Logic/Access/Backend/UserGuard.php
UserGuard.GrantAddContentToPage
function GrantAddContentToPage(Page $page) { //dummy content for evaluation $content = new Content(); $content->SetUserGroup(GroupFinder::FindPageGroup($page)); $pageRights = RightsFinder::FindPageRights($page); if ($pageRights) { $content->SetUserGroupRights($pageRights->GetContentRights()); } return $this->Grant(BackendAction::Create(), $content); }
php
function GrantAddContentToPage(Page $page) { //dummy content for evaluation $content = new Content(); $content->SetUserGroup(GroupFinder::FindPageGroup($page)); $pageRights = RightsFinder::FindPageRights($page); if ($pageRights) { $content->SetUserGroupRights($pageRights->GetContentRights()); } return $this->Grant(BackendAction::Create(), $content); }
[ "function", "GrantAddContentToPage", "(", "Page", "$", "page", ")", "{", "//dummy content for evaluation", "$", "content", "=", "new", "Content", "(", ")", ";", "$", "content", "->", "SetUserGroup", "(", "GroupFinder", "::", "FindPageGroup", "(", "$", "page", ")", ")", ";", "$", "pageRights", "=", "RightsFinder", "::", "FindPageRights", "(", "$", "page", ")", ";", "if", "(", "$", "pageRights", ")", "{", "$", "content", "->", "SetUserGroupRights", "(", "$", "pageRights", "->", "GetContentRights", "(", ")", ")", ";", "}", "return", "$", "this", "->", "Grant", "(", "BackendAction", "::", "Create", "(", ")", ",", "$", "content", ")", ";", "}" ]
Grant evaluation for adding content on top of a page area @param Page $page The page @return GrantResult GrantResult Returns the grant result telling if creation is allowed
[ "Grant", "evaluation", "for", "adding", "content", "on", "top", "of", "a", "page", "area" ]
train
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Access/Backend/UserGuard.php#L643-L654
agentmedia/phine-core
src/Core/Logic/Access/Backend/UserGuard.php
UserGuard.GrantAddContentToLayoutArea
function GrantAddContentToLayoutArea(Area $area) { $result = $this->Grant(BackendAction::Create(), $area); if (!$result->ToBool()) { return $result; } return $this->GrantAddContentToLayout($area->GetLayout()); }
php
function GrantAddContentToLayoutArea(Area $area) { $result = $this->Grant(BackendAction::Create(), $area); if (!$result->ToBool()) { return $result; } return $this->GrantAddContentToLayout($area->GetLayout()); }
[ "function", "GrantAddContentToLayoutArea", "(", "Area", "$", "area", ")", "{", "$", "result", "=", "$", "this", "->", "Grant", "(", "BackendAction", "::", "Create", "(", ")", ",", "$", "area", ")", ";", "if", "(", "!", "$", "result", "->", "ToBool", "(", ")", ")", "{", "return", "$", "result", ";", "}", "return", "$", "this", "->", "GrantAddContentToLayout", "(", "$", "area", "->", "GetLayout", "(", ")", ")", ";", "}" ]
Grant evaluation for adding content to layout area @param Area $area @return GrantResult
[ "Grant", "evaluation", "for", "adding", "content", "to", "layout", "area" ]
train
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Access/Backend/UserGuard.php#L660-L668
agentmedia/phine-core
src/Core/Logic/Access/Backend/UserGuard.php
UserGuard.GrantAddContentToLayout
function GrantAddContentToLayout(Layout $layout) { //dummy content for evaluation $content = new Content(); $content->SetUserGroup($layout->GetUserGroup()); $layoutRights = $layout->GetUserGroupRights(); if ($layoutRights) { $content->SetUserGroupRights($layoutRights->GetContentRights()); } return $this->Grant(BackendAction::Create(), $content); }
php
function GrantAddContentToLayout(Layout $layout) { //dummy content for evaluation $content = new Content(); $content->SetUserGroup($layout->GetUserGroup()); $layoutRights = $layout->GetUserGroupRights(); if ($layoutRights) { $content->SetUserGroupRights($layoutRights->GetContentRights()); } return $this->Grant(BackendAction::Create(), $content); }
[ "function", "GrantAddContentToLayout", "(", "Layout", "$", "layout", ")", "{", "//dummy content for evaluation", "$", "content", "=", "new", "Content", "(", ")", ";", "$", "content", "->", "SetUserGroup", "(", "$", "layout", "->", "GetUserGroup", "(", ")", ")", ";", "$", "layoutRights", "=", "$", "layout", "->", "GetUserGroupRights", "(", ")", ";", "if", "(", "$", "layoutRights", ")", "{", "$", "content", "->", "SetUserGroupRights", "(", "$", "layoutRights", "->", "GetContentRights", "(", ")", ")", ";", "}", "return", "$", "this", "->", "Grant", "(", "BackendAction", "::", "Create", "(", ")", ",", "$", "content", ")", ";", "}" ]
Grant evaluation for adding content on top of a layout area @param Layout $layout The layout @return GrantResult Returns the grant result telling if creation is allowed
[ "Grant", "evaluation", "for", "adding", "content", "on", "top", "of", "a", "layout", "area" ]
train
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Access/Backend/UserGuard.php#L674-L685
agentmedia/phine-core
src/Core/Logic/Access/Backend/UserGuard.php
UserGuard.GrantAddContentToContainer
function GrantAddContentToContainer(Container $container) { //dummy content for evaluation $content = new Content(); $content->SetUserGroup($container->GetUserGroup()); $containerRights = $container->GetUserGroupRights(); if ($containerRights) { $content->SetUserGroupRights($containerRights->GetContentRights()); } return $this->Grant(BackendAction::Create(), $content); }
php
function GrantAddContentToContainer(Container $container) { //dummy content for evaluation $content = new Content(); $content->SetUserGroup($container->GetUserGroup()); $containerRights = $container->GetUserGroupRights(); if ($containerRights) { $content->SetUserGroupRights($containerRights->GetContentRights()); } return $this->Grant(BackendAction::Create(), $content); }
[ "function", "GrantAddContentToContainer", "(", "Container", "$", "container", ")", "{", "//dummy content for evaluation", "$", "content", "=", "new", "Content", "(", ")", ";", "$", "content", "->", "SetUserGroup", "(", "$", "container", "->", "GetUserGroup", "(", ")", ")", ";", "$", "containerRights", "=", "$", "container", "->", "GetUserGroupRights", "(", ")", ";", "if", "(", "$", "containerRights", ")", "{", "$", "content", "->", "SetUserGroupRights", "(", "$", "containerRights", "->", "GetContentRights", "(", ")", ")", ";", "}", "return", "$", "this", "->", "Grant", "(", "BackendAction", "::", "Create", "(", ")", ",", "$", "content", ")", ";", "}" ]
Grant evaluation for adding content on top of a container @param Container $container The container @return GrantResult Returns the grant result telling if creation is allowed
[ "Grant", "evaluation", "for", "adding", "content", "on", "top", "of", "a", "container" ]
train
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Access/Backend/UserGuard.php#L716-L727
vaniocz/stdlib
src/UniversalJsonSerializer.php
UniversalJsonSerializer.serialize
public static function serialize($value): string { $serialized = json_encode( self::encode($value, new SplObjectStorage()), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES ); if (json_last_error() !== JSON_ERROR_NONE) { throw new \InvalidArgumentException(json_last_error_msg()); } return $serialized; }
php
public static function serialize($value): string { $serialized = json_encode( self::encode($value, new SplObjectStorage()), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES ); if (json_last_error() !== JSON_ERROR_NONE) { throw new \InvalidArgumentException(json_last_error_msg()); } return $serialized; }
[ "public", "static", "function", "serialize", "(", "$", "value", ")", ":", "string", "{", "$", "serialized", "=", "json_encode", "(", "self", "::", "encode", "(", "$", "value", ",", "new", "SplObjectStorage", "(", ")", ")", ",", "JSON_UNESCAPED_UNICODE", "|", "JSON_UNESCAPED_SLASHES", ")", ";", "if", "(", "json_last_error", "(", ")", "!==", "JSON_ERROR_NONE", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "json_last_error_msg", "(", ")", ")", ";", "}", "return", "$", "serialized", ";", "}" ]
Serialize the given value into a JSON encoded string. @param mixed $value The value to be serialized. @return string The JSON encoded string.
[ "Serialize", "the", "given", "value", "into", "a", "JSON", "encoded", "string", "." ]
train
https://github.com/vaniocz/stdlib/blob/06a8343c42829d8fdeecad2bb5c30946fbd73e74/src/UniversalJsonSerializer.php#L22-L34