idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
4,500
|
public static function getMinuteTimestamp ( $ now = null ) { $ now = $ now === null ? time ( ) : $ now ; $ diff = $ now % 60 ; return $ now - $ diff ; }
|
get the timestamp at current minute start
|
4,501
|
final public static function exec ( string $ cmd , array $ args = [ ] ) { foreach ( $ args as $ key => $ val ) $ args [ $ key ] = escapeshellarg ( $ val ) ; $ cmd = vsprintf ( $ cmd , $ args ) ; exec ( $ cmd , $ output , $ retcode ) ; if ( $ retcode !== 0 ) return false ; return $ output ; }
|
Execute arbitrary shell commands . Use with care .
|
4,502
|
final public static function get_mimetype ( string $ fname , string $ path_to_file = null ) { if ( null === $ mime = self :: _mime_extension ( $ fname ) ) return self :: _mime_magic ( $ fname , $ path_to_file ) ; return $ mime ; }
|
Find a mime type .
|
4,503
|
private static function _mime_extension ( string $ fname ) { $ pinfo = pathinfo ( $ fname ) ; if ( ! isset ( $ pinfo [ 'extension' ] ) ) return null ; switch ( strtolower ( $ pinfo [ 'extension' ] ) ) { case 'css' : return 'text/css' ; case 'js' : return 'application/javascript' ; case 'json' : return 'application/json' ; case 'htm' : case 'html' : return 'text/html; charset=utf-8' ; } return null ; }
|
Get MIME by extension .
|
4,504
|
private static function _mime_magic ( string $ fname , string $ path_to_file = null ) { if ( function_exists ( 'mime_content_type' ) && ( $ mime = @ mime_content_type ( $ fname ) ) && $ mime != 'application/octet-stream' ) return $ mime ; if ( $ path_to_file && is_executable ( $ path_to_file ) ) { $ bin = $ path_to_file ; } elseif ( ! ( $ bin = self :: exec ( "bash -c 'type -p file'" ) [ 0 ] ) ) { return 'application/octet-stream' ; } if ( ( $ mimes = self :: exec ( '%s -bip %s' , [ $ bin , $ fname ] ) ) && preg_match ( '!^[a-z0-9\-]+/!i' , $ mimes [ 0 ] ) ) return $ mimes [ 0 ] ; return 'application/octet-stream' ; }
|
Get MIME type with mime_content_type or file .
|
4,505
|
public static function http_client ( array $ kwargs ) { $ url = $ method = null ; $ headers = $ get = $ post = $ custom_opts = [ ] ; $ expect_json = false ; extract ( self :: extract_kwargs ( $ kwargs , [ 'url' => null , 'method' => 'GET' , 'headers' => [ ] , 'get' => [ ] , 'post' => [ ] , 'custom_opts' => [ ] , 'expect_json' => false , ] ) ) ; if ( ! $ url ) throw new CommonError ( "URL not set." ) ; $ opts = [ CURLOPT_RETURNTRANSFER => true , CURLOPT_SSL_VERIFYPEER => true , CURLOPT_CONNECTTIMEOUT => 16 , CURLOPT_TIMEOUT => 16 , CURLOPT_FOLLOWLOCATION => true , CURLOPT_MAXREDIRS => 8 , CURLOPT_HEADER => false , ] ; foreach ( $ custom_opts as $ key => $ val ) $ opts [ $ key ] = $ val ; $ conn = curl_init ( ) ; foreach ( $ opts as $ key => $ val ) curl_setopt ( $ conn , $ key , $ val ) ; if ( $ headers ) curl_setopt ( $ conn , CURLOPT_HTTPHEADER , $ headers ) ; if ( $ get ) { $ url .= strpos ( $ url , '?' ) !== false ? '&' : '?' ; $ url .= http_build_query ( $ get ) ; } curl_setopt ( $ conn , CURLOPT_URL , $ url ) ; if ( is_array ( $ post ) ) $ post = http_build_query ( $ post ) ; switch ( $ method ) { case 'GET' : break ; case 'HEAD' : case 'OPTIONS' : curl_setopt ( $ conn , CURLOPT_NOBODY , true ) ; curl_setopt ( $ conn , CURLOPT_HEADER , true ) ; break ; case 'POST' : case 'PUT' : case 'DELETE' : case 'PATCH' : case 'TRACE' : curl_setopt ( $ conn , CURLOPT_CUSTOMREQUEST , $ method ) ; curl_setopt ( $ conn , CURLOPT_POSTFIELDS , $ post ) ; break ; default : return [ - 1 , null ] ; } $ body = curl_exec ( $ conn ) ; $ info = curl_getinfo ( $ conn ) ; curl_close ( $ conn ) ; if ( in_array ( $ method , [ 'HEAD' , 'OPTIONS' ] ) ) return [ $ info [ 'http_code' ] , $ body ] ; if ( $ expect_json ) $ body = @ json_decode ( $ body , true ) ; return [ $ info [ 'http_code' ] , $ body ] ; }
|
cURL - based HTTP client .
|
4,506
|
final public static function check_dict ( array $ array , array $ keys , bool $ trim = false ) { $ checked = [ ] ; foreach ( $ keys as $ key ) { if ( ! isset ( $ array [ $ key ] ) ) return false ; $ val = $ array [ $ key ] ; if ( $ trim ) { if ( ! is_string ( $ val ) ) return false ; $ val = trim ( $ val ) ; if ( ! $ val ) return false ; } $ checked [ $ key ] = $ val ; } return $ checked ; }
|
Check if a dict contains all necessary keys .
|
4,507
|
final public static function check_idict ( array $ array , array $ keys , bool $ trim = false ) { if ( false === $ array = self :: check_dict ( $ array , $ keys , $ trim ) ) return false ; foreach ( $ array as $ val ) { if ( ! is_numeric ( $ val ) && ! is_string ( $ val ) ) return false ; } return $ array ; }
|
Check if a dict contains all necessary keys with elements being immutables i . e . numeric or string .
|
4,508
|
final public static function extract_kwargs ( array $ input_array , array $ init_array ) { foreach ( array_keys ( $ init_array ) as $ key ) { if ( isset ( $ input_array [ $ key ] ) ) $ init_array [ $ key ] = $ input_array [ $ key ] ; } return $ init_array ; }
|
Initiate a kwargs array for safe extraction .
|
4,509
|
public static function isValid ( $ visibility ) { switch ( $ visibility ) { case Visibility :: TYPE_PRIVATE : case Visibility :: TYPE_PROTECTED : case Visibility :: TYPE_PUBLIC : return true ; } throw new \ InvalidArgumentException ( 'The ' . $ visibility . ' is not allowed' ) ; }
|
Validate visiblity .
|
4,510
|
public function render ( ) { if ( ! $ this -> _enableXDebugOverlay ) { ini_set ( 'xdebug.overload_var_dump' , 'off' ) ; } $ debuggerCount = count ( $ this -> _debuggers ) ; $ this -> setName ( str_replace ( '{count}' , '{' . $ debuggerCount . '}' , self :: NAME ) ) ; parent :: render ( ) ; }
|
Renders the panel HTML .
|
4,511
|
public function generateEntityCodeAction ( $ id = null ) { $ request = $ this -> getRequest ( ) ; $ id = $ request -> get ( $ this -> admin -> getIdParameter ( ) ) ; if ( $ id ) { $ subject = $ this -> admin -> getObject ( $ id ) ; if ( ! $ subject ) { $ error = sprintf ( 'unable to find the object with id : %s' , $ id ) ; return new JsonResponse ( [ 'error' => $ error ] ) ; } try { $ this -> admin -> checkAccess ( 'edit' , $ subject ) ; } catch ( Exception $ exc ) { $ error = $ exc -> getMessage ( ) ; return new JsonResponse ( [ 'error' => $ error ] ) ; } } else { $ subject = $ this -> admin -> getNewInstance ( ) ; } $ this -> admin -> setSubject ( $ subject ) ; $ form = $ this -> admin -> getForm ( ) ; $ form -> setData ( $ subject ) ; $ form -> submit ( $ request -> request -> get ( $ form -> getName ( ) ) ) ; $ entity = $ form -> getData ( ) ; $ field = $ request -> query -> get ( 'field' , 'code' ) ; $ registry = $ this -> get ( 'blast_core.code_generators' ) ; $ generator = $ registry :: getCodeGenerator ( get_class ( $ entity ) , $ field ) ; try { $ code = $ generator :: generate ( $ entity ) ; return new JsonResponse ( [ 'code' => $ code ] ) ; } catch ( \ Exception $ exc ) { $ error = $ this -> get ( 'translator' ) -> trans ( $ exc -> getMessage ( ) ) ; return new JsonResponse ( [ 'error' => $ error , 'generator' => get_class ( $ generator ) ] ) ; } }
|
Generate Entity Code action .
|
4,512
|
protected function printPendingVersion ( Version $ version , $ style ) { $ id = $ version -> getId ( ) ; $ reflectionClass = new \ ReflectionClass ( $ version -> getMigration ( ) ) ; $ absolutePath = $ reflectionClass -> getFileName ( ) ; $ fileName = $ absolutePath ? $ this -> getRelativePath ( getcwd ( ) , $ absolutePath ) : '' ; $ this -> output -> writeln ( "\t<$style>[$id] $fileName</$style>" ) ; }
|
Formats and prints a pending version with the given style .
|
4,513
|
public function setStyle ( $ style ) { $ dir = ForumEnv :: get ( 'WEB_ROOT' ) . 'themes/' . $ style . '/' ; if ( ! is_dir ( $ dir ) ) { throw new RunBBException ( 'The style ' . $ style . ' doesn\'t exist' ) ; } if ( is_file ( $ dir . 'bootstrap.php' ) ) { $ vars = include_once $ dir . 'bootstrap.php' ; if ( ! is_array ( $ vars ) ) { $ vars = [ ] ; } foreach ( $ vars as $ key => $ assets ) { if ( $ key === 'jsraw' || ! in_array ( $ key , [ 'js' , 'jshead' , 'css' ] ) ) { continue ; } foreach ( $ assets as $ asset ) { $ params = ( $ key === 'css' ) ? [ 'type' => 'text/css' , 'rel' => 'stylesheet' ] : ( ( $ key === 'js' || $ key === 'jshead' ) ? [ 'type' => 'text/javascript' ] : [ ] ) ; $ this -> addAsset ( $ key , $ asset , $ params ) ; } } $ this -> set ( 'jsraw' , isset ( $ vars [ 'jsraw' ] ) ? $ vars [ 'jsraw' ] : '' ) ; } if ( isset ( $ vars [ 'themeTemplates' ] ) && $ vars [ 'themeTemplates' ] == true ) { $ templatesDir = ForumEnv :: get ( 'WEB_ROOT' ) . 'themes/' . $ style . '/view' ; } else { $ templatesDir = ForumEnv :: get ( 'FORUM_ROOT' ) . 'View/' ; } $ this -> set ( 'style' , ( string ) $ style ) ; $ this -> addTemplatesDirectory ( $ templatesDir ) ; }
|
Initialise style load assets for given style
|
4,514
|
public function dumpAction ( ) { return $ this -> newActionMatcher ( ) -> thenExecute ( function ( $ action ) { echo "Action '" . $ action -> getName ( ) . "' : " . var_export ( $ action -> getProperties ( ) , true ) . "\n" ; } ) ; }
|
Used for debug purposes mainly
|
4,515
|
public function upload ( FileRequest $ request ) { $ crudeName = $ request -> input ( 'crudeName' ) ; $ crude = CrudeInstance :: get ( $ crudeName ) ; $ files = $ request -> file ( ) [ 'file' ] ; $ id = $ request -> input ( 'modelId' ) ; $ errors = [ ] ; if ( $ crude instanceof \ JanDolata \ CrudeCRUD \ Engine \ Interfaces \ WithValidationInterface ) { foreach ( $ files as $ key => $ file ) { $ rules = $ crude -> getValidationRules ( [ 'file' ] ) ; $ mime = $ file -> getMimeType ( ) ; $ fileTypeRules = 'file_' . collect ( explode ( '/' , $ mime ) ) -> first ( ) ; empty ( $ crude -> getValidationRules ( [ $ fileTypeRules ] ) [ $ fileTypeRules ] ) ? $ rules = $ rules : $ rules [ 'file' ] = $ rules [ 'file' ] . '|' . $ crude -> getValidationRules ( [ $ fileTypeRules ] ) [ $ fileTypeRules ] ; $ validator = Validator :: make ( [ 'file' => $ file ] , $ rules ) ; if ( $ validator -> fails ( ) ) { unset ( $ files [ $ key ] ) ; $ errors [ ] = $ file -> getClientOriginalName ( ) . ': ' . $ validator -> messages ( ) -> first ( ) ; } } } $ model = empty ( $ files ) ? $ crude -> getById ( $ id ) : $ crude -> uploadFilesById ( $ id , $ files ) ; $ response = [ 'success' => true , 'model' => $ model ] ; if ( ! empty ( $ errors ) ) { $ response = array_merge ( $ response , [ 'errors' => join ( '<br/>' , $ errors ) ] ) ; $ response [ 'success' ] = false ; } return $ response ; }
|
Handle files upload file on model is a helper field
|
4,516
|
public function downloadAll ( $ crudeName = null , $ id = null ) { if ( ! $ crudeName || ! $ id ) return redirect ( ) -> back ( ) ; $ crude = CrudeInstance :: get ( $ crudeName ) ; if ( ! $ crude ) return redirect ( ) -> back ( ) ; $ model = $ crude -> getModel ( ) -> find ( $ id ) ; if ( ! $ model ) return redirect ( ) -> back ( ) ; $ filesZip = CrudeZip :: run ( $ model ) ; if ( ! $ filesZip ) return redirect ( ) -> back ( ) ; return response ( ) -> download ( $ filesZip , $ crudeName . '-' . $ id . '.zip' ) -> deleteFileAfterSend ( true ) ; }
|
Download all files for model
|
4,517
|
public function getNamespace ( ) { if ( ! isset ( $ this -> namespace ) ) { $ reflectionClass = new \ ReflectionClass ( $ this -> name ) ; $ this -> namespace = $ reflectionClass -> getNamespaceName ( ) ; } return $ this -> namespace ; }
|
Get namespace of the class
|
4,518
|
public function getPropertyInfo ( $ prop ) { if ( ! $ this -> loaded ) { $ this -> load ( ) ; } if ( isset ( $ this -> propertiesInfos [ $ prop ] ) ) { return $ this -> propertiesInfos [ $ prop ] ; } return false ; }
|
Get property information
|
4,519
|
public function getPropertyInfoForField ( $ field ) { if ( ! $ this -> loaded ) { $ this -> load ( ) ; } foreach ( $ this -> propertiesInfos as $ name => $ infos ) { if ( $ infos -> getField ( ) == $ field ) { return $ infos ; } } return false ; }
|
Get property info corresponding to a field
|
4,520
|
public function getPropertyForField ( $ field ) { if ( ! $ this -> loaded ) { $ this -> load ( ) ; } foreach ( $ this -> propertiesInfos as $ name => $ infos ) { if ( $ infos -> getField ( ) == $ field ) { return new \ ReflectionProperty ( $ this -> name , $ name ) ; } } return false ; }
|
Get ReflectionProperty for a field
|
4,521
|
public function setCollection ( $ collection ) { if ( ! $ this -> loaded ) { $ this -> load ( ) ; } $ this -> collectionInfo -> setCollection ( $ collection ) ; return $ this ; }
|
Set the collection
|
4,522
|
private function load ( ) { $ reflectionClass = new \ ReflectionClass ( $ this -> name ) ; $ this -> collectionInfo = new CollectionInfo ( ) ; foreach ( $ this -> reader -> getClassAnnotations ( $ reflectionClass ) as $ annotation ) { $ this -> processClassAnnotation ( $ annotation ) ; } $ properties = $ reflectionClass -> getProperties ( ) ; foreach ( $ properties as $ property ) { foreach ( $ this -> reader -> getPropertyAnnotations ( $ property ) as $ annotation ) { if ( ! isset ( $ this -> propertiesInfos [ $ property -> getName ( ) ] ) ) { $ this -> propertiesInfos [ $ property -> getName ( ) ] = new PropertyInfo ( ) ; } $ this -> processPropertiesAnnotation ( $ property -> getName ( ) , $ annotation ) ; } } $ this -> eventManager = new EventManager ( ) ; if ( $ this -> hasEvent ) { $ methods = $ reflectionClass -> getMethods ( ) ; foreach ( $ methods as $ method ) { $ annotations = $ this -> reader -> getMethodAnnotations ( $ method ) ; if ( ! empty ( $ annotations ) ) { foreach ( $ annotations as $ annotation ) { if ( in_array ( 'JPC\MongoDB\ODM\Annotations\Event\Event' , class_implements ( $ annotation ) ) ) { $ this -> eventManager -> add ( $ annotation , $ method -> getName ( ) ) ; } } } } } $ this -> loaded = true ; }
|
Load all metadata
|
4,523
|
private function processClassAnnotation ( $ annotation ) { $ class = get_class ( $ annotation ) ; switch ( $ class ) { case "JPC\MongoDB\ODM\Annotations\Mapping\Document" : $ this -> collectionInfo -> setCollection ( $ annotation -> collectionName ) ; if ( null !== ( $ rep = $ annotation -> repositoryClass ) ) { $ this -> collectionInfo -> setRepository ( $ annotation -> repositoryClass ) ; } else { if ( class_exists ( $ this -> getName ( ) . 'Repository' ) ) { $ this -> collectionInfo -> setRepository ( $ this -> getName ( ) . 'Repository' ) ; } else { $ this -> collectionInfo -> setRepository ( "JPC\MongoDB\ODM\Repository" ) ; } } if ( null !== ( $ rep = $ annotation -> hydratorClass ) ) { $ this -> collectionInfo -> setHydrator ( $ annotation -> hydratorClass ) ; } else { $ this -> collectionInfo -> setHydrator ( "JPC\MongoDB\ODM\Hydrator" ) ; } $ this -> checkCollectionCreationOptions ( $ annotation ) ; break ; case "JPC\MongoDB\ODM\GridFS\Annotations\Mapping\Document" : $ this -> collectionInfo -> setBucketName ( $ annotation -> bucketName ) ; $ this -> collectionInfo -> setCollection ( $ annotation -> bucketName . ".files" ) ; if ( null !== ( $ rep = $ annotation -> repositoryClass ) ) { $ this -> collectionInfo -> setRepository ( $ annotation -> repositoryClass ) ; } else { $ this -> collectionInfo -> setRepository ( "JPC\MongoDB\ODM\GridFS\Repository" ) ; } if ( null !== ( $ rep = $ annotation -> hydratorClass ) ) { $ this -> collectionInfo -> setHydrator ( $ annotation -> hydratorClass ) ; } else { $ this -> collectionInfo -> setHydrator ( "JPC\MongoDB\ODM\GridFS\Hydrator" ) ; } break ; case "JPC\MongoDB\ODM\Annotations\Mapping\Option" : $ this -> processOptionAnnotation ( $ annotation ) ; break ; case "JPC\MongoDB\ODM\Annotations\Event\HasLifecycleCallbacks" : $ this -> hasEvent = true ; break ; } }
|
Process class annotation to extract infos
|
4,524
|
private function processOptionAnnotation ( \ JPC \ MongoDB \ ODM \ Annotations \ Mapping \ Option $ annotation ) { $ options = [ ] ; if ( isset ( $ annotation -> writeConcern ) ) { $ options [ "writeConcern" ] = $ annotation -> writeConcern -> getWriteConcern ( ) ; } if ( isset ( $ annotation -> readConcern ) ) { $ options [ "readConcern" ] = $ annotation -> readConcern -> getReadConcern ( ) ; } if ( isset ( $ annotation -> readPreference ) ) { $ options [ "readPreference" ] = $ annotation -> readPreference -> getReadPreference ( ) ; } if ( isset ( $ annotation -> typeMap ) ) { $ options [ "typeMap" ] = $ annotation -> typeMap ; } $ this -> collectionInfo -> setOptions ( $ options ) ; }
|
Process option annotation
|
4,525
|
private function processPropertiesAnnotation ( $ name , $ annotation ) { $ class = get_class ( $ annotation ) ; switch ( $ class ) { case "JPC\MongoDB\ODM\Annotations\Mapping\Id" : $ this -> propertiesInfos [ $ name ] -> setField ( "_id" ) ; $ this -> idGenerator = $ annotation -> generator ; break ; case "JPC\MongoDB\ODM\Annotations\Mapping\Field" : $ this -> propertiesInfos [ $ name ] -> setField ( $ annotation -> name ) ; break ; case "JPC\MongoDB\ODM\Annotations\Mapping\EmbeddedDocument" : $ this -> propertiesInfos [ $ name ] -> setEmbedded ( true ) ; $ this -> propertiesInfos [ $ name ] -> setEmbeddedClass ( $ annotation -> document ) ; break ; case "JPC\MongoDB\ODM\Annotations\Mapping\MultiEmbeddedDocument" : $ this -> propertiesInfos [ $ name ] -> setMultiEmbedded ( true ) ; $ this -> propertiesInfos [ $ name ] -> setEmbeddedClass ( $ annotation -> document ) ; break ; case "JPC\MongoDB\ODM\Annotations\Mapping\Id" : $ this -> propertiesInfos [ $ name ] -> setField ( "_id" ) ; break ; case "JPC\MongoDB\ODM\GridFS\Annotations\Mapping\Stream" : $ this -> propertiesInfos [ $ name ] -> setField ( "stream" ) ; break ; case "JPC\MongoDB\ODM\GridFS\Annotations\Mapping\Filename" : $ this -> propertiesInfos [ $ name ] -> setField ( "filename" ) ; break ; case "JPC\MongoDB\ODM\GridFS\Annotations\Mapping\Aliases" : $ this -> propertiesInfos [ $ name ] -> setField ( "aliases" ) ; break ; case "JPC\MongoDB\ODM\GridFS\Annotations\Mapping\ChunkSize" : $ this -> propertiesInfos [ $ name ] -> setField ( "chunkSize" ) ; break ; case "JPC\MongoDB\ODM\GridFS\Annotations\Mapping\UploadDate" : $ this -> propertiesInfos [ $ name ] -> setField ( "uploadDate" ) ; break ; case "JPC\MongoDB\ODM\GridFS\Annotations\Mapping\Length" : $ this -> propertiesInfos [ $ name ] -> setField ( "length" ) ; break ; case "JPC\MongoDB\ODM\GridFS\Annotations\Mapping\ContentType" : $ this -> propertiesInfos [ $ name ] -> setField ( "contentType" ) ; break ; case "JPC\MongoDB\ODM\GridFS\Annotations\Mapping\Md5" : $ this -> propertiesInfos [ $ name ] -> setField ( "md5" ) ; break ; case "JPC\MongoDB\ODM\GridFS\Annotations\Mapping\Metadata" : $ this -> propertiesInfos [ $ name ] -> setMetadata ( true ) ; break ; case "JPC\MongoDB\ODM\Annotations\Mapping\RefersOne" : $ referenceInfo = new ReferenceInfo ( ) ; $ referenceInfo -> setDocument ( $ annotation -> document ) -> setCollection ( $ annotation -> collection ) ; $ this -> propertiesInfos [ $ name ] -> setReferenceInfo ( $ referenceInfo ) ; break ; case "JPC\MongoDB\ODM\Annotations\Mapping\RefersMany" : $ referenceInfo = new ReferenceInfo ( ) ; $ referenceInfo -> setIsMultiple ( true ) -> setDocument ( $ annotation -> document ) -> setCollection ( $ annotation -> collection ) ; $ this -> propertiesInfos [ $ name ] -> setReferenceInfo ( $ referenceInfo ) ; break ; case "JPC\MongoDB\ODM\Annotations\Mapping\DiscriminatorField" : $ this -> propertiesInfos [ $ name ] -> setDiscriminatorField ( $ annotation -> field ) ; break ; case "JPC\MongoDB\ODM\Annotations\Mapping\DiscriminatorMap" : $ this -> propertiesInfos [ $ name ] -> setDiscriminatorMap ( $ annotation -> map ) ; break ; case "JPC\MongoDB\ODM\Annotations\Mapping\DiscriminatorMethod" : $ this -> propertiesInfos [ $ name ] -> setDiscriminatorMethod ( $ annotation -> method ) ; break ; } }
|
Process property annotation
|
4,526
|
private function checkCollectionCreationOptions ( \ JPC \ MongoDB \ ODM \ Annotations \ Mapping \ Document $ annotation ) { $ options = [ ] ; if ( $ annotation -> capped ) { $ options [ "capped" ] = true ; $ options [ "size" ] = $ annotation -> size ; if ( $ annotation -> max != false ) { $ options [ "max" ] = $ annotation -> max ; } } $ this -> collectionInfo -> setCreationOptions ( $ options ) ; }
|
Check and set collection creation options
|
4,527
|
public static function applyCallback ( callable $ callback , NodeInterface $ root , $ targetClass = ChildNodeInterface :: class ) { $ processed = [ ] ; $ f = function ( ChildNodeInterface $ targetNode ) use ( $ callback , $ targetClass , & $ f , & $ processed ) { if ( in_array ( $ targetNode , $ processed , true ) ) { return ; } $ nodes = $ targetNode instanceof ParentNodeInterface ? $ targetNode -> getChildrenRecursive ( ) -> toArray ( ) : [ ] ; $ nodes [ ] = $ targetNode ; foreach ( $ nodes as $ node ) { $ node instanceof $ targetClass && call_user_func ( $ callback , $ node ) ; $ node instanceof ParentNodeInterface && $ node -> children ( ) -> onItemAdd ( $ f ) ; $ processed [ ] = $ node ; } } ; $ f ( $ root ) ; }
|
Applies callback to root node if it s existing and further descendant nodes directly after adding to tree .
|
4,528
|
public function show ( $ posts , Request $ request ) { $ file = $ posts ; $ markdown = $ this -> pagekit -> markdown ( $ file ) ; $ view = "page::missing-page" ; if ( $ request -> has ( 'page' ) ) : $ markdown = $ this -> pagekit -> markdown ( $ request -> page , $ posts ) ; endif ; if ( ! empty ( $ markdown ) ) : $ view = 'page::markdown.show' ; endif ; return view ( $ view , compact ( 'markdown' ) ) ; }
|
Show a specific page params
|
4,529
|
public function getCronjobs ( ) { if ( ! $ this -> cronjobs ) { $ cronjobs = array ( ) ; $ results = $ this -> serviceLocator -> get ( 'Application' ) -> getEventManager ( ) -> trigger ( __FUNCTION__ , $ this , array ( 'cronjobs' => $ cronjobs ) ) ; if ( $ results ) { foreach ( $ results as $ key => $ cron ) { foreach ( $ cron as $ id => $ conf ) { $ cronjobs [ $ id ] = $ conf ; } } } $ this -> setCronjobs ( $ cronjobs ) ; } return $ this -> cronjobs ; }
|
trigger an event and fetch crons Return array
|
4,530
|
public function schedule ( ) { $ em = $ this -> getEm ( ) ; $ pending = $ this -> getPending ( ) ; $ exists = array ( ) ; foreach ( $ pending as $ job ) { $ identifier = $ job -> getCode ( ) ; $ identifier .= $ job -> getScheduleTime ( ) -> getTimeStamp ( ) ; $ exists [ $ identifier ] = true ; } $ scheduleAhead = $ this -> getScheduleAhead ( ) * 60 ; $ cronRegistry = $ this -> getCronjobs ( ) ; foreach ( $ cronRegistry as $ code => $ item ) { $ now = time ( ) ; $ timeAhead = $ now + $ scheduleAhead ; for ( $ time = $ now ; $ time < $ timeAhead ; $ time += 60 ) { $ scheduleTime = new \ DateTime ( ) ; $ scheduleTime -> setTimestamp ( $ time ) ; $ scheduleTime -> setTime ( $ scheduleTime -> format ( 'H' ) , $ scheduleTime -> format ( 'i' ) ) ; $ scheduleTimestamp = $ scheduleTime -> getTimestamp ( ) ; $ identifier = $ code . $ scheduleTimestamp ; if ( isset ( $ exists [ $ identifier ] ) ) { continue ; } $ job = new Entity \ Cronjob ; if ( $ this -> matchTime ( $ scheduleTimestamp , $ item [ 'frequency' ] ) ) { $ job -> setCode ( $ code ) -> setStatus ( Mapper \ Cronjob :: STATUS_PENDING ) -> setCreateTime ( new \ DateTime ) -> setScheduleTime ( $ scheduleTime ) ; $ em -> persist ( $ job ) ; $ exists [ $ identifier ] = true ; } } } $ em -> flush ( ) ; return $ this ; }
|
schedule cron jobs
|
4,531
|
public function resolve ( $ value , & $ resolutionType ) { if ( is_array ( $ value ) ) { $ value = $ value [ 0 ] ; } if ( is_string ( $ value ) ) { if ( strpos ( $ value , '|' ) !== false ) { $ resolutionType = ResolveAdaptorInterface :: TYPE_PIPELINE ; return $ this -> resolveMiddlewarePipeline ( $ value ) ; } elseif ( strpos ( $ value , '::' ) !== false ) { $ resolutionType = ResolveAdaptorInterface :: TYPE_STATIC ; return $ this -> resolveStatic ( $ value ) ; } elseif ( strpos ( $ value , '->' ) !== false ) { $ resolutionType = ResolveAdaptorInterface :: TYPE_INSTANCE ; return $ this -> resolveInstanceMethod ( $ value ) ; } else { $ resolutionType = ResolveAdaptorInterface :: TYPE_INVOKE ; return $ this -> resolveInvokable ( $ value ) ; } } else { $ resolutionType = ResolveAdaptorInterface :: TYPE_ORIGINAL ; return $ value ; } }
|
Attempt to convert a provided value into a callable .
|
4,532
|
protected function resolveMiddlewarePipeline ( $ value ) { $ value = strstr ( $ value , '|' , true ) ; $ instantiator = $ this -> instantiator ; $ middleware = $ instantiator ( \ Weave \ Middleware \ Middleware :: class ) ; return function ( Request $ request , $ response = null ) use ( $ middleware , $ value ) { return $ middleware -> chain ( $ value , $ request , $ response ) ; } ; }
|
Resolve the provided value to a named middleware chain .
|
4,533
|
protected function resolveInstanceMethod ( $ value ) { $ callable = explode ( '->' , $ value ) ; $ instantiator = $ this -> instantiator ; $ callable [ 0 ] = $ instantiator ( $ callable [ 0 ] ) ; return function ( ... $ params ) use ( $ callable ) { return call_user_func_array ( $ callable , $ params ) ; } ; }
|
Resolve the provided value to an instancelass method call .
|
4,534
|
private function processData ( array $ data ) : void { foreach ( $ data [ 'formatters' ] as $ locale => $ f ) { if ( ! isset ( $ this -> formatters [ $ locale ] ) ) { $ this -> formatters [ $ locale ] = array ( ) ; } foreach ( $ f as $ formatter => $ d ) { $ calendar = \ IntlDateFormatter :: GREGORIAN ; if ( isset ( $ d [ 'calendar' ] ) && $ d [ 'calendar' ] === 'traditional' ) { $ calendar = \ IntlDateFormatter :: TRADITIONAL ; } $ this -> formatters [ $ locale ] [ $ formatter ] = new \ IntlDateFormatter ( $ locale , null , null , null , $ calendar , $ d [ 'pattern' ] ) ; } } }
|
Processes the resource file data
|
4,535
|
public function getFormatter ( string $ formatter , ? string $ locale = null ) : \ IntlDateFormatter { if ( $ locale === null ) { $ locale = $ this -> locale ; } if ( ! isset ( $ this -> formatters [ $ locale ] ) ) { throw new \ InvalidArgumentException ( 'Locale data not found.' ) ; } if ( ! isset ( $ this -> formatters [ $ locale ] [ $ formatter ] ) ) { throw new \ InvalidArgumentException ( 'Formatter not found for specified locale.' ) ; } return $ this -> formatters [ $ locale ] [ $ formatter ] ; }
|
Returns a IntlDateFormatter object
|
4,536
|
public function signXML ( $ data ) { $ xml = new DOMDocument ; $ xml -> preserveWhiteSpace = false ; $ xml -> loadXML ( $ data ) ; $ sig = new DOMDocument ; $ sig -> preserveWhiteSpace = false ; $ sig -> loadXML ( '<Signature xmlns="http://www.w3.org/2000/09/xmldsig#"> <SignedInfo> <CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/> <SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/> <Reference URI=""> <Transforms> <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/> </Transforms> <DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/> <DigestValue/> </Reference> </SignedInfo> <SignatureValue/> <KeyInfo><KeyName/></KeyInfo> </Signature>' ) ; $ sig = $ xml -> importNode ( $ sig -> documentElement , true ) ; $ xml -> documentElement -> appendChild ( $ sig ) ; $ xpath = $ this -> getXPath ( $ xml ) ; $ digestValue = $ xpath -> query ( 'ds:Signature/ds:SignedInfo/ds:Reference/ds:DigestValue' ) -> item ( 0 ) ; $ digestValue -> nodeValue = $ this -> generateDigest ( $ xml ) ; $ signedInfo = $ xpath -> query ( 'ds:Signature/ds:SignedInfo' ) -> item ( 0 ) ; $ signatureValue = $ xpath -> query ( 'ds:Signature/ds:SignatureValue' ) -> item ( 0 ) ; $ signatureValue -> nodeValue = $ this -> generateSignature ( $ signedInfo ) ; $ keyName = $ xpath -> query ( 'ds:Signature/ds:KeyInfo/ds:KeyName' ) -> item ( 0 ) ; $ keyName -> nodeValue = $ this -> getPublicKeyDigest ( ) ; return $ xml -> saveXML ( ) ; }
|
Sign an XML request
|
4,537
|
public function generateDigest ( DOMDocument $ xml ) { $ xml = $ xml -> cloneNode ( true ) ; foreach ( $ this -> getXPath ( $ xml ) -> query ( 'ds:Signature' ) as $ node ) { $ node -> parentNode -> removeChild ( $ node ) ; } $ message = $ this -> c14n ( $ xml ) ; return base64_encode ( hash ( 'sha256' , $ message , true ) ) ; }
|
Generate sha256 digest of xml
|
4,538
|
public function generateSignature ( DOMNode $ xml ) { $ message = $ this -> c14n ( $ xml ) ; $ key = openssl_get_privatekey ( 'file://' . $ this -> getPrivateKeyPath ( ) , $ this -> getPrivateKeyPassphrase ( ) ) ; if ( $ key && openssl_sign ( $ message , $ signature , $ key , OPENSSL_ALGO_SHA256 ) ) { openssl_free_key ( $ key ) ; return base64_encode ( $ signature ) ; } $ error = 'Invalid private key.' ; while ( $ msg = openssl_error_string ( ) ) { $ error .= ' ' . $ msg ; } throw new InvalidRequestException ( $ error ) ; }
|
Generate RSA signature of SignedInfo element
|
4,539
|
protected function getProcessingTypesForClient ( array $ processingTypes = null ) { if ( is_null ( $ processingTypes ) ) { $ processingTypes = $ this -> systemConfig -> getAllAvailableProcessingTypes ( ) ; } return array_map ( function ( $ processingTypeClass ) { return $ this -> prepareProcessingType ( $ processingTypeClass ) ; } , $ processingTypes ) ; }
|
Loads available DataTypes from system config and converts some to cient format
|
4,540
|
protected function getPreparedCssContent ( ) { if ( $ this -> preparedContent === null ) { $ this -> preparedContent = Placeholder :: replaceStringsAndComments ( $ this -> getCssContent ( ) ) ; $ this -> preparedContent = preg_replace ( '/^([^\r\n]+)(_COMMENT_[a-f0-9]{32}_)([\r\n\t\f]+)/m' , "\\2\n\\1\\3" , $ this -> preparedContent ) ; $ this -> preparedContent = preg_replace ( '/^([ \t\f]*)(_COMMENT_[a-f0-9]{32}_)/m' , "\\2\n" , $ this -> preparedContent ) ; $ this -> preparedContent = str_replace ( [ "{" , "}" , ";" ] , [ "{\n" , "}\n" , ";\n" ] , $ this -> preparedContent ) ; } return $ this -> preparedContent ; }
|
Gets a prepared version of the CSS content for parsing .
|
4,541
|
protected function getCssResource ( ) { $ handle = fopen ( "php://memory" , "rw" ) ; fputs ( $ handle , $ this -> getPreparedCssContent ( ) ) ; rewind ( $ handle ) ; return $ handle ; }
|
Gets the CSS content as resource .
|
4,542
|
public function serialize ( ) { return serialize ( ( object ) [ 'classname' => $ this -> classname , 'type' => $ this -> type , 'service' => $ this -> service , 'parameters' => $ this -> parameters , 'request' => $ this -> request , 'query' => $ this -> query ] ) ; }
|
Return the serialized data
|
4,543
|
public function unserialize ( $ data ) { $ parts = unserialize ( $ data ) ; $ this -> classname = $ parts -> classname ; $ this -> type = $ parts -> type ; $ this -> service = $ parts -> service ; $ this -> parameters = $ parts -> parameters ; $ this -> request = $ parts -> request ; $ this -> query = $ parts -> query ; }
|
Return the unserialized object
|
4,544
|
public static function hex ( string $ name = null ) { if ( empty ( $ name ) ) { return static :: $ hexmap ; } return static :: $ hexmap [ $ name ] ?? false ; }
|
Returns the hexadecimal CSS color given the canonical name .
|
4,545
|
public function generate ( $ outputPath ) { $ this -> process ( ) ; $ baseDir = dirname ( $ outputPath ) ; if ( ! is_dir ( $ baseDir ) ) { mkdir ( $ baseDir , 700 , true ) ; } return ( bool ) file_put_contents ( $ outputPath , $ this -> getContent ( ) ) ; }
|
save generated file to path returns true if file was successfully created false otherwise
|
4,546
|
protected function formatValue ( $ value ) { if ( is_array ( $ value ) ) { return Formatter :: formatArray ( $ value ) ; } return Formatter :: formatScalar ( $ value ) ; }
|
Format a value before processing .
|
4,547
|
public function hasArgument ( string $ name ) : bool { $ this -> parsePathArguments ( ) ; return isset ( $ this -> arguments [ $ name ] ) ; }
|
checks if path contains argument with given name
|
4,548
|
public function readArgument ( string $ name ) : ValueReader { $ this -> parsePathArguments ( ) ; if ( isset ( $ this -> arguments [ $ name ] ) ) { return ValueReader :: forValue ( $ this -> arguments [ $ name ] ) ; } return ValueReader :: forValue ( null ) ; }
|
returns argument with given name or default if not set
|
4,549
|
private function parsePathArguments ( ) { if ( null !== $ this -> arguments ) { return ; } $ arguments = [ ] ; preg_match ( '/^' . self :: pattern ( $ this -> configuredPath ) . '/' , $ this -> calledPath , $ arguments ) ; array_shift ( $ arguments ) ; $ names = [ ] ; $ this -> arguments = [ ] ; preg_match_all ( '/[{][^}]*[}]/' , str_replace ( '/' , '\/' , $ this -> configuredPath ) , $ names ) ; foreach ( $ names [ 0 ] as $ key => $ name ) { if ( isset ( $ arguments [ $ key ] ) ) { $ this -> arguments [ str_replace ( [ '{' , '}' ] , '' , $ name ) ] = $ arguments [ $ key ] ; } } }
|
parses path arguments from called path
|
4,550
|
public function remaining ( string $ default = null ) { $ matches = [ ] ; preg_match ( '/(' . self :: pattern ( $ this -> configuredPath ) . ')([^?]*)?/' , $ this -> calledPath , $ matches ) ; $ last = count ( $ matches ) - 1 ; if ( 2 > $ last ) { return $ default ; } if ( isset ( $ matches [ $ last ] ) && ! empty ( $ matches [ $ last ] ) ) { return $ matches [ $ last ] ; } return $ default ; }
|
returns remaining path that was not matched by original path
|
4,551
|
public function getTemplate ( $ entityType ) { $ params = [ 'fields' => 'attributes.title' , 'limit' => 1 , ] ; $ definition = $ this -> search ( 'EntityType' , [ 'title' => $ entityType ] , $ params ) ; return array_fill_keys ( array_merge ( [ '_id' ] , array_column ( $ definition [ 0 ] [ 'attributes' ] , 'title' ) ) , null ) ; }
|
Returns an array that has all the fields according to the definition in Communibase .
|
4,552
|
public function getById ( $ entityType , $ id , array $ params = [ ] , $ version = null ) { if ( empty ( $ id ) ) { throw new Exception ( 'Id is empty' ) ; } if ( ! static :: isIdValid ( $ id ) ) { throw new Exception ( 'Id is invalid, please use a correctly formatted id' ) ; } return ( $ version === null ) ? $ this -> doGet ( $ entityType . '.json/crud/' . $ id , $ params ) : $ this -> doGet ( $ entityType . '.json/history/' . $ id . '/' . $ version , $ params ) ; }
|
Get a single Entity by its id
|
4,553
|
public function getByRef ( array $ ref , array $ parentEntity = [ ] ) { $ document = $ parentEntity ; if ( strpos ( $ ref [ 'rootDocumentEntityType' ] , 'parent' ) === false ) { if ( empty ( $ document [ '_id' ] ) || $ document [ '_id' ] !== $ ref [ 'rootDocumentId' ] ) { $ document = $ this -> getById ( $ ref [ 'rootDocumentEntityType' ] , $ ref [ 'rootDocumentId' ] ) ; } if ( count ( $ document ) === 0 ) { throw new Exception ( 'Invalid document reference (document cannot be found by Id)' ) ; } } $ container = $ document ; foreach ( $ ref [ 'path' ] as $ pathInDocument ) { if ( ! array_key_exists ( $ pathInDocument [ 'field' ] , $ container ) ) { throw new Exception ( 'Could not find the path in document' ) ; } $ container = $ container [ $ pathInDocument [ 'field' ] ] ; if ( empty ( $ pathInDocument [ 'objectId' ] ) ) { continue ; } if ( ! is_array ( $ container ) ) { throw new Exception ( 'Invalid value for path in document' ) ; } $ result = array_filter ( $ container , function ( $ item ) use ( $ pathInDocument ) { return $ item [ '_id' ] === $ pathInDocument [ 'objectId' ] ; } ) ; if ( count ( $ result ) === 0 ) { throw new Exception ( 'Empty result of reference' ) ; } $ container = reset ( $ result ) ; } return $ container ; }
|
Get a single Entity by a ref - string
|
4,554
|
public function getByIds ( $ entityType , array $ ids , array $ params = [ ] ) { $ validIds = array_values ( array_unique ( array_filter ( $ ids , [ __CLASS__ , 'isIdValid' ] ) ) ) ; if ( count ( $ validIds ) === 0 ) { return [ ] ; } $ doSortByIds = empty ( $ params [ 'sort' ] ) ; $ results = $ this -> search ( $ entityType , [ '_id' => [ '$in' => $ validIds ] ] , $ params ) ; if ( ! $ doSortByIds ) { return $ results ; } $ flipped = array_flip ( $ validIds ) ; foreach ( $ results as $ result ) { $ flipped [ $ result [ '_id' ] ] = $ result ; } return array_filter ( array_values ( $ flipped ) , function ( $ result ) { return is_array ( $ result ) && count ( $ result ) > 0 ; } ) ; }
|
Get an array of entities by their ids
|
4,555
|
public function getIds ( $ entityType , array $ selector = [ ] , array $ params = [ ] ) { $ params [ 'fields' ] = '_id' ; return array_column ( $ this -> search ( $ entityType , $ selector , $ params ) , '_id' ) ; }
|
Get result entityIds of a certain search
|
4,556
|
public function getId ( $ entityType , array $ selector = [ ] ) { $ params = [ 'limit' => 1 ] ; $ ids = ( array ) $ this -> getIds ( $ entityType , $ selector , $ params ) ; return array_shift ( $ ids ) ; }
|
Get the id of an entity based on a search
|
4,557
|
public function update ( $ entityType , array $ properties ) { if ( empty ( $ properties [ '_id' ] ) ) { return $ this -> doPost ( $ entityType . '.json/crud/' , [ ] , $ properties ) ; } return $ this -> doPut ( $ entityType . '.json/crud/' . $ properties [ '_id' ] , [ ] , $ properties ) ; }
|
This will save an entity in Communibase . When a _id - field is found this entity will be updated
|
4,558
|
public function finalize ( $ entityType , $ id ) { if ( $ entityType !== 'Invoice' ) { throw new Exception ( 'Cannot call finalize on ' . $ entityType ) ; } return $ this -> doPost ( $ entityType . '.json/finalize/' . $ id ) ; }
|
Finalize an invoice by adding an invoiceNumber to it . Besides invoice items will receive a generalLedgerAccountNumber . This number will be unique and sequential within the daybook of the invoice .
|
4,559
|
protected function doGet ( $ path , array $ params = null , array $ data = null ) { return $ this -> getResult ( 'GET' , $ path , $ params , $ data ) ; }
|
Perform the actual GET
|
4,560
|
protected function doPost ( $ path , array $ params = null , array $ data = null ) { return $ this -> getResult ( 'POST' , $ path , $ params , $ data ) ; }
|
Perform the actual POST
|
4,561
|
protected function doPut ( $ path , array $ params = null , array $ data = null ) { return $ this -> getResult ( 'PUT' , $ path , $ params , $ data ) ; }
|
Perform the actual PUT
|
4,562
|
protected function doDelete ( $ path , array $ params = null , array $ data = null ) { return $ this -> getResult ( 'DELETE' , $ path , $ params , $ data ) ; }
|
Perform the actual DELETE
|
4,563
|
private function parseResult ( $ response , $ httpCode ) { $ result = json_decode ( $ response , true ) ; if ( is_array ( $ result ) ) { return $ result ; } throw new Exception ( '"' . $ this -> getLastJsonError ( ) . '" in ' . $ response , $ httpCode ) ; }
|
Parse the Communibase result and if necessary throw an exception
|
4,564
|
private function getLastJsonError ( ) { static $ messages = [ JSON_ERROR_DEPTH => 'Maximum stack depth exceeded' , JSON_ERROR_STATE_MISMATCH => 'Underflow or the modes mismatch' , JSON_ERROR_CTRL_CHAR => 'Unexpected control character found' , JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON' , JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded' , ] ; $ jsonLastError = json_last_error ( ) ; return array_key_exists ( $ jsonLastError , $ messages ) ? $ messages [ $ jsonLastError ] : 'Empty response received' ; }
|
Error message based on the most recent JSON error .
|
4,565
|
private function call ( $ method , array $ arguments ) { try { if ( isset ( $ this -> extraHeaders [ 'host' ] ) ) { $ arguments [ 1 ] [ 'headers' ] [ 'Host' ] = $ this -> extraHeaders [ 'host' ] ; } if ( $ this -> logger ) { $ this -> logger -> startQuery ( $ method . ' ' . reset ( $ arguments ) , $ arguments ) ; } $ response = call_user_func_array ( [ $ this -> getClient ( ) , $ method ] , $ arguments ) ; if ( $ this -> logger ) { $ this -> logger -> stopQuery ( ) ; } return $ response ; } catch ( ClientException $ e ) { $ response = $ e -> getResponse ( ) ; $ response = json_decode ( $ response === null ? '' : $ response -> getBody ( ) , true ) ; throw new Exception ( $ response [ 'message' ] , $ response [ 'code' ] , $ e , ( ( $ _ = & $ response [ 'errors' ] ) ? : [ ] ) ) ; } catch ( ConnectException $ e ) { throw new Exception ( 'Can not connect' , 500 , $ e , [ ] ) ; } }
|
Perform the actual call to Communibase
|
4,566
|
protected function run ( Request $ request ) { $ handler = $ request -> getAttribute ( 'dispatch.handler' , false ) ; if ( $ handler === false ) { return $ this -> chain ( $ request ) ; } $ request = $ request -> withAttribute ( 'dispatch.handler' , $ this -> resolver -> shift ( $ handler ) ) ; $ dispatchable = $ this -> resolver -> resolve ( $ handler , $ resolutionType ) ; $ parameters = [ $ dispatchable , $ resolutionType , DispatchAdaptorInterface :: SOURCE_DISPATCH_MIDDLEWARE , $ request ] ; $ response = $ this -> getResponseObject ( ) ; if ( $ response !== null ) { $ parameters [ ] = $ response ; } return $ this -> dispatcher -> dispatch ( ... $ parameters ) ? : $ this -> chain ( $ request ) ; }
|
Handle a dispatch .
|
4,567
|
public function sort ( ) { if ( $ this -> modules ) { $ modules = [ ] ; $ sorter = new StringSort ( ) ; foreach ( $ this -> modules as $ slug => $ module ) { $ sorter -> add ( $ slug , array_intersect ( array_keys ( $ module -> getAttribute ( 'require' ) ) , array_keys ( $ this -> modules ) ) ) ; } foreach ( $ sorter -> sort ( ) as $ slug ) { $ modules [ $ slug ] = $ this -> modules [ $ slug ] ; } $ this -> modules = $ modules ; } return $ this ; }
|
Sort modules by their dependencies .
|
4,568
|
public function register ( ) { foreach ( $ this -> modules as $ module ) { if ( $ aggregator = $ module -> getAttribute ( 'aggregator' ) ) { $ this -> container -> register ( $ aggregator ) ; } } return $ this ; }
|
Register modules with service container .
|
4,569
|
private function getRangeData ( ShippingMethodCost $ cost ) { return [ 'min' => $ cost -> getRangeFrom ( ) , 'max' => $ cost -> getRangeTo ( ) , 'price' => $ cost -> getCost ( ) -> getGrossAmount ( ) , ] ; }
|
Returns costs data as an array
|
4,570
|
public function load ( ServiceContainer $ container , array $ params ) { $ container -> define ( 'ecomdev.phpspec.magento_di_adapter.vfs' , $ this -> vfsFactory ( ) ) ; $ container -> define ( 'ecomdev.phpspec.magento_di_adapter.code_generator.io' , $ this -> ioFactory ( ) ) ; $ container -> define ( 'ecomdev.phpspec.magento_di_adapter.code_generator.defined_classes' , $ this -> simplifiedDefinedClassesFactory ( ) ) ; $ container -> define ( 'ecomdev.phpspec.magento_di_adapter.parameter_validator' , $ this -> parameterValidatorFactory ( ) ) ; $ container -> define ( 'runner.maintainers.ecomdev_magento_collaborator' , $ this -> collaboratorMaintainerFactory ( ) , [ 'runner.maintainers' ] ) ; }
|
Load collaborator into PHPSpec ServiceContainer
|
4,571
|
public function parameterValidatorFactory ( ) { return function ( ServiceContainer $ container ) { $ parameterValidator = new ParameterValidator ( $ container -> get ( 'ecomdev.phpspec.magento_di_adapter.code_generator.io' ) , $ container -> get ( 'ecomdev.phpspec.magento_di_adapter.code_generator.defined_classes' ) , $ container -> get ( 'loader.transformer.typehintindex' ) ) ; $ parameterValidator -> addGenerator ( Generator \ Factory :: class , Generator \ Factory :: ENTITY_TYPE ) -> addGenerator ( Generator \ Repository :: class , Generator \ Repository :: ENTITY_TYPE ) -> addGenerator ( Generator \ Converter :: class , Generator \ Converter :: ENTITY_TYPE ) -> addGenerator ( Generator \ Persistor :: class , Generator \ Persistor :: ENTITY_TYPE ) -> addGenerator ( MapperGenerator :: class , MapperGenerator :: ENTITY_TYPE ) -> addGenerator ( SearchResults :: class , SearchResults :: ENTITY_TYPE ) ; return $ parameterValidator ; } ; }
|
Factory for instantiation of parameter validator
|
4,572
|
public function fromResponse ( array $ data ) { $ map = array ( 'id' => 'setId' , 'start' => 'setStart' , 'end' => 'setEnd' , 'hash' => 'setHash' , 'parameters' => 'setParameters' , 'created_at' => 'setCreatedAt' , 'progress' => 'setProgress' , 'status' => 'setStatus' , 'feeds' => 'setFeeds' , 'sample' => 'setSample' , 'data' => 'setData' , ) ; foreach ( $ map as $ key => $ setter ) { if ( isset ( $ data [ $ key ] ) ) { $ this -> $ setter ( $ data [ $ key ] ) ; } } return $ this ; }
|
Hydrates this preview from an array of API responses
|
4,573
|
public function create ( ) { $ params = array ( 'start' => $ this -> getStart ( ) , 'hash' => $ this -> getHash ( ) , 'parameters' => implode ( ',' , $ this -> getParameters ( ) ) ) ; if ( is_int ( $ this -> end ) ) { $ params [ 'end' ] = $ this -> getEnd ( ) ; } $ this -> fromResponse ( $ this -> getUser ( ) -> post ( 'preview/create' , $ params ) ) ; }
|
Create the preview represented by the parameters in this object
|
4,574
|
public static function listHistorics ( $ user , $ page = 1 , $ per_page = 20 ) { try { $ res = $ user -> post ( 'historics/get' , array ( 'page' => $ page , 'max' => $ page , ) ) ; $ retval = array ( 'count' => $ res [ 'count' ] , 'historics' => array ( ) ) ; foreach ( $ res [ 'data' ] as $ historic ) { $ retval [ 'historics' ] [ ] = new self ( $ user , $ historic ) ; } return $ retval ; } catch ( DataSift_Exception_APIError $ e ) { switch ( $ e -> getCode ( ) ) { case 400 : throw new DataSift_Exception_InvalidData ( $ e -> getMessage ( ) ) ; default : throw new DataSift_Exception_APIError ( 'Unexpected APIError code: ' . $ e -> getCode ( ) . ' [' . $ e -> getMessage ( ) . ']' ) ; } } }
|
List Historics queries .
|
4,575
|
public function reloadData ( ) { if ( $ this -> _deleted ) { throw new DataSift_Exception_InvalidData ( 'Cannot reload the data for a deleted Historic.' ) ; } if ( $ this -> _playback_id === false ) { throw new DataSift_Exception_InvalidData ( 'Cannot reload the data for a Historic with no playback ID.' ) ; } try { $ this -> initFromArray ( $ this -> _user -> post ( 'historics/get' , array ( 'id' => $ this -> _playback_id ) ) ) ; } catch ( DataSift_Exception_APIError $ e ) { switch ( $ e -> getCode ( ) ) { case 400 : throw new DataSift_Exception_InvalidData ( $ e -> getMessage ( ) ) ; default : throw new DataSift_Exception_APIError ( 'Unexpected APIError code: ' . $ e -> getCode ( ) . ' [' . $ e -> getMessage ( ) . ']' ) ; } } }
|
Reload the data for this object from the API .
|
4,576
|
protected function initFromArray ( $ data ) { if ( ! isset ( $ data [ 'id' ] ) ) { throw new DataSift_Exception_APIError ( 'No playback ID in the response' ) ; } if ( $ data [ 'id' ] != $ this -> _playback_id ) { throw new DataSift_Exception_APIError ( 'Incorrect playback ID in the response' ) ; } if ( ! isset ( $ data [ 'definition_id' ] ) ) { throw new DataSift_Exception_APIError ( 'No definition hash in the response' ) ; } $ this -> _hash = $ data [ 'definition_id' ] ; if ( ! isset ( $ data [ 'name' ] ) ) { throw new DataSift_Exception_APIError ( 'No name in the response' ) ; } $ this -> _name = $ data [ 'name' ] ; if ( ! isset ( $ data [ 'start' ] ) ) { throw new DataSift_Exception_APIError ( 'No start timestamp in the response' ) ; } $ this -> _start = $ data [ 'start' ] ; if ( ! isset ( $ data [ 'end' ] ) ) { throw new DataSift_Exception_APIError ( 'No end timestamp in the response' ) ; } $ this -> _end = $ data [ 'end' ] ; if ( ! isset ( $ data [ 'created_at' ] ) ) { throw new DataSift_Exception_APIError ( 'No created at timestamp in the response' ) ; } $ this -> _created_at = $ data [ 'created_at' ] ; if ( ! isset ( $ data [ 'status' ] ) ) { throw new DataSift_Exception_APIError ( 'No status in the response' ) ; } $ this -> _status = $ data [ 'status' ] ; if ( ! isset ( $ data [ 'progress' ] ) ) { throw new DataSift_Exception_APIError ( 'No progress in the response' ) ; } $ this -> _progress = $ data [ 'progress' ] ; if ( ! isset ( $ data [ 'sources' ] ) ) { throw new DataSift_Exception_APIError ( 'No sources in the response' ) ; } $ this -> _sources = $ data [ 'sources' ] ; if ( ! isset ( $ data [ 'sample' ] ) ) { throw new DataSift_Exception_APIError ( 'No smaple in the response' ) ; } $ this -> _sample = $ data [ 'sample' ] ; if ( isset ( $ data [ 'estimated_completion' ] ) ) { $ this -> _estimated_completion = $ data [ 'estimated_completion' ] ; } if ( $ this -> _status == 'deleted' ) { $ this -> _deleted = true ; } }
|
Initialise this object from the data in the given array .
|
4,577
|
public function prepare ( ) { if ( $ this -> _deleted ) { throw new DataSift_Exception_InvalidData ( 'Cannot prepare a deleted Historic.' ) ; } if ( $ this -> _playback_id !== false ) { throw new DataSift_Exception_InvalidData ( 'This historic query has already been prepared.' ) ; } try { $ res = $ this -> _user -> post ( 'historics/prepare' , array ( 'hash' => $ this -> _hash , 'start' => $ this -> _start , 'end' => $ this -> _end , 'name' => $ this -> _name , 'sources' => implode ( ',' , $ this -> _sources ) , 'sample' => $ this -> _sample , ) ) ; if ( isset ( $ res [ 'id' ] ) ) { $ this -> _playback_id = $ res [ 'id' ] ; } else { throw new DataSift_Exception_APIError ( 'Prepared successfully but no playback ID in the response' ) ; } if ( isset ( $ res [ 'dpus' ] ) ) { $ this -> _dpus = $ res [ 'dpus' ] ; } else { throw new DataSift_Exception_APIError ( 'Prepared successfully but no DPU cost in the response' ) ; } if ( isset ( $ res [ 'availability' ] ) ) { $ this -> _availability = $ res [ 'availability' ] ; } else { throw new DataSift_Exception_APIError ( 'Prepared successfully but no availability in the response' ) ; } } catch ( DataSift_Exception_APIError $ e ) { switch ( $ e -> getCode ( ) ) { case 400 : throw new DataSift_Exception_InvalidData ( $ e -> getMessage ( ) ) ; default : throw new DataSift_Exception_APIError ( 'Unexpected APIError code: ' . $ e -> getCode ( ) . ' [' . $ e -> getMessage ( ) . ']' ) ; } } }
|
Call the DataSift API to prepare this historic query .
|
4,578
|
public function stop ( ) { if ( $ this -> _deleted ) { throw new DataSift_Exception_InvalidData ( 'Cannot stop a deleted Historic.' ) ; } if ( $ this -> _playback_id === false || strlen ( $ this -> _playback_id ) == 0 ) { throw new DataSift_Exception_InvalidData ( 'Cannot stop a historic query that hasn\'t been prepared.' ) ; } try { $ res = $ this -> _user -> post ( 'historics/stop' , array ( 'id' => $ this -> _playback_id , ) ) ; } catch ( DataSift_Exception_APIError $ e ) { switch ( $ e -> getCode ( ) ) { case 400 : throw new DataSift_Exception_InvalidData ( $ e -> getMessage ( ) ) ; case 404 : throw new DataSift_Exception_InvalidData ( $ e -> getMessage ( ) ) ; default : throw new DataSift_Exception_APIError ( 'Unexpected APIError code: ' . $ e -> getCode ( ) . ' [' . $ e -> getMessage ( ) . ']' ) ; } } }
|
Stop this historic query .
|
4,579
|
public function pause ( $ reason = false ) { if ( $ this -> _deleted ) { throw new DataSift_Exception_InvalidData ( 'Cannot pause a deleted Historic.' ) ; } if ( $ this -> _playback_id === false || strlen ( $ this -> _playback_id ) == 0 ) { throw new DataSift_Exception_InvalidData ( 'Cannot pause a historic query that hasn\'t been prepared.' ) ; } try { $ params = array ( 'id' => $ this -> _playback_id ) ; if ( $ reason ) { $ params [ 'reason' ] = $ reason ; } $ res = $ this -> _user -> post ( 'historics/pause' , $ params ) ; } catch ( DataSift_Exception_APIError $ e ) { switch ( $ e -> getCode ( ) ) { case 400 : throw new DataSift_Exception_InvalidData ( $ e -> getMessage ( ) ) ; case 404 : throw new DataSift_Exception_InvalidData ( $ e -> getMessage ( ) ) ; default : throw new DataSift_Exception_APIError ( 'Unexpected APIError code: ' . $ e -> getCode ( ) . ' [' . $ e -> getMessage ( ) . ']' ) ; } } }
|
Pause this historic query .
|
4,580
|
final public function internalSetParent ( ParentNodeInterface $ parent ) { $ this -> emit ( 'parent.change' , [ $ parent , $ this ] ) ; $ this -> parentNode = $ parent ; }
|
Attaches component to registry .
|
4,581
|
public function create ( $ table , $ data ) { $ keys = array_keys ( $ data ) ; $ values = ':' . implode ( ',:' , $ keys ) ; $ keys = implode ( ',' , $ keys ) ; return $ this -> query ( $ this -> set ( "INSERT INTO {$table} ({$keys}) VALUES({$values})" , $ data ) ) ; }
|
Perform an INSERT statement .
|
4,582
|
public function delete ( $ table , $ data , $ conjunction = 'AND' ) { $ keys = array_keys ( $ data ) ; $ pairs = Array ( ) ; foreach ( $ keys as $ key ) { $ pairs [ ] = "{$key}=:{$key}" ; } $ pairs = implode ( " {$conjunction} " , $ pairs ) ; return $ this -> query ( $ this -> set ( "DELETE FROM {$table} WHERE {$pairs}" , $ data ) ) ; }
|
Perform a DELETE statement .
|
4,583
|
public function update ( $ table , $ data , $ where , $ conjunction = 'AND' ) { $ values = array_merge ( array_values ( $ data ) , array_values ( $ where ) ) ; $ keys = array_keys ( $ data ) ; $ pairs = Array ( ) ; foreach ( $ keys as $ key ) { $ pairs [ ] = "{$key}=?" ; } $ pairs = implode ( ',' , $ pairs ) ; $ keys = array_keys ( $ where ) ; $ condition = Array ( ) ; foreach ( $ keys as $ key ) { $ condition [ ] = "{$key}=?" ; } $ condition = implode ( " {$conjunction} " , $ condition ) ; return $ this -> query ( $ this -> set ( "UPDATE {$table} SET {$pairs} WHERE {$condition}" , $ values ) ) ; }
|
Perform an UPDATE statement .
|
4,584
|
public function select ( $ table , $ select , $ where , $ conjunction = 'AND' ) { $ keys = array_keys ( $ where ) ; $ pairs = Array ( ) ; foreach ( $ keys as $ key ) { $ pairs [ ] = "{$key}=:{$key}" ; } $ pairs = implode ( " {$conjunction} " , $ pairs ) ; if ( is_array ( $ select ) ) { $ select = implode ( ',' , $ select ) ; } return $ this -> query ( $ this -> set ( "SELECT {$select} FROM {$table} WHERE {$pairs}" , $ where ) ) ; }
|
Perform a SELECT statement .
|
4,585
|
public function set ( $ q , $ args ) { if ( is_array ( $ args ) && isset ( $ args [ 'raw' ] ) ) { $ q = implode ( $ args [ 'raw' ] , explode ( '?' , $ q , 2 ) ) ; ; } else if ( is_array ( $ args ) ) { $ first = array_keys ( $ args ) ; $ first = array_shift ( $ first ) ; if ( ! is_numeric ( $ first ) ) { return $ this -> setAssociativeArrayPlaceHolders ( $ q , $ args ) ; } return $ this -> setQuestionMarkPlaceHolders ( $ q , $ args ) ; } else { $ q = implode ( $ this -> prepareType ( $ args ) , explode ( '?' , $ q , 2 ) ) ; } return $ q ; }
|
Bind passed variables into a query string and do proper type checking and escaping before binding .
|
4,586
|
private function setQuestionMarkPlaceHolders ( $ q , $ args ) { foreach ( $ args as $ k => $ a ) { if ( is_array ( $ a ) && isset ( $ a [ 'raw' ] ) ) { $ args [ $ k ] = $ a [ 'raw' ] ; } else { $ args [ $ k ] = $ this -> prepareType ( $ a ) ; } } $ positions = Array ( ) ; $ p = - 1 ; while ( ( $ p = strpos ( $ q , '?' , $ p + 1 ) ) !== false ) { $ positions [ ] = $ p ; } if ( count ( $ args ) != count ( $ positions ) ) { throw new \ Disco \ exceptions \ DBQuery ( 'Number of passed arguements does not match the number of `?` placeholders' ) ; } $ args = array_reverse ( $ args ) ; $ positions = array_reverse ( $ positions ) ; foreach ( $ positions as $ k => $ pos ) { $ q = substr_replace ( $ q , $ args [ $ k ] , $ pos , 1 ) ; } return $ q ; }
|
Set ? mark value placeholders with the values passed in args in the order they are set in the query and the args .
|
4,587
|
private function prepareType ( $ arg ) { if ( ( $ arg === null || $ arg == 'null' ) && $ arg !== 0 ) { return 'NULL' ; } if ( ! is_numeric ( $ arg ) ) { return $ this -> quote ( $ arg ) ; } return $ arg ; }
|
Determine the type of variable being bound into the query either a String or Numeric .
|
4,588
|
public static function create ( $ url , $ pipelineId , $ apiToken , $ password ) { $ baseUrl = $ url . '/rest_services/v1/' . $ pipelineId ; $ httpClient = new CurlHttpClient ( ) ; $ httpClient -> setUserCredentials ( $ apiToken , $ password ) ; $ dateTimeFormat = Defaults :: DATE_FORMAT ; $ repoFactory = new RestRepositoryFactory ( $ baseUrl , $ httpClient , $ dateTimeFormat ) ; $ infoMethods = new RestInfoMethods ( $ baseUrl , $ httpClient ) ; $ entityTypes = array_flip ( $ infoMethods -> fetchEntityPublic ( ) ) ; $ client = new PipelinerClient ( $ entityTypes , $ repoFactory , $ infoMethods ) ; return $ client ; }
|
Creates a PipelinerClient object with sensible default configuration . Will perform a HTTP request to fetch the existing entity types for the pipeline .
|
4,589
|
public function getRepository ( $ entityName ) { if ( $ entityName instanceof Entity ) { $ entityName = $ entityName -> getType ( ) ; } if ( ! isset ( $ this -> repositories [ $ entityName ] ) ) { $ plural = $ this -> getCollectionName ( $ entityName ) ; $ this -> repositories [ $ entityName ] = $ this -> repositoryFactory -> createRepository ( $ entityName , $ plural ) ; } return $ this -> repositories [ $ entityName ] ; }
|
Returns a repository for the specified entity .
|
4,590
|
public function parse ( \ Twig_Token $ token ) { $ lineno = $ token -> getLine ( ) ; $ nodes [ 'criteria' ] = $ this -> parser -> getExpressionParser ( ) -> parseExpression ( ) ; $ this -> parser -> getStream ( ) -> expect ( 'as' ) ; $ targets = $ this -> parser -> getExpressionParser ( ) -> parseAssignmentExpression ( ) ; $ this -> parser -> getStream ( ) -> expect ( \ Twig_Token :: BLOCK_END_TYPE ) ; $ nodes [ 'body' ] = $ this -> parser -> subparse ( array ( $ this , 'endOfTag' ) , true ) ; $ this -> parser -> getStream ( ) -> expect ( \ Twig_Token :: BLOCK_END_TYPE ) ; $ elementsTarget = $ targets -> getNode ( 0 ) ; $ nodes [ 'elementsTarget' ] = new \ Twig_Node_Expression_AssignName ( $ elementsTarget -> getAttribute ( 'name' ) , $ elementsTarget -> getLine ( ) ) ; return new PageNode ( $ nodes , array ( ) , $ lineno , $ this -> getTag ( ) ) ; }
|
Define how our page tag should be parsed .
|
4,591
|
private static function initialize ( $ method , $ ssl , $ url , $ headers , $ params , $ userAgent , $ qs , $ raw = false ) { $ ch = curl_init ( ) ; switch ( strtolower ( $ method ) ) { case 'post' : curl_setopt ( $ ch , CURLOPT_POST , true ) ; curl_setopt ( $ ch , CURLOPT_POSTFIELDS , ( $ raw ? $ params : json_encode ( $ params ) ) ) ; break ; case 'get' : curl_setopt ( $ ch , CURLOPT_HTTPGET , true ) ; break ; case 'put' : curl_setopt ( $ ch , CURLOPT_CUSTOMREQUEST , 'PUT' ) ; curl_setopt ( $ ch , CURLOPT_POSTFIELDS , json_encode ( $ params ) ) ; break ; case 'delete' : curl_setopt ( $ ch , CURLOPT_CUSTOMREQUEST , 'DELETE' ) ; break ; default : throw new DataSift_Exception_NotYetImplemented ( 'Method not of valid type' ) ; } $ url = self :: appendQueryString ( $ url , $ qs ) ; curl_setopt ( $ ch , CURLOPT_URL , $ url ) ; curl_setopt ( $ ch , CURLOPT_HEADER , true ) ; curl_setopt ( $ ch , CURLOPT_HTTPHEADER , $ headers ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , true ) ; curl_setopt ( $ ch , CURLOPT_USERAGENT , $ userAgent ) ; if ( $ ssl ) { curl_setopt ( $ ch , CURLOPT_SSL_VERIFYPEER , true ) ; curl_setopt ( $ ch , CURLOPT_SSL_VERIFYHOST , 2 ) ; curl_setopt ( $ ch , CURLOPT_SSLVERSION , 'CURL_SSLVERSION_TLSv1_2' ) ; } return $ ch ; }
|
Initalize the cURL connection .
|
4,592
|
protected static function decodeBody ( array $ res ) { $ format = isset ( $ res [ 'headers' ] [ 'x-datasift-format' ] ) ? $ res [ 'headers' ] [ 'x-datasift-format' ] : $ res [ 'headers' ] [ 'content-type' ] ; $ retval = array ( ) ; if ( strtolower ( $ format ) == 'json_new_line' ) { foreach ( explode ( "\n" , $ res [ 'body' ] ) as $ json_string ) { $ retval [ ] = json_decode ( $ json_string , true ) ; } } else { $ retval = json_decode ( $ res [ 'body' ] , true ) ; } return $ retval ; }
|
Decode the JSON response depending on the format .
|
4,593
|
private static function parseHTTPResponse ( $ str ) { $ retval = array ( 'headers' => array ( ) , 'body' => '' , ) ; $ lastfield = false ; $ fields = explode ( "\n" , preg_replace ( '/\x0D\x0A[\x09\x20]+/' , ' ' , $ str ) ) ; foreach ( $ fields as $ field ) { if ( strlen ( trim ( $ field ) ) == 0 ) { $ lastfield = ':body' ; } elseif ( $ lastfield == ':body' ) { $ retval [ 'body' ] .= $ field . "\n" ; } else { if ( ( $ field [ 0 ] == ' ' or $ field [ 0 ] == "\t" ) and $ lastfield !== false ) { $ retval [ 'headers' ] [ $ lastfield ] .= ' ' . $ field ; } elseif ( preg_match ( '/([^:]+): (.+)/m' , $ field , $ match ) ) { $ match [ 1 ] = strtolower ( $ match [ 1 ] ) ; if ( isset ( $ retval [ 'headers' ] [ $ match [ 1 ] ] ) ) { if ( is_array ( $ retval [ 'headers' ] [ $ match [ 1 ] ] ) ) { $ retval [ 'headers' ] [ $ match [ 1 ] ] [ ] = $ match [ 2 ] ; } else { $ retval [ 'headers' ] [ $ match [ 1 ] ] = array ( $ retval [ 'headers' ] [ $ match [ 1 ] ] , $ match [ 2 ] ) ; } } else { $ retval [ 'headers' ] [ $ match [ 1 ] ] = trim ( $ match [ 2 ] ) ; } } } } return $ retval ; }
|
Parse an HTTP response . Separates the headers from the body and puts the headers into an associative array .
|
4,594
|
public function onKernelRequest ( GetResponseEvent $ event ) { $ this -> errorHandler -> registerErrorHandler ( $ this -> notifier ) ; $ this -> errorHandler -> registerShutdownHandler ( $ this -> notifier ) ; }
|
Register error handler .
|
4,595
|
public function onKernelException ( GetResponseForExceptionEvent $ event ) { if ( $ event -> getException ( ) instanceof HttpException ) { return ; } $ this -> setException ( $ event -> getException ( ) ) ; }
|
Save exception .
|
4,596
|
public function onKernelResponse ( FilterResponseEvent $ event ) { if ( $ this -> getException ( ) ) { $ this -> notifier -> reportException ( $ this -> getException ( ) ) ; $ this -> setException ( null ) ; } }
|
Wrap exception with additional info .
|
4,597
|
public function setTheme ( DataSourceViewInterface $ dataSource , $ theme , array $ vars = [ ] ) { $ this -> themes [ $ dataSource -> getName ( ) ] = ( $ theme instanceof Twig_Template ) ? $ theme : $ this -> environment -> loadTemplate ( $ theme ) ; $ this -> themesVars [ $ dataSource -> getName ( ) ] = $ vars ; }
|
Set theme for specific DataSource . Theme is nothing more than twig template that contains some or all of blocks required to render DataSource .
|
4,598
|
public function setRoute ( DataSourceViewInterface $ dataSource , $ route , array $ additional_parameters = [ ] ) { $ this -> routes [ $ dataSource -> getName ( ) ] = $ route ; $ this -> additional_parameters [ $ dataSource -> getName ( ) ] = $ additional_parameters ; }
|
Set route and optionally additional parameters for specific DataSource .
|
4,599
|
private function resolveMaxResultsOptions ( array $ options , DataSourceViewInterface $ dataSource ) { $ optionsResolver = new OptionsResolver ( ) ; $ optionsResolver -> setDefaults ( [ 'route' => $ this -> getCurrentRoute ( $ dataSource ) , 'active_class' => 'active' , 'additional_parameters' => [ ] , 'results' => [ 5 , 10 , 20 , 50 , 100 ] ] ) -> setAllowedTypes ( 'route' , 'string' ) -> setAllowedTypes ( 'active_class' , 'string' ) -> setAllowedTypes ( 'additional_parameters' , 'array' ) -> setAllowedTypes ( 'results' , 'array' ) ; return $ optionsResolver -> resolve ( $ options ) ; }
|
Validate and resolve options passed in Twig to datasource_results_per_page_widget
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.