idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
17,200
public function onPreDispatch ( ActionDispatchEvent $ event ) { $ message = sprintf ( 'Match callable "%s" for action "%s".' , Reflection :: getCalledMethod ( $ event -> getCallable ( ) -> getReflection ( ) ) , $ event -> getAction ( ) -> getName ( ) ) ; $ this -> logger -> debug ( $ message ) ; }
On pre dispatch event
17,201
public function onPostDispatch ( ActionDispatchEvent $ event ) { $ message = sprintf ( 'Complete handle API method "%s". Response object: %s' , $ event -> getAction ( ) -> getName ( ) , get_class ( $ event -> getResponse ( ) ) ) ; $ this -> logger -> debug ( $ message ) ; }
On post dispatch
17,202
public function onView ( ActionViewEvent $ event ) { $ message = sprintf ( 'The action "%s" return not ResponseInterface instance. Try create Response instance via result data...' , $ event -> getAction ( ) -> getName ( ) ) ; $ this -> logger -> debug ( $ message ) ; }
On view event
17,203
public static function autoLoadEntity ( $ sEntity , array $ aSql , $ sPrefix = '' , $ bAddOnStdClass = false , $ sEntityNamespace = null ) { if ( $ sEntity === '' ) { return ; } if ( $ sEntityNamespace !== null ) { self :: setEntityNamespace ( $ sEntityNamespace ) ; } $ sEntityName = self :: $ _sEntityNamespace . $ sEntity ; if ( ! class_exists ( $ sEntityName ) ) { return ; } $ oEntityCall = new $ sEntityName ; $ oReflectionClass = new \ ReflectionClass ( $ sEntityName ) ; $ oReflectionProperties = $ oReflectionClass -> getProperties ( ) ; foreach ( $ oReflectionProperties as $ aProperty ) { if ( preg_match ( '/@map ([a-zA-Z_]+)/' , $ aProperty -> getDocComment ( ) , $ aMatch ) ) { $ sEntitieRealName = $ aMatch [ 1 ] ; } else { $ sEntitieRealName = $ aProperty -> getName ( ) ; } if ( method_exists ( $ oEntityCall , 'set_' . $ aProperty -> getName ( ) ) ) { if ( isset ( $ aSql [ $ sPrefix . $ sEntitieRealName ] ) ) { $ sMethodName = 'set_' . $ aProperty -> getName ( ) ; $ oEntityCall -> $ sMethodName ( $ aSql [ $ sPrefix . $ sEntitieRealName ] ) ; } } } if ( $ bAddOnStdClass === true ) { foreach ( $ aSql as $ sKey => $ asField ) { if ( preg_match ( '/^\.[^.]+$/' , $ sKey ) ) { $ sParameterName = str_replace ( '.' , '' , $ sKey ) ; $ oEntityCall -> $ sParameterName = $ aSql [ $ sKey ] ; } } } return $ oEntityCall ; }
auto load the domain by a sql return
17,204
public static function getAllEntity ( $ oEntityCall , $ bReturnNotNulOnly = false ) { if ( ! is_object ( $ oEntityCall ) ) { return array ( ) ; } $ oReflectionClass = new \ ReflectionClass ( get_class ( $ oEntityCall ) ) ; $ oReflectionMethod = $ oReflectionClass -> getMethods ( ) ; $ aFieldsToReturn = array ( ) ; foreach ( $ oReflectionMethod as $ aMethod ) { if ( preg_match ( '/^get_[a-zA-Z_]+/' , $ aMethod -> getName ( ) ) ) { $ sMethodsCall = $ aMethod -> getName ( ) ; $ sFieldName = preg_replace ( '/^get_/' , '' , $ aMethod -> getName ( ) ) ; if ( $ oEntityCall -> $ sMethodsCall ( ) !== null || ( $ oEntityCall -> $ sMethodsCall ( ) === null && $ bReturnNotNulOnly === false ) ) { $ aFieldsToReturn [ $ sFieldName ] = $ oEntityCall -> $ sMethodsCall ( ) ; } } } $ oReflectionProperties = $ oReflectionClass -> getProperties ( ) ; foreach ( $ oEntityCall as $ sKey => $ aProperty ) { $ aFieldsToReturn [ $ sKey ] = self :: getAllEntity ( $ aProperty , $ bReturnNotNulOnly ) ; } return $ aFieldsToReturn ; }
get all field of entity in array
17,205
public function aroundProcessRelation ( \ Magento \ Quote \ Model \ Quote \ Relation $ subject , \ Closure $ proceed , \ Magento \ Framework \ Model \ AbstractModel $ object ) { $ proceed ( $ object ) ; assert ( $ object instanceof \ Magento \ Quote \ Model \ Quote ) ; $ quoteId = $ object -> getId ( ) ; $ addrShipping = $ object -> getShippingAddress ( ) ; $ total = $ addrShipping -> getData ( \ Praxigento \ Wallet \ Model \ Quote \ Address \ Total \ Partial :: CODE_TOTAL ) ; $ baseTotal = $ addrShipping -> getData ( \ Praxigento \ Wallet \ Model \ Quote \ Address \ Total \ Partial :: CODE_BASE_TOTAL ) ; $ exist = $ this -> daoPartialQuote -> getById ( $ quoteId ) ; if ( $ exist ) { $ baseTotalExist = $ exist -> getBasePartialAmount ( ) ; if ( $ baseTotalExist == $ baseTotal ) { } elseif ( abs ( $ baseTotal ) < Cfg :: DEF_ZERO ) { $ this -> daoPartialQuote -> deleteById ( $ quoteId ) ; } else { $ exist -> setPartialAmount ( $ total ) ; $ exist -> setBasePartialAmount ( $ baseTotal ) ; $ this -> daoPartialQuote -> updateById ( $ quoteId , $ exist ) ; } } elseif ( abs ( $ baseTotal ) > Cfg :: DEF_ZERO ) { $ baseCurr = $ object -> getBaseCurrencyCode ( ) ; $ curr = $ object -> getQuoteCurrencyCode ( ) ; $ data = new \ Praxigento \ Wallet \ Repo \ Data \ Partial \ Quote ( ) ; $ data -> setQuoteRef ( $ quoteId ) ; $ data -> setPartialAmount ( $ total ) ; $ data -> setCurrency ( $ curr ) ; $ data -> setBasePartialAmount ( $ baseTotal ) ; $ data -> setBaseCurrency ( $ baseCurr ) ; $ this -> daoPartialQuote -> create ( $ data ) ; } }
Process original relations then save partial payment totals .
17,206
public function getAPIKey ( ) { $ key = SiteConfig :: current_site_config ( ) -> GoogleAPIKey ; if ( ! $ key ) { $ key = self :: config ( ) -> api_key ; } return $ key ; }
Answers the API key from site or YAML configuration .
17,207
public function getAPILanguage ( ) { $ lang = SiteConfig :: current_site_config ( ) -> GoogleAPILanguage ; if ( ! $ lang ) { $ lang = self :: config ( ) -> api_language ; } return $ lang ; }
Answers the API language from site or YAML configuration .
17,208
public function getAnalyticsTrackingID ( ) { $ id = SiteConfig :: current_site_config ( ) -> GoogleAnalyticsTrackingID ; if ( ! $ id ) { $ id = self :: config ( ) -> analytics_tracking_id ; } return $ id ; }
Answers the analytics tracking ID from site or YAML configuration .
17,209
public function getVerificationCode ( ) { $ code = SiteConfig :: current_site_config ( ) -> GoogleVerificationCode ; if ( ! $ code ) { $ code = self :: config ( ) -> verification_code ; } return $ code ; }
Answers the site verification code from site or YAML configuration .
17,210
public function isAnalyticsEnabled ( ) { $ enabled = SiteConfig :: current_site_config ( ) -> GoogleAnalyticsEnabled ; if ( ! $ enabled ) { $ enabled = self :: config ( ) -> analytics_enabled ; } return ( boolean ) $ enabled ; }
Answers true if analytics is enabled for the site .
17,211
protected function loadUserRolesViaData ( $ userId ) { $ crudRoles = $ this -> userRoleIdentifier -> listEntries ( [ 'user' => $ userId ] , [ 'user' => '=' ] ) ; $ roles = [ 'ROLE_USER' ] ; if ( $ crudRoles !== null ) { foreach ( $ crudRoles as $ crudRole ) { $ role = $ crudRole -> get ( 'role' ) ; $ roles [ ] = $ role [ 'name' ] ; } } return $ roles ; }
Loads the roles of an user via an AbstractData instance .
17,212
protected function loadUserRolesViaManyToMany ( $ user ) { $ roles = [ 'ROLE_USER' ] ; if ( is_string ( $ this -> userRoleIdentifier ) ) { foreach ( $ user -> get ( $ this -> userRoleIdentifier ) as $ role ) { $ roles [ ] = $ role [ 'name' ] ; } } return $ roles ; }
Loads the roles of an user via a many - to - many relationship
17,213
public function loadUserByUsername ( $ username ) { $ users = $ this -> userData -> listEntries ( [ $ this -> usernameField => $ username ] , [ $ this -> usernameField => '=' ] , 0 , 1 ) ; if ( count ( $ users ) === 0 ) { throw new UsernameNotFoundException ( ) ; } $ user = $ users [ 0 ] ; $ roles = is_string ( $ this -> userRoleIdentifier ) ? $ this -> loadUserRolesViaManyToMany ( $ user ) : $ this -> loadUserRolesViaData ( $ user -> get ( 'id' ) ) ; $ userObj = new User ( $ this -> usernameField , $ this -> passwordField , $ this -> saltField , $ user , $ roles ) ; return $ userObj ; }
Loads and returns an user by username . Throws an UsernameNotFoundException on not existing username .
17,214
public static function add ( $ label , $ urlCode = null , $ addedArgs = array ( ) ) { self :: $ items [ ] = new BreadcrumbItem ( $ label , $ urlCode , $ addedArgs ) ; }
Add a new item to the breadcrumb
17,215
public function render ( ) { $ path = $ this -> resolvePathVariable ( ) ; $ content = "PATH=$path \n" . implode ( PHP_EOL , $ this -> getJobs ( ) ) ; return $ content ; }
Render the crontab and associated jobs
17,216
public function jobExists ( $ job = '' ) { $ process = new Process ( 'crontab -l' ) ; $ process -> run ( ) ; $ output = ( $ process -> getIncrementalOutput ( ) ) ; $ jobs = array_filter ( explode ( PHP_EOL , $ output ) , function ( $ line ) { return '' != trim ( $ line ) ; } ) ; return is_array ( $ jobs ) ? array_search ( $ job , $ jobs ) : false ; }
search job in jobs
17,217
private function parseHeader ( $ header ) { $ header = explode ( "\n" , $ header ) ; $ statusLine = explode ( ' ' , trim ( $ header [ 0 ] ) , 3 ) ; if ( ! isset ( $ statusLine [ 2 ] ) || substr ( $ statusLine [ 2 ] , 0 , 5 ) !== 'HTTP/' ) { throw new HttpException ( 'Request is not HTTP complaint.' , HttpCode :: BAD_REQUEST , array ( ) , true ) ; } if ( isset ( $ statusLine [ 1 ] [ self :: MAX_URI_LENGTH ] ) ) { throw new HttpException ( 'URI should be equal or less than ' . self :: MAX_URI_LENGTH . ' characters' , HttpCode :: REQUEST_URI_TOO_LONG ) ; } $ this -> method = $ statusLine [ 0 ] ; $ fullUri = explode ( '?' , $ statusLine [ 1 ] , 2 ) ; $ this -> uri = $ fullUri [ 0 ] ; if ( isset ( $ fullUri [ 1 ] ) ) { $ this -> queryString = $ fullUri [ 1 ] ; } $ this -> protocolVersion = substr ( $ statusLine [ 2 ] , 5 ) ; if ( $ this -> protocolVersion !== '1.1' && $ this -> protocolVersion !== '1.0' ) { throw new HttpException ( 'Requested HTTP version is not supported' , HttpCode :: VERSION_NOT_SUPPORTED , array ( ) , true ) ; } unset ( $ header [ 0 ] ) ; $ this -> populateHeaders ( $ header ) ; $ this -> isRequestCollected = true ; }
Parses HTTP header & populates http headers
17,218
public function getHydratorClass ( $ class ) { $ inflector = $ this -> configuration -> getInflector ( ) ; $ realClass = $ inflector -> getUserClassName ( $ class ) ; $ hydratorClass = $ inflector -> getGeneratedClassName ( $ realClass , [ 'generator' => get_class ( $ this ) ] ) ; if ( ! class_exists ( $ hydratorClass ) ) { $ ast = $ this -> generateAst ( $ realClass , $ hydratorClass ) ; $ this -> configuration -> getGeneratorStrategy ( ) -> generate ( $ ast ) ; $ this -> configuration -> getAutoloader ( ) -> __invoke ( $ hydratorClass ) ; } return $ hydratorClass ; }
Returns a hydrator class for a class name
17,219
protected function generateAst ( $ realClass , $ hydratorClass ) { $ originalClass = new \ ReflectionClass ( $ realClass ) ; $ builder = new ClassBuilder ; $ traverser = new NodeTraverser ; $ ast = $ builder -> fromReflection ( $ originalClass ) ; $ traverser -> addVisitor ( new MethodDisablerVisitor ( function ( ) { return false ; } ) ) ; $ this -> addMethodVisitors ( $ originalClass , $ traverser ) ; $ traverser -> addVisitor ( new ClassExtensionVisitor ( $ realClass , $ realClass ) ) ; $ traverser -> addVisitor ( new ClassImplementorVisitor ( $ realClass , [ 'Indigo\\Hydra\\Hydrator' ] ) ) ; $ traverser -> addVisitor ( new ClassRenamerVisitor ( $ originalClass , $ hydratorClass ) ) ; return $ traverser -> traverse ( $ ast ) ; }
Generates an AST out of a given reflection class and a target hydrator name
17,220
protected function addMethodVisitors ( \ ReflectionClass $ originalClass , NodeTraverser $ traverser ) { $ accessibleProperties = $ this -> getProperties ( $ originalClass , \ ReflectionProperty :: IS_PUBLIC | \ ReflectionProperty :: IS_PROTECTED ) ; $ propertyWriters = $ this -> getPropertyWriters ( $ originalClass ) ; $ traverser -> addVisitor ( new Visitor \ ConstructorMethod ( $ accessibleProperties , $ propertyWriters ) ) ; $ traverser -> addVisitor ( new Visitor \ HydrateMethod ( $ accessibleProperties , $ propertyWriters ) ) ; $ traverser -> addVisitor ( new Visitor \ ExtractMethod ( $ accessibleProperties , $ propertyWriters ) ) ; }
Adds method visitors
17,221
protected function getPropertyWriters ( \ ReflectionClass $ originalClass ) { $ propertyWriters = $ this -> getProperties ( $ originalClass , \ ReflectionProperty :: IS_PRIVATE ) ; foreach ( $ propertyWriters as & $ property ) { $ property = new PropertyAccessor ( $ property , 'Writer' ) ; } return $ propertyWriters ; }
Retrieves instance of private property writers
17,222
public function set ( $ name , $ value , $ ttl = 0 ) { $ name = trim ( $ name ) ; if ( $ name == '' ) { throw new CacheException ( 'Cache-entry name cannot be empty' ) ; } $ name = $ this -> _prependPrefix ( $ name ) ; if ( is_resource ( $ value ) ) { throw new CacheException ( 'Cannot cache values of type "resource"' ) ; } if ( ! $ this -> validateValueSize ( $ value ) ) { ExceptionHandler :: notice ( "Value in $name is too big to be stored in memcache." ) ; } if ( $ ttl > 2592000 ) { $ ttl = time ( ) + $ ttl ; } assert ( 'strlen($name) <= 250' ) ; if ( strlen ( $ name ) > 250 ) return false ; $ result = $ this -> _Memcache -> set ( $ name , $ value , 0 , $ ttl ) ; if ( $ result === false && ! Memcache :: isConnected ( $ this -> _Memcache ) ) { throw new CacheException ( "Failed to set '$name', Memcache appears to be disconnected!?" ) ; } return $ result ; }
Add an entry to the MemcacheCache .
17,223
public function get ( $ name , & $ error = false ) { if ( ! $ this -> _enabled ) { return null ; } $ name = $ this -> _prependPrefix ( $ name ) ; error_clear_last ( ) ; $ value = @ $ this -> _Memcache -> get ( $ name ) ; $ last_error = error_get_last ( ) ; if ( $ value === false && $ last_error !== null && $ last_error [ 'type' ] === E_WARNING ) { $ error = true ; return null ; } if ( $ value === false ) { $ value = null ; } return $ value ; }
Retrieve an entry from the MemcacheCache .
17,224
public function delete ( $ name ) { $ name = $ this -> _prependPrefix ( $ name ) ; $ result = @ $ this -> _Memcache -> delete ( $ name ) ; return $ result ; }
Delete an entry from the MemcacheCache .
17,225
public function Initialize ( ) { $ this -> Head = new HeadModule ( $ this ) ; $ this -> AddJsFile ( 'jquery.js' ) ; $ this -> AddJsFile ( 'jquery.livequery.js' ) ; $ this -> AddJsFile ( 'jquery.form.js' ) ; $ this -> AddJsFile ( 'jquery.popup.js' ) ; $ this -> AddJsFile ( 'jquery.gardenhandleajaxform.js' ) ; $ this -> AddJsFile ( 'global.js' ) ; $ this -> AddCssFile ( 'style.css' ) ; $ this -> AddModule ( 'GuestModule' ) ; parent :: Initialize ( ) ; }
CSS JS and module includes .
17,226
public function Inform ( ) { $ this -> DeliveryType ( DELIVERY_TYPE_BOOL ) ; $ this -> DeliveryMethod ( DELIVERY_METHOD_JSON ) ; NotificationsController :: InformNotifications ( $ this ) ; $ this -> FireEvent ( 'BeforeInformNotifications' ) ; $ this -> Render ( ) ; }
Adds inform messages to response for inclusion in pages dynamically .
17,227
public static function InformNotifications ( $ Sender ) { $ Session = Gdn :: Session ( ) ; if ( ! $ Session -> IsValid ( ) ) return ; $ ActivityModel = new ActivityModel ( ) ; $ Where = array ( 'NotifyUserID' => Gdn :: Session ( ) -> UserID , 'Notified' => ActivityModel :: SENT_PENDING ) ; $ Where [ 'DateUpdated >' ] = Gdn_Format :: ToDateTime ( strtotime ( '-5 minutes' ) ) ; $ Activities = $ ActivityModel -> GetWhere ( $ Where , 0 , 5 ) -> ResultArray ( ) ; $ ActivityIDs = ConsolidateArrayValuesByKey ( $ Activities , 'ActivityID' ) ; $ ActivityModel -> SetNotified ( $ ActivityIDs ) ; foreach ( $ Activities as $ Activity ) { if ( $ Activity [ 'Photo' ] ) $ UserPhoto = Anchor ( Img ( $ Activity [ 'Photo' ] , array ( 'class' => 'ProfilePhotoMedium' ) ) , $ Activity [ 'Url' ] , 'Icon' ) ; else $ UserPhoto = '' ; $ Excerpt = Gdn_Format :: Display ( $ Activity [ 'Story' ] ) ; $ ActivityClass = ' Activity-' . $ Activity [ 'ActivityType' ] ; $ Sender -> InformMessage ( $ UserPhoto . Wrap ( $ Activity [ 'Headline' ] , 'div' , array ( 'class' => 'Title' ) ) . Wrap ( $ Excerpt , 'div' , array ( 'class' => 'Excerpt' ) ) , 'Dismissable AutoDismiss' . $ ActivityClass . ( $ UserPhoto == '' ? '' : ' HasIcon' ) ) ; } }
Grabs all new notifications and adds them to the sender s inform queue .
17,228
protected function scopedInfo ( $ id ) { list ( $ rawId , $ scope ) = $ this -> splitId ( $ id ) ; if ( empty ( $ scope ) ) { $ scope = $ this -> default_scope ; $ def = $ this -> getResolver ( ) -> getService ( $ rawId ) ; if ( is_array ( $ def ) && isset ( $ def [ 'scope' ] ) ) { $ scope = $ def [ 'scope' ] ; } } return [ $ rawId , $ scope ] ; }
Returns the raw id and the scope base on default or defined
17,229
protected function scopedData ( $ data , $ scope ) { if ( is_array ( $ data ) && isset ( $ data [ 'class' ] ) ) { $ data [ 'scope' ] = $ scope ; } else { $ data = [ 'class' => $ data , 'scope' => $ scope ] ; } return $ data ; }
Append scope to data
17,230
public function injectIntoMethod ( $ object , $ methodName = "injectDependencies" ) { $ ref = new \ ReflectionClass ( $ object ) ; try { $ refMethod = $ ref -> getMethod ( $ methodName ) ; } catch ( ReflectionException $ e ) { return null ; } $ toInject = [ ] ; foreach ( $ refMethod -> getParameters ( ) as $ p ) { $ className = $ p -> getClass ( ) -> name ; if ( $ className === "Pimple\\Container" ) { $ toInject [ ] = $ this -> container ; } else { $ toInject [ ] = $ this -> container [ $ className ] ; } } return $ refMethod -> invoke ( $ object , ... $ toInject ) ; }
Inject dependencies from or including the Pimple container into a given method on a given object
17,231
public function injectIntoConstructor ( $ classToBuildName , array $ toInject = [ ] ) { $ ref = new \ ReflectionClass ( $ classToBuildName ) ; try { $ constr = $ ref -> getConstructor ( ) ; } catch ( ReflectionException $ e ) { return null ; } $ numToSkip = count ( $ toInject ) ; foreach ( $ constr -> getParameters ( ) as $ p ) { if ( $ numToSkip > 0 ) { $ numToSkip -- ; continue ; } $ classToInjectName = $ p -> getClass ( ) -> name ; if ( $ classToInjectName === "Pimple\\Container" ) { $ toInject [ ] = $ this -> container ; } else { $ toInject [ ] = $ this -> container [ $ classToInjectName ] ; } } return new $ classToBuildName ( ... $ toInject ) ; }
Inject dependencies from or including the Pimple container into a a given class s constructor Optionally providing a number of arguments to the constructor to prepend .
17,232
public function fib ( $ n ) { if ( $ n < 3 ) return 1 ; $ k = $ n / 2 ; $ a = $ this -> fib ( $ k + 1 ) ; $ b = $ this -> fib ( $ k ) ; if ( $ n % 2 == 1 ) { return $ a * $ a + $ b * $ b ; } else { return $ b * ( 2 * $ a - $ b ) ; } }
Returns n th Fibonacci number
17,233
public function select ( \ FreeFW \ Core \ StorageModel & $ p_model , array $ p_conditions = [ ] ) { $ source = $ p_model :: getSource ( ) ; $ properties = $ p_model :: getProperties ( ) ; $ values = [ ] ; $ result = \ FreeFW \ DI \ DI :: get ( 'FreeFW::Model::ResultSet' ) ; $ where = '' ; foreach ( $ p_conditions as $ idx => $ oneCondition ) { $ part = $ this -> renderCondition ( $ oneCondition ) ; if ( $ where != '' ) { $ where = $ where . ' AND ' ; } $ where = $ where . $ part [ 'sql' ] ; $ values = array_merge ( $ values , $ part [ 'values' ] ) ; } $ sql = 'SELECT * FROM ' . $ source . ' WHERE ' . $ where ; $ this -> logger -> debug ( 'PDOStorage.select : ' . $ sql ) ; try { $ query = $ this -> provider -> prepare ( $ sql , array ( \ PDO :: ATTR_CURSOR => \ PDO :: CURSOR_FWDONLY ) ) ; if ( $ query -> execute ( $ values ) ) { while ( $ row = $ query -> fetch ( \ PDO :: FETCH_OBJ ) ) { $ model = clone ( $ p_model ) ; $ model -> init ( ) -> setFromArray ( $ row ) ; $ result [ ] = $ model ; } } else { $ this -> logger -> debug ( 'PDOStorage.select.error : ' . print_r ( $ query -> errorInfo ( ) , true ) ) ; $ localErr = $ query -> errorInfo ( ) ; $ code = 0 ; $ message = 'PDOStorage.select.error : ' . print_r ( $ query -> errorInfo ( ) , true ) ; die ( $ message ) ; if ( is_array ( $ localErr ) && count ( $ localErr ) > 1 ) { $ code = intval ( $ localErr [ 0 ] ) ; $ message = $ localErr [ 2 ] ; } $ p_model -> addError ( $ code , $ message ) ; } } catch ( \ Exception $ ex ) { var_dump ( $ ex ) ; } return $ result ; }
Select the model
17,234
protected function renderConditionField ( \ FreeFW \ Interfaces \ ConditionInterface $ p_field ) { if ( $ p_field instanceof \ FreeFW \ Model \ ConditionMember ) { $ field = $ p_field -> getField ( ) ; return $ this -> renderModelField ( $ field ) ; } else { if ( $ p_field instanceof \ FreeFW \ Model \ ConditionValue ) { $ value = $ p_field -> getField ( ) ; return $ this -> renderValueField ( $ value ) ; } else { throw new \ FreeFW \ Core \ FreeFWStorageException ( sprintf ( 'Unknown condition objecte !' ) ) ; } } }
Render a condition
17,235
protected function renderCondition ( \ FreeFW \ Model \ Condition $ p_condition ) { $ result = [ ] ; $ left = $ p_condition -> getLeftMember ( ) ; $ right = $ p_condition -> getRightMember ( ) ; $ oper = $ p_condition -> getOperator ( ) ; switch ( $ oper ) { case \ FreeFW \ Storage \ Storage :: COND_LOWER : case \ FreeFW \ Storage \ Storage :: COND_LOWER_EQUAL : case \ FreeFW \ Storage \ Storage :: COND_GREATER : case \ FreeFW \ Storage \ Storage :: COND_GREATER_EQUAL : case \ FreeFW \ Storage \ Storage :: COND_EQUAL : if ( $ left !== null && $ right !== null ) { $ leftDatas = $ this -> renderConditionField ( $ left ) ; $ rightDatas = $ this -> renderConditionField ( $ right ) ; $ result = [ 'sql' => $ leftDatas [ 'id' ] . ' ' . $ oper . ' ' . $ rightDatas [ 'id' ] , 'values' => [ ] , 'type' => false ] ; if ( $ leftDatas [ 'type' ] === false ) { $ result [ 'values' ] [ $ leftDatas [ 'id' ] ] = $ leftDatas [ 'value' ] ; } else { $ result [ 'type' ] = $ leftDatas [ 'type' ] ; } if ( $ rightDatas [ 'type' ] === false ) { $ result [ 'values' ] [ $ rightDatas [ 'id' ] ] = $ rightDatas [ 'value' ] ; } else { $ result [ 'type' ] = $ rightDatas [ 'type' ] ; } } else { throw new \ FreeFW \ Core \ FreeFWStorageException ( sprintf ( 'Wrong fields for %s condition' , $ oper ) ) ; } break ; default : throw new \ FreeFW \ Core \ FreeFWStorageException ( sprintf ( 'Unknown condition : %s !' , $ oper ) ) ; break ; } return $ result ; }
Render a full condition
17,236
protected function renderModelField ( string $ p_field ) { $ parts = explode ( '.' , $ p_field ) ; $ class = $ parts [ 0 ] ; $ field = $ parts [ 1 ] ; if ( ! array_key_exists ( $ class , self :: $ models ) ) { self :: $ models [ $ class ] = \ FreeFW \ DI \ DI :: get ( $ class ) ; } $ model = self :: $ models [ $ class ] ; $ source = $ model :: getSource ( ) ; $ properties = $ model :: getProperties ( ) ; $ type = \ FreeFW \ Constants :: TYPE_STRING ; if ( array_key_exists ( $ field , $ properties ) ) { $ real = $ source . '.' . $ properties [ $ field ] [ FFCST :: PROPERTY_PRIVATE ] ; $ type = $ properties [ $ field ] [ FFCST :: PROPERTY_TYPE ] ; } else { throw new \ FreeFW \ Core \ FreeFWStorageException ( sprintf ( 'Unknown field : %s !' , $ p_field ) ) ; } return [ 'id' => $ real , 'value' => $ p_field , 'type' => $ type ] ; }
Render a model field
17,237
protected function renderValueField ( $ p_value ) { self :: $ uniqid = self :: $ uniqid + 1 ; return [ 'id' => ':i' . rand ( 10 , 99 ) . '_' . self :: $ uniqid , 'value' => $ p_value , 'type' => false ] ; }
Render a value
17,238
public static function load ( $ instance_identifier ) { $ args = func_get_args ( ) ; $ instance_identifier = array_shift ( $ args ) ; $ factory_args = $ args ; $ instance_identifier = explode ( ':' , $ instance_identifier ) ; $ classname = $ instance_identifier [ 0 ] ; if ( $ classname { 0 } != '\\' ) { $ classname = '\\Morrow\\' . $ classname ; } $ instancename = ( isset ( $ instance_identifier [ 1 ] ) ) ? $ instance_identifier [ 1 ] : '_morrow_default' ; if ( count ( $ factory_args ) === 0 ) { if ( isset ( self :: $ _params [ $ classname ] [ $ instancename ] ) ) { $ classname = self :: $ _params [ $ classname ] [ $ instancename ] [ 'classname' ] ; $ factory_args = self :: $ _params [ $ classname ] [ $ instancename ] [ 'args' ] ; } else { $ factory_args = [ ] ; } } $ instance = & self :: $ _instances [ $ classname ] [ $ instancename ] ; if ( isset ( $ instance ) ) { if ( $ instance instanceof $ classname ) return $ instance ; else { throw new \ Exception ( 'instance "' . $ instancename . '" already defined of class "' . get_class ( $ instance ) . '"' ) ; return false ; } } if ( empty ( $ factory_args ) ) { $ instance = new $ classname ; } else { $ factory_args = array_map ( function ( $ param ) { if ( ! is_object ( $ param ) || get_class ( $ param ) !== 'Morrow\\Factory' ) return $ param ; return call_user_func_array ( '\\Morrow\\Factory::load' , $ param -> _getProxyParameters ( ) ) ; } , $ factory_args ) ; $ ref = new \ ReflectionClass ( $ classname ) ; $ instance = $ ref -> newInstanceArgs ( $ factory_args ) ; } if ( isset ( self :: $ _onload_callbacks [ $ classname ] ) ) { foreach ( self :: $ _onload_callbacks [ $ classname ] as $ callback ) { call_user_func ( $ callback , $ instance ) ; } } if ( isset ( self :: $ _onload_callbacks [ $ classname . ':' . $ instancename ] ) ) { foreach ( self :: $ _onload_callbacks [ $ classname . ':' . $ instancename ] as $ callback ) { call_user_func ( $ callback , $ instance ) ; } } return $ instance ; }
Initializes a class with optionally prepared constructor parameters and returns the instance .
17,239
public static function prepare ( $ instance_identifier , $ parameters = null ) { $ args = func_get_args ( ) ; $ params = explode ( ':' , $ instance_identifier ) ; $ classname = $ params [ 0 ] ; if ( $ classname { 0 } !== '\\' ) { $ classname = '\\Morrow\\' . $ classname ; } $ instancename = ( isset ( $ params [ 1 ] ) ) ? $ params [ 1 ] : '_morrow_default' ; self :: $ _params [ $ classname ] [ $ instancename ] = [ 'classname' => $ classname , 'args' => array_slice ( $ args , 1 ) , ] ; }
Handles the preparation of class instantiation by deposit the constructor parameters . That allows the lazy loading functionality .
17,240
public static function onload ( $ instance_identifier , $ callback , $ ignore_instancename = false ) { $ args = func_get_args ( ) ; $ params = explode ( ':' , $ instance_identifier ) ; $ classname = $ params [ 0 ] ; if ( $ classname { 0 } !== '\\' ) { $ classname = '\\Morrow\\' . $ classname ; } $ instancename = ( isset ( $ params [ 1 ] ) ) ? $ params [ 1 ] : '_morrow_default' ; if ( $ ignore_instancename ) { self :: $ _onload_callbacks [ $ classname ] [ ] = $ callback ; } else { self :: $ _onload_callbacks [ $ classname . ':' . $ instancename ] [ ] = $ callback ; } }
Registers a callback that is executed when an instance is created .
17,241
public function open ( ) { if ( @ ! socket_connect ( $ this -> socket , $ this -> host , $ this -> port ) ) { Logger :: get ( ) -> error ( socket_strerror ( socket_last_error ( ) ) ) ; throw new Exception ( 'Socket connection error: ' . socket_strerror ( socket_last_error ( ) ) ) ; } }
Open the connection to the socket .
17,242
public function setStatusCode ( $ statusCode , $ message = null ) { $ this -> statusCode = ( int ) $ statusCode ; $ this -> addMeta ( [ 'status' => [ 'code' => ( int ) $ statusCode ] ] ) ; if ( ! empty ( $ message ) ) { $ this -> setStatusMessage ( $ message ) ; } return $ this ; }
Set status code .
17,243
public function setErrors ( MessageBag $ errors ) { $ this -> errors = $ errors ; if ( ! $ errors -> isEmpty ( ) ) { $ this -> addMeta ( [ 'errors' => $ errors -> all ( ) ] ) ; } return $ this ; }
Set a message bag of errors .
17,244
public function reload ( ) { if ( $ this -> root !== $ this ) { $ this -> root -> reload ( ) ; return ; } if ( ! isset ( $ this -> store ) ) { return ; } if ( ! $ this -> store -> touch ( ) ) { return ; } try { $ this -> store -> open ( false ) ; $ this -> data = $ this -> store -> read ( ) ; } catch ( AccessException $ e ) { throw new AccessException ( 'Could not read configration: ' . $ e -> getMessage ( ) , null , $ e ) ; } $ this -> store -> close ( ) ; }
Reload configuration document from store .
17,245
public function save ( ) { if ( $ this -> root !== $ this ) { return $ this -> root -> save ( ) ; } if ( ! isset ( $ this -> store ) ) { return false ; } if ( ! $ this -> updated ) { return true ; } $ this -> store -> open ( true ) ; $ this -> store -> write ( $ this -> data ) ; $ this -> store -> close ( ) ; $ this -> updated = false ; return true ; }
Save configuration . If this is not the root configuration the root configuration will be saved instead .
17,246
public function build ( PackageWrapper $ package , $ isDev ) { $ this -> execute ( 'grunt' , [ ] , $ this -> io , $ package -> getPath ( ) ) ; }
Run this build tool for this package
17,247
public function setId ( string $ id ) : NodeInterface { $ this -> _id = $ id ; if ( $ this -> _name === null ) { $ this -> setName ( $ id ) ; } return $ this ; }
Sets the value of field id .
17,248
public function getMetadata ( ) : Data { if ( $ this -> _metadata === null ) { $ this -> _metadata = new Data ( ) ; $ this -> setMetadata ( [ ] ) ; } return $ this -> _metadata ; }
Returns the value of field _metadata .
17,249
public function setMetadata ( array $ metadata ) { $ this -> getMetadata ( ) -> setData ( array_replace_recursive ( $ this -> getDefaultMetadata ( ) , $ metadata ) ) ; return $ this ; }
Sets the value of field metadata .
17,250
public function setMetadataAttr ( string $ attr , $ value , array $ options = [ ] ) { $ this -> getMetadata ( ) -> set ( $ attr , $ value , $ options ) ; return $ this ; }
Sets a metadata attribute .
17,251
public function getMetadataAttr ( string $ attr , $ defaultValue = null , array $ options = [ ] ) { return $ this -> getMetadata ( ) -> get ( $ attr , $ defaultValue , $ options ) ; }
Returns a metadata attribute .
17,252
public function findParents ( array $ filters = [ ] , array $ options = [ ] ) { $ options = array_replace ( [ 'returnFirstResult' => false , 'indexById' => false ] , $ options ) ; $ parents = $ this -> getAllParents ( $ options ) ; if ( $ parents && $ filters ) { $ result = [ ] ; foreach ( $ parents as $ i => $ parent ) { foreach ( $ filters as $ f => $ v ) { $ method = 'get' . ucfirst ( $ f ) ; if ( ! method_exists ( $ parent , $ method ) || $ parent -> $ method ( ) !== $ v ) { continue 2 ; } } if ( $ options [ 'indexById' ] ) { $ result [ $ i ] = $ parent ; } else { $ result [ ] = $ parent ; } } } else { $ result = $ parents ; } return $ options [ 'returnFirstResult' ] && $ result ? array_values ( $ result ) [ 0 ] : $ result ; }
Finds parent nodes all the way up until we reach the root node .
17,253
public function getAllParents ( array $ options = [ ] ) : array { $ options = array_replace ( [ 'indexById' => false , 'skipIds' => [ ] ] , $ options ) ; $ parents = [ ] ; $ ids = [ $ this -> getId ( ) ] ; foreach ( $ this -> getParents ( ) as $ id => $ parent ) { if ( in_array ( $ id , $ options [ 'skipIds' ] ) ) { continue ; } $ ids [ ] = $ id ; if ( $ options [ 'indexById' ] ) { $ parents [ $ id ] = $ parent ; } else { $ parents [ ] = $ parent ; } $ parents = array_merge ( $ parents , $ parent -> getAllParents ( array_merge ( $ options , [ 'skipIds' => $ ids ] ) ) ) ; } return $ parents ; }
Returns all parents from this node .
17,254
public function getParent ( string $ id = null ) { if ( ! $ this -> _parents || ( $ id !== null && ! isset ( $ this -> _parents [ $ id ] ) ) ) { return null ; } return $ id !== null ? $ this -> _parents [ $ id ] : $ this -> _parents [ array_rand ( $ this -> _parents ) ] ; }
Returns the value of field _parent .
17,255
public function addParent ( NodeInterface $ parent , bool $ setParentsChild = true ) : NodeInterface { if ( ! $ this -> supportsParent ( $ parent ) ) { throw ParentTypeNotSupportedException :: create ( $ this , $ parent ) ; } $ this -> _parents [ $ parent -> getId ( ) ] = $ parent ; if ( $ setParentsChild ) { $ parent -> addChild ( $ this , false ) ; } $ this -> notifySubscribers ( self :: EVENT_ADD_PARENT , [ 'oldParents' => $ this -> _parents , 'newParent' => $ parent , 'child' => $ this ] ) ; return $ this ; }
Sets the value of field parent .
17,256
public function removeParent ( string $ parentId , bool $ setParentsChild = true ) : NodeInterface { if ( isset ( $ this -> _parents [ $ parentId ] ) ) { $ parent = $ this -> getParent ( $ parentId ) ; $ this -> notifySubscribers ( self :: EVENT_REMOVE_PARENT , [ 'oldParents' => $ this -> _parents , 'parentToRemove' => $ parent , 'child' => $ this ] ) ; if ( $ setParentsChild ) { $ parent -> removeChild ( $ this -> getId ( ) , false ) ; } unset ( $ this -> _parents [ $ parentId ] ) ; } return $ this ; }
Removes a parent from this node .
17,257
public function clearParents ( ) : NodeInterface { foreach ( $ this -> getParents ( ) as $ parent ) { $ this -> removeParent ( $ parent -> getId ( ) ) ; } return $ this ; }
Clears all parents of this node .
17,258
public function setChildren ( array $ children ) : NodeInterface { foreach ( $ this -> getChildren ( ) as $ node ) { $ this -> removeChild ( $ node -> getId ( ) ) ; } foreach ( $ children as $ child ) { $ this -> addChild ( $ child ) ; } return $ this ; }
Sets the value of field children .
17,259
public function addChild ( NodeInterface $ child , bool $ setParent = true ) : NodeInterface { if ( ! $ this -> supportsChild ( $ child ) ) { throw ChildTypeNotSupportedException :: create ( $ this , $ child ) ; } $ this -> _children [ $ child -> getId ( ) ] = $ child ; if ( $ setParent ) { $ child -> addParent ( $ this , false ) ; } foreach ( $ this -> getAllParentsAndCurrentNode ( ) as $ parent ) { $ child -> addSubscriber ( $ parent ) ; } $ this -> notifySubscribers ( self :: EVENT_ADD_CHILD , [ 'parent' => $ this , 'child' => $ child ] ) ; return $ this ; }
Adds a child to this node .
17,260
public function removeChild ( string $ childId , bool $ setParent = true ) : NodeInterface { if ( $ this -> hasChild ( $ childId ) ) { $ child = $ this -> getChild ( $ childId ) ; if ( $ setParent ) { $ child -> removeParent ( $ this -> getId ( ) , false ) ; } unset ( $ this -> _children [ $ childId ] ) ; $ this -> notifySubscribers ( self :: EVENT_REMOVE_CHILD , [ 'parent' => $ this , 'child' => $ child ] ) ; foreach ( $ this -> getAllParents ( ) as $ parent ) { $ child -> removeSubscriber ( $ parent -> getId ( ) ) ; } } return $ this ; }
Removes a child .
17,261
public function getChild ( string $ id ) : NodeInterface { if ( ! $ this -> hasChild ( $ id ) ) { throw ChildDoesNotExistException :: create ( $ this -> getId ( ) , $ id ) ; } return $ this -> _children [ $ id ] ; }
Returns a child by ID .
17,262
public function findChildren ( array $ filters = [ ] , array $ options = [ ] ) { $ options = array_replace ( [ 'returnFirstResult' => false ] , $ options ) ; if ( empty ( $ filters ) ) { $ result = array_values ( $ this -> _nodes ) ; } else if ( count ( $ filters ) === 1 && isset ( $ filters [ 'id' ] ) ) { $ result = $ this -> hasNode ( $ filters [ 'id' ] ) ? [ $ this -> getNode ( $ filters [ 'id' ] ) ] : [ ] ; } else { $ result = [ ] ; foreach ( $ this -> getNodes ( ) as $ child ) { foreach ( $ filters as $ f => $ v ) { $ method = 'get' . ucfirst ( $ f ) ; if ( ! method_exists ( $ child , $ method ) || $ child -> $ method ( ) !== $ v ) { continue 2 ; } } $ result [ ] = $ child ; } } return $ options [ 'returnFirstResult' ] && $ result ? $ result [ 0 ] : $ result ; }
Finds children .
17,263
public function addNode ( NodeInterface $ node ) : NodeInterface { $ this -> _nodes [ $ node -> getId ( ) ] = $ node ; if ( $ this -> getParent ( ) ) { $ this -> getParent ( ) -> addNode ( $ node ) ; } return $ this ; }
Adds a node to this graph .
17,264
public function removeNode ( NodeInterface $ node ) : NodeInterface { unset ( $ this -> _nodes [ $ node -> getId ( ) ] ) ; if ( $ this -> getParent ( ) ) { $ this -> getParent ( ) -> removeNode ( $ node ) ; } return $ this ; }
Removes a node .
17,265
public function validate ( array $ options = [ ] ) { $ options = array_replace ( [ 'validateMinChildren' => true , 'validateMaxChildren' => true , 'validateParentMandatory' => true , 'validateParentMustNotBeSet' => true ] , $ options ) ; $ countChildren = $ this -> countChildren ( ) ; if ( $ options [ 'validateMinChildren' ] && ( $ min = $ this -> getValidationConfig ( 'minChildren' ) ) !== null && $ min > $ countChildren ) { throw ValidationException :: create ( 'Children must be, at least, ' . $ min . '. Currently, node "' . $ this -> getId ( ) . '" has ' . $ countChildren . ' children.' ) ; } if ( $ options [ 'validateMaxChildren' ] && ( $ max = $ this -> getValidationConfig ( 'maxChildren' ) ) !== null && $ max < $ countChildren ) { throw ValidationException :: create ( 'Children cannot exceed a maximum of ' . $ max . '. Currently, node "' . $ this -> getId ( ) . '" has ' . $ countChildren . ' children.' ) ; } if ( $ options [ 'validateParentMandatory' ] && $ this -> getValidationConfig ( 'parentMandatory' ) && $ this -> getParent ( ) === null ) { throw ValidationException :: create ( 'Node "' . $ this -> getId ( ) . '" must have a Parent!' ) ; } if ( $ options [ 'validateParentMustNotBeSet' ] && $ this -> getValidationConfig ( 'parentMustNotBeSet' ) && $ this -> getParent ( ) !== null ) { throw ValidationException :: create ( 'Node "' . $ this -> getId ( ) . '" must NOT have a Parent!' ) ; } }
This method is called after initializing the data .
17,266
public function setValidationConfig ( string $ name , $ value ) : NodeInterface { $ this -> setMetadataAttr ( 'validations.' . $ name , $ value ) ; return $ this ; }
Sets a validation config .
17,267
public function setSubscribers ( array $ subscribers ) : NodeInterface { $ this -> _subscribers = [ ] ; foreach ( $ subscribers as $ subscriber ) { $ this -> addSubscriber ( $ subscriber ) ; } return $ this ; }
Sets the value of field subscribers .
17,268
public function addSubscriber ( SubscriberInterface $ subscriber ) : NodeInterface { $ this -> _subscribers [ $ subscriber -> getId ( ) ] = $ subscriber ; return $ this ; }
Adds a subscriber .
17,269
public function removeSubscriber ( $ idOrSubscriber ) : NodeInterface { if ( ! is_string ( $ idOrSubscriber ) && ( ! is_object ( $ idOrSubscriber ) || ! ( $ idOrSubscriber instanceof SubscriberInterface ) ) ) { throw new \ InvalidArgumentException ( 'Argument "$idOrSubscriber" must be a string or an instance of ' . 'IronEdge\Component\Graph\Event\SubscriberInterface.' ) ; } $ id = is_string ( $ idOrSubscriber ) ? $ idOrSubscriber : $ idOrSubscriber -> getId ( ) ; unset ( $ this -> _subscribers [ $ id ] ) ; return $ this ; }
Removes a subscriber .
17,270
public function handleEvent ( string $ eventId , array $ eventData ) { switch ( $ eventId ) { case self :: EVENT_ADD_CHILD : $ node = $ eventData [ 'child' ] ; $ this -> addNode ( $ node ) ; break ; case self :: EVENT_REMOVE_CHILD : $ node = $ eventData [ 'child' ] ; $ this -> removeNode ( $ node ) ; break ; case self :: EVENT_ADD_PARENT : $ child = $ eventData [ 'child' ] ; $ newParent = $ eventData [ 'newParent' ] ; $ nodes = $ child -> getNodes ( ) + [ $ child ] ; foreach ( $ nodes as $ n ) { $ n -> addSubscriber ( $ newParent ) ; $ newParent -> addNode ( $ n ) ; } break ; case self :: EVENT_REMOVE_PARENT : $ child = $ eventData [ 'child' ] ; $ oldParent = $ eventData [ 'parentToRemove' ] ; $ nodes = $ child -> getNodes ( ) + [ $ child ] ; foreach ( $ nodes as $ n ) { $ n -> removeSubscriber ( $ oldParent ) ; $ oldParent -> removeNode ( $ n ) ; } break ; default : break ; } }
This method is called when an event is fired .
17,271
public function notifySubscribers ( string $ eventId , array $ eventData ) { foreach ( $ this -> getSubscribers ( ) as $ subscriber ) { $ subscriber -> handleEvent ( $ eventId , $ eventData ) ; } }
Fires an event . Subscribers gets notified about this event .
17,272
public function toArray ( array $ options = [ ] ) { $ childrenIds = [ ] ; foreach ( $ this -> getChildren ( ) as $ child ) { $ childrenIds [ ] = $ child -> getId ( ) ; } return [ 'id' => $ this -> getId ( ) , 'name' => $ this -> getName ( ) , 'type' => $ this -> getType ( ) , 'metadata' => $ this -> getMetadata ( ) -> getData ( ) , 'parentId' => $ this -> getParent ( ) ? $ this -> getParent ( ) -> getId ( ) : null , 'childrenIds' => $ childrenIds ] ; }
Returns an array representation of this node .
17,273
public function scan ( ) { $ paths = $ this -> getScanPaths ( ) ; $ components = [ ] ; foreach ( $ paths as $ key => $ path ) { $ manifests = $ this -> app [ 'files' ] -> glob ( "{$path}/component.json" ) ; is_array ( $ manifests ) || $ manifests = [ ] ; foreach ( $ manifests as $ manifest ) { $ name = Json :: make ( $ manifest ) -> get ( 'name' ) ; $ components [ $ name ] = new Component ( $ this -> app , $ name , dirname ( $ manifest ) ) ; } } return $ components ; }
Get & scan all components .
17,274
protected function formatCached ( $ cached ) { $ components = [ ] ; foreach ( $ cached as $ name => $ component ) { $ path = $ this -> config ( 'paths.components' ) . '/' . $ name ; $ components [ $ name ] = new Component ( $ this -> app , $ name , $ path ) ; } return $ components ; }
Format the cached data as array of components .
17,275
public function getByStatus ( $ status ) { $ components = [ ] ; foreach ( $ this -> all ( ) as $ name => $ component ) { if ( $ component -> isStatus ( $ status ) ) { $ components [ $ name ] = $ component ; } } return $ components ; }
Get components by status .
17,276
public function getOrdered ( $ direction = 'asc' ) { $ components = $ this -> enabled ( ) ; uasort ( $ components , function ( Component $ a , Component $ b ) use ( $ direction ) { if ( $ a -> order == $ b -> order ) { return 0 ; } if ( $ direction == 'desc' ) { return $ a -> order < $ b -> order ? 1 : - 1 ; } return $ a -> order > $ b -> order ? 1 : - 1 ; } ) ; return $ components ; }
Get all ordered components .
17,277
public function find ( $ name ) { foreach ( $ this -> all ( ) as $ component ) { if ( $ component -> getLowerName ( ) === strtolower ( $ name ) ) { return $ component ; } } return ; }
Find a specific component .
17,278
public function findOrFail ( $ name ) { $ component = $ this -> find ( $ name ) ; if ( $ component !== null ) { return $ component ; } throw new ComponentNotFoundException ( "Component [{$name}] does not exist!" ) ; }
Find a specific component if there return that otherwise throw exception .
17,279
public function getComponentPath ( $ component ) { try { return $ this -> findOrFail ( $ component ) -> getPath ( ) . '/' ; } catch ( ComponentNotFoundException $ e ) { return $ this -> getPath ( ) . '/' . Str :: studly ( $ component ) . '/' ; } }
Get component path for a specific component .
17,280
public function setUsed ( $ name ) { $ component = $ this -> findOrFail ( $ name ) ; $ this -> app [ 'files' ] -> put ( $ this -> getUsedStoragePath ( ) , $ component ) ; }
Set component used for cli session .
17,281
public function states ( $ translate = false ) { $ states = $ this -> getSNMP ( ) -> subOidWalk ( self :: OID_STATUS , 12 ) ; if ( ! $ translate ) return $ states ; return $ this -> getSNMP ( ) -> translate ( $ states , self :: $ STATES ) ; }
Get an array of device interface states
17,282
public function jabberStates ( $ translate = false ) { $ states = $ this -> getSNMP ( ) -> subOidWalk ( self :: OID_JABBER_STATE , 12 ) ; if ( ! $ translate ) return $ states ; return $ this -> getSNMP ( ) -> translate ( $ states , self :: $ JABBER_STATES ) ; }
Get an array of device interface jabber states
17,283
public function jackTypes ( $ translate = false ) { $ types = $ this -> getSNMP ( ) -> subOidWalk ( self :: OID_JACK_TYPE , 12 ) ; if ( ! $ translate ) return $ types ; return $ this -> getSNMP ( ) -> translate ( $ types , self :: $ JACK_TYPES ) ; }
Get an array of device jack types
17,284
protected function execute ( InputInterface $ input , OutputInterface $ output ) { $ this -> input = $ input ; $ this -> output = $ output ; $ repository = $ this -> getContainer ( ) -> get ( 'ezpublish.api.repository' ) ; $ contentService = $ repository -> getContentService ( ) ; $ contentTypeService = $ repository -> getContentTypeService ( ) ; $ locationService = $ repository -> getLocationService ( ) ; $ questionHelper = $ this -> getHelper ( 'question' ) ; $ struct = array ( ) ; $ struct [ 'parentLocationID' ] = $ this -> getParentLocationID ( $ locationService , $ questionHelper ) ; $ struct [ 'contentTypeIdentifier' ] = $ this -> getContentTypeIdentifier ( $ contentTypeService , $ questionHelper ) ; $ contentType = $ contentTypeService -> loadContentTypeByIdentifier ( $ struct [ 'contentTypeIdentifier' ] ) ; $ languageCode = $ contentType -> mainLanguageCode ; $ struct [ 'languageCode' ] = $ languageCode ; $ struct [ 'fields' ] = array ( ) ; $ fields = $ contentType -> getFieldDefinitions ( ) ; foreach ( $ fields as $ field ) { $ fieldName = $ field -> getName ( $ languageCode ) ; $ fieldIdentifier = $ field -> identifier ; $ fieldValue = $ this -> getFieldValue ( $ questionHelper , $ fieldName ) ; $ struct [ 'fields' ] [ ] = array ( 'identifier' => $ fieldIdentifier , 'value' => $ fieldValue ) ; } $ configResolver = $ this -> getContainer ( ) -> get ( 'ezpublish.config.resolver' ) ; $ adminID = $ this -> getContainer ( ) -> getParameter ( 'smile_ez_tools.adminid' ) ; $ smileEzContentService = new Content ( $ repository ) ; $ smileEzContentService -> setAdminID ( $ adminID ) ; try { $ smileEzContentService -> add ( $ struct ) ; $ output -> writeln ( "<info>Content created</info>" ) ; } catch ( UnauthorizedException $ e ) { $ output -> writeln ( "<error>" . $ e -> getMessage ( ) . "</error>" ) ; } catch ( ForbiddenException $ e ) { $ output -> writeln ( "<error>" . $ e -> getMessage ( ) . "</error>" ) ; } }
Execute Content generate command
17,285
public function createSessionContainer ( ) { if ( ! isset ( $ this -> config [ 'container' ] ) ) { session_start ( ) ; return ; } $ sessionContainerType = $ this -> config [ 'container' ] ; $ className = '\ntentan\sessions\containers\\' . Text :: ucamelize ( $ sessionContainerType ) . 'SessionContainer' ; $ sessionContainer = new $ className ( $ this -> config ) ; return $ sessionContainer ; }
Create and return an instance of the custom session container if required .
17,286
public function handle ( Entity $ entity ) { if ( in_array ( SoftDeletes :: class , class_uses_recursive ( get_class ( $ entity ) ) ) && ! $ entity -> isForceDeleting ( ) ) { return ; } foreach ( $ entity -> getEntityAttributes ( ) as $ attribute ) { if ( $ entity -> relationLoaded ( $ relation = $ attribute -> getAttribute ( 'slug' ) ) && ( $ values = $ entity -> getRelationValue ( $ relation ) ) && ! $ values -> isEmpty ( ) ) { forward_static_call_array ( [ $ attribute -> getAttribute ( 'type' ) , 'destroy' ] , [ $ values -> pluck ( 'id' ) -> toArray ( ) ] ) ; } } }
Handle the entity deletion .
17,287
final protected static function replaceKey ( $ data , $ search , $ replace ) { foreach ( $ data as $ key => $ value ) { if ( is_array ( $ value ) ) { $ data [ $ key ] = $ value = self :: replaceKey ( $ data [ $ key ] , $ search , $ replace ) ; } if ( $ key == $ search ) { $ data [ $ replace ] = $ value ; unset ( $ data [ $ search ] ) ; } } return $ data ; }
Recursively replace keys of associative arrays
17,288
public static function getRegisteredWrappers ( ) { if ( static :: $ wrapperRegistry === null ) { static :: $ wrapperRegistry = [ ] ; if ( extension_loaded ( 'intl' ) ) { static :: $ wrapperRegistry [ ] = 'Zend\Stdlib\StringWrapper\Intl' ; } if ( extension_loaded ( 'mbstring' ) ) { static :: $ wrapperRegistry [ ] = 'Zend\Stdlib\StringWrapper\MbString' ; } if ( extension_loaded ( 'iconv' ) ) { static :: $ wrapperRegistry [ ] = 'Zend\Stdlib\StringWrapper\Iconv' ; } static :: $ wrapperRegistry [ ] = 'Zend\Stdlib\StringWrapper\Native' ; } return static :: $ wrapperRegistry ; }
Get registered wrapper classes
17,289
public static function registerWrapper ( $ wrapper ) { $ wrapper = ( string ) $ wrapper ; if ( ! in_array ( $ wrapper , static :: $ wrapperRegistry , true ) ) { static :: $ wrapperRegistry [ ] = $ wrapper ; } }
Register a string wrapper class
17,290
public static function unregisterWrapper ( $ wrapper ) { $ index = array_search ( ( string ) $ wrapper , static :: $ wrapperRegistry , true ) ; if ( $ index !== false ) { unset ( static :: $ wrapperRegistry [ $ index ] ) ; } }
Unregister a string wrapper class
17,291
public static function getWrapper ( $ encoding = 'UTF-8' , $ convertEncoding = null ) { foreach ( static :: getRegisteredWrappers ( ) as $ wrapperClass ) { if ( $ wrapperClass :: isSupported ( $ encoding , $ convertEncoding ) ) { $ wrapper = new $ wrapperClass ( $ encoding , $ convertEncoding ) ; $ wrapper -> setEncoding ( $ encoding , $ convertEncoding ) ; return $ wrapper ; } } throw new Exception \ RuntimeException ( 'No wrapper found supporting "' . $ encoding . '"' . ( ( $ convertEncoding !== null ) ? ' and "' . $ convertEncoding . '"' : '' ) ) ; }
Get the first string wrapper supporting the given character encoding and supports to convert into the given convert encoding .
17,292
public function format ( ) { if ( strlen ( $ this -> phoneNumber ) >= 7 ) { return sprintf ( $ this -> format , $ this -> getCountryCode ( ) , $ this -> getAreaCode ( ) , $ this -> getPrefix ( ) , $ this -> getLineNumber ( ) ) ; } return null ; }
Get formatted phone number for display This assumes a flattened format like 11235551234
17,293
public function getComponent ( $ component = null ) { if ( null === $ this -> components ) { $ pattern = '/ (?<countryCode>(\+?\d{1,2})?\D*) # optional country code (?<areaCode>(\d{3})?\D*) # optional area code (?<prefix>(\d{3})\D*) # first three (prefix) (?<lineNumber>(\d{4})) # last four (line number) (?<extensionDelimiter>(?:\D+|$)) # extension delimiter or EOL (?<extension>(\d*)) # optional extension /x' ; if ( preg_match ( $ pattern , $ this -> phoneNumber , $ matches ) ) { $ this -> components = $ matches ; } } switch ( $ component ) { case self :: COUNTRY_CODE : return ! empty ( $ this -> components [ 'countryCode' ] ) ? $ this -> components [ 'countryCode' ] : '+1' ; break ; case self :: AREA_CODE : return $ this -> components [ 'areaCode' ] ; break ; case self :: PREFIX : return $ this -> components [ 'prefix' ] ; break ; case self :: LINE_NUMBER : return $ this -> components [ 'lineNumber' ] ; break ; case self :: EXTENSION_DELIMITER : return $ this -> components [ 'extensionDelimiter' ] ; break ; case self :: EXTENSION : return $ this -> components [ 'extension' ] ; break ; default : return null ; } }
Get phone number component
17,294
public function setDisplayFormat ( $ displayFormat = self :: FORMAT_NA ) { if ( substr_count ( $ displayFormat , '%d' ) !== 4 ) { throw new \ BadFunctionCallException ( 'The format passed must be passed in the sprintf() format, and have exactly 4 digit components' ) ; } $ this -> displayFormat = $ displayFormat ; }
Sets the display format
17,295
public function labels ( $ labels = null ) { if ( $ labels === null ) { return $ this -> _labels ; } $ this -> _labels = $ labels ; return $ this ; }
Label definitions for validation
17,296
public function param ( $ param , $ value , $ type = null ) { return $ this -> setParameter ( $ param , $ value , $ type ) ; }
Set the value of a parameter in the query .
17,297
public function transmute ( InputDescriptor $ input , $ targetFormat ) { if ( ! in_array ( $ targetFormat , array ( 'image' , 'audio' , 'video' , 'flash' , 'text' ) ) ) { return null ; } $ mediaType = $ this -> mediaTypeManager -> find ( $ input -> getMediaType ( ) ) ; return $ this -> extractor -> extract ( $ input , $ mediaType , $ targetFormat ) ; }
Transmute file to target format .
17,298
protected function startBindingsPlugin ( $ app ) { $ this -> requiresPlugins ( Commands :: class , Events :: class ) ; $ this -> onRegister ( 'bindings' , function ( Application $ app ) { $ legacy = ! class_exists ( 'Illuminate\Foundation\Application' ) || version_compare ( \ Illuminate \ Foundation \ Application :: VERSION , '5.7.0' , '<' ) ; if ( $ legacy ) { foreach ( $ this -> bindings as $ binding => $ class ) { $ this -> app -> bind ( $ binding , $ class ) ; } } foreach ( $ this -> weaklings as $ binding => $ class ) { $ this -> bindIf ( $ binding , $ class ) ; } foreach ( [ 'share' => $ this -> share , 'shared' => $ this -> shared ] as $ type => $ bindings ) { foreach ( $ bindings as $ binding => $ class ) { $ this -> share ( $ binding , $ class , [ ] , $ type === 'shared' ) ; } } if ( $ legacy ) { foreach ( $ this -> singletons as $ binding => $ class ) { if ( $ this -> strict && ! class_exists ( $ class ) && ! interface_exists ( $ class ) ) { throw new \ Exception ( get_called_class ( ) . ": Could not find alias class [{$class}]. This exception is only thrown when \$strict checking is enabled" ) ; } $ this -> app -> singleton ( $ binding , $ class ) ; } } foreach ( $ this -> aliases as $ alias => $ full ) { if ( $ this -> strict && ! class_exists ( $ full ) && ! interface_exists ( $ full ) ) { throw new \ Exception ( get_called_class ( ) . ": Could not find alias class [{$full}]. This exception is only thrown when \$strict checking is enabled" ) ; } $ this -> app -> alias ( $ alias , $ full ) ; } } ) ; }
startBindingsPlugin method .
17,299
protected function bindIf ( $ abstract , $ concrete = null , $ shared = true , $ alias = null ) { if ( ! $ this -> app -> bound ( $ abstract ) ) { $ concrete = $ concrete ? : $ abstract ; $ this -> app -> bind ( $ abstract , $ concrete , $ shared ) ; } }
Registers a binding if it hasn t already been registered .