idx
int64
0
60.3k
question
stringlengths
99
4.85k
target
stringlengths
5
718
51,900
public static function getSubArrayFromArrayByKeys ( array $ array , array $ keys ) { $ result = [ ] ; foreach ( $ keys as $ key ) { if ( array_key_exists ( $ key , $ array ) ) { $ result [ $ key ] = $ array [ $ key ] ; } } return $ result ; }
Get SubArray from array by keys
51,901
public static function doDelete ( $ values , ConnectionInterface $ con = null ) { if ( null === $ con ) { $ con = Propel :: getServiceContainer ( ) -> getWriteConnection ( M2PTableMap :: DATABASE_NAME ) ; } if ( $ values instanceof Criteria ) { $ criteria = $ values ; } elseif ( $ values instanceof \ Attogram \ SharedM...
Performs a DELETE on the database given a M2P or Criteria object OR a primary key value .
51,902
public static function doInsert ( $ criteria , ConnectionInterface $ con = null ) { if ( null === $ con ) { $ con = Propel :: getServiceContainer ( ) -> getWriteConnection ( M2PTableMap :: DATABASE_NAME ) ; } if ( $ criteria instanceof Criteria ) { $ criteria = clone $ criteria ; } else { $ criteria = $ criteria -> bui...
Performs an INSERT on the database given a M2P or Criteria object .
51,903
final public function filterByLevel ( $ level , array $ levels = [ ] ) { if ( $ level !== $ this -> minLevel ) { $ this -> minLevel = $ level ; $ this -> consumer = null ; } if ( ! empty ( $ levels ) ) { $ this -> levels = $ levels ; $ this -> consumer = null ; } return $ this ; }
One can set minimum level of logs that will be streamed to OutputWriter by this LogsMonitor . This is optional and if method is not call all available logs are supposed to be streamed .
51,904
final public function filterByContext ( array $ context ) { if ( $ context !== $ this -> withContext ) { $ this -> withContext = $ context ; $ this -> consumer = null ; } return $ this ; }
One can set context that is required to stream logs to OutputWriter by this LogsMonitor . This is optional and if method is not call all available logs are supposed to be streamed .
51,905
final public function setOutputWriter ( OutputWriter $ outputWriter ) { if ( $ outputWriter !== $ this -> outputWriter ) { $ this -> outputWriter = $ outputWriter ; $ this -> consumer = null ; } return $ this ; }
Call of this method is required before logs are streamed to OutputWriter .
51,906
public static function name ( $ color ) { if ( false === is_string ( $ color ) ) { return trigger_error ( sprintf ( 'Argument 1 passed to %s() must be of the type string, "%s" given' , __METHOD__ , gettype ( $ color ) ) , E_USER_ERROR ) ; } if ( 1 !== preg_match ( '#^[0-9a-fA-F]{6,6}$#' , $ color ) ) { return trigger_e...
Convert a hexadecimal color to color name in human language
51,907
private static function index ( ) { $ colors = ColorList :: get ( 'colors' ) ; foreach ( $ colors as $ hex => $ color ) { $ rgb = static :: rgb ( $ hex ) ; $ hsl = static :: hsl ( $ hex ) ; $ shade = ColorList :: get ( [ 'shades' , $ color [ 's' ] ] ) ; $ base = ColorList :: get ( [ 'base' , $ shade [ 'b' ] ] ) ; stati...
Initialise all colors
51,908
private static function rgb ( $ color ) { return ( object ) [ 'r' => intval ( hexdec ( substr ( $ color , 0 , 2 ) ) ) , 'g' => intval ( hexdec ( substr ( $ color , 2 , 2 ) ) ) , 'b' => intval ( hexdec ( substr ( $ color , 4 , 2 ) ) ) ] ; }
Convert hexadecimal color to RGB
51,909
private static function hsl ( $ color ) { $ r = intval ( hexdec ( substr ( $ color , 0 , 2 ) ) ) / 255 ; $ g = intval ( hexdec ( substr ( $ color , 2 , 2 ) ) ) / 255 ; $ b = intval ( hexdec ( substr ( $ color , 4 , 2 ) ) ) / 255 ; $ min = min ( $ r , $ g , $ b ) ; $ max = max ( $ r , $ g , $ b ) ; $ delta = $ max - $ m...
Convert hexadecimal color to HSL
51,910
public function serialize ( SerializedTokenIterator $ it ) { $ it -> append ( $ this -> type ) ; $ it -> append ( $ this -> text ) ; }
Serialize the token into the given token interation .
51,911
public static function getTypeName ( $ type ) { static $ ref = [ ] ; $ key = static :: class ; if ( empty ( $ ref [ $ key ] ) ) { $ ref [ $ key ] = new \ ReflectionClass ( $ key ) ; } foreach ( $ ref [ $ key ] -> getConstants ( ) as $ k => $ v ) { if ( $ v === $ type && strpos ( $ k , 'T_' ) === 0 ) { return $ k ; } } ...
Get a human - readable name of the given token type .
51,912
public static function getEntityManager ( $ db = null , $ context = 'shared' ) { $ dbConfig = \ erdiko \ core \ Helper :: getConfig ( "database" , $ context ) ; if ( $ db == null ) $ db = $ dbConfig [ 'default' ] ; $ dbParams = $ dbConfig [ 'connections' ] [ $ db ] ; $ dbParams [ 'dbname' ] = $ dbParams [ 'database' ] ...
Get Doctrine entity manager
51,913
public static function update ( $ entity ) { $ entityManager = self :: getEntityManager ( ) ; $ entity = $ entityManager -> merge ( $ entity ) ; $ entityManager -> flush ( ) ; return $ entity ; }
Update a single record Convenience method to update a row . You should use the Doctrine EntityManager directly to take control of the Entity merge process .
51,914
public function addSeedBatch ( \ Librinfo \ SeedBatchBundle \ Entity \ SeedBatch $ seedBatch ) { $ this -> seedBatches [ ] = $ seedBatch ; return $ this ; }
Add seedBatch .
51,915
public function removeSeedBatch ( \ Librinfo \ SeedBatchBundle \ Entity \ SeedBatch $ seedBatch ) { return $ this -> seedBatches -> removeElement ( $ seedBatch ) ; }
Remove seedBatch .
51,916
public function setProducer ( \ Librinfo \ CRMBundle \ Entity \ Organism $ producer = null ) { $ this -> producer = $ producer ; return $ this ; }
Set producer .
51,917
public function addCertification ( \ Librinfo \ SeedBatchBundle \ Entity \ Certification $ certifications ) { $ this -> certifications [ ] = $ certifications ; return $ this ; }
Add certifications .
51,918
public function removeCertification ( \ Librinfo \ SeedBatchBundle \ Entity \ Certification $ certification ) { $ this -> certifications -> removeElement ( $ certification ) ; }
Remove certification .
51,919
public function replaceTags ( $ model ) { if ( isset ( $ model -> attributes ) ) { foreach ( $ model -> attributes as $ key => $ attribute ) { if ( in_array ( $ key , $ this -> dataAttributes ) ) { $ val = Yii :: $ app -> formatter -> asDatetime ( $ model -> { $ key } , 'short' ) ; } else { $ val = $ model -> { $ key }...
Replace tags by values in text and subject field
51,920
public function replaceExtraTag ( $ tag , $ value ) { $ this -> subject = str_replace ( '{' . $ tag . '}' , $ value , $ this -> subject ) ; $ this -> user_subject = str_replace ( '{' . $ tag . '}' , $ value , $ this -> user_subject ) ; $ this -> text = str_replace ( '{' . $ tag . '}' , $ value , $ this -> text ) ; $ th...
Replace additional tags in email subject and text
51,921
public function fields ( $ fields ) { if ( ! is_string ( $ fields ) ) { throw new FatalException ( 'Only strings are allowed in COUNT query' ) ; } $ this -> fields = sprintf ( 'COUNT(%s)' , DatabaseConnectionFactory :: get ( ) -> quoteIdentifier ( $ fields ) ) ; return $ this ; }
Set the field to count .
51,922
public function get ( Container $ container ) { if ( $ this -> singleton ) { if ( $ this -> instance === null ) { $ f = $ this -> factory ; $ this -> instance = $ f ( $ container ) ; } return $ this -> instance ; } else { $ f = $ this -> factory ; return $ f ( $ container ) ; } }
Gets the value instance .
51,923
public function loadMedia ( ) { $ files = $ this -> getMediaFiles ( ) ; foreach ( $ files as $ file ) { $ mediaFile = $ this -> getCollection ( ) -> newMedia ( ) ; $ mediaFile -> setFile ( $ file ) ; $ this -> appendMediaInCollection ( $ mediaFile ) ; } }
Load media for a collection
51,924
public function istantiateObjects ( ) { $ this -> validateObjectClassName ( ) ; $ objects_iterator = new ArrayIterator ; $ this -> appendObjectDataToIterator ( $ objects_iterator ) ; $ this -> objects_istantiated = $ objects_iterator ; return $ this -> objects_istantiated ; }
Assuming that we can pass all the proprieties to that object as an array we istantiate each of that StdClass as a IstantiatedObject
51,925
public static function isDue ( $ pattern , \ DateTime $ time = null ) { if ( $ time === null ) { $ time = new \ DateTime ( ) ; } $ time -> setTime ( $ time -> format ( 'H' ) , $ time -> format ( 'i' ) ) ; $ expression = Expression :: createFromPattern ( $ pattern ) ; foreach ( self :: $ _formats as $ pos => $ fmt ) { i...
Returns true if the time matches the pattern supplied . Time defaults to current time .
51,926
final public function getAttributes ( $ parsed = false ) { if ( ! is_array ( $ this -> attributes ) ) { $ this -> attributes = array ( ) ; } return ( $ parsed ) ? $ this -> parseAttributes ( ) : $ this -> attributes ; }
Fetches the attributes of the fieldset
51,927
final public function setModel ( IModel $ model ) { $ this -> model = $ model ; $ this -> setData ( $ model -> toArray ( false , true ) ) ; return $ this ; }
Maps the form to a model
51,928
public function getModel ( ) { if ( ! $ this -> model ) return null ; $ data = $ this -> data ; if ( $ this -> isValid ( ) && $ this -> model ) { foreach ( $ this -> fieldsets as $ name ) { if ( ! isset ( $ this -> elements [ $ name ] ) ) continue ; $ fieldset = $ this -> elements [ $ name ] -> options -> value ; $ fie...
Fetches the populated model
51,929
public function add ( $ element ) { if ( ( is_object ( $ element ) && ! is_a ( $ element , 'DScribe\Form\Element' ) ) || ( ! is_object ( $ element ) && ! is_array ( $ element ) ) ) throw new Exception ( 'Form elements must be either an array or an object subclass of DScribe\Form\Element' ) ; else if ( is_array ( $ elem...
Adds an element to the fieldset
51,930
final public function setData ( $ data ) { if ( ( is_object ( $ data ) && ! is_a ( $ data , 'Object' ) ) || ( ! is_object ( $ data ) && ! is_array ( $ data ) ) ) throw new \ Exception ( 'Data must be either an array or an object that extends Object: ' . gettype ( $ data ) ) ; $ data = is_array ( $ data ) ? $ data : $ d...
Sets data to validate
51,931
final public function getData ( $ toArray = false ) { if ( is_null ( $ this -> valid ) ) throw new \ Exception ( 'Form must be validated before you can get data' ) ; if ( $ toArray ) return ( $ this -> data ) ? $ this -> data : array ( ) ; else return ( $ this -> data ) ? new \ Object ( $ this -> data ) : new \ Object ...
Fetches the filtered data
51,932
public function render ( ) { $ rendered = '' ; foreach ( $ this -> elements as $ element ) { if ( ! method_exists ( $ this , 'openTag' ) ) { $ element -> name = $ this -> multiple ? $ element -> name . '[]' : $ this -> getName ( ) . '[' . $ element -> name . ']' ; $ element -> parent = $ this -> getName ( ) ; } $ rende...
Renders the elements of the fieldset out
51,933
public static function formatBytes ( $ bytes , $ precision = 2 ) { if ( $ bytes < 1024 ) { return $ bytes . ' B' ; } elseif ( $ bytes < 1048576 ) { return round ( $ bytes / 1024 , $ precision ) . ' KB' ; } elseif ( $ bytes < 1073741824 ) { return round ( $ bytes / 1048576 , $ precision ) . ' MB' ; } elseif ( $ bytes < ...
Convert size in bytes to human readable format
51,934
public function validate ( $ command ) { if ( $ command instanceof SelfValidating ) { return $ this -> container -> call ( [ $ command , 'validate' ] ) ; } $ validatorClass = $ this -> getValidatorClass ( $ command ) ; if ( ! $ validatorClass ) { return ; } $ validator = $ this -> container -> make ( $ validatorClass )...
Validate a command with its appropriate validator .
51,935
protected function loadBuffer ( ) { $ this -> remainder = 0 ; if ( $ this -> ended ) { return ; } while ( ! $ this -> stream -> eof ( ) && strlen ( $ this -> buffer ) < self :: BUFFER_SIZE ) { $ this -> buffer .= $ this -> stream -> read ( self :: BUFFER_SIZE ) ; } $ m = NULL ; if ( preg_match ( "'^\r?\n?([a-fA-F0-9]+)...
Load data of the next chunk into memory .
51,936
protected function wrap ( StorageInterface $ input , array $ definition ) { foreach ( $ definition as $ property => $ class ) { $ is_array = $ class { 0 } == '[' && $ class { 1 } == ']' ; $ class = ltrim ( $ class , '[]' ) ; $ value = $ input [ $ property ] ; if ( ! class_exists ( $ class ) || ! is_subclass_of ( $ clas...
Wrap input elements in classes
51,937
protected function getData ( $ key ) { $ query = $ this -> db -> query ( "SELECT value FROM cache WHERE key='" . $ this -> key ( $ key ) . "' AND expire >= datetime('now')" ) ; return $ query -> fetch ( ) ; }
Retrieves the data from the database
51,938
protected function writeData ( $ key , $ value , $ ttl ) { if ( ! is_numeric ( $ ttl ) || $ ttl < 0 ) throw new CacheException ( 'TTL invalid: ' . $ ttl ) ; if ( $ ttl == 0 ) $ expiration = "datetime('now', '+100 years')" ; else $ expiration = "datetime('now', '+{$ttl} seconds')" ; return $ this -> db -> queryExec ( "I...
Writes the data to the database
51,939
public function previous ( ) { $ this -> _itemValid = true ; if ( ! prev ( $ this -> _items ) ) { $ this -> _itemValid = false ; } else { $ this -> _itemPosition -- ; } }
set previous item as current item
51,940
public function parseFeed ( $ url , $ nativeOrder = false , $ force = false ) { require_once PATH_SYSTEM . '/vendors/SimplePie.php' ; $ feed = new SimplePie ( ) ; $ feed -> set_timeout ( $ this -> timeout ) ; $ feed -> set_feed_url ( $ url ) ; $ feed -> enable_order_by_date ( ! $ nativeOrder ) ; $ feed -> force_feed ( ...
Opens an RSS feed parses and loads the contents .
51,941
public function setUp ( $ kernelDir , FileLocatorInterface $ fileLocator ) { $ this -> kernelDir = realpath ( $ kernelDir ) ; $ this -> fileLocator = $ fileLocator ; }
abstract class setting up method
51,942
protected function resolveTargetFilePath ( $ target , $ basePath ) { switch ( true ) { case strpos ( $ target , '@' ) === 0 : $ targetPath = $ this -> fileLocator -> locate ( $ target ) ; break ; case strpos ( $ target , '/' ) === 0 : $ targetPath = sprintf ( '%s%s' , $ this -> kernelDir , $ target ) ; break ; default ...
resolve given target file path
51,943
public function getTypeId ( $ type , $ createIfMissing = true ) { if ( null === $ this -> types ) { $ this -> loadCache ( ) ; } if ( false === ( $ key = array_search ( $ type , $ this -> types , true ) ) ) { if ( ! $ createIfMissing ) { return null ; } try { $ this -> backend -> getConnection ( ) -> insert ( 'apb_msg_t...
Get type identifier
51,944
public function getType ( $ id ) { if ( null === $ id ) { return null ; } if ( null === $ this -> types ) { $ this -> loadCache ( ) ; } if ( ! isset ( $ this -> types [ $ id ] ) ) { $ this -> loadCache ( ) ; if ( ! isset ( $ this -> types [ $ id ] ) ) { $ this -> types [ $ id ] = false ; } } if ( false === $ this -> ty...
Get type from identifier
51,945
public function convertQueryCondition ( $ value ) { if ( null === $ value ) { return 0 ; } if ( ! is_array ( $ value ) ) { $ value = [ $ value ] ; } $ hasOperator = false ; if ( ! Misc :: isIndexed ( $ value ) ) { $ operator = array_keys ( $ value ) [ 0 ] ; $ values = $ value [ $ operator ] [ 0 ] ; $ hasOperator = true...
Convert given query condition value which is supposed to contain types identifiers to integer identifiers
51,946
public function getUsingFileTimestamps ( $ key ) { $ value = $ this -> get ( $ this -> cacheKey ( $ key ) ) ; $ timestamps = $ this -> get ( $ this -> cachetskey ( $ key ) ) ; if ( $ value !== false && $ timestamps !== false ) { foreach ( $ timestamps as $ file => $ timestamp ) { if ( filemtime ( $ file ) !== $ timesta...
get cache using key but check associated timestamps on cached file array
51,947
public function putUsingFileTimestamps ( $ key , $ value , array $ filenames , $ duration = null ) { if ( empty ( $ duration ) ) $ duration = 0 ; $ files = array ( ) ; foreach ( $ filenames as $ file ) { $ files [ $ file ] = filemtime ( $ file ) ; } $ timestamps = md5 ( $ files ) ; $ this -> put ( $ this -> cacheKey ( ...
put cache value into cache store using timestamps of supplied files as a tie on the validity of the cache
51,948
public function getFileContents ( $ filename ) { $ cachecontents = $ this -> get ( $ this -> cachefilekey ( $ filename ) ) ; if ( $ cachecontents !== false && is_array ( $ cachecontents ) ) { $ contents = array_key_exists ( 'v' , $ cachecontents ) ? $ cachecontents [ 'v' ] : false ; $ timestamp = array_key_exists ( 't'...
return the file contents but cache the results indefinitely break cache if timestamp changes
51,949
public function request ( $ type , $ url , $ args = [ ] ) { $ response = $ this -> getHTTPClient ( ) -> $ type ( $ url , $ args ) -> getBody ( ) -> getContents ( ) ; return json_decode ( $ response ) ; }
Our main request method to Montage . Uses Guzzle under the hood to make the request and will return the json_decoded response from Montage .
51,950
public function auth ( $ user = null , $ password = null ) { if ( $ this -> token ) return $ this ; if ( is_null ( $ user ) || is_null ( $ password ) ) { throw new MontageAuthException ( 'Must provide a username and password.' ) ; } try { $ response = $ this -> request ( 'post' , $ this -> url ( 'auth' ) , [ 'form_para...
Authenticate with Montage and set the local token .
51,951
public function url ( $ endpoint , $ schema = null , $ doc_id = null , $ file_id = null ) { return sprintf ( 'api/v%d/%s' , $ this -> version , $ this -> endpoint ( $ endpoint , $ schema , $ doc_id , $ file_id ) ) ; }
Gets a formatted Montage endpoint prefixed with api version .
51,952
private function getHTTPClient ( ) { $ config = [ 'base_uri' => sprintf ( 'http://%s.%s/' , $ this -> subdomain , $ this -> domain ) , 'headers' => [ 'Accept' => 'application/json' , 'User-Agent' => sprintf ( 'Montage PHP v%d' , $ this -> version ) , 'X-Requested-With' => 'XMLHttpRequest' ] ] ; if ( $ this -> token ) {...
Does what it says . Gets a guzzle client with an Authorization header set in case of an existing token .
51,953
private function endpoint ( $ endpoint , $ schema = null , $ doc_id = null , $ file_id = null ) { $ endpoints = [ 'auth' => 'auth/' , 'user' => 'auth/user/' , 'schema-list' => 'schemas/' , 'schema-detail' => 'schemas/%s/' , 'document-query' => 'schemas/%s/query/' , 'document-save' => 'schemas/%s/save/' , 'document-deta...
Creates a formatted Montage API endpoint string .
51,954
public function schemas ( $ schemaName = null ) { if ( is_null ( $ schemaName ) ) { $ url = $ this -> url ( 'schema-list' ) ; return $ this -> request ( 'get' , $ url ) ; } return $ this -> schema ( $ schemaName ) ; }
Get a list of all schemas for the given users token .
51,955
public static function hypotenuse ( Segment $ a , Segment $ b ) : Segment { $ hypotenuse = $ a -> length ( ) -> power ( new Integer ( 2 ) ) -> add ( $ b -> length ( ) -> power ( new Integer ( 2 ) ) ) -> squareRoot ( ) ; return new Segment ( $ hypotenuse ) ; }
Compute the hypotenuse for adjacent sides A and B
51,956
public static function adjacentSide ( Segment $ hypotenuse , Segment $ adjacentSide ) : Segment { $ side = $ hypotenuse -> length ( ) -> power ( new Integer ( 2 ) ) -> subtract ( $ adjacentSide -> length ( ) -> power ( new Integer ( 2 ) ) ) -> squareRoot ( ) ; return new Segment ( $ side ) ; }
Compute a side A or B from the hypotenuse and one side
51,957
public function createFromImportedData ( $ data ) { $ revision = new Revision ( ) ; $ revision -> setReleasedAt ( new \ DateTime ( $ data [ 'released_at' ] ) ) ; $ revision -> setReleasedBy ( $ data [ 'released_by' ] ) ; $ revision -> setComment ( $ data [ 'comment' ] ) ; foreach ( $ data [ 'groups' ] as $ groupData ) ...
Create Revision instance from imported data .
51,958
public function identQuote ( string $ name ) { return $ this -> iquotechar . str_replace ( $ this -> iquotechar , $ this -> iquotechar . $ this -> iquotechar , $ name ) . $ this -> iquotechar ; }
Quote the name of an identity
51,959
public function getName ( $ entity , $ quote = true ) { if ( is_object ( $ entity ) ) $ entity = $ entity -> getName ( ) ; if ( ! is_string ( $ entity ) ) throw new InvalidTypeException ( "Provide a string or a object with a getName method" ) ; $ entity = $ this -> table_prefix . $ entity ; return $ quote ? $ this -> i...
Return the identity name quoted and prefixed with the configured prefix .
51,960
public function truncateTable ( $ table ) { $ query = "TRUNCATE " . $ this -> getName ( $ table -> getName ( ) ) ; $ this -> db -> exec ( $ query ) ; return $ this ; }
Remove all rows from the table
51,961
public function toSQL ( Parameters $ params , Query \ Clause $ clause , bool $ inner_clause = false ) { $ params -> setDriver ( $ this ) ; return $ clause -> toSQL ( $ params , $ inner_clause ) ; }
Write an query clause as SQL query syntax
51,962
public static function fromNative ( ) { $ args = func_get_args ( ) ; $ hour = new Hour ( $ args [ 0 ] ) ; $ minute = new Minute ( $ args [ 1 ] ) ; $ second = new Second ( $ args [ 2 ] ) ; return new static ( $ hour , $ minute , $ second ) ; }
Returns a nee Time object from native int hour minute and second
51,963
public static function fromNativeDateTime ( \ DateTime $ time ) { $ hour = \ intval ( $ time -> format ( 'G' ) ) ; $ minute = \ intval ( $ time -> format ( 'i' ) ) ; $ second = \ intval ( $ time -> format ( 's' ) ) ; return static :: fromNative ( $ hour , $ minute , $ second ) ; }
Returns a new Time from a native PHP \ DateTime
51,964
public function sameValueAs ( ValueObjectInterface $ time ) { if ( false === Util :: classEquals ( $ this , $ time ) ) { return false ; } return $ this -> getHour ( ) -> sameValueAs ( $ time -> getHour ( ) ) && $ this -> getMinute ( ) -> sameValueAs ( $ time -> getMinute ( ) ) && $ this -> getSecond ( ) -> sameValueAs ...
Tells whether two Time are equal by comparing their values
51,965
public static function factory ( $ resource = '' , $ size = null ) { $ type = gettype ( $ resource ) ; if ( $ type == 'string' ) { $ stream = fopen ( 'php://temp' , 'r+' ) ; if ( $ resource !== '' ) { fwrite ( $ stream , $ resource ) ; fseek ( $ stream , 0 ) ; } return new self ( $ stream ) ; } if ( $ type == 'resource...
Create a new stream based on the input type
51,966
protected function getModuleInfo ( ) : array { if ( $ this -> moduleInfo === null ) { $ this -> moduleInfo = $ this -> package ( ) -> getExtra ( ) [ 'module' ] ?? [ ] ; } return $ this -> moduleInfo ; }
Resolve module info
51,967
protected function resolveTitle ( ) : string { $ title = trim ( $ this -> getModuleInfo ( ) [ 'title' ] ?? '' ) ; if ( empty ( $ title ) ) { $ name = substr ( $ this -> name , strpos ( $ this -> name , '/' ) + 1 ) ; $ name = array_map ( function ( $ value ) { return strtolower ( $ value ) ; } , explode ( '-' , $ name )...
Resolve module s title
51,968
protected function resolveDirectory ( string $ name ) : string { $ dir = rtrim ( $ this -> manager -> vendorDir ( ) , DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR ; $ dir .= rtrim ( implode ( DIRECTORY_SEPARATOR , explode ( '/' , $ name ) ) , DIRECTORY_SEPARATOR ) ; return $ dir ; }
Resolve module s directory
51,969
protected function resolveCollector ( ) : ? string { $ value = $ this -> getModuleInfo ( ) [ 'collector' ] ?? null ; return is_string ( $ value ) ? $ value : null ; }
Resolve collector class
51,970
protected function resolveInstaller ( ) : ? string { $ value = $ this -> getModuleInfo ( ) [ 'installer' ] ?? null ; return is_string ( $ value ) ? $ value : null ; }
Resolve installer class
51,971
protected function resolveAssets ( ) : ? string { $ module = $ this -> getModuleInfo ( ) ; if ( ! isset ( $ module [ 'assets' ] ) ) { return null ; } $ directory = $ this -> directory ( ) . DIRECTORY_SEPARATOR . trim ( $ module [ 'assets' ] , DIRECTORY_SEPARATOR ) ; return is_dir ( $ directory ) ? realpath ( $ director...
Resolve assets dir
51,972
private function initTableTypes ( ) { $ this -> tableTypes = [ ] ; foreach ( $ this -> loadTableTypes ( ) as $ type ) { if ( ! $ type instanceof TableTypeInterface ) { throw new UnexpectedTypeException ( $ type , TableTypeInterface :: class ) ; } $ this -> tableTypes [ get_class ( $ type ) ] = $ type ; } }
Initializes the table types .
51,973
private function initTableTypeExtensions ( ) { $ this -> tableTypeExtensions = [ ] ; foreach ( $ this -> loadTableTypeExtensions ( ) as $ extension ) { if ( ! $ extension instanceof TableTypeExtensionInterface ) { throw new UnexpectedTypeException ( $ extension , TableTypeExtensionInterface :: class ) ; } $ type = $ ex...
Initializes the table type extensions .
51,974
private function initColumnTypes ( ) { $ this -> columnTypes = [ ] ; foreach ( $ this -> loadColumnTypes ( ) as $ type ) { if ( ! $ type instanceof ColumnTypeInterface ) { throw new UnexpectedTypeException ( $ type , ColumnTypeInterface :: class ) ; } $ this -> columnTypes [ get_class ( $ type ) ] = $ type ; } }
Initializes the column types .
51,975
private function initColumnTypeExtensions ( ) { $ this -> columnTypeExtensions = [ ] ; foreach ( $ this -> loadColumnTypeExtensions ( ) as $ extension ) { if ( ! $ extension instanceof ColumnTypeExtensionInterface ) { throw new UnexpectedTypeException ( $ extension , ColumnTypeExtensionInterface :: class ) ; } $ type =...
Initializes the column type extensions .
51,976
private function initFilterTypes ( ) { $ this -> filterTypes = [ ] ; foreach ( $ this -> loadFilterTypes ( ) as $ type ) { if ( ! $ type instanceof FilterTypeInterface ) { throw new UnexpectedTypeException ( $ type , FilterTypeInterface :: class ) ; } $ this -> filterTypes [ get_class ( $ type ) ] = $ type ; } }
Initializes the filter types .
51,977
private function initFilterTypeExtensions ( ) { $ this -> filterTypeExtensions = [ ] ; foreach ( $ this -> loadFilterTypeExtensions ( ) as $ extension ) { if ( ! $ extension instanceof FilterTypeExtensionInterface ) { throw new UnexpectedTypeException ( $ extension , FilterTypeExtensionInterface :: class ) ; } $ type =...
Initializes the filter type extensions .
51,978
private function initActionTypes ( ) { $ this -> actionTypes = [ ] ; foreach ( $ this -> loadActionTypes ( ) as $ type ) { if ( ! $ type instanceof ActionTypeInterface ) { throw new UnexpectedTypeException ( $ type , ActionTypeInterface :: class ) ; } $ this -> actionTypes [ get_class ( $ type ) ] = $ type ; } }
Initializes the action types .
51,979
private function initActionTypeExtensions ( ) { $ this -> actionTypeExtensions = [ ] ; foreach ( $ this -> loadActionTypeExtensions ( ) as $ extension ) { if ( ! $ extension instanceof ActionTypeExtensionInterface ) { throw new UnexpectedTypeException ( $ extension , ActionTypeExtensionInterface :: class ) ; } $ type =...
Initializes the action type extensions .
51,980
private function initAdapterFactories ( ) { $ this -> adapterFactories = [ ] ; foreach ( $ this -> loadAdapterFactories ( ) as $ adapter ) { if ( ! $ adapter instanceof AdapterFactoryInterface ) { throw new UnexpectedTypeException ( $ adapter , AdapterFactoryInterface :: class ) ; } $ this -> adapterFactories [ get_cla...
Initializes the adapter factories .
51,981
public function getEnumOptions ( $ oid ) { $ query = new Query ( "SELECT enumlabel FROM pg_enum WHERE enumtypid = %oid:int%" , array ( 'oid' => $ oid ) ) ; return $ this -> db -> query ( $ query ) -> fetch ( ) ; }
Get array of enum options
51,982
public function findByName ( $ name ) { $ result = $ this -> db -> query ( new Query ( <<<SQLSELECT t.oid AS oid, t.typname AS name, n.nspname as "schema", t.typlen AS length, t.typtype AS type, t.typcategory AS category, t.typarray AS "arrayType", t.typdefault AS default, t.typdefaultbin AS...
Init a type by it s name . Most likely used for enum types
51,983
public function isDirty ( ) : bool { foreach ( $ this -> __state as $ prop => $ val ) { if ( $ this -> isModified ( $ prop ) ) { return true ; } } return false ; }
Returns true if any of the model s properties was modified .
51,984
public static function removeDir ( $ path ) { if ( is_file ( $ path ) ) { unlink ( $ path ) ; } else { foreach ( scandir ( $ path ) as $ dir ) { if ( $ dir === '.' || $ dir === '..' ) { continue ; } static :: removeDir ( $ path . '/' . $ dir ) ; } rmdir ( $ path ) ; } }
Recursive remove dir
51,985
public static function recurseCopyIfEdited ( $ src = '' , $ dst = '' , array $ excludes = [ 'php' ] ) { if ( ! is_dir ( $ dst ) && ( ! mkdir ( $ dst ) && ! is_dir ( $ dst ) ) ) { throw new Exception ( 'Copy dir error, access denied for path: ' . $ dst ) ; } $ dir = opendir ( $ src ) ; if ( ! $ dir ) { throw new Excepti...
Recursive copy files if edited
51,986
public function start ( ) { if ( $ this -> active ) return $ this ; if ( PHP_SAPI === "cli" ) { $ this -> startCLISession ( ) ; } else { $ this -> startHTTPSession ( ) ; } if ( ! $ this -> has ( 'session_mgmt' , 'start_time' ) ) $ this -> set ( 'session_mgmt' , 'start_time' , time ( ) ) ; return $ this ; }
Actually start the session
51,987
public function setSessionID ( string $ session_id ) { if ( ! defined ( 'WEDETO_TEST' ) || WEDETO_TEST === 0 ) throw new \ RuntimeException ( "Cannot change the session ID" ) ; $ this -> session_id = $ session_id ; return $ this ; }
Change the session ID useful for tests . Disallowed in normal operation .
51,988
public function startHTTPSession ( ) { if ( session_status ( ) === PHP_SESSION_DISABLED ) throw new \ RuntimeException ( "Sesssions are disabled" ) ; if ( session_status ( ) === PHP_SESSION_ACTIVE ) throw new \ LogicException ( "Repeated session initialization" ) ; session_set_cookie_params ( $ this -> lifetime , $ thi...
Set up a HTTP session using cookies and the PHP session machinery
51,989
private function secureSession ( ) { $ expired = false ; if ( $ this -> has ( 'session_mgmt' , 'destroyed' ) ) { $ when = $ this -> get ( 'session_mgmt' , 'destroyed' ) ; $ ua = $ this -> get ( 'session_mgmt' , 'last_ua' ) ; $ ip = $ this -> get ( 'session_mgmt' , 'last_ip' ) ; $ now = time ( ) ; $ diff = $ now - $ whe...
Secure the session
51,990
public function resetID ( ) { if ( session_status ( ) === PHP_SESSION_ACTIVE ) { $ this -> set ( 'session_mgmt' , 'destroyed' , time ( ) ) ; $ auth = $ this -> get ( 'authentication' ) ; if ( $ auth ) unset ( $ this [ 'authentication' ] ) ; $ new_session_id = self :: create_new_id ( ) ; $ this -> set ( 'session_mgmt' ,...
Should be called when the session ID should be changed for example after logging in or out .
51,991
private static function create_new_id ( string $ prefix = "Wedeto" ) { if ( version_compare ( PHP_VERSION , '7.1.0' ) > 0 ) return session_create_id ( $ prefix ) ; return $ prefix . bin2hex ( random_bytes ( 16 ) ) ; }
Helper function . PHP 7 . 1 introduces session_create_id function . This is used in PHP 7 . 1 but a fallback using random_bytes is used on PHP 7 . 0 .
51,992
public function destroy ( ) { if ( $ this -> active ) { $ this -> clear ( ) ; if ( session_status ( ) === PHP_SESSION_ACTIVE ) session_commit ( ) ; $ this -> active = false ; } return $ this ; }
Should be called when the session should be cleared and destroyed .
51,993
public static function init ( ) { self :: add ( self :: HEADER_SET_COOKIE , '__Host-sess=' . session_id ( ) . '; path=' . Request :: $ subfolders . '; Secure; HttpOnly; SameSite;' ) ; if ( Request :: isSecure ( ) ) { self :: add ( self :: HEADER_CONTENT_SECURITY_POLICY , self :: HEADER_CONTENT_SECURITY_POLICY_CONTENT_S...
Adds content security policy headers
51,994
public static function parseParams ( $ url_parsed ) { $ vid = FALSE ; $ url_seperator = FALSE ; if ( preg_match ( '/^\/watch$/' , $ url_parsed [ 'path' ] ) ) { $ fragment_regex = '/^\!v\=([a-zA-Z0-9]+).*$/' ; if ( isset ( $ url_parsed [ 'fragment' ] ) && preg_match ( $ fragment_regex , $ url_parsed [ 'fragment' ] ) ) {...
helper function extract video id and other parameters from url
51,995
public function update ( $ name , $ is_public , $ is_archived , $ is_guest_accessible , $ topic , $ owner_user_id ) { $ queryParams = array ( 'name' => $ name , 'privacy' => ( ( $ is_public === true ) ? 'public' : 'private' ) , 'is_archived' => $ is_archived , 'is_guest_accessible' => $ is_guest_accessible , 'topic' =>...
Update room All values are required!
51,996
public function setTopic ( $ topic ) { $ queryParams = array ( 'topic' => $ topic , ) ; $ room_id_or_name = $ this -> getId ( ) ; $ response = $ this -> request -> put ( 'room/' . $ room_id_or_name . '/topic' , $ queryParams ) ; return $ this -> request -> returnResponseObject ( $ response ) ; }
Set room topic
51,997
public function errorAction ( ) { $ validationResults = $ this -> arguments -> getValidationResults ( ) -> getFlattenedErrors ( ) ; $ result = array ( ) ; foreach ( $ validationResults as $ key => $ validationResult ) { foreach ( $ validationResult as $ error ) { $ translatedMessage = $ this -> translator -> translateB...
Return validation results as json
51,998
protected function interact ( InputInterface $ input , OutputInterface $ output ) { $ questionHelper = $ this -> getHelper ( 'question' ) ; $ formatter = $ this -> getHelper ( 'formatter' ) ; $ rootDir = $ this -> getRootDir ( ) ; $ fs = new Filesystem ( ) ; $ appPath = explode ( '/' , $ rootDir ) ; $ appName = $ appPa...
Configures deployment .
51,999
protected function initConfig ( Filesystem $ fs , $ rootDir ) { $ bundleDir = $ this -> getBundleVendorDir ( ) ; $ path = $ this -> getCapistranoDir ( ) ; if ( ! $ fs -> exists ( $ path . '/deploy.rb' ) || ! $ fs -> exists ( $ path . '/deploy/production.rb' ) ) { return $ fs -> mirror ( $ bundleDir . '/Resources/config...
Dump capistrano configuration skin from Resources directory .