idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
55,100
public function tail ( ) { $ last = count ( $ this -> parts ) - 1 ; if ( $ last < 0 ) { return null ; } return $ this -> parts [ $ last ] ; }
Take a look at the last part of the Message .
55,101
public function append ( $ parts ) { if ( $ parts instanceof Message ) { $ parts = $ parts -> toArray ( ) ; } elseif ( ! is_array ( $ parts ) ) { throw new \ Exception ( 'Trying to append non array (' . gettype ( $ parts ) . ').' ) ; } $ this -> parts = array_merge ( $ this -> parts , $ parts ) ; return $ this ; }
Append a the given parts to the Message .
55,102
public function prependRoutingInformation ( array $ routing ) { $ count = count ( $ routing ) ; if ( 0 == $ count ) { return ; } $ count -- ; while ( ! $ routing [ $ count ] ) { unset ( $ routing [ $ count ] ) ; $ count -- ; } $ routing [ ] = '' ; $ this -> routing = array_merge ( $ routing , $ this -> routing ) ; }
Prepend the given routing information to the Message .
55,103
public function stripRoutingInformation ( ) { if ( ! $ this -> hasRoutingInformation ( ) ) { return $ this ; } while ( true ) { $ part = array_shift ( $ this -> parts ) ; if ( ! $ part ) { break ; } $ this -> routing [ ] = $ part ; } return $ this ; }
Strips first routing headers from this message . This function assumes there is a routing header present results can be unexpected if not .
55,104
protected function createProcess ( string $ cmd , string $ cwd ) : Process { $ process = $ this -> processFactory -> getProcess ( $ cmd , $ cwd , $ this -> discoverSystemEnvironment ( ) ) ; $ process -> setTimeout ( null ) ; return $ process ; }
Creates a new process for the execution of a command .
55,105
protected function discoverSystemEnvironment ( ) { $ env = [ ] ; $ output = shell_exec ( 'env' ) ; if ( $ output ) { $ lines = explode ( "\n" , $ output ) ; foreach ( $ lines as $ line ) { $ values = explode ( '=' , $ line ) ; if ( ! empty ( $ values [ 0 ] ) && ! empty ( $ values [ 1 ] ) ) { $ env [ $ values [ 0 ] ] = $ values [ 1 ] ; } } } return $ env ; }
Discovers the current system environment and returns it .
55,106
protected function convertToDateTime ( $ date ) { if ( $ date instanceof \ DateTime ) { return $ date ; } if ( is_string ( $ date ) ) { return new \ DateTime ( $ date ) ; } throw new TransformationFailure ( 'YAML Front Matter dates must be quoted.' ) ; }
YAML dates should be quoted . They must be proper iso8601 if they are not quoted .
55,107
public function getOption ( $ key = null ) { if ( is_null ( $ key ) ) { return $ this -> defaultParams ; } return $ this -> defaultParams [ $ key ] ; }
return all configuration or only given key value
55,108
public function parseControllerString ( $ controllerString ) { $ partsArray = explode ( '@' , $ controllerString ) ; if ( count ( $ partsArray ) > 2 ) { throw new \ Exception ( "Error parsing controller string, too many @'s found. Only use one to destinguish the controller method." , 1 ) ; } else { if ( strpos ( $ partsArray [ 0 ] , ':' ) ) { $ parts = explode ( ':' , $ partsArray [ 0 ] ) ; $ this -> controller_name = array_pop ( $ parts ) ; $ this -> controller = $ this -> controller_name . '.php' ; $ this -> controller_path = implode ( '\\' , $ parts ) ; } else { $ this -> controller_name = $ partsArray [ 0 ] ; $ this -> controller = $ this -> controller_name . '.php' ; } $ this -> action = $ partsArray [ 1 ] ; } }
Gets parts of route controller string
55,109
public function compilePath ( $ path ) { if ( preg_match_all ( '/\{(\w+)\}/' , $ path , $ matches , PREG_SET_ORDER ) == false ) { return $ path ; } else { foreach ( $ matches as $ match ) { $ this -> params [ ] = $ match [ 1 ] ; } $ static = preg_replace ( '/\{(\w+)\}/i' , "" , $ path ) ; $ static = rtrim ( $ static , '/' ) ; $ path = '/' . str_replace ( '/' , '\/' , $ path ) . '/' ; $ regex = preg_replace ( '/\{(\w+)\}/' , '(\w+)' , $ path ) ; $ this -> static_path = $ static ; $ this -> regex = $ regex ; } }
Compiles route path
55,110
public function toArray ( $ filter = ReflectionProperty :: IS_PROTECTED ) { $ objectArray = [ ] ; $ ref = new ReflectionClass ( $ this ) ; $ properties = $ ref -> getProperties ( $ filter ) ; foreach ( $ properties as $ property ) { $ propertyName = $ property -> getName ( ) ; if ( isset ( $ this -> $ propertyName ) ) { $ objectArray [ $ propertyName ] = $ this -> $ propertyName ; } } return $ objectArray ; }
Convert the current object to array
55,111
public function parent ( $ node = null ) { if ( $ node ) { $ parents = $ this -> xpath ( 'ancestor-or-self::' . $ node ) ; } else { $ parents = $ this -> xpath ( 'parent::*' ) ; } return $ parents [ 0 ] ; }
Gets the parent or a preferred ancestor of the current element .
55,112
public static function getDependency ( $ locale ) { $ locale = PropelL10n :: normalize ( $ locale ) ; if ( self :: hasDependency ( $ locale ) ) { return self :: $ dependencies [ $ locale ] ; } return null ; }
Returns the dependency for the given locale or null if locale doesn t exist
55,113
public static function hasDependency ( $ locale ) { $ locale = PropelL10n :: normalize ( $ locale ) ; return isset ( self :: $ dependencies [ $ locale ] ) ; }
Checks wether there is a dependency registered for the given locale
55,114
public static function countDependencies ( $ locale ) { $ locale = PropelL10n :: normalize ( $ locale ) ; $ count = 0 ; while ( isset ( self :: $ dependencies [ $ locale ] ) ) { $ locale = self :: $ dependencies [ $ locale ] ; $ count ++ ; } return $ count ; }
Counts the dependencies a locale may have .
55,115
public static function factory ( $ config = array ( ) ) { $ default = array ( 'base_url' => 'https://bitpay.com/api' , ) ; $ required = array ( 'apiKey' ) ; $ config = Collection :: fromConfig ( $ config , $ default , $ required ) ; $ client = new self ( $ config -> get ( 'base_url' ) , $ config ) ; $ client -> setDescription ( ServiceDescription :: factory ( __DIR__ . DIRECTORY_SEPARATOR . 'client.json' ) ) ; $ client -> setDefaultOption ( 'auth' , array ( $ config [ 'apiKey' ] , '' , 'Basic' ) ) ; return $ client ; }
Factory method to create a new Bitpay client
55,116
public function createInvoice ( $ parameters ) { if ( array_key_exists ( 'posData' , $ parameters ) ) { $ parameters = $ this -> hashPosData ( $ parameters ) ; } return $ this -> getCommand ( 'createInvoice' , $ parameters ) -> getResult ( ) ; }
Create a new BitPay invoice
55,117
public function verifyNotification ( $ jsonString ) { if ( ! $ jsonString ) { throw new CallbackJsonMissingException ( ) ; } $ json = json_decode ( $ jsonString , true ) ; if ( ! is_array ( $ json ) ) { throw new CallbackInvalidJsonException ( ) ; } if ( ! array_key_exists ( 'posData' , $ json ) ) { throw new CallbackPosDataMissingException ( ) ; } $ posData = json_decode ( $ json [ 'posData' ] , true ) ; if ( $ posData [ 'hash' ] != $ this -> generateHash ( serialize ( $ posData [ 'posData' ] ) ) ) { throw new CallbackBadHashException ( ) ; } $ json [ 'posData' ] = $ posData [ 'posData' ] ; return Invoice :: fromArray ( $ json ) ; }
Call from your notification handler to convert raw post data to an array containing invoice data
55,118
private function generateHash ( $ data ) { $ key = $ this -> getConfig ( 'apiKey' ) ; $ hmac = base64_encode ( hash_hmac ( 'sha256' , $ data , $ key , true ) ) ; return strtr ( $ hmac , array ( '+' => '-' , '/' => '_' , '=' => '' ) ) ; }
Generate Callback hash
55,119
private function hashPosData ( $ parameters ) { $ hashedPosData = array ( 'posData' => $ parameters [ 'posData' ] ) ; $ hashedPosData [ 'hash' ] = $ this -> generateHash ( serialize ( $ parameters [ 'posData' ] ) ) ; $ parameters [ 'posData' ] = json_encode ( $ hashedPosData ) ; if ( strlen ( $ parameters [ 'posData' ] ) > self :: POS_DATA_MAX_LENGTH ) { throw new PosDataLengthException ( 'posData cannot exceed ' . self :: POS_DATA_MAX_LENGTH . ' characters (including hash)' ) ; } return $ parameters ; }
Hash the posData
55,120
public function make ( $ module , $ action = "" , $ id = null , $ params = [ ] ) { $ url = URL_ABSOLUTE . $ module ; if ( $ action !== "" ) { $ url .= '-' . $ action ; if ( $ id !== null ) { $ url .= '-' . $ id ; } } $ first = true ; foreach ( $ params as $ i => $ param ) { if ( $ first ) { $ url .= "?" ; $ first = false ; } else { $ url .= "&" ; } $ url .= $ i . "=" . $ param ; } return $ url ; }
make an url for page
55,121
public function updateInverse ( AbstractModel $ foreign ) { $ rel = $ this -> getRel ( ) -> getInverseOfRel ( ) ; if ( $ rel instanceof UpdateInverseInterface ) { $ rel -> updateInverse ( $ this -> getModel ( ) , $ foreign ) ; } }
Call updateInverse on the rel
55,122
public function createGroup ( $ name , $ overwrite = false ) { if ( isset ( $ this -> groups [ $ name ] ) ) { return $ this -> groups [ $ name ] ; } $ assets = $ this -> createAssetArray ( $ name ) ; $ filters = $ this -> createFilterArray ( $ name ) ; $ coll = new AssetCollection ( $ assets , $ filters ) ; if ( $ output = $ this -> getConfig ( $ name , 'output' ) ) { $ coll -> setTargetPath ( $ output ) ; } $ write_output = true ; if ( ! $ overwrite ) { if ( file_exists ( $ output = public_path ( $ coll -> getTargetPath ( ) ) ) ) { $ output_mtime = filemtime ( $ output ) ; $ asset_mtime = $ coll -> getLastModified ( ) ; if ( $ asset_mtime && $ output_mtime >= $ asset_mtime ) { $ write_output = false ; } } } if ( $ overwrite || $ write_output ) { $ writer = new AssetWriter ( public_path ( ) ) ; $ writer -> writeAsset ( $ coll ) ; } return $ this -> groups [ $ name ] = $ coll ; }
Create a new AssetCollection instance for the given group .
55,123
public function url ( $ name , array $ options = null ) { $ options = is_null ( $ options ) ? array ( ) : $ options ; $ group = $ this -> createGroup ( $ name ) ; $ cache_buster = '' ; if ( array_get ( $ options , 'md5' , $ this -> md5 ) ) { $ cache_buster = '?' . md5_file ( $ this -> file ( $ name ) ) ; } $ secure = array_get ( $ options , 'secure' , $ this -> secure ) ; return URL :: asset ( $ group -> getTargetPath ( ) , $ secure ) . $ cache_buster ; }
Generate the URL for a given asset group .
55,124
protected function createAssetArray ( $ name ) { $ config = $ this -> getConfig ( $ name , 'assets' , array ( ) ) ; $ assets = array ( ) ; foreach ( $ config as $ asset ) { if ( $ this -> assets -> has ( $ asset ) ) { $ assets [ ] = $ this -> assets -> get ( $ asset ) ; } elseif ( str_contains ( $ asset , array ( '/' , '.' , '-' ) ) ) { $ assets [ ] = $ this -> parseAssetDefinition ( $ asset ) ; } else { throw new \ InvalidArgumentException ( "No asset '$asset' defined" ) ; } } return $ assets ; }
Create an array of AssetInterface objects for a group .
55,125
protected function createFilterArray ( $ name ) { $ config = $ this -> getConfig ( $ name , 'filters' , array ( ) ) ; $ filters = array ( ) ; foreach ( $ config as $ filter ) { $ filters [ ] = $ this -> filters -> get ( $ filter ) ; } return $ filters ; }
Create an array of FilterInterface objects for a group .
55,126
protected function createFilterManager ( ) { $ manager = new FilterManager ( ) ; $ filters = Config :: get ( $ this -> namespace . '::filters' , array ( ) ) ; foreach ( $ filters as $ name => $ filter ) { $ manager -> set ( $ name , $ this -> createFilter ( $ filter ) ) ; } return $ this -> filters = $ manager ; }
Creates the filter manager from the config file s filter array .
55,127
protected function createFilter ( $ filter ) { if ( is_callable ( $ filter ) ) { return call_user_func ( $ filter ) ; } elseif ( is_string ( $ filter ) ) { return new $ filter ( ) ; } elseif ( is_object ( $ filter ) ) { return $ filter ; } else { throw new \ InvalidArgumentException ( "Cannot convert $filter to filter" ) ; } }
Create a filter object from a value in the config file .
55,128
protected function parseAssetDefinition ( $ asset ) { if ( starts_with ( $ asset , 'http://' ) ) { return new HttpAsset ( $ asset ) ; } elseif ( str_contains ( $ asset , array ( '*' , '?' ) ) ) { return new GlobAsset ( $ this -> absolutePath ( $ asset ) ) ; } else { return new FileAsset ( $ this -> absolutePath ( $ asset ) ) ; } }
Create an asset object from a string definition .
55,129
public function getColumns ( ) { $ columns = $ this -> builder ( ) -> queryWithBinding ( Expressions :: getColumns ( $ this -> tableName ) ) -> get ( ) -> all ( ) ; $ _columns = [ ] ; foreach ( $ columns as $ column ) { $ _columns [ ] = Repository :: getPlatformColumn ( $ column ) ; } return $ _columns ; }
Returns columns in a table .
55,130
protected function runQueryWithExpression ( String $ expresison , int $ type = 1 ) { $ query = $ this -> builder ( ) -> query ( $ expresison , $ type ) ; Scheme :: destroyColumns ( ) ; return $ query ; }
Processes a raw query .
55,131
protected function addForeign ( String $ definition ) { $ this -> runQueryWithExpression ( Expressions :: addForeign ( $ this -> tableName , $ definition ) ) ; }
Add foreign key to table .
55,132
public function getAkas ( ) { if ( true === $ this -> isReady ) { $ sCacheFile = $ this -> sRoot . '/cache/' . md5 ( $ this -> iId ) . '_akas.cache' ; $ bUseCache = false ; if ( is_readable ( $ sCacheFile ) ) { $ iDiff = round ( abs ( time ( ) - filemtime ( $ sCacheFile ) ) / 60 ) ; if ( $ iDiff < $ this -> iCache || false ) { if ( true === self :: IMDB_DEBUG ) { echo '<pre><b>Using cache:</b> ' . basename ( $ sCacheFile ) . '</pre>' ; } $ bUseCache = true ; $ sSource = file_get_contents ( $ sCacheFile ) ; } } if ( $ bUseCache ) { if ( IMDB :: IMDB_DEBUG ) { echo '<b>- Using cache for Akas from ' . $ sCacheFile . '</b><br>' ; } $ aRawReturn = file_get_contents ( $ sCacheFile ) ; $ aReturn = unserialize ( $ aRawReturn ) ; return IMDBHelper :: arrayOutput ( $ this -> bArrayOutput , $ this -> sSeparator , $ this -> sNotFound , $ aReturn ) ; } else { $ fullAkas = sprintf ( 'http://www.imdb.com/title/tt%s/releaseinfo' , $ this -> iId ) ; $ aCurlInfo = IMDBHelper :: runCurl ( $ fullAkas ) ; $ sSource = $ aCurlInfo [ 'contents' ] ; if ( false === $ sSource ) { if ( true === self :: IMDB_DEBUG ) { echo '<pre><b>cURL error:</b> ' . var_dump ( $ aCurlInfo ) . '</pre>' ; } return false ; } $ aReturned = IMDBHelper :: matchRegex ( $ sSource , "~<td>(.*?)<\/td>\s+<td>(.*?)<\/td>~" ) ; if ( $ aReturned ) { $ aReturn = array ( ) ; foreach ( $ aReturned [ 1 ] as $ i => $ strName ) { if ( strpos ( $ strName , '(' ) === false ) { $ aReturn [ ] = array ( 'title' => IMDBHelper :: cleanString ( $ aReturned [ 2 ] [ $ i ] ) , 'country' => IMDBHelper :: cleanString ( $ strName ) ) ; } } file_put_contents ( $ sCacheFile , serialize ( $ aReturn ) ) ; return IMDBHelper :: arrayOutput ( $ this -> bArrayOutput , $ this -> sSeparator , $ this -> sNotFound , $ aReturn ) ; } } } return IMDBHelper :: arrayOutput ( $ this -> bArrayOutput , $ this -> sSeparator , $ this -> sNotFound ) ; }
Returns all local names
55,133
private function fetchChildrenResources ( array & $ data , Context $ context ) { $ resourceName = $ this -> config -> getResourceName ( ) ; $ resource = $ context -> getResource ( $ resourceName ) ; $ childrenConfigurations = $ this -> get ( 'ekyna_admin.pool_registry' ) -> getChildren ( $ this -> config ) ; foreach ( $ childrenConfigurations as $ childConfig ) { $ childResourceName = $ childConfig -> getResourceName ( true ) ; if ( ! array_key_exists ( $ childResourceName , $ data ) ) { $ customizeQb = null ; $ metadata = $ this -> get ( $ childConfig -> getServiceKey ( 'metadata' ) ) ; if ( $ metadata -> hasAssociation ( $ resourceName ) ) { $ mapping = $ metadata -> getAssociationMapping ( $ resourceName ) ; if ( $ mapping [ 'type' ] === ClassMetadataInfo :: MANY_TO_ONE ) { $ customizeQb = function ( QueryBuilder $ qb , $ alias ) use ( $ resourceName , $ resource ) { $ qb -> andWhere ( sprintf ( $ alias . '.%s = :resource' , $ resourceName ) ) -> setParameter ( 'resource' , $ resource ) ; } ; } else { throw new \ RuntimeException ( sprintf ( '"%s" is not a supported association type.' , $ childResourceName ) ) ; } } else { throw new \ RuntimeException ( sprintf ( 'Association "%s" not found.' , $ childResourceName ) ) ; } $ table = $ this -> getTableFactory ( ) -> createBuilder ( $ childConfig -> getTableType ( ) , [ 'name' => $ childConfig -> getId ( ) , 'customize_qb' => $ customizeQb , ] ) -> getTable ( $ context -> getRequest ( ) ) ; $ data [ $ childResourceName ] = $ table -> createView ( ) ; } } }
Fetches children resources .
55,134
protected function createNewResourceForm ( Context $ context , $ footer = true , array $ options = [ ] ) { $ resource = $ context -> getResource ( ) ; $ action = $ this -> generateResourcePath ( $ resource , 'new' ) ; $ form = $ this -> createForm ( $ this -> config -> getFormType ( ) , $ resource , array_merge ( [ 'action' => $ action , 'method' => 'POST' , 'attr' => [ 'class' => 'form-horizontal form-with-tabs' ] , 'admin_mode' => true , '_redirect_enabled' => true , ] , $ options ) ) ; if ( $ footer ) { $ referer = $ context -> getRequest ( ) -> headers -> get ( 'referer' ) ; if ( 0 < strlen ( $ referer ) && false === strpos ( $ referer , $ action ) ) { $ cancelPath = $ referer ; } else { if ( $ this -> hasParent ( ) ) { $ cancelRoute = $ this -> getParent ( ) -> getConfiguration ( ) -> getRoute ( 'show' ) ; } else { $ cancelRoute = $ this -> config -> getRoute ( 'list' ) ; } $ cancelPath = $ this -> generateUrl ( $ cancelRoute , $ context -> getIdentifiers ( ) ) ; } $ form -> add ( 'actions' , 'form_actions' , [ 'buttons' => [ 'saveAndList' => [ 'type' => 'submit' , 'options' => [ 'button_class' => 'primary' , 'label' => 'ekyna_core.button.save_and_list' , 'attr' => [ 'icon' => 'list' ] , ] , ] , 'save' => [ 'type' => 'submit' , 'options' => [ 'button_class' => 'primary' , 'label' => 'ekyna_core.button.save' , 'attr' => [ 'icon' => 'ok' ] , ] , ] , 'cancel' => [ 'type' => 'button' , 'options' => [ 'label' => 'ekyna_core.button.cancel' , 'button_class' => 'default' , 'as_link' => true , 'attr' => [ 'class' => 'form-cancel-btn' , 'icon' => 'remove' , 'href' => $ cancelPath , ] , ] , ] , ] , ] ) ; } return $ form ; }
Creates the new resource form .
55,135
protected function createRemoveResourceForm ( Context $ context , $ message = null , $ footer = true , array $ options = [ ] ) { if ( null === $ message ) { $ message = 'ekyna_core.message.remove_confirm' ; } $ resource = $ context -> getResource ( ) ; $ action = $ this -> generateResourcePath ( $ resource , 'remove' ) ; $ form = $ this -> createFormBuilder ( null , array_merge ( [ 'action' => $ action , 'attr' => [ 'class' => 'form-horizontal' ] , 'method' => 'POST' , 'admin_mode' => true , '_redirect_enabled' => true , ] , $ options ) ) -> add ( 'confirm' , 'checkbox' , [ 'label' => $ message , 'attr' => [ 'align_with_widget' => true ] , 'required' => true , 'constraints' => [ new Constraints \ IsTrue ( ) , ] ] ) -> getForm ( ) ; if ( $ footer ) { $ referer = $ context -> getRequest ( ) -> headers -> get ( 'referer' ) ; if ( 0 < strlen ( $ referer ) && false === strpos ( $ referer , $ action ) ) { $ cancelPath = $ referer ; } else { if ( $ this -> hasParent ( ) ) { $ cancelPath = $ this -> generateUrl ( $ this -> getParent ( ) -> getConfiguration ( ) -> getRoute ( 'show' ) , $ context -> getIdentifiers ( ) ) ; } else { $ cancelPath = $ this -> generateResourcePath ( $ resource ) ; } } $ form -> add ( 'actions' , 'form_actions' , [ 'buttons' => [ 'remove' => [ 'type' => 'submit' , 'options' => [ 'button_class' => 'danger' , 'label' => 'ekyna_core.button.remove' , 'attr' => [ 'icon' => 'trash' ] , ] , ] , 'cancel' => [ 'type' => 'button' , 'options' => [ 'label' => 'ekyna_core.button.cancel' , 'button_class' => 'default' , 'as_link' => true , 'attr' => [ 'class' => 'form-cancel-btn' , 'icon' => 'remove' , 'href' => $ cancelPath , ] , ] , ] , ] , ] ) ; } return $ form ; }
Creates the remove resource form .
55,136
protected function appendBreadcrumb ( $ name , $ label , $ route = null , array $ parameters = [ ] ) { $ this -> container -> get ( 'ekyna_admin.menu.builder' ) -> breadcrumbAppend ( $ name , $ label , $ route , $ parameters ) ; }
Appends a link or span to the admin breadcrumb
55,137
protected function findResourceOrThrowException ( array $ criteria ) { if ( null === $ resource = $ this -> getRepository ( ) -> findOneBy ( $ criteria ) ) { throw new NotFoundHttpException ( 'Resource not found.' ) ; } return $ resource ; }
Finds a resource or throw a not found exception
55,138
protected function isGranted ( $ attributes , $ object = null , $ throwException = true ) { if ( is_null ( $ object ) ) { $ object = $ this -> config -> getObjectIdentity ( ) ; } else { $ object = $ this -> get ( 'ekyna_admin.pool_registry' ) -> getObjectIdentity ( $ object ) ; } if ( ! $ this -> get ( 'security.authorization_checker' ) -> isGranted ( $ attributes , $ object ) ) { if ( $ throwException ) { throw new AccessDeniedHttpException ( 'You are not allowed to view this resource.' ) ; } return false ; } return true ; }
Checks if the attributes are granted against the current token .
55,139
protected function createModal ( $ action ) { $ modal = new Modal ( sprintf ( '%s.header.%s' , $ this -> config -> getId ( ) , $ action ) ) ; $ buttons = [ ] ; if ( in_array ( $ action , [ 'new' , 'edit' , 'remove' ] ) ) { $ submitButton = [ 'id' => 'submit' , 'label' => 'ekyna_core.button.save' , 'icon' => 'glyphicon glyphicon-ok' , 'cssClass' => 'btn-success' , 'autospin' => true , ] ; if ( $ action === 'edit' ) { $ submitButton [ 'icon' ] = 'glyphicon glyphicon-ok' ; $ submitButton [ 'cssClass' ] = 'btn-warning' ; } elseif ( $ action === 'remove' ) { $ submitButton [ 'label' ] = 'ekyna_core.button.remove' ; $ submitButton [ 'icon' ] = 'glyphicon glyphicon-trash' ; $ submitButton [ 'cssClass' ] = 'btn-danger' ; } $ buttons [ ] = $ submitButton ; } $ buttons [ ] = [ 'id' => 'close' , 'label' => 'ekyna_core.button.cancel' , 'icon' => 'glyphicon glyphicon-remove' , 'cssClass' => 'btn-default' , ] ; $ modal -> setButtons ( $ buttons ) ; return $ modal ; }
Creates a modal object .
55,140
public static function configure ( EventManagerInterface $ eventManager , ServiceLocatorInterface $ serviceLocator , array $ listeners ) { if ( ! empty ( $ listeners ) ) { foreach ( $ listeners as $ key => $ value ) { if ( $ value instanceof ListenerAggregateInterface ) { $ listener = $ value ; } elseif ( is_string ( $ value ) && $ serviceLocator -> has ( $ value ) ) { $ listener = $ serviceLocator -> get ( $ value ) ; } elseif ( is_string ( $ value ) && class_exists ( $ value ) ) { $ listener = new $ value ( ) ; } else { $ listener = $ value ; } if ( $ listener instanceof ListenerAggregateInterface ) { $ eventManager -> attachAggregate ( $ listener ) ; } elseif ( isset ( $ listener [ 'event' ] ) && isset ( $ listener [ 'callback' ] ) ) { $ eventManager -> attach ( $ listener [ 'event' ] , $ listener [ 'callback' ] ) ; } else { throw new InvalidListenerException ( sprintf ( "Listener for service ID %s doesn't implement ListenerAggregateInterface" , $ value ) ) ; } } } }
Attach listeners from array
55,141
public static function run ( App $ cdl , string $ method , Slim $ app , Type $ type , array $ routes ) : void { foreach ( $ routes as $ options ) { if ( isset ( $ options [ 'action' ] ) && $ cdl -> hasRoute ( $ method , $ options [ 'action' ] ) ) { $ route = $ cdl -> getRoute ( $ method , $ options [ 'action' ] ) ; self :: hookRoute ( $ cdl , $ app , new $ route ( $ cdl , $ type , $ options ) , $ method ) ; } else { self :: hookError ( $ cdl , $ app , $ method , $ options ) ; } } }
Dispatches the given data and registers the appropriate route
55,142
private static function hookRoute ( App $ cdl , Slim $ app , Route $ route , string $ method ) { $ options = $ route -> getOptions ( ) ; $ routing = $ app -> { $ method } ( $ options [ 'url' ] , System :: jsonResponse ( function ( Request $ request , Response $ response , array $ args ) use ( $ route ) { return $ route -> dispatch ( $ request , $ response , $ args ) ; } ) ) ; self :: applyMiddleware ( $ cdl , $ options , $ routing ) ; }
Hooks a custom route into the slim framework
55,143
private static function hookError ( App $ cdl , Slim $ app , string $ method , array $ options ) { $ routing = $ app -> { $ method } ( $ options [ 'url' ] , System :: jsonResponse ( function ( ) { return Route :: noRoute ( ) ; } ) ) ; self :: applyMiddleware ( $ cdl , $ options , $ routing ) ; }
Adds an error Message if this route is defined but contains no action
55,144
private static function applyMiddleware ( App $ cdl , array $ settings , \ Slim \ Route $ route ) : void { if ( isset ( $ settings [ 'middleware' ] ) && ! empty ( $ settings [ 'middleware' ] ) ) { foreach ( $ settings [ 'middleware' ] as $ middleware ) { if ( $ cdl -> hasMiddleware ( $ middleware ) ) { $ middleware = $ cdl -> getMiddleware ( $ middleware ) ; $ route -> add ( $ middleware :: getInstance ( ) ) ; } } } }
Adds all given middleware to the current route if they exist
55,145
protected function getContent ( $ contentId ) { $ content = null ; if ( ! is_null ( $ contentId ) ) { $ language = $ this -> currentSiteManager -> getSiteLanguage ( ) ; $ content = $ this -> contentRepository -> findPublishedVersion ( $ contentId , $ language ) ; } if ( is_null ( $ content ) && $ this -> requestStack -> getMasterRequest ( ) -> get ( 'token' ) ) { $ content = new FakeContent ( ) ; } return $ content ; }
Get content to display
55,146
protected function _normalizeChild ( $ child , $ config = null ) { if ( is_scalar ( $ child ) || is_null ( $ child ) ) { return $ this -> _normalizeSimpleChild ( $ child , $ config ) ; } return $ this -> _normalizeComplexChild ( $ child , $ config ) ; }
Normalizes a map child element .
55,147
protected function _createChildInstance ( $ child , $ config = null ) { $ childConfig = $ this -> _getChildConfig ( $ child , $ config ) ; $ factory = $ this -> _getChildFactory ( $ child , $ config ) ; return $ factory -> make ( $ childConfig ) ; }
Creates a new instance of a child element .
55,148
public static function normalizeUrl ( $ url ) { if ( substr ( $ url , 0 , 1 ) != '/' ) $ url = '/' . $ url ; if ( substr ( $ url , - 1 ) == '/' ) $ url = substr ( $ url , 0 , - 1 ) ; if ( ! strlen ( $ url ) ) $ url = '/' ; return $ url ; }
Adds leading slash and removes trailing slash from the URL .
55,149
public static function segmentizeUrl ( $ url ) { $ url = self :: normalizeUrl ( $ url ) ; $ segments = explode ( '/' , $ url ) ; $ result = array ( ) ; foreach ( $ segments as $ segment ) { if ( strlen ( $ segment ) ) $ result [ ] = $ segment ; } return $ result ; }
Splits an URL by segments separated by the slash symbol .
55,150
public static function rebuildUrl ( array $ urlArray ) { $ url = '' ; foreach ( $ urlArray as $ segment ) { if ( strlen ( $ segment ) ) $ url .= '/' . trim ( $ segment ) ; } return self :: normalizeUrl ( $ url ) ; }
Rebuilds a URL from an array of segments .
55,151
public static function segmentIsOptional ( $ segment ) { $ name = mb_substr ( $ segment , 1 ) ; $ optMarkerPos = mb_strpos ( $ name , '?' ) ; if ( $ optMarkerPos === false ) return false ; $ regexMarkerPos = mb_strpos ( $ name , '|' ) ; if ( $ regexMarkerPos === false ) return true ; if ( $ optMarkerPos !== false && $ regexMarkerPos !== false ) return $ optMarkerPos < $ regexMarkerPos ; return false ; }
Checks whether an URL pattern segment is optional .
55,152
public static function getParameterName ( $ segment ) { $ name = mb_substr ( $ segment , 1 ) ; $ optMarkerPos = mb_strpos ( $ name , '?' ) ; $ regexMarkerPos = mb_strpos ( $ name , '|' ) ; if ( $ optMarkerPos !== false && $ regexMarkerPos !== false ) { if ( $ optMarkerPos < $ regexMarkerPos ) return mb_substr ( $ name , 0 , $ optMarkerPos ) ; else return mb_substr ( $ name , 0 , $ regexMarkerPos ) ; } if ( $ optMarkerPos !== false ) return mb_substr ( $ name , 0 , $ optMarkerPos ) ; if ( $ regexMarkerPos !== false ) return mb_substr ( $ name , 0 , $ regexMarkerPos ) ; return $ name ; }
Extracts the parameter name from a URL pattern segment definition .
55,153
public static function getSegmentRegExp ( $ segment ) { if ( ( $ pos = mb_strpos ( $ segment , '|' ) ) !== false ) { $ regexp = mb_substr ( $ segment , $ pos + 1 ) ; if ( ! mb_strlen ( $ regexp ) ) return false ; return '/' . $ regexp . '/' ; } return false ; }
Extracts the regular expression from a URL pattern segment definition .
55,154
public static function getSegmentDefaultValue ( $ segment ) { $ optMarkerPos = mb_strpos ( $ segment , '?' ) ; if ( $ optMarkerPos === false ) return false ; $ regexMarkerPos = mb_strpos ( $ segment , '|' ) ; $ value = false ; if ( $ regexMarkerPos !== false ) $ value = mb_substr ( $ segment , $ optMarkerPos + 1 , $ regexMarkerPos - $ optMarkerPos - 1 ) ; else $ value = mb_substr ( $ segment , $ optMarkerPos + 1 ) ; return strlen ( $ value ) ? $ value : false ; }
Extracts the default parameter value from a URL pattern segment definition .
55,155
public function uploadAction ( ) { $ authenticationService = $ this -> getServiceLocator ( ) -> get ( 'zfcuser_auth_service' ) ; if ( ! $ authenticationService -> hasIdentity ( ) ) { return $ this -> redirect ( ) -> toRoute ( 'zfcuser' ) ; } $ user = $ this -> getUser ( ) ; if ( ! $ user ) { return $ this -> notFoundAction ( ) ; } $ options = $ this -> getOptions ( ) ; $ form = $ this -> getServiceLocator ( ) -> get ( 'HtProfileImage\ProfileImageForm' ) ; $ request = $ this -> getRequest ( ) ; $ imageUploaded = false ; if ( $ request -> isPost ( ) ) { $ negotiator = new FormatNegotiator ( ) ; $ format = $ negotiator -> getBest ( $ request -> getHeader ( 'Accept' ) -> getFieldValue ( ) , [ 'application/json' , 'text/html' ] ) ; if ( $ this -> profileImageService -> storeImage ( $ user , $ request -> getFiles ( ) -> toArray ( ) ) ) { if ( $ format -> getValue ( ) === 'application/json' ) { return new Model \ JsonModel ( [ 'uploaded' => true ] ) ; } elseif ( $ options -> getPostUploadRoute ( ) ) { return call_user_func_array ( [ $ this -> redirect ( ) , 'toRoute' ] , ( array ) $ options -> getPostUploadRoute ( ) ) ; } $ imageUploaded = true ; } else { $ response = $ this -> getResponse ( ) ; $ response -> setStatusCode ( 400 ) ; if ( $ format -> getValue ( ) === 'application/json' ) { return new Model \ JsonModel ( [ 'error' => true , 'messages' => $ form -> getMessages ( ) ] ) ; } } } return new Model \ ViewModel ( [ 'form' => $ form , 'imageUploaded' => $ imageUploaded , 'user' => $ user ] ) ; }
Uploads User Image
55,156
public function displayAction ( ) { $ id = $ this -> params ( ) -> fromRoute ( 'id' , null ) ; $ filter = $ this -> params ( ) -> fromRoute ( 'filter' , null ) ; if ( ! $ id ) { return $ this -> notFoundAction ( ) ; } $ user = $ this -> getUserMapper ( ) -> findById ( $ id ) ; if ( ! $ user ) { return $ this -> notFoundAction ( ) ; } $ image = $ this -> profileImageService -> getUserImage ( $ user , $ filter ) ; return new ImageModel ( $ image ) ; }
Displays User Image
55,157
function mod ( $ data , $ op = null ) { if ( ! ( $ this -> data instanceof Expr ) ) { $ this -> data = new Expr ( $ this -> name ) ; } if ( $ data instanceof Expr ) { $ this -> data -> add ( $ data ) ; } elseif ( ! isset ( $ op ) && is_numeric ( $ data ) ) { $ this -> data -> add ( new Expr ( "+ $data" ) ) ; } else { $ this -> data -> add ( new Expr ( "%s %s" , isset ( $ op ) ? $ op : "||" , $ data ) ) ; } return $ this ; }
Modify the data
55,158
public function init ( ) { parent :: init ( ) ; $ defaults = [ self :: TYPE_INFO => [ '{class}' => 'alert alert-info alert-dismissible' , '{icon}' => '<i class="icon fa fa-info-circle"></i>' , '{title}' => Yii :: t ( 'cza' , 'Tips' ) , '{content}' => '' ] , self :: TYPE_DANGER => [ '{class}' => 'alert alert-danger alert-dismissible' , '{icon}' => '<i class="icon fa fa-ban"></i>' , '{title}' => Yii :: t ( 'cza' , 'Alert' ) , '{content}' => '' ] , self :: TYPE_WARNING => [ '{class}' => 'alert alert-warning alert-dismissible' , '{icon}' => '<i class="icon fa fa-warning"></i>' , '{title}' => Yii :: t ( 'cza' , 'Warning' ) , '{content}' => '' ] , self :: TYPE_SUCCESS => [ '{class}' => 'alert alert-success alert-dismissible' , '{icon}' => '<i class="icon fa fa-info"></i>' , '{title}' => Yii :: t ( 'cza' , 'Alert' ) , '{content}' => '' ] , ] ; $ this -> blockTypes = array_replace_recursive ( $ defaults , $ this -> blockTypes ) ; }
with outside wrapper or not
55,159
public function get ( $ css = null , $ compress = true ) { if ( null === $ css ) { foreach ( ( array ) $ this -> _list as $ src ) { if ( ! file_exists ( $ src ) ) { continue ; } $ css .= file_get_contents ( $ src ) ; } } $ this -> _list = [ ] ; return $ compress ? $ this -> parse ( $ css ) : $ css ; }
Get Packed CSS
55,160
public function setPath ( $ path ) { if ( file_exists ( $ path ) ) { $ this -> path = $ path ; } else { throw new NotFoundException ( sprintf ( 'The requested page was not found (searching "%s")!' , $ path ) ) ; } return $ this ; }
Define the path of the document to treat
55,161
protected function buildResponse ( $ etag = null , DateTime $ lastModified = null ) { if ( 'POST' === $ this -> getRequest ( ) -> getMethod ( ) ) { $ response = new Response ( ) ; $ response -> setPrivate ( ) ; return $ response ; } else return parent :: buildResponse ( $ etag , $ lastModified ) ; }
Build the response so that depending on settings it s cacheable
55,162
public static function morphKeys ( $ originalArray , $ morphTo = 'camel' ) { $ newArray = [ ] ; foreach ( $ originalArray as $ key => $ value ) { if ( is_array ( $ value ) ) { $ value = static :: morphKeys ( $ value , $ morphTo ) ; } $ newKey = '' ; switch ( $ morphTo ) { case 'camel' : $ newKey = StringHelper :: camelCase ( $ key ) ; break 1 ; case 'snake' : $ newKey = StringHelper :: snakeCase ( $ key ) ; break 1 ; } $ newArray [ $ newKey ] = $ value ; } return $ newArray ; }
Will camelize all keys found in a array or multi dimensional array
55,163
public static function castValues ( Array $ originalArray ) { foreach ( $ originalArray as $ key => $ value ) { switch ( true ) { case $ value === 'true' : $ originalArray [ $ key ] = true ; break 1 ; case $ value === 'false' : $ originalArray [ $ key ] = false ; break 1 ; case is_numeric ( $ value ) : $ originalArray [ $ key ] = ( int ) $ value ; break 1 ; case is_string ( $ value ) && null !== ( $ jsonToArray = json_decode ( $ value , true ) ) : $ originalArray [ $ key ] = $ jsonToArray ; break 1 ; } } return $ originalArray ; }
Will cast 123 as int true as the boolean true etc
55,164
public static function sortByPriority ( Array $ originalArray , Array $ priority , $ strictMatch = true ) { $ priorityArray = [ ] ; foreach ( $ priority as $ priorityElement ) { foreach ( $ priorityElement as $ priorityKey => $ priorityValue ) { foreach ( $ originalArray as $ originalElementKey => $ originalElement ) { foreach ( $ originalElement as $ originalKey => $ originalValue ) { $ isMatch = false ; if ( $ strictMatch === true && $ priorityKey === $ originalKey && $ priorityValue === $ originalValue ) { $ isMatch = true ; } if ( $ strictMatch === false && strcasecmp ( $ priorityKey , $ originalKey ) === 0 && strcasecmp ( $ priorityValue , $ originalValue ) === 0 ) { $ isMatch = true ; } if ( $ isMatch ) { $ priorityArray [ ] = $ originalElement ; unset ( $ originalArray [ $ originalElementKey ] ) ; } } } } } return array_merge ( $ priorityArray , $ originalArray ) ; }
Re - orders an array by moving elements to the top of the array based on a pre - defined array stating which elements to move to top of array
55,165
public function checkIsOnAdmin ( MvcEvent $ e ) { $ matches = $ e -> getRouteMatch ( ) ; if ( ! $ matches instanceof Router \ RouteMatch ) { throw new \ Exception ( 'No Route Matched Found, Make sure for the event priority!' ) ; } $ matchedRouteName = $ matches -> getMatchedRouteName ( ) ; if ( ( $ slashOcurr = strpos ( $ matchedRouteName , '/' ) ) !== false ) { $ matchedRouteName = substr ( $ matchedRouteName , 0 , $ slashOcurr ) ; } if ( $ matchedRouteName !== \ yimaAdminor \ Module :: ADMIN_ROUTE_NAME ) { return false ; } self :: $ isOnAdmin = true ; return true ; }
Check is Matched Route from Admin and Set - Service \ Share flag
55,166
public function getPassWordHash ( ) { if ( empty ( $ this -> wpPassWordHash ) ) { $ this -> wpPassWordHash = new PasswordHash ( 8 , true ) ; } return $ this -> wpPassWordHash ; }
Gets the instance of the WP PasswordHash class
55,167
public function check ( string $ password , string $ hashedPassword ) : bool { return $ this -> getPassWordHash ( ) -> checkPassword ( $ password , $ hashedPassword ) ; }
Check hash . Generate hash from user provided password string or data array and check against existing hash .
55,168
public function check ( $ value ) : bool { try { if ( false == \ DateTime :: createFromFormat ( $ this -> rule , $ value ) ) { return false ; } return true ; } catch ( \ Exception $ e ) { return false ; } }
Check the constraint . Child classes should attempt to report the error to the validator .
55,169
public function getHtmlByMarkdown ( $ string ) { if ( false === class_exists ( '\Parsedown' ) ) { throw new \ RuntimeException ( 'Missing Parsedown. Try: composer require "erusev/parsedown" "^1.6.1"' ) ; } $ parse = new Parsedown ( ) ; $ parse -> setBreaksEnabled ( $ this -> isParameterParseDownBreaksEnabled ( ) ) ; return $ parse -> text ( $ string ) ; }
Get HTML By Markdown
55,170
public function getStringByByte ( $ bytes , $ decimals = 2 , $ decimalPoint = '.' , $ thousandsSeparator = ',' ) { $ size = [ 'B' , 'kB' , 'MB' , 'GB' , 'TB' , 'PB' , 'EB' , 'ZB' , 'YB' , ] ; $ factor = intval ( floor ( ( strlen ( $ bytes ) - 1 ) / 3 ) ) ; if ( false === isset ( $ size [ $ factor ] ) ) { return $ bytes ; } return sprintf ( '%s %s' , number_format ( $ bytes / pow ( 1024 , $ factor ) , $ decimals , $ decimalPoint , $ thousandsSeparator ) , $ size [ $ factor ] ) ; }
Get Human Readable Bytes
55,171
public function getStringByDate ( DateTime $ date ) { $ dateNow = new DateTime ( ) ; if ( $ dateNow < $ date ) { return 'Future date not implemented.' ; } if ( $ date -> format ( 'Ymd' ) === $ dateNow -> format ( 'Ymd' ) ) { return $ this -> getTranslator ( ) -> trans ( 'time.today' ) ; } if ( $ date -> format ( 'Ymd' ) === ( ( new DateTime ( 'yesterday' ) ) -> format ( 'Ymd' ) ) ) { return $ this -> getTranslator ( ) -> trans ( 'time.yesterday' ) ; } $ diffDays = ceil ( ( $ dateNow -> getTimestamp ( ) - $ date -> getTimestamp ( ) ) / 86400 ) ; if ( 7 > $ diffDays ) { return $ this -> getTranslator ( ) -> trans ( 'time.days_ago' , [ '{days}' => $ diffDays , ] ) ; } if ( $ date -> format ( 'W' ) === ( new DateTime ( '-1 Week' ) ) -> format ( 'W' ) ) { return $ this -> getTranslator ( ) -> trans ( 'time.last_week' ) ; } if ( 28 > $ diffDays ) { return $ this -> getTranslator ( ) -> trans ( 'time.weeks_ago' , [ '{weeks}' => floor ( $ diffDays / 7 ) , ] ) ; } if ( $ date -> format ( 'Ym' ) === ( new DateTime ( '-1 month' ) ) -> format ( 'Ym' ) ) { return $ this -> getTranslator ( ) -> trans ( 'time.last_month' ) ; } if ( $ date -> format ( 'Y' ) === ( $ dateNow -> format ( 'Y' ) - 1 ) ) { return $ this -> getTranslator ( ) -> trans ( 'time.last_year' ) ; } return $ this -> getTranslator ( ) -> trans ( 'time.years_ago' , [ '{years}' => $ dateNow -> format ( 'Y' ) - $ date -> format ( 'Y' ) , ] ) ; }
Get String By Date
55,172
public function getResource ( $ name = null ) { if ( null === $ name ) { $ name = $ this -> config -> getResourceName ( ) ; } if ( isset ( $ this -> resources [ $ name ] ) ) { return $ this -> resources [ $ name ] ; } return null ; }
Returns a resource by name .
55,173
public function getIdentifiers ( $ with_current = false ) { $ identifiers = [ ] ; foreach ( $ this -> resources as $ name => $ resource ) { if ( ! ( ! $ with_current && $ name === $ this -> config -> getResourceName ( ) ) ) { $ identifiers [ $ name . 'Id' ] = $ resource -> getId ( ) ; } } return $ identifiers ; }
Returns the identifiers .
55,174
public function getTemplateVars ( array $ extra = [ ] ) { $ extraKeys = array_keys ( $ extra ) ; if ( 0 < count ( $ extraKeys ) ) { foreach ( array_keys ( $ this -> resources ) as $ key ) { if ( array_key_exists ( $ key , $ extraKeys ) ) { throw new \ RuntimeException ( sprintf ( 'Key "%s" used in extra template vars overrides a resource key.' , $ key ) ) ; } } foreach ( [ 'identifiers' , 'resource_name' , 'resource_id' , 'route_prefix' ] as $ key ) { if ( array_key_exists ( $ key , $ extraKeys ) ) { throw new \ RuntimeException ( sprintf ( 'Key "%s" is reserved and cannot be used in extra template vars.' , $ key ) ) ; } } } return array_merge ( $ this -> resources , [ 'identifiers' => $ this -> getIdentifiers ( ) , 'resource_name' => $ this -> config -> getResourceName ( ) , 'resource_id' => $ this -> config -> getId ( ) , 'route_prefix' => $ this -> config -> getRoutePrefix ( ) , 'form_template' => $ this -> config -> getTemplate ( '_form.html' ) , ] , $ extra ) ; }
Returns the template resources vars .
55,175
public function getMarkerId ( $ marker , $ prefix = null ) { $ marker = $ this -> pointToIndArray ( $ marker ) ; $ key = substr ( md5 ( $ marker [ 0 ] . $ marker [ 1 ] ) , 0 , 6 ) ; if ( ! isset ( $ this -> _markerId [ $ key ] ) ) { $ this -> _markerId [ $ key ] = 'mk' . $ this -> mapId . static :: $ markerCount ++ ; if ( $ prefix ) { $ this -> _markerId [ $ key ] = $ prefix . ucfirst ( $ this -> _markerId [ $ key ] ) ; } } return $ this -> _markerId [ $ key ] ; }
Generate an ID for marker on a sequential order .
55,176
public function attach ( $ service , $ callback , $ priority = 1 ) { $ service = $ this -> normalizeServiceName ( $ service ) ; if ( empty ( $ this -> services [ $ service ] ) ) { $ this -> services [ $ service ] = new PriorityQueue ( ) ; } if ( is_string ( $ callback ) ) { $ id = $ callback ; $ callback = null ; } else { $ id = null ; } $ listener = new LazyCallbackHandler ( $ callback , array ( 'service' => $ service , 'priority' => $ priority , 'service_id' => $ id ) ) ; $ this -> services [ $ service ] -> insert ( $ listener , $ priority ) ; return $ listener ; }
Attach service listener
55,177
public function detach ( LazyCallbackHandler $ listener ) { $ service = $ listener -> getMetadatum ( 'service' ) ; $ service = $ this -> normalizeServiceName ( $ service ) ; if ( ! $ service || empty ( $ this -> services [ $ service ] ) ) { return false ; } $ return = $ this -> services [ $ service ] -> remove ( $ listener ) ; if ( ! $ return ) { return false ; } if ( ! count ( $ this -> services [ $ service ] ) ) { unset ( $ this -> services [ $ service ] ) ; } return true ; }
Detach service listener
55,178
public function trigger ( CommandInterface $ command , $ callback = null ) { if ( $ callback && ! is_callable ( $ callback ) ) { throw new Exception \ InvalidCallbackException ( 'Invalid callback provided' ) ; } $ service = $ this -> normalizeServiceName ( $ command -> getService ( ) ) ; $ responses = new ResponseCollection ( ) ; $ command -> setResponses ( $ responses ) ; if ( ! isset ( $ this -> services [ $ service ] ) || $ this -> services [ $ service ] -> isEmpty ( ) ) { return $ responses ; } $ exception = null ; foreach ( $ this -> services [ $ service ] as $ listener ) { if ( ! $ listener -> getCallback ( ) ) { $ listener -> setCallback ( $ this -> getServiceLoader ( ) -> load ( $ listener -> getMetadatum ( 'service_id' ) ) ) ; } try { $ response = call_user_func ( $ listener -> getCallback ( ) , $ command ) ; $ exception = null ; } catch ( Exception \ SkippableException $ ex ) { if ( ! $ exception ) { $ exception = $ ex ; } if ( $ command -> propagationIsStopped ( ) ) { $ responses -> setStopped ( true ) ; break ; } else { continue ; } } $ responses -> push ( $ response ) ; if ( $ command -> propagationIsStopped ( ) ) { $ responses -> setStopped ( true ) ; break ; } if ( $ callback && call_user_func ( $ callback , $ responses -> last ( ) ) ) { $ responses -> setStopped ( true ) ; break ; } } if ( $ exception && $ responses -> isEmpty ( ) ) { throw $ exception ; } return $ responses ; }
Trigger all listeners for a given command
55,179
public function querySelector ( $ selector ) { $ converter = new CssSelectorConverter ( ) ; $ xpathQuery = $ converter -> toXPath ( $ selector ) ; $ result = $ this -> xpath -> query ( $ xpathQuery ) ; if ( ! $ result -> item ( 0 ) ) { return null ; } return new Node ( $ result -> item ( 0 ) ) ; }
select single element from dom using css style selectors
55,180
public function querySelectorAll ( $ selector ) { $ converter = new CssSelectorConverter ( ) ; $ xpathQuery = $ converter -> toXPath ( $ selector ) ; $ results = $ this -> xpath -> query ( $ xpathQuery ) ; if ( ! $ results -> item ( 0 ) ) { return [ ] ; } $ return = new NodeCollection ( ) ; for ( $ i = 0 ; $ i < $ results -> length ; $ i ++ ) { $ node = new Node ( $ results -> item ( $ i ) ) ; $ return -> append ( $ node ) ; } return $ return ; }
select multiple elements from dom using css style selectors
55,181
private function registerData ( $ domain , $ dataset , $ action = 'create' ) { foreach ( $ dataset as $ reference => $ data ) { $ this -> addReference ( $ reference , $ domain -> getAction ( $ action ) -> denormalize ( $ data ) -> resolve ( ) ) ; } }
Register given data set into given domain .
55,182
public function query ( $ query , $ bindData = [ ] ) { try { if ( empty ( $ bindData ) ) { $ statement = $ this -> pdo -> query ( $ query ) ; } else { $ statement = $ this -> prepareQuery ( $ query , $ bindData ) ; $ statement -> execute ( ) ; $ statement -> errorCode ( ) ; } } catch ( \ PDOException $ e ) { $ boundData = json_encode ( $ bindData ) ; throw new DatabaseDriverException ( "{$e->getMessage()} [$query] [BOUND DATA:$boundData]" ) ; } if ( $ this -> logger ) { $ this -> logger -> debug ( $ query , $ bindData ) ; } $ rows = $ this -> fetchRows ( $ statement ) ; $ statement -> closeCursor ( ) ; return $ rows ; }
Pepare and execute a query while binding data at the same time . Prevents the writing of repetitive prepare and execute statements . This method returns an array which contains the results of the query that was executed . For queries which do not return any results a null is returned .
55,183
private function expand ( $ params ) { unset ( $ params [ 'driver' ] ) ; if ( isset ( $ params [ 'file' ] ) ) { if ( $ params [ 'file' ] != '' ) { return $ params [ 'file' ] ; } } $ equated = [ ] ; foreach ( $ params as $ key => $ value ) { if ( $ value == '' ) { continue ; } else { $ equated [ ] = "$key=$value" ; } } return implode ( ';' , $ equated ) ; }
Expands the configuration array into a format that can easily be passed to PDO .
55,184
public function describeTable ( $ table ) { $ table = explode ( '.' , $ table ) ; if ( count ( $ table ) > 1 ) { $ schema = $ table [ 0 ] ; $ table = $ table [ 1 ] ; } else { $ schema = $ this -> getDefaultSchema ( ) ; $ table = $ table [ 0 ] ; } return $ this -> getDescriptor ( ) -> describeTables ( $ schema , [ $ table ] , true ) ; }
Returns the description of a database table as an associative array .
55,185
private function getDescriptor ( ) { if ( ! is_object ( $ this -> descriptor ) ) { $ descriptorClass = '\\ntentan\\atiaa\\descriptors\\' . ucfirst ( $ this -> config [ 'driver' ] ) . 'Descriptor' ; $ this -> descriptor = new $ descriptorClass ( $ this ) ; } return $ this -> descriptor ; }
Returns an instance of a descriptor for a given driver .
55,186
public function getIndex ( ) { if ( ! $ this -> index ) { $ this -> index = $ this -> entityManager -> createIndex ( $ this -> class ) ; $ this -> index -> save ( ) ; } return $ this -> index ; }
Gets the index object for the class this repository applies to .
55,187
public function findAll ( ) { $ collection = new ArrayCollection ( ) ; if ( $ this -> meta instanceof Node ) { foreach ( $ this -> getIndex ( ) -> query ( 'id:*' ) as $ node ) { $ collection -> add ( $ this -> entityManager -> loadNode ( $ node ) ) ; } } elseif ( $ this -> meta instanceof Relation ) { foreach ( $ this -> getIndex ( ) -> query ( 'id:*' ) as $ rel ) { $ collection -> add ( $ this -> entityManager -> loadRelation ( $ rel ) ) ; } } return $ collection ; }
Gets all nodes or relations .
55,188
public function findOneBy ( array $ criteria ) { if ( count ( $ criteria ) == 0 ) { throw new Exception ( "Please supply at least one criteria to findOneBy()." ) ; } if ( $ this -> meta instanceof Node ) { $ query = $ this -> createIndexQuery ( $ criteria ) ; if ( $ node = $ this -> getIndex ( ) -> queryOne ( $ query ) ) { return $ this -> entityManager -> loadNode ( $ node ) ; } } elseif ( $ this -> meta instanceof Relation ) { $ result_sets = array ( ) ; $ query_criteria = array ( ) ; foreach ( $ criteria as $ k => $ v ) { $ key = Meta \ Reflection :: normalizeProperty ( $ k ) ; if ( $ key == $ this -> meta -> getStart ( ) -> getName ( ) || $ key == $ this -> meta -> getEnd ( ) -> getName ( ) ) { $ result_sets [ ] = $ this -> getRelationsByNode ( $ key , $ v ) ; } else { $ query_criteria [ $ k ] = $ v ; } } if ( count ( $ query_criteria ) > 0 ) { $ query = $ this -> createIndexQuery ( $ query_criteria ) ; $ result_sets [ ] = $ this -> getIndex ( ) -> query ( $ query ) ; } $ results = count ( $ result_sets ) > 1 ? call_user_func_array ( 'array_intersect' , $ result_sets ) : $ result_sets [ 0 ] ; return empty ( $ results ) ? null : $ this -> entityManager -> loadRelation ( $ results [ 0 ] ) ; } return null ; }
Finds one node or relation by search criteria .
55,189
public function findBy ( array $ criteria ) { if ( count ( $ criteria ) == 0 ) { throw new Exception ( "Please supply at least one criteria to findBy()." ) ; } $ collection = new ArrayCollection ( ) ; if ( $ this -> meta instanceof Node ) { $ query = $ this -> createIndexQuery ( $ criteria ) ; foreach ( $ this -> getIndex ( ) -> query ( $ query ) as $ node ) { $ collection -> add ( $ this -> entityManager -> loadNode ( $ node ) ) ; } } elseif ( $ this -> meta instanceof Relation ) { $ result_sets = array ( ) ; $ query_criteria = array ( ) ; foreach ( $ criteria as $ k => $ v ) { $ key = Meta \ Reflection :: normalizeProperty ( $ k ) ; if ( $ key == $ this -> meta -> getStart ( ) -> getName ( ) || $ key == $ this -> meta -> getEnd ( ) -> getName ( ) ) { $ result_sets [ ] = $ this -> getRelationsByNode ( $ key , $ v ) ; } else { $ query_criteria [ $ k ] = $ v ; } } if ( count ( $ query_criteria ) > 0 ) { $ query = $ this -> createIndexQuery ( $ query_criteria ) ; $ result_sets [ ] = $ this -> getIndex ( ) -> query ( $ query ) ; } $ results = count ( $ result_sets ) > 1 ? call_user_func_array ( 'array_intersect' , $ result_sets ) : $ result_sets [ 0 ] ; foreach ( $ results as $ rel ) { $ collection -> add ( $ this -> entityManager -> loadRelation ( $ rel ) ) ; } } return $ collection ; }
Finds all nodes an relations by search criteria .
55,190
private function createIndexQuery ( array $ criteria ) { $ query = new IndexQuery ( ) ; foreach ( $ criteria as $ key => $ value ) { $ query -> addAndTerm ( $ key , $ value ) ; } return $ query -> getQuery ( ) ; }
Creates an index query out of the supplied criteria .
55,191
private function getSearchableProperty ( $ property ) { $ property = Meta \ Reflection :: normalizeProperty ( $ property ) ; foreach ( $ this -> meta -> getIndexedProperties ( ) as $ p ) { if ( Meta \ Reflection :: normalizeProperty ( $ p -> getName ( ) ) == $ property ) { return $ property ; } } if ( $ this -> meta instanceof Node ) { throw new Exception ( "Property $property is not indexed or does not exist in {$this->meta->getName()}." ) ; } else { throw new Exception ( "Property noName is either not indexed, not a start/end, or does not exist in {$this->meta->getName()}." ) ; } }
Gets a indexed property name after doing required string manipulations .
55,192
public function registerTwig ( ) { \ Twig_Autoloader :: register ( ) ; $ loader = new \ Twig_Loader_Filesystem ( $ _SERVER [ 'DOCUMENT_ROOT' ] . '/../src/' . $ this -> app -> getProjectName ( ) . '/View' ) ; $ twig = new \ Twig_Environment ( $ loader , array ( 'cache' => $ _SERVER [ 'DOCUMENT_ROOT' ] . '/../app/cache/twig' , 'auto_reload' => true ) ) ; return $ twig ; }
Register new Twig_Environment
55,193
public function createValidator ( ) { $ sv = Validation :: createValidatorBuilder ( ) -> enableAnnotationMapping ( ) -> getValidator ( ) ; $ validator = new Validator ( $ sv ) ; return $ validator ; }
Creates an instance of the Symfony Validator
55,194
protected function newPath ( $ path ) { list ( $ mnt , $ remain ) = $ this -> splitPath ( $ path ) ; return new Path ( $ path , $ remain , $ this -> getFilesystemAt ( $ mnt ) ) ; }
Generate Path object . Override this method if you want to
55,195
protected function splitPath ( $ path ) { $ pref = $ this -> getMountPoint ( $ path ) ; $ remain = ltrim ( substr ( $ path , strlen ( $ pref ) ) , '/' ) ; return [ $ pref , $ remain ] ; }
Split into mount point and the remain
55,196
protected function saveToCache ( $ key , $ obj ) { if ( isset ( $ this -> path_cache [ $ key [ 0 ] ] ) && sizeof ( $ this -> path_cache [ $ key [ 0 ] ] ) > 1 ) { $ this -> path_cache [ $ key [ 0 ] ] = [ ] ; } $ this -> path_cache [ $ key [ 0 ] ] [ $ key ] = $ obj ; }
Save Path object to local cache
55,197
public function getInstance ( ) { if ( ! $ this -> isInstanceLoaded ( ) ) { $ inst = $ this -> loadInstance ( ) ; if ( ! $ this -> instance ) $ this -> instance = $ inst ; } return $ this -> instance ; }
The default implementation checks if the instance already was loaded if not it will load it store it and return .
55,198
protected function encode ( $ value ) { $ key = ( string ) $ value ; if ( ! isset ( static :: $ cacheEncode [ $ key ] ) ) { $ isAngularVar = false ; if ( \ mb_substr ( $ value , 0 , 2 ) == '{{' && \ mb_substr ( $ value , - 2 ) == '}}' ) { $ isAngularVar = true ; $ value = \ trim ( \ mb_substr ( $ value , 2 , - 2 ) ) ; } static :: $ cacheEncode [ $ key ] = \ rawurlencode ( $ value ) ; static :: $ cacheEncode [ $ key ] = \ strtr ( static :: $ cacheEncode [ $ key ] , static :: $ urlencodeCorrectionMap ) ; if ( $ isAngularVar === true ) { static :: $ cacheEncode [ $ key ] = '{{ ' . static :: $ cacheEncode [ $ key ] . ' }}' ; } } return static :: $ cacheEncode [ $ key ] ; }
Encode a path segment .
55,199
public function encode ( $ number ) { $ number = ( int ) $ number ; $ result = array ( ) ; if ( 0 === $ number ) { $ result [ ] = $ this -> dictionary [ 0 ] ; } while ( $ number > 0 ) { $ result [ ] = $ this -> dictionary [ ( $ number % $ this -> radix ) ] ; $ number = floor ( $ number / $ this -> radix ) ; } return implode ( '' , array_reverse ( $ result ) ) ; }
Base 62 encodes a number .